[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-26 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb9eb1982980: Support for instrumenting only selected files 
or functions (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D94820?vs=319359=319444#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -973,6 +973,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1655,6 +1655,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@
   kw_nonlazybind,
   kw_nomerge,
   kw_nonnull,
+  kw_noprofile,
   kw_noredzone,
   kw_noreturn,
   kw_nosync,
Index: llvm/lib/AsmParser/LLParser.cpp
===
--- 

[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/docs/UsersManual.rst:2271
 
+.. option:: -fprofile-list=
+

MaskRay wrote:
> This can be added below `-fprofile-exclude-files=`
I considered it but that's in the GCOV section and this flag only applies to 
the LLVM instrumentation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/docs/UsersManual.rst:2271
 
+.. option:: -fprofile-list=
+

This can be added below `-fprofile-exclude-files=`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D94820#2523461 , @thakis wrote:

> Looks like this breaks tests on windows: 
> http://45.33.8.238/win/32075/step_7.txt
>
> Please take a look, and revert for now if it takes a while to fix.

Thanks for the heads up, I suspect it might be because of the Windows paths in 
the list file. I've reverted the change so I can test the fix on Windows before 
relanding.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-26 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests on windows: http://45.33.8.238/win/32075/step_7.txt

Please take a look, and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-26 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4edf35f11a9e: Support for instrumenting only selected files 
or functions (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D94820?vs=318257=319359#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/SourceBasedCodeCoverage.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -973,6 +973,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1655,6 +1655,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@
   kw_nonlazybind,
   kw_nomerge,
   kw_nonnull,
+  kw_noprofile,
   kw_noredzone,
   kw_noreturn,
   kw_nosync,
Index: llvm/lib/AsmParser/LLParser.cpp

[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-25 Thread David Li via Phabricator via cfe-commits
davidxl accepted this revision.
davidxl added a comment.
This revision is now accepted and ready to land.

my bad -- I missed the test case.  LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/test/CodeGen/profile-filter.c:17
+// RUN: %clang_cc1 -fprofile-instrument=clang 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
+
+unsigned i;

davidxl wrote:
> phosek wrote:
> > davidxl wrote:
> > > Can you add a test case with both include and exclude list (the 
> > > intersection of INCLUDE_SET & !EXCLUDE_SET)?
> > See the case above this one which has:
> > ```
> > fun:test*
> > !fun:test1
> > ```
> > Is that what you have in mind?
> Right
Do we need to do anything then since this test case already exists?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-25 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: clang/test/CodeGen/profile-filter.c:17
+// RUN: %clang_cc1 -fprofile-instrument=clang 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
+
+unsigned i;

phosek wrote:
> davidxl wrote:
> > Can you add a test case with both include and exclude list (the 
> > intersection of INCLUDE_SET & !EXCLUDE_SET)?
> See the case above this one which has:
> ```
> fun:test*
> !fun:test1
> ```
> Is that what you have in mind?
Right


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/test/CodeGen/profile-filter.c:17
+// RUN: %clang_cc1 -fprofile-instrument=clang 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
+
+unsigned i;

davidxl wrote:
> Can you add a test case with both include and exclude list (the intersection 
> of INCLUDE_SET & !EXCLUDE_SET)?
See the case above this one which has:
```
fun:test*
!fun:test1
```
Is that what you have in mind?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-25 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: clang/test/CodeGen/profile-filter.c:17
+// RUN: %clang_cc1 -fprofile-instrument=clang 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
+
+unsigned i;

Can you add a test case with both include and exclude list (the intersection of 
INCLUDE_SET & !EXCLUDE_SET)?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek marked an inline comment as done.
phosek added a comment.

@davidxl @vsk do you have any further comments?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek marked an inline comment as done.
phosek added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:851
+return "csllvm";
+  default:
+llvm_unreachable("unknown instrumentation type");

vsk wrote:
> If we add an instrumentation kind, it may be more convenient to trigger a 
> -Wcovered-switch warning (by removing this default case) vs. seeing a crash 
> at runtime.
Done, I've also decided to move the helper function inside the `ProfileList` 
class to hide the detail of how `ProfileInstrKind` translates to section name.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 318257.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

Files:
  clang/docs/SourceBasedCodeCoverage.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -974,6 +974,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1639,6 +1639,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@
   kw_nonlazybind,
   kw_nomerge,
   kw_nonnull,
+  kw_noprofile,
   kw_noredzone,
   kw_noreturn,
   kw_nosync,
Index: llvm/lib/AsmParser/LLParser.cpp
===
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1368,6 +1368,7 @@
 case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
 case lltok::kw_nosync: B.addAttribute(Attribute::NoSync); break;
 case lltok::kw_nocf_check: B.addAttribute(Attribute::NoCfCheck); break;
+

[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:851
+return "csllvm";
+  default:
+llvm_unreachable("unknown instrumentation type");

If we add an instrumentation kind, it may be more convenient to trigger a 
-Wcovered-switch warning (by removing this default case) vs. seeing a crash at 
runtime.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek marked an inline comment as not done.
phosek added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2591
+  }
+  return false;
+}

davidxl wrote:
> phosek wrote:
> > davidxl wrote:
> > > If the profile list contains only one line of exclude list, it seems that 
> > > all functions will be rejected as the function returns 'false' by default 
> > > for all other functions?
> > That's correct, would you expect a different behavior and if so what should 
> > that behavior be?
> > 
> > Currently, the profile list is used to build up a list of functions and 
> > files that should be instrumented. Any function or file that's not covered 
> > by the profile list is automatically excluded (not included may be more 
> > correct). Having just excludes without any includes means that nothing will 
> > be instrumented.
> It is natural and more useful to let user simply specify exclude lists so 
> they don't need to worry about patterns of other functions to be instrumented.
> 
> This means that when only exclude list is specified, the default should be 
> flipped to be true (instrument everything else).
> 
> If there only include list, the default is false.
> 
> If there are both, the include list should be used to specify a super set 
> while the exclude list (taking precedence) used to specify a subset from the 
> super set.
That makes sense, I've implemented that in the latest patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 318132.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

Files:
  clang/docs/SourceBasedCodeCoverage.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -974,6 +974,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1639,6 +1639,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@
   kw_nonlazybind,
   kw_nomerge,
   kw_nonnull,
+  kw_noprofile,
   kw_noredzone,
   kw_noreturn,
   kw_nosync,
Index: llvm/lib/AsmParser/LLParser.cpp
===
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1368,6 +1368,7 @@
 case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
 case lltok::kw_nosync: B.addAttribute(Attribute::NoSync); break;
 case lltok::kw_nocf_check: B.addAttribute(Attribute::NoCfCheck); break;
+

[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-20 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2591
+  }
+  return false;
+}

phosek wrote:
> davidxl wrote:
> > If the profile list contains only one line of exclude list, it seems that 
> > all functions will be rejected as the function returns 'false' by default 
> > for all other functions?
> That's correct, would you expect a different behavior and if so what should 
> that behavior be?
> 
> Currently, the profile list is used to build up a list of functions and files 
> that should be instrumented. Any function or file that's not covered by the 
> profile list is automatically excluded (not included may be more correct). 
> Having just excludes without any includes means that nothing will be 
> instrumented.
It is natural and more useful to let user simply specify exclude lists so they 
don't need to worry about patterns of other functions to be instrumented.

This means that when only exclude list is specified, the default should be 
flipped to be true (instrument everything else).

If there only include list, the default is false.

If there are both, the include list should be used to specify a super set while 
the exclude list (taking precedence) used to specify a subset from the super 
set.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/docs/SourceBasedCodeCoverage.rst:86
+.. code-block:: none
+
+  # all functions whose name starts with foo will be instrumented.

davidxl wrote:
> what is the default section name?
It's `*` which always matches.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2569
+  // If the profile list is empty, then instrument everything.
+  if (ProfileList.isEmpty())
+return true;

davidxl wrote:
> Should the option to turn on instrumentation also be checked?
Currently, this method is only invoked from `CodeGenFunction` which does its 
own check, but I'm happy to include a check here in case there are ever other 
callers.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2591
+  }
+  return false;
+}

davidxl wrote:
> If the profile list contains only one line of exclude list, it seems that all 
> functions will be rejected as the function returns 'false' by default for all 
> other functions?
That's correct, would you expect a different behavior and if so what should 
that behavior be?

Currently, the profile list is used to build up a list of functions and files 
that should be instrumented. Any function or file that's not covered by the 
profile list is automatically excluded (not included may be more correct). 
Having just excludes without any includes means that nothing will be 
instrumented.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 317796.
phosek marked 3 inline comments as done.
Herald added a reviewer: jansvoboda11.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

Files:
  clang/docs/SourceBasedCodeCoverage.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -974,6 +974,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1639,6 +1639,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@
   kw_nonlazybind,
   kw_nomerge,
   kw_nonnull,
+  kw_noprofile,
   kw_noredzone,
   kw_noreturn,
   kw_nosync,
Index: llvm/lib/AsmParser/LLParser.cpp
===
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1368,6 +1368,7 @@
 case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
 case lltok::kw_nosync: B.addAttribute(Attribute::NoSync); break;
  

[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-19 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: clang/docs/SourceBasedCodeCoverage.rst:77
+the files and functions specified in ``file.list`` will be instrumented.  The
+option can be specified multiple times to pass multiple files:
+

perhaps documenting how compiler generated functions are handled? 



Comment at: clang/docs/SourceBasedCodeCoverage.rst:86
+.. code-block:: none
+
+  # all functions whose name starts with foo will be instrumented.

what is the default section name?



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2569
+  // If the profile list is empty, then instrument everything.
+  if (ProfileList.isEmpty())
+return true;

Should the option to turn on instrumentation also be checked?



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2591
+  }
+  return false;
+}

If the profile list contains only one line of exclude list, it seems that all 
functions will be rejected as the function returns 'false' by default for all 
other functions?



Comment at: clang/lib/CodeGen/CodeGenModule.h:1280
 
+  bool isProfileInstrumented(llvm::Function *Fn, SourceLocation Loc,
+ StringRef Section = StringRef()) const;

Document the method and params.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94820/new/

https://reviews.llvm.org/D94820

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: davidxl, vsk, gulfem.
Herald added subscribers: dexonsmith, wenlei, dang, jdoerfert, steven_wu, 
hiraditya, mgorny.
phosek requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This change implements support for applying profile instrumentation
only to selected files or functions. The implementation uses the
sanitizer special case list format to select which files and functions
to instrument, and relies on the new noprofile IR attribute to exclude
functions from instrumentation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94820

Files:
  clang/docs/SourceBasedCodeCoverage.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -974,6 +974,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1639,6 +1639,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@