Skip to content

Commit 6f06eda

Browse files
committed
bugpoint: Add option to disable attribute removal
This takes a long time and never reduces anything useful for me (e.g. I've been waiting for 3 hours on a testcase and it hasn't found any attributes to remove yet). This should probably start by assuming no attributes matter, and adding back.
1 parent dc02eb1 commit 6f06eda

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

llvm/test/BugPoint/func-attrs.ll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
; RUN: bugpoint -load %llvmshlibdir/BugpointPasses%shlibext %s -output-prefix %t -bugpoint-crashfuncattr -silence-passes
2-
; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck %s
2+
; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck -check-prefixes=ALL,ENABLED %s
3+
; RUN: bugpoint -disable-attribute-remove -load %llvmshlibdir/BugpointPasses%shlibext %s -output-prefix %t -bugpoint-crashfuncattr -silence-passes
4+
; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck -check-prefixes=ALL,DISABLED %s
5+
36
; REQUIRES: plugins
47

5-
; CHECK: f() #[[ATTRS:[0-9]+]]
8+
; ALL: f() #[[ATTRS:[0-9]+]]
69
define void @f() #0 {
710
ret void
811
}
912

10-
; CHECK: attributes #[[ATTRS]] = { "bugpoint-crash" }
11-
attributes #0 = { noinline "bugpoint-crash" "no-frame-pointer-elim-non-leaf" }
13+
; ENABLED: attributes #[[ATTRS]] = { "bugpoint-crash" }
14+
; DISABLED: attributes #[[ATTRS]] = { noinline "bugpoint-crash" "no-frame-pointer-elim-non-leaf" }
15+
attributes #0 = { noinline "bugpoint-crash" "no-frame-pointer-elim-non-leaf" }

llvm/tools/bugpoint/CrashDebugger.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ cl::opt<bool> NoGlobalRM("disable-global-remove",
4444
cl::desc("Do not remove global variables"),
4545
cl::init(false));
4646

47+
cl::opt<bool> NoAttributeRM("disable-attribute-remove",
48+
cl::desc("Do not remove function attributes"),
49+
cl::init(false));
50+
4751
cl::opt<bool> ReplaceFuncsWithNull(
4852
"replace-funcs-with-null",
4953
cl::desc("When stubbing functions, replace all uses will null"),
@@ -1203,36 +1207,38 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) {
12031207
BD.EmitProgressBitcode(BD.getProgram(), "reduced-function");
12041208
}
12051209

1206-
// For each remaining function, try to reduce that function's attributes.
1207-
std::vector<std::string> FunctionNames;
1208-
for (Function &F : BD.getProgram())
1209-
FunctionNames.push_back(F.getName());
1210+
if (!NoAttributeRM) {
1211+
// For each remaining function, try to reduce that function's attributes.
1212+
std::vector<std::string> FunctionNames;
1213+
for (Function &F : BD.getProgram())
1214+
FunctionNames.push_back(F.getName());
12101215

1211-
if (!FunctionNames.empty() && !BugpointIsInterrupted) {
1212-
outs() << "\n*** Attempting to reduce the number of function attributes in "
1213-
"the testcase\n";
1216+
if (!FunctionNames.empty() && !BugpointIsInterrupted) {
1217+
outs() << "\n*** Attempting to reduce the number of function attributes"
1218+
" in the testcase\n";
12141219

1215-
unsigned OldSize = 0;
1216-
unsigned NewSize = 0;
1217-
for (std::string &Name : FunctionNames) {
1218-
Function *Fn = BD.getProgram().getFunction(Name);
1219-
assert(Fn && "Could not find funcion?");
1220+
unsigned OldSize = 0;
1221+
unsigned NewSize = 0;
1222+
for (std::string &Name : FunctionNames) {
1223+
Function *Fn = BD.getProgram().getFunction(Name);
1224+
assert(Fn && "Could not find funcion?");
12201225

1221-
std::vector<Attribute> Attrs;
1222-
for (Attribute A : Fn->getAttributes().getFnAttributes())
1223-
Attrs.push_back(A);
1226+
std::vector<Attribute> Attrs;
1227+
for (Attribute A : Fn->getAttributes().getFnAttributes())
1228+
Attrs.push_back(A);
12241229

1225-
OldSize += Attrs.size();
1226-
Expected<bool> Result =
1230+
OldSize += Attrs.size();
1231+
Expected<bool> Result =
12271232
ReduceCrashingFunctionAttributes(BD, Name, TestFn).reduceList(Attrs);
1228-
if (Error E = Result.takeError())
1229-
return E;
1233+
if (Error E = Result.takeError())
1234+
return E;
12301235

1231-
NewSize += Attrs.size();
1232-
}
1236+
NewSize += Attrs.size();
1237+
}
12331238

1234-
if (OldSize < NewSize)
1235-
BD.EmitProgressBitcode(BD.getProgram(), "reduced-function-attributes");
1239+
if (OldSize < NewSize)
1240+
BD.EmitProgressBitcode(BD.getProgram(), "reduced-function-attributes");
1241+
}
12361242
}
12371243

12381244
// Attempt to change conditional branches into unconditional branches to

0 commit comments

Comments
 (0)