[llvm-commits] [dragonegg] r130863 - in /dragonegg/trunk: README src/Backend.cpp
Duncan Sands
baldrick at free.fr
Wed May 4 13:16:08 PDT 2011
Author: baldrick
Date: Wed May 4 15:16:08 2011
New Revision: 130863
URL: http://llvm.org/viewvc/llvm-project?rev=130863&view=rev
Log:
Remove the -fplugin-arg-dragonegg-disable-llvm-optzns option, and instead
make it possible to specify any desired LLVM optimization level using the
-fplugin-arg-dragonegg-llvm-ir-optimize=N and
-fplugin-arg-dragonegg-llvm-codegen-optimize=N flags.
Modified:
dragonegg/trunk/README
dragonegg/trunk/src/Backend.cpp
Modified: dragonegg/trunk/README
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/README?rev=130863&r1=130862&r2=130863&view=diff
==============================================================================
--- dragonegg/trunk/README (original)
+++ dragonegg/trunk/README Wed May 4 15:16:08 2011
@@ -125,8 +125,19 @@
-fplugin-arg-dragonegg-debug-pass-structure
Output information about the passes being run.
--fplugin-arg-dragonegg-disable-llvm-optzns
- Do not perform any LLVM IR optimizations even if compiling at -O1, -O2 etc.
+-fplugin-arg-dragonegg-llvm-ir-optimize=N
+ Run the LLVM IR optimizers at optimization level N, overriding the GCC
+ optimization level. Usually if you pass -O1, -O2 etc to GCC then the
+ LLVM IR level optimizers are also run at -O1, -O2 etc. Use this option
+ to change this, disassociating the LLVM optimization level from the GCC
+ one. For example, -fplugin-arg-dragonegg-llvm-ir-optimize=0 disables
+ all LLVM IR optimizations.
+
+-fplugin-arg-dragonegg-llvm-codegen-optimize=N
+ Run the LLVM code generator optimizers at optimization level N, overriding
+ the GCC optimization level. Usually if you pass -O1, -O2 etc to GCC then
+ the LLVM code generators optimize at a corresponding level. Use this option
+ to change this, disassociating the LLVM optimization level from the GCC one.
-fplugin-arg-dragonegg-enable-gcc-optzns
Run the GCC tree optimizers as well as the LLVM IR optimizers. Only early GCC
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=130863&r1=130862&r2=130863&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Wed May 4 15:16:08 2011
@@ -103,10 +103,11 @@
static bool DebugPassArguments;
static bool DebugPassStructure;
-static bool DisableLLVMOptimizations;
static bool EnableGCCOptimizations;
static bool EmitIR;
static bool SaveGCCOutput;
+static int LLVMCodeGenOptimizeArg = -1;
+static int LLVMIROptimizeArg = -1;
std::vector<std::pair<Constant*, int> > StaticCtors, StaticDtors;
SmallSetVector<Constant*, 32> AttributeUsedGlobals;
@@ -265,6 +266,24 @@
}
}
+/// CodeGenOptLevel - The optimization level to be used by the code generators.
+static CodeGenOpt::Level CodeGenOptLevel() {
+ int OptLevel = LLVMCodeGenOptimizeArg >= 0 ?
+ LLVMCodeGenOptimizeArg : optimize;
+ if (OptLevel <= 0)
+ return CodeGenOpt::None;
+ if (OptLevel == 1)
+ return CodeGenOpt::Less;
+ if (OptLevel == 2) // Includes -Os.
+ return CodeGenOpt::Default;
+ return CodeGenOpt::Aggressive;
+}
+
+/// IROptLevel - The optimization level to be used by the IR level optimizers.
+static int IROptLevel() {
+ return LLVMIROptimizeArg >= 0 ? LLVMIROptimizeArg : optimize;
+}
+
// GuessAtInliningThreshold - Figure out a reasonable threshold to pass llvm's
// inliner. gcc has many options that control inlining, but we have decided
// not to support anything like that for llvm-gcc.
@@ -273,7 +292,7 @@
// Reduce inline limit.
return 75;
- if (optimize >= 3)
+ if (IROptLevel() >= 3)
return 275;
return 225;
}
@@ -688,7 +707,7 @@
HasPerFunctionPasses = true;
#endif
- if (optimize > 0 && !DisableLLVMOptimizations) {
+ if (IROptLevel() > 0) {
HasPerFunctionPasses = true;
TargetLibraryInfo *TLI =
@@ -698,7 +717,7 @@
PerFunctionPasses->add(TLI);
PerFunctionPasses->add(createCFGSimplificationPass());
- if (optimize == 1)
+ if (IROptLevel() == 1)
PerFunctionPasses->add(createPromoteMemoryToRegisterPass());
else
PerFunctionPasses->add(createScalarReplAggregatesPass());
@@ -715,15 +734,6 @@
FunctionPassManager *PM = PerFunctionPasses;
HasPerFunctionPasses = true;
- CodeGenOpt::Level OptLevel = CodeGenOpt::Default; // -O2, -Os, and -Oz
- if (optimize == 0)
- OptLevel = CodeGenOpt::None;
- else if (optimize == 1)
- OptLevel = CodeGenOpt::Less;
- else if (optimize == 3)
- // -O3 and above.
- OptLevel = CodeGenOpt::Aggressive;
-
// Request that addPassesToEmitFile run the Verifier after running
// passes which modify the IR.
#ifndef NDEBUG
@@ -737,7 +747,7 @@
InitializeOutputStreams(false);
if (TheTarget->addPassesToEmitFile(*PM, FormattedOutStream,
TargetMachine::CGFT_AssemblyFile,
- OptLevel, DisableVerify))
+ CodeGenOptLevel(), DisableVerify))
DieAbjectly("Error interfacing to target machine!");
}
@@ -759,40 +769,38 @@
PerModulePasses->add(new TargetData(*TheTarget->getTargetData()));
bool HasPerModulePasses = false;
- if (!DisableLLVMOptimizations) {
- TargetLibraryInfo *TLI =
- new TargetLibraryInfo(Triple(TheModule->getTargetTriple()));
- if (flag_no_simplify_libcalls)
- TLI->disableAllFunctions();
- PerModulePasses->add(TLI);
-
- bool NeedAlwaysInliner = false;
- llvm::Pass *InliningPass = 0;
- if (flag_inline_small_functions && !flag_no_inline) {
- InliningPass = createFunctionInliningPass(); // Inline small functions
- } else {
- // If full inliner is not run, check if always-inline is needed to handle
- // functions that are marked as always_inline.
- // TODO: Consider letting the GCC inliner do this.
- for (Module::iterator I = TheModule->begin(), E = TheModule->end();
- I != E; ++I)
- if (I->hasFnAttr(Attribute::AlwaysInline)) {
- NeedAlwaysInliner = true;
- break;
- }
-
- if (NeedAlwaysInliner)
- InliningPass = createAlwaysInlinerPass(); // Inline always_inline funcs
- }
+ TargetLibraryInfo *TLI =
+ new TargetLibraryInfo(Triple(TheModule->getTargetTriple()));
+ if (flag_no_simplify_libcalls)
+ TLI->disableAllFunctions();
+ PerModulePasses->add(TLI);
+
+ bool NeedAlwaysInliner = false;
+ llvm::Pass *InliningPass = 0;
+ if (flag_inline_small_functions && !flag_no_inline) {
+ InliningPass = createFunctionInliningPass(); // Inline small functions
+ } else {
+ // If full inliner is not run, check if always-inline is needed to handle
+ // functions that are marked as always_inline.
+ // TODO: Consider letting the GCC inliner do this.
+ for (Module::iterator I = TheModule->begin(), E = TheModule->end();
+ I != E; ++I)
+ if (I->hasFnAttr(Attribute::AlwaysInline)) {
+ NeedAlwaysInliner = true;
+ break;
+ }
- HasPerModulePasses = true;
- createStandardModulePasses(PerModulePasses, optimize,
- optimize_size,
- flag_unit_at_a_time, flag_unroll_loops,
- !flag_no_simplify_libcalls, flag_exceptions,
- InliningPass);
+ if (NeedAlwaysInliner)
+ InliningPass = createAlwaysInlinerPass(); // Inline always_inline funcs
}
+ HasPerModulePasses = true;
+ createStandardModulePasses(PerModulePasses, IROptLevel(),
+ optimize_size,
+ flag_unit_at_a_time, flag_unroll_loops,
+ !flag_no_simplify_libcalls, flag_exceptions,
+ InliningPass);
+
if (EmitIR && 0) {
// Emit an LLVM .bc file to the output. This is used when passed
// -emit-llvm -c to the GCC driver.
@@ -817,14 +825,6 @@
new FunctionPassManager(TheModule);
PM->add(new TargetData(*TheTarget->getTargetData()));
- CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
-
- switch (optimize) {
- default: break;
- case 0: OptLevel = CodeGenOpt::None; break;
- case 3: OptLevel = CodeGenOpt::Aggressive; break;
- }
-
// Request that addPassesToEmitFile run the Verifier after running
// passes which modify the IR.
#ifndef NDEBUG
@@ -838,7 +838,7 @@
InitializeOutputStreams(false);
if (TheTarget->addPassesToEmitFile(*PM, FormattedOutStream,
TargetMachine::CGFT_AssemblyFile,
- OptLevel, DisableVerify))
+ CodeGenOptLevel(), DisableVerify))
DieAbjectly("Error interfacing to target machine!");
}
}
@@ -2400,7 +2400,6 @@
static FlagDescriptor PluginFlags[] = {
{ "debug-pass-structure", &DebugPassStructure},
{ "debug-pass-arguments", &DebugPassArguments},
- { "disable-llvm-optzns", &DisableLLVMOptimizations },
{ "enable-gcc-optzns", &EnableGCCOptimizations },
{ "emit-ir", &EmitIR },
{ "save-gcc-output", &SaveGCCOutput },
@@ -2454,27 +2453,47 @@
int argc = plugin_info->argc;
for (int i = 0; i < argc; ++i) {
- bool Found = false;
+ if (!strcmp (argv[i].key, "llvm-ir-optimize") ||
+ !strcmp (argv[i].key, "llvm-codegen-optimize")) {
+ if (!argv[i].value) {
+ error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
+ plugin_name, argv[i].key);
+ return 1;
+ }
+ if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || argv[i].value[1]) {
+ error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"),
+ plugin_name, argv[i].key, argv[i].value);
+ return 1;
+ }
+ int OptLevel = argv[i].value[0] - '0';
+ if (argv[i].key[5] == 'i')
+ LLVMIROptimizeArg = OptLevel;
+ else
+ LLVMCodeGenOptimizeArg = OptLevel;
+ continue;
+ }
+
+ // All remaining options are flags, so complain if there is an argument.
+ if (argv[i].value) {
+ error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"),
+ plugin_name, argv[i].key, argv[i].value);
+ return 1;
+ }
// Look for a matching flag.
- for (FlagDescriptor *F = PluginFlags; F->Key; ++F) {
- if (strcmp (argv[i].key, F->Key))
- continue;
-
- if (argv[i].value)
- warning (0, G_("option '-fplugin-arg-%s-%s=%s' ignored"
- " (superfluous '=%s')"),
- plugin_name, argv[i].key, argv[i].value, argv[i].value);
- else
+ bool Found = false;
+ for (FlagDescriptor *F = PluginFlags; F->Key; ++F)
+ if (!strcmp (argv[i].key, F->Key)) {
+ Found = true;
*F->Flag = true;
+ break;
+ }
- Found = true;
- break;
+ if (!Found) {
+ error(G_("invalid option '-fplugin-arg-%s-%s'"),
+ plugin_name, argv[i].key);
+ return 1;
}
-
- if (!Found)
- warning (0, G_("plugin %qs: unrecognized argument %qs ignored"),
- plugin_name, argv[i].key);
}
}
More information about the llvm-commits
mailing list