[llvm-commits] [llvm] r131824 - /llvm/trunk/tools/opt/opt.cpp

Chris Lattner sabre at nondot.org
Sat May 21 23:27:39 PDT 2011


On May 21, 2011, at 11:02 PM, Cameron Zwarich wrote:

> This changed the opt pass order by removing the global passes that run first:
> 
> Pass Arguments:  -targetdata -no-aa -tbaa -basicaa -simplifycfg -domtree -scalarrepl -early-cse
> Target Data Layout
> No Alias Analysis (always returns 'may' alias)
> Type-Based Alias Analysis
> Basic Alias Analysis (stateless AA impl)
>  ModulePass Manager
>    FunctionPass Manager
>      Simplify the CFG
>      Dominator Tree Construction
>      Scalar Replacement of Aggregates (DT)
>      Early CSE
> 
> In the future, it would be a good idea to compare -debug-pass=Structure output when making changes that are supposed to preserve existing behavior. It would also be good to check that clang still includes these passes.

Hi Cameron,

What behavior are you saying that I'm changing here?  "opt" has a bunch of different codepaths.

-Chris

> 
> Cameron
> 
> On May 21, 2011, at 5:21 PM, Chris Lattner wrote:
> 
>> Author: lattner
>> Date: Sat May 21 19:21:33 2011
>> New Revision: 131824
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=131824&view=rev
>> Log:
>> switch opt to using PassManagerBuilder.h
>> 
>> Modified:
>>   llvm/trunk/tools/opt/opt.cpp
>> 
>> Modified: llvm/trunk/tools/opt/opt.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=131824&r1=131823&r2=131824&view=diff
>> ==============================================================================
>> --- llvm/trunk/tools/opt/opt.cpp (original)
>> +++ llvm/trunk/tools/opt/opt.cpp Sat May 21 19:21:33 2011
>> @@ -35,7 +35,7 @@
>> #include "llvm/Support/ManagedStatic.h"
>> #include "llvm/Support/PluginLoader.h"
>> #include "llvm/Support/PrettyStackTrace.h"
>> -#include "llvm/Support/StandardPasses.h"
>> +#include "llvm/Support/PassManagerBuilder.h"
>> #include "llvm/Support/SystemUtils.h"
>> #include "llvm/Support/ToolOutputFile.h"
>> #include "llvm/LinkAllPasses.h"
>> @@ -387,10 +387,12 @@
>>    AU.setPreservesAll();
>>  }
>> };
>> + 
>> +} // anonymous namespace
>> 
>> char BreakpointPrinter::ID = 0;
>> 
>> -inline void addPass(PassManagerBase &PM, Pass *P) {
>> +static inline void addPass(PassManagerBase &PM, Pass *P) {
>>  // Add the pass to the pass manager...
>>  PM.add(P);
>> 
>> @@ -403,31 +405,30 @@
>> /// duplicates llvm-gcc behaviour.
>> ///
>> /// OptLevel - Optimization Level
>> -void AddOptimizationPasses(PassManagerBase &MPM, PassManagerBase &FPM,
>> -                           unsigned OptLevel) {
>> -  createStandardFunctionPasses(&FPM, OptLevel);
>> +static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
>> +                                  unsigned OptLevel) {
>> +  PassManagerBuilder Builder;
>> +  Builder.OptLevel = OptLevel;
>> 
>> -  llvm::Pass *InliningPass = 0;
>>  if (DisableInline) {
>>    // No inlining pass
>>  } else if (OptLevel) {
>>    unsigned Threshold = 225;
>>    if (OptLevel > 2)
>>      Threshold = 275;
>> -    InliningPass = createFunctionInliningPass(Threshold);
>> +    Builder.Inliner = createFunctionInliningPass(Threshold);
>>  } else {
>> -    InliningPass = createAlwaysInlinerPass();
>> +    Builder.Inliner = createAlwaysInlinerPass();
>>  }
>> -  createStandardModulePasses(&MPM, OptLevel,
>> -                             /*OptimizeSize=*/ false,
>> -                             UnitAtATime,
>> -                             /*UnrollLoops=*/ OptLevel > 1,
>> -                             !DisableSimplifyLibCalls,
>> -                             /*HaveExceptions=*/ true,
>> -                             InliningPass);
>> +  Builder.DisableUnitAtATime = !UnitAtATime;
>> +  Builder.DisableUnrollLoops = OptLevel == 0;
>> +  Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
>> +  
>> +  Builder.populateFunctionPassManager(FPM);
>> +  Builder.populateModulePassManager(MPM);
>> }
>> 
>> -void AddStandardCompilePasses(PassManagerBase &PM) {
>> +static void AddStandardCompilePasses(PassManagerBase &PM) {
>>  PM.add(createVerifierPass());                  // Verify that input is correct
>> 
>>  addPass(PM, createLowerSetJmpPass());          // Lower llvm.setjmp/.longjmp
>> @@ -438,19 +439,16 @@
>> 
>>  if (DisableOptimizations) return;
>> 
>> -  llvm::Pass *InliningPass = !DisableInline ? createFunctionInliningPass() : 0;
>> -
>>  // -std-compile-opts adds the same module passes as -O3.
>> -  createStandardModulePasses(&PM, 3,
>> -                             /*OptimizeSize=*/ false,
>> -                             /*UnitAtATime=*/ true,
>> -                             /*UnrollLoops=*/ true,
>> -                             !DisableSimplifyLibCalls,
>> -                             /*HaveExceptions=*/ true,
>> -                             InliningPass);
>> +  PassManagerBuilder Builder;
>> +  if (!DisableInline)
>> +    Builder.Inliner = createFunctionInliningPass();
>> +  Builder.OptLevel = 3;
>> +  Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
>> +  Builder.populateModulePassManager(PM);
>> }
>> 
>> -void AddStandardLinkPasses(PassManagerBase &PM) {
>> +static void AddStandardLinkPasses(PassManagerBase &PM) {
>>  PM.add(createVerifierPass());                  // Verify that input is correct
>> 
>>  // If the -strip-debug command line option was specified, do it.
>> @@ -459,13 +457,11 @@
>> 
>>  if (DisableOptimizations) return;
>> 
>> -  createStandardLTOPasses(&PM, /*Internalize=*/ !DisableInternalize,
>> -                          /*RunInliner=*/ !DisableInline,
>> -                          /*VerifyEach=*/ VerifyEach);
>> +  PassManagerBuilder Builder;
>> +  Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
>> +                                 /*RunInliner=*/ !DisableInline);
>> }
>> 
>> -} // anonymous namespace
>> -
>> 
>> //===----------------------------------------------------------------------===//
>> // main for opt
>> @@ -566,9 +562,9 @@
>>  if (TD)
>>    Passes.add(TD);
>> 
>> -  OwningPtr<PassManager> FPasses;
>> +  OwningPtr<FunctionPassManager> FPasses;
>>  if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
>> -    FPasses.reset(new PassManager());
>> +    FPasses.reset(new FunctionPassManager(M.get()));
>>    if (TD)
>>      FPasses->add(new TargetData(*TD));
>>  }
>> @@ -687,7 +683,8 @@
>>    AddOptimizationPasses(Passes, *FPasses, 3);
>> 
>>  if (OptLevelO1 || OptLevelO2 || OptLevelO3)
>> -    FPasses->run(*M.get());
>> +    for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
>> +      FPasses->run(*F);
>> 
>>  // Check that the module is well formed on completion of optimization
>>  if (!NoVerify && !VerifyEach)
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list