1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Support for instrumenting only selected files or functions

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.

Differential Revision: https://reviews.llvm.org/D94820
This commit is contained in:
Petr Hosek 2021-01-15 01:14:37 -08:00
parent 7ab636be94
commit a8839c989d
11 changed files with 42 additions and 0 deletions

View File

@ -656,6 +656,7 @@ enum AttributeKindCodes {
ATTR_KIND_MUSTPROGRESS = 70,
ATTR_KIND_NO_CALLBACK = 71,
ATTR_KIND_HOT = 72,
ATTR_KIND_NO_PROFILE = 73,
};
enum ComdatSelectionKindCodes {

View File

@ -148,6 +148,9 @@ def NoSync : EnumAttr<"nosync">;
/// Disable Indirect Branch Tracking.
def NoCfCheck : EnumAttr<"nocf_check">;
/// Function should be instrumented.
def NoProfile : EnumAttr<"noprofile">;
/// Function doesn't unwind stack.
def NoUnwind : EnumAttr<"nounwind">;

View File

@ -663,6 +663,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(nonlazybind);
KEYWORD(nomerge);
KEYWORD(nonnull);
KEYWORD(noprofile);
KEYWORD(noredzone);
KEYWORD(noreturn);
KEYWORD(nosync);

View File

@ -1368,6 +1368,7 @@ bool LLParser::parseFnAttributeValuePairs(AttrBuilder &B,
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;
case lltok::kw_noprofile: B.addAttribute(Attribute::NoProfile); break;
case lltok::kw_norecurse: B.addAttribute(Attribute::NoRecurse); break;
case lltok::kw_nounwind: B.addAttribute(Attribute::NoUnwind); break;
case lltok::kw_null_pointer_is_valid:
@ -1778,6 +1779,7 @@ bool LLParser::parseOptionalParamAttrs(AttrBuilder &B) {
case lltok::kw_noinline:
case lltok::kw_nonlazybind:
case lltok::kw_nomerge:
case lltok::kw_noprofile:
case lltok::kw_noredzone:
case lltok::kw_noreturn:
case lltok::kw_nocf_check:
@ -1886,6 +1888,7 @@ bool LLParser::parseOptionalReturnAttrs(AttrBuilder &B) {
case lltok::kw_noinline:
case lltok::kw_nonlazybind:
case lltok::kw_nomerge:
case lltok::kw_noprofile:
case lltok::kw_noredzone:
case lltok::kw_noreturn:
case lltok::kw_nocf_check:

View File

@ -210,6 +210,7 @@ enum Kind {
kw_nonlazybind,
kw_nomerge,
kw_nonnull,
kw_noprofile,
kw_noredzone,
kw_noreturn,
kw_nosync,

View File

@ -680,6 +680,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
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:

View File

@ -403,6 +403,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
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))

View File

@ -1655,6 +1655,7 @@ static bool isFuncOnlyAttr(Attribute::AttrKind Kind) {
case Attribute::StrictFP:
case Attribute::NullPointerIsValid:
case Attribute::MustProgress:
case Attribute::NoProfile:
return true;
default:
break;

View File

@ -1591,6 +1591,8 @@ static bool InstrumentAllFunctions(
for (auto &F : M) {
if (F.isDeclaration())
continue;
if (F.hasFnAttribute(llvm::Attribute::NoProfile))
continue;
auto &TLI = LookupTLI(F);
auto *BPI = LookupBPI(F);
auto *BFI = LookupBFI(F);

View File

@ -973,6 +973,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
case Attribute::UWTable:
case Attribute::NoCfCheck:
case Attribute::MustProgress:
case Attribute::NoProfile:
break;
}

View File

@ -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 }