Skip to content

Commit 5c17323

Browse files
committed
[bugpoint] Add support for -Oz and properly enable -Os.
This patch adds -Oz as option and also properly enables support for -Os. Currently, the existing check for -Os is dead, because the enclosing if only checks of O1, O2 and O3. There is still a difference between the -Oz pipeline compared to opt, but I have not been able to track that down yet. Reviewers: bogner, sebpop, efriedma Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D67593 llvm-svn: 372079
1 parent 6455938 commit 5c17323

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

llvm/tools/bugpoint/bugpoint.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ static cl::opt<bool> OptLevelOs(
8080
cl::desc(
8181
"Like -O2 with extra optimizations for size. Similar to clang -Os"));
8282

83+
static cl::opt<bool>
84+
OptLevelOz("Oz",
85+
cl::desc("Like -Os but reduces code size further. Similar to clang -Oz"));
86+
8387
static cl::opt<bool>
8488
OptLevelO3("O3", cl::desc("Optimization level 3. Identical to 'opt -O3'"));
8589

@@ -109,6 +113,26 @@ class AddToDriver : public legacy::FunctionPassManager {
109113
};
110114
}
111115

116+
// This routine adds optimization passes based on selected optimization level,
117+
// OptLevel.
118+
//
119+
// OptLevel - Optimization Level
120+
static void AddOptimizationPasses(legacy::FunctionPassManager &FPM,
121+
unsigned OptLevel,
122+
unsigned SizeLevel) {
123+
PassManagerBuilder Builder;
124+
Builder.OptLevel = OptLevel;
125+
Builder.SizeLevel = SizeLevel;
126+
127+
if (OptLevel > 1)
128+
Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false);
129+
else
130+
Builder.Inliner = createAlwaysInlinerLegacyPass();
131+
132+
Builder.populateFunctionPassManager(FPM);
133+
Builder.populateModulePassManager(FPM);
134+
}
135+
112136
#ifdef LINK_POLLY_INTO_TOOLS
113137
namespace polly {
114138
void initializePollyPasses(llvm::PassRegistry &Registry);
@@ -189,18 +213,16 @@ int main(int argc, char **argv) {
189213
Builder.populateLTOPassManager(PM);
190214
}
191215

192-
if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
193-
PassManagerBuilder Builder;
194-
if (OptLevelO1)
195-
Builder.Inliner = createAlwaysInlinerLegacyPass();
196-
else if (OptLevelOs || OptLevelO2)
197-
Builder.Inliner = createFunctionInliningPass(
198-
2, OptLevelOs ? 1 : 0, false);
199-
else
200-
Builder.Inliner = createFunctionInliningPass(275);
201-
Builder.populateFunctionPassManager(PM);
202-
Builder.populateModulePassManager(PM);
203-
}
216+
if (OptLevelO1)
217+
AddOptimizationPasses(PM, 1, 0);
218+
else if (OptLevelO2)
219+
AddOptimizationPasses(PM, 2, 0);
220+
else if (OptLevelO3)
221+
AddOptimizationPasses(PM, 3, 0);
222+
else if (OptLevelOs)
223+
AddOptimizationPasses(PM, 2, 1);
224+
else if (OptLevelOz)
225+
AddOptimizationPasses(PM, 2, 2);
204226

205227
for (const PassInfo *PI : PassList)
206228
D.addPass(PI->getPassArgument());

0 commit comments

Comments
 (0)