[PATCH] Always emit function declaration when generating profile instrumentation

Alex L arphaman at gmail.com
Wed May 28 13:06:33 PDT 2014


Sure, We need to call CodeGenPGO::assignRegionCounters for all functions
because we want to emit counter variables for all functions in a
translation unit, even if they aren't used. Currently static functions, and
also class methods defined inside a class and inline methods defined
outside of class aren't processed by assignRegionCounters when they aren't
used. Therefore we have to emit those functions so that the profile
counters are also emitted for them.


2014-05-28 12:23 GMT-07:00 Reid Kleckner <rnk at google.com>:

> Can you explain why this works at all?  Why aren't the counters emitted as
> linkonce_odr globals?
>
>
> On Tue, May 27, 2014 at 4:39 PM, Alex L <arphaman at gmail.com> wrote:
>
>> This is needed to ensure that the profile counters are emitted
>> for all functions and methods.
>>
>>
>> -------------- next part --------------
>> Index: lib/CodeGen/CodeGenModule.cpp
>> ===================================================================
>>
>> --- lib/CodeGen/CodeGenModule.cpp	(revision 209698)
>> +++ lib/CodeGen/CodeGenModule.cpp	(working copy)
>> @@ -1073,6 +1073,8 @@
>>    if (LangOpts.EmitAllDecls)
>>      return false;
>>
>> +  if(CodeGenOpts.ProfileInstrGenerate && isa<FunctionDecl>(Global))
>>
>>
>> +    return false;
>>    return !getContext().DeclMustBeEmitted(Global);
>>  }
>>
>> @@ -3028,6 +3030,16 @@
>>      break;
>>
>>    // C++ Decls
>> +  case Decl::CXXRecord: {
>> +    if(!CodeGenOpts.ProfileInstrGenerate)
>>
>>
>> +      break;
>> +    CXXRecordDecl *Record = cast<CXXRecordDecl>(D);
>> +    for(CXXRecordDecl::method_iterator I = Record->method_begin(); I != Record->method_end(); ++I) {
>> +      if(I->hasBody())
>>
>> +        EmitTopLevelDecl(*I);
>>
>> +    }
>> +    break;
>> +  }
>>    case Decl::Namespace:
>>      EmitNamespace(cast<NamespaceDecl>(D));
>>      break;
>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140528/44f8af97/attachment.html>


More information about the cfe-commits mailing list