diff options
| author | Chris Bieneman <chris.bieneman@me.com> | 2021-10-11 12:31:02 -0500 |
|---|---|---|
| committer | Chris Bieneman <chris.bieneman@me.com> | 2021-10-11 14:50:34 -0500 |
| commit | 121b2252de0eed68f2ddf5f09e924a6c35423d47 (patch) | |
| tree | e06befcd6cd040e8415cb4c891f6b56d2c8b9852 /clang/lib/CodeGen/CodeGenModule.cpp | |
| parent | edfdce2627633a161292c6ba46e868330569ee9d (diff) | |
AddGlobalAnnotations for function with or without function body.
When AnnotateAttr is on a function, AddGlobalAnnotations is only called
in CodeGenModule::EmitGlobalFunctionDefinition which means AnnotateAttr
on function declaration without function body will be ignored.
The patch will move AddGlobalAnnotations to
CodeGenModule::SetFunctionAttributes, so with or without function body,
the AnnotateAttr will get code gen for a function.
It'll help case when AnnotateAttr is on external function, and the
AnnotateAttr will be consumed in IR level.
For example, a pass to collect num of uses for functions with
__attribute((annotate("count_use"))) after optimizations,
As long as there's __attribute((annotate("count_use"))), function with
or without function body should be counted.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D111109
Patch by: python3kgae (Xiang Li)
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index d4e3186c10a5..9fa5e9cf1b79 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2195,6 +2195,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, CalleeIdx, PayloadIndices, /* VarArgsArePassed */ false)})); } + + if (FD->hasAttr<AnnotateAttr>()) + AddGlobalAnnotations(FD, F); } void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) { @@ -4893,8 +4896,6 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, AddGlobalCtor(Fn, CA->getPriority()); if (const DestructorAttr *DA = D->getAttr<DestructorAttr>()) AddGlobalDtor(Fn, DA->getPriority(), true); - if (D->hasAttr<AnnotateAttr>()) - AddGlobalAnnotations(D, Fn); } void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { |
