1 //===- NewPMDriver.cpp - Driver for opt with new PM -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file is just a split of the code that logically belongs in opt.cpp but
12 /// that includes the new pass manager headers.
14 //===----------------------------------------------------------------------===//
16 #include "NewPMDriver.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Analysis/CGSCCPassManager.h"
20 #include "llvm/Bitcode/BitcodeWriterPass.h"
21 #include "llvm/IR/Dominators.h"
22 #include "llvm/IR/IRPrintingPasses.h"
23 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/IR/PassManager.h"
26 #include "llvm/IR/Verifier.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/ToolOutputFile.h"
32 using namespace opt_tool;
35 DebugPM("debug-pass-manager", cl::Hidden,
36 cl::desc("Print pass management debugging information"));
38 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
39 tool_output_file *Out, StringRef PassPipeline,
40 OutputKind OK, VerifierKind VK) {
41 FunctionAnalysisManager FAM(DebugPM);
42 CGSCCAnalysisManager CGAM(DebugPM);
43 ModuleAnalysisManager MAM(DebugPM);
45 // Register all the basic analyses with the managers.
46 registerModuleAnalyses(MAM);
47 registerCGSCCAnalyses(CGAM);
48 registerFunctionAnalyses(FAM);
50 // Cross register the analysis managers through their proxies.
51 MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
52 MAM.registerPass(CGSCCAnalysisManagerModuleProxy(CGAM));
53 CGAM.registerPass(FunctionAnalysisManagerCGSCCProxy(FAM));
54 CGAM.registerPass(ModuleAnalysisManagerCGSCCProxy(MAM));
55 FAM.registerPass(CGSCCAnalysisManagerFunctionProxy(CGAM));
56 FAM.registerPass(ModuleAnalysisManagerFunctionProxy(MAM));
58 ModulePassManager MPM(DebugPM);
59 if (VK > VK_NoVerifier)
60 MPM.addPass(VerifierPass());
62 if (!parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass, DebugPM)) {
63 errs() << Arg0 << ": unable to parse pass pipeline description.\n";
67 if (VK > VK_NoVerifier)
68 MPM.addPass(VerifierPass());
70 // Add any relevant output pass at the end of the pipeline.
73 break; // No output pass needed.
74 case OK_OutputAssembly:
75 MPM.addPass(PrintModulePass(Out->os()));
77 case OK_OutputBitcode:
78 MPM.addPass(BitcodeWriterPass(Out->os()));
82 // Before executing passes, print the final values of the LLVM options.
83 cl::PrintOptionValues();
85 // Now that we have all of the passes ready, run them.
89 if (OK != OK_NoOutput)