diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1970,6 +1970,13 @@ let SimpleHandler = 1; } +def NoProfileFunction : InheritableAttr { + let Spellings = [GCC<"no_profile">]; + let Subjects = SubjectList<[Function]>; + let Documentation = [NoProfileDocs]; + let SimpleHandler = 1; +} + def NotTailCalled : InheritableAttr { let Spellings = [Clang<"not_tail_called">]; let Subjects = SubjectList<[Function]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -2559,6 +2559,17 @@ }]; } +def NoProfileDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +Use the ``no_profile`` attribute on a function to declaration to denote that +the compiler should not instrument the function with profile related +instrumentation, such as via the +``-fprofile-generate`` / ``-fprofile-instr-generate`` / +``-fcs-profile-generate`` / ``-fprofile-arcs`` flags. +}]; +} + def NoSanitizeDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -893,6 +893,9 @@ if (D && D->hasAttr()) Fn->addFnAttr("cfi-canonical-jump-table"); + if (D && D->hasAttr()) + Fn->addFnAttr(llvm::Attribute::NoProfile); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) diff --git a/clang/test/CodeGen/fprofile.c b/clang/test/CodeGen/fprofile.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/fprofile.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \ +// RUN: -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fprofile-instrument=csllvm -disable-llvm-passes \ +// RUN: -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fprofile-instrument=clang -disable-llvm-passes \ +// RUN: -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fprofile-arcs -disable-llvm-passes \ +// RUN: -emit-llvm -o - %s | FileCheck %s +int g(int); + +void __attribute__((no_profile)) no_instr() { +// CHECK: define {{.*}} void @no_instr() [[ATTR:#[0-9]+]] +} + +void instr(void) { +// CHECK: define {{.*}} void @instr() [[ATTR2:#[0-9]+]] +} +// CHECK: attributes [[ATTR]] = {{.*}} noprofile +// CHECK-NOT: attributes [[ATTR2]] = {{.*}} noprofile diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -99,6 +99,7 @@ // CHECK-NEXT: NoMerge (SubjectMatchRule_function) // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function) // CHECK-NEXT: NoMips16 (SubjectMatchRule_function) +// CHECK-NEXT: NoProfileFunction (SubjectMatchRule_function) // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global) // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global) // CHECK-NEXT: NoSpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)