llvm.org GIT mirror llvm / 7b4eb02
Move some logic to populateLTOPassManager. This will avoid code duplication in the next commit which calls it directly from the gold plugin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216211 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
4 changed file(s) with 58 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
1919 namespace llvm {
2020 class Pass;
2121 class TargetLibraryInfo;
22 class TargetMachine;
2223
2324 // The old pass manager infrastructure is hidden in a legacy namespace now.
2425 namespace legacy {
118119 bool RerollLoops;
119120 bool LoadCombine;
120121 bool DisableGVNLoadPRE;
122 bool VerifyInput;
123 bool VerifyOutput;
124 bool StripDebug;
121125
122126 private:
123127 /// ExtensionList - This is list of all of the extensions that are registered.
135139 private:
136140 void addExtensionsToPM(ExtensionPointTy ETy, PassManagerBase &PM) const;
137141 void addInitialAliasAnalysisPasses(PassManagerBase &PM) const;
142 void addLTOOptimizationPasses(PassManagerBase &PM);
138143
139144 public:
140145 /// populateFunctionPassManager - This fills in the function pass manager,
144149
145150 /// populateModulePassManager - This sets up the primary pass manager.
146151 void populateModulePassManager(PassManagerBase &MPM);
147 void populateLTOPassManager(PassManagerBase &PM);
152 void populateLTOPassManager(PassManagerBase &PM, TargetMachine *TM = nullptr);
148153 };
149154
150155 /// Registers a function for adding a standard set of passes. This should be
457457 // Instantiate the pass manager to organize the passes.
458458 PassManager passes;
459459
460 // Start off with a verification pass.
461 passes.add(createVerifierPass());
462 passes.add(createDebugInfoVerifierPass());
463
464460 // Add an appropriate DataLayout instance for this module...
465461 mergedModule->setDataLayout(TargetMach->getSubtargetImpl()->getDataLayout());
466 passes.add(new DataLayoutPass(mergedModule));
467
468 TargetMach->addAnalysisPasses(passes);
469462
470463 Triple TargetTriple(TargetMach->getTargetTriple());
471 // Enabling internalize here would use its AllButMain variant. It
472 // keeps only main if it exists and does nothing for libraries. Instead
473 // we create the pass ourselves with the symbol list provided by the linker.
474 if (!DisableOpt) {
475 PassManagerBuilder PMB;
476 PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
477 if (!DisableInline)
478 PMB.Inliner = createFunctionInliningPass();
479 PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple);
480 PMB.populateLTOPassManager(passes);
481 }
482
483 // Make sure everything is still good.
484 passes.add(createVerifierPass());
485 passes.add(createDebugInfoVerifierPass());
464 PassManagerBuilder PMB;
465 PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
466 if (!DisableInline)
467 PMB.Inliner = createFunctionInliningPass();
468 PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple);
469 if (DisableOpt)
470 PMB.OptLevel = 0;
471 PMB.VerifyInput = true;
472 PMB.VerifyOutput = true;
473
474 PMB.populateLTOPassManager(passes, TargetMach);
486475
487476 PassManager codeGenPasses;
488477
1616 #include "llvm-c/Transforms/PassManagerBuilder.h"
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/Analysis/Passes.h"
19 #include "llvm/IR/DataLayout.h"
1920 #include "llvm/IR/Verifier.h"
2021 #include "llvm/PassManager.h"
2122 #include "llvm/Support/CommandLine.h"
2223 #include "llvm/Support/ManagedStatic.h"
2324 #include "llvm/Target/TargetLibraryInfo.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetSubtargetInfo.h"
2427 #include "llvm/Transforms/IPO.h"
2528 #include "llvm/Transforms/Scalar.h"
2629 #include "llvm/Transforms/Vectorize.h"
7780 RerollLoops = RunLoopRerolling;
7881 LoadCombine = RunLoadCombine;
7982 DisableGVNLoadPRE = false;
83 VerifyInput = false;
84 VerifyOutput = false;
85 StripDebug = false;
8086 }
8187
8288 PassManagerBuilder::~PassManagerBuilder() {
312318 addExtensionsToPM(EP_OptimizerLast, MPM);
313319 }
314320
315 void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM) {
316 // Add LibraryInfo if we have some.
317 if (LibraryInfo)
318 PM.add(new TargetLibraryInfo(*LibraryInfo));
319
321 void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) {
320322 // Provide AliasAnalysis services for optimizations.
321323 addInitialAliasAnalysisPasses(PM);
322324
407409 PM.add(createGlobalDCEPass());
408410 }
409411
412 void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
413 TargetMachine *TM) {
414 if (TM) {
415 const DataLayout *DL = TM->getSubtargetImpl()->getDataLayout();
416 PM.add(new DataLayoutPass(*DL));
417 TM->addAnalysisPasses(PM);
418 }
419
420 if (LibraryInfo)
421 PM.add(new TargetLibraryInfo(*LibraryInfo));
422
423 if (VerifyInput)
424 PM.add(createVerifierPass());
425
426 if (StripDebug)
427 PM.add(createStripSymbolsPass(true));
428
429 if (VerifyInput)
430 PM.add(createDebugInfoVerifierPass());
431
432 if (OptLevel != 0)
433 addLTOOptimizationPasses(PM);
434
435 if (VerifyOutput) {
436 PM.add(createVerifierPass());
437 PM.add(createDebugInfoVerifierPass());
438 }
439 }
440
410441 inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
411442 return reinterpret_cast(P);
412443 }
253253 }
254254
255255 static void AddStandardLinkPasses(PassManagerBase &PM) {
256 PM.add(createVerifierPass()); // Verify that input is correct
257
258 // If the -strip-debug command line option was specified, do it.
259 if (StripDebug)
260 addPass(PM, createStripSymbolsPass(true));
261
262 // Verify debug info only after it's (possibly) stripped.
263 PM.add(createDebugInfoVerifierPass());
264
265 if (DisableOptimizations) return;
266
267256 PassManagerBuilder Builder;
257 Builder.VerifyInput = true;
258 Builder.StripDebug = StripDebug;
259 if (DisableOptimizations)
260 Builder.OptLevel = 0;
261
268262 if (!DisableInline)
269263 Builder.Inliner = createFunctionInliningPass();
270264 Builder.populateLTOPassManager(PM);