[LLVMdev] Instrumentation passes and -O0 optimization level

Alexander Potapenko glider at google.com
Tue Nov 22 03:18:49 PST 2011


Hi LLVMdev,

llvm::PassManagerBuilder allows to customize the default pass
sequenceby registering passes at specific extension points.However all
of theextensions if the -O0 flag is added to the command line; as
thecomment says, "If all optimizations are disabled, just run
thealways-inline pass."This doesn't play well with
_instrumentation_passes which should not be disabled regardless of the
optimizationlevel.

My proposal is to add a specific extension point to preserve a
passeven if O0 is used (below is the usage example with
theAddressSanitizer pass)Another solution would be to introduce a
passattribute which tells whether the pass should be preserved if
theoptimizations are disabled, but this will require some refactoring
ofthe PassManagerBuilder class.

What do you think of the following patch?


-------------------------8<--------------------------------------------------Index:
include/llvm/Transforms/IPO/PassManagerBuilder.h===================================================================---
include/llvm/Transforms/IPO/PassManagerBuilder.h    (revision
144800)+++ include/llvm/Transforms/IPO/PassManagerBuilder.h
(working copy)@@ -67,7 +67,12 @@   /// EP_ScalarOptimizerLate - This
extension point allows addingoptimization   /// passes after most of
the main optimizations, but before the last   /// cleanup-ish
optimizations.-    EP_ScalarOptimizerLate+
EP_ScalarOptimizerLate,++    /// EP_EnabledOnOptLevel0 - This
extension point allows adding passes that+    /// should not be
disabled by O0 optimization level. The passes will be+    /// inserted
after the inlining pass.+    EP_EnabledOnOptLevel0 };
 /// The Optimization Level - Specify the basic optimization
level.Index: lib/Transforms/IPO/PassManagerBuilder.cpp===================================================================---
lib/Transforms/IPO/PassManagerBuilder.cpp   (revision 144800)+++
lib/Transforms/IPO/PassManagerBuilder.cpp   (working copy)@@ -101,6
+101,7 @@     MPM.add(Inliner);     Inliner = 0;   }+
addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);   return; }
Index: tools/clang/lib/CodeGen/BackendUtil.cpp===================================================================---
tools/clang/lib/CodeGen/BackendUtil.cpp     (revision 144800)+++
tools/clang/lib/CodeGen/BackendUtil.cpp     (working copy)@@ -150,6
+150,8 @@ if (CodeGenOpts.AddressSanitizer) {
PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
                     addAddressSanitizerPass);+
PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,+
                      addAddressSanitizerPass); }
 // Figure out TargetLibraryInfo.-------------------------8<--------------------------------------------------
TIA,Alexander Potapenko
Software Engineer
Google Moscow




More information about the llvm-dev mailing list