diff options
author | Wei Mi <wmi@google.com> | 2020-05-14 12:05:49 -0700 |
---|---|---|
committer | Wei Mi <wmi@google.com> | 2020-06-02 17:23:17 -0700 |
commit | 7a6c89427c9babc8e4a69e8a2b61bbf4a4b80c56 (patch) | |
tree | d3ada157b2294ec5973f6bf09c0008e8ad7e615f /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | 2d2a603d663328e25774982947e3a8a65e098678 (diff) | |
download | llvm-7a6c89427c9babc8e4a69e8a2b61bbf4a4b80c56.zip llvm-7a6c89427c9babc8e4a69e8a2b61bbf4a4b80c56.tar.gz llvm-7a6c89427c9babc8e4a69e8a2b61bbf4a4b80c56.tar.bz2 |
[SampleFDO] Add use-sample-profile function attribute.
When sampleFDO is enabled, people may expect they can use
-fno-profile-sample-use to opt-out using sample profile for a certain file.
That could be either for debugging purpose or for performance tuning purpose.
However, when thinlto is enabled, if a function in file A compiled with
-fno-profile-sample-use is imported to another file B compiled with
-fprofile-sample-use, the inlined copy of the function in file B may still
get its profile annotated.
The inconsistency may even introduce profile unused warning because if the
target is not compiled with explicit debug information flag, the function
in file A won't have its debug information enabled (debug information will
be enabled implicitly only when -fprofile-sample-use is used). After it is
imported into file B which is compiled with -fprofile-sample-use, profile
annotation for the outline copy of the function will fail because the
function has no debug information, and that will trigger profile unused
warning.
We add a new attribute use-sample-profile to control whether a function
will use its sample profile no matter for its outline or inline copies.
That will make the behavior of -fno-profile-sample-use consistent.
Differential Revision: https://reviews.llvm.org/D79959
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d6622a4..0fa795d 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -791,6 +791,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CGM.getCodeGenOpts().ProfileSampleAccurate) Fn->addFnAttr("profile-sample-accurate"); + if (!CGM.getCodeGenOpts().SampleProfileFile.empty()) + Fn->addFnAttr("use-sample-profile"); + if (D && D->hasAttr<CFICanonicalJumpTableAttr>()) Fn->addFnAttr("cfi-canonical-jump-table"); |