Skip to content

Commit 65fcc0e

Browse files
committed
[Attributor] Function seed allow list
- Adds a command line option to seed only selected functions. - Makes seed allow listing exclusive to assertions enabled builds. Reviewed By: sstefan1 Differential Revision: https://reviews.llvm.org/D86129
1 parent 7ea0ee3 commit 65fcc0e

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,21 @@ static cl::opt<bool>
9797
"derived from non-exact functions via cloning"),
9898
cl::init(false));
9999

100+
// These options can only used for debug builds.
101+
#ifndef NDEBUG
100102
static cl::list<std::string>
101103
SeedAllowList("attributor-seed-allow-list", cl::Hidden,
102-
cl::desc("Comma seperated list of attrbute names that are "
104+
cl::desc("Comma seperated list of attribute names that are "
103105
"allowed to be seeded."),
104106
cl::ZeroOrMore, cl::CommaSeparated);
105107

108+
static cl::list<std::string> FunctionSeedAllowList(
109+
"attributor-function-seed-allow-list", cl::Hidden,
110+
cl::desc("Comma seperated list of function names that are "
111+
"allowed to be seeded."),
112+
cl::ZeroOrMore, cl::CommaSeparated);
113+
#endif
114+
106115
static cl::opt<bool>
107116
DumpDepGraph("attributor-dump-dep-graph", cl::Hidden,
108117
cl::desc("Dump the dependency graph to dot files."),
@@ -1568,9 +1577,17 @@ bool Attributor::registerFunctionSignatureRewrite(
15681577
}
15691578

15701579
bool Attributor::shouldSeedAttribute(AbstractAttribute &AA) {
1571-
if (SeedAllowList.size() == 0)
1572-
return true;
1573-
return std::count(SeedAllowList.begin(), SeedAllowList.end(), AA.getName());
1580+
bool Result = true;
1581+
#ifndef NDEBUG
1582+
if (SeedAllowList.size() != 0)
1583+
Result =
1584+
std::count(SeedAllowList.begin(), SeedAllowList.end(), AA.getName());
1585+
Function *Fn = AA.getAnchorScope();
1586+
if (FunctionSeedAllowList.size() != 0 && Fn)
1587+
Result &= std::count(FunctionSeedAllowList.begin(),
1588+
FunctionSeedAllowList.end(), Fn->getName());
1589+
#endif
1590+
return Result;
15741591
}
15751592

15761593
ChangeStatus Attributor::rewriteFunctionSignatures(

llvm/test/Transforms/Attributor/allow_list.ll

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
; RUN: opt -S -passes=attributor --attributor-seed-allow-list asd < %s | FileCheck %s --check-prefixes=CHECK_DISABLED
33
; RUN: opt -S -passes=attributor --attributor-seed-allow-list AAValueSimplify < %s | FileCheck %s --check-prefixes=CHECK_ENABLED
44

5+
; RUN: opt -S -passes=attributor --attributor-function-seed-allow-list asd < %s | FileCheck %s --check-prefixes=CHECK_DISABLED_FUNCTION
6+
7+
; RUN: opt -S -passes=attributor --attributor-function-seed-allow-list range_use1 < %s | FileCheck %s --check-prefixes=CHECK_ENABLED_FUNCTION
8+
9+
10+
11+
512
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
613

714
; Function Attrs: nounwind uwtable
@@ -12,22 +19,67 @@ define internal i32 @range_test(i32 %a) #0 {
1219
; CHECK_DISABLED-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A]], 100
1320
; CHECK_DISABLED-NEXT: [[TMP2:%.*]] = zext i1 [[TMP1]] to i32
1421
; CHECK_DISABLED-NEXT: ret i32 [[TMP2]]
22+
;
23+
; CHECK_DISABLED_FUNCTION: Function Attrs: noinline nounwind uwtable
24+
; CHECK_DISABLED_FUNCTION-LABEL: define {{[^@]+}}@range_test
25+
; CHECK_DISABLED_FUNCTION-SAME: (i32 [[A:%.*]])
26+
; CHECK_DISABLED_FUNCTION-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A]], 100
27+
; CHECK_DISABLED_FUNCTION-NEXT: [[TMP2:%.*]] = zext i1 [[TMP1]] to i32
28+
; CHECK_DISABLED_FUNCTION-NEXT: ret i32 [[TMP2]]
29+
;
30+
; CHECK_ENABLED_FUNCTION: Function Attrs: noinline nounwind readnone uwtable
31+
; CHECK_ENABLED_FUNCTION-LABEL: define {{[^@]+}}@range_test()
32+
; CHECK_ENABLED_FUNCTION-NEXT: ret i32 1
1533
;
1634
%1 = icmp sgt i32 %a, 100
1735
%2 = zext i1 %1 to i32
1836
ret i32 %2
1937
}
2038

2139
; Function Attrs: nounwind uwtable
22-
define i32 @range_use() #0 {
40+
define i32 @range_use1() #0 {
2341
; CHECK_DISABLED: Function Attrs: noinline nounwind uwtable
24-
; CHECK_DISABLED-LABEL: define {{[^@]+}}@range_use()
42+
; CHECK_DISABLED-LABEL: define {{[^@]+}}@range_use1()
2543
; CHECK_DISABLED-NEXT: [[TMP1:%.*]] = call i32 @range_test(i32 123)
2644
; CHECK_DISABLED-NEXT: ret i32 [[TMP1]]
2745
;
2846
; CHECK_ENABLED: Function Attrs: noinline nounwind uwtable
29-
; CHECK_ENABLED-LABEL: define {{[^@]+}}@range_use()
47+
; CHECK_ENABLED-LABEL: define {{[^@]+}}@range_use1()
3048
; CHECK_ENABLED-NEXT: ret i32 1
49+
;
50+
; CHECK_DISABLED_FUNCTION: Function Attrs: noinline nounwind uwtable
51+
; CHECK_DISABLED_FUNCTION-LABEL: define {{[^@]+}}@range_use1()
52+
; CHECK_DISABLED_FUNCTION-NEXT: [[TMP1:%.*]] = call i32 @range_test(i32 123)
53+
; CHECK_DISABLED_FUNCTION-NEXT: ret i32 [[TMP1]]
54+
;
55+
; CHECK_ENABLED_FUNCTION: Function Attrs: nofree noinline nosync nounwind readnone uwtable willreturn
56+
; CHECK_ENABLED_FUNCTION-LABEL: define {{[^@]+}}@range_use1()
57+
; CHECK_ENABLED_FUNCTION-NEXT: ret i32 1
58+
;
59+
%1 = call i32 @range_test(i32 123)
60+
ret i32 %1
61+
}
62+
63+
; Function Attrs: nounwind uwtable
64+
define i32 @range_use2() #0 {
65+
; CHECK_DISABLED: Function Attrs: noinline nounwind uwtable
66+
; CHECK_DISABLED-LABEL: define {{[^@]+}}@range_use2()
67+
; CHECK_DISABLED-NEXT: [[TMP1:%.*]] = call i32 @range_test(i32 123)
68+
; CHECK_DISABLED-NEXT: ret i32 [[TMP1]]
69+
;
70+
; CHECK_ENABLED: Function Attrs: noinline nounwind uwtable
71+
; CHECK_ENABLED-LABEL: define {{[^@]+}}@range_use2()
72+
; CHECK_ENABLED-NEXT: ret i32 1
73+
;
74+
; CHECK_DISABLED_FUNCTION: Function Attrs: noinline nounwind uwtable
75+
; CHECK_DISABLED_FUNCTION-LABEL: define {{[^@]+}}@range_use2()
76+
; CHECK_DISABLED_FUNCTION-NEXT: [[TMP1:%.*]] = call i32 @range_test(i32 123)
77+
; CHECK_DISABLED_FUNCTION-NEXT: ret i32 [[TMP1]]
78+
;
79+
; CHECK_ENABLED_FUNCTION: Function Attrs: noinline nounwind uwtable
80+
; CHECK_ENABLED_FUNCTION-LABEL: define {{[^@]+}}@range_use2()
81+
; CHECK_ENABLED_FUNCTION-NEXT: [[TMP1:%.*]] = call i32 @range_test()
82+
; CHECK_ENABLED_FUNCTION-NEXT: ret i32 [[TMP1]]
3183
;
3284
%1 = call i32 @range_test(i32 123)
3385
ret i32 %1

0 commit comments

Comments
 (0)