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/Analysis/LazyCallGraph.h"
21 #include "llvm/Bitcode/BitcodeWriterPass.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;
34 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
35 tool_output_file *Out, StringRef PassPipeline,
36 OutputKind OK, VerifierKind VK) {
37 FunctionAnalysisManager FAM;
38 CGSCCAnalysisManager CGAM;
39 ModuleAnalysisManager MAM;
41 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
42 MAM.registerPass(CREATE_PASS);
43 #include "PassRegistry.def"
45 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
46 CGAM.registerPass(CREATE_PASS);
47 #include "PassRegistry.def"
49 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
50 FAM.registerPass(CREATE_PASS);
51 #include "PassRegistry.def"
53 // Cross register the analysis managers through their proxies.
54 MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
55 MAM.registerPass(CGSCCAnalysisManagerModuleProxy(CGAM));
56 CGAM.registerPass(FunctionAnalysisManagerCGSCCProxy(FAM));
57 CGAM.registerPass(ModuleAnalysisManagerCGSCCProxy(MAM));
58 FAM.registerPass(CGSCCAnalysisManagerFunctionProxy(CGAM));
59 FAM.registerPass(ModuleAnalysisManagerFunctionProxy(MAM));
61 ModulePassManager MPM;
62 if (VK > VK_NoVerifier)
63 MPM.addPass(VerifierPass());
65 if (!parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass)) {
66 errs() << Arg0 << ": unable to parse pass pipeline description.\n";
70 if (VK > VK_NoVerifier)
71 MPM.addPass(VerifierPass());
73 // Add any relevant output pass at the end of the pipeline.
76 break; // No output pass needed.
77 case OK_OutputAssembly:
78 MPM.addPass(PrintModulePass(Out->os()));
80 case OK_OutputBitcode:
81 MPM.addPass(BitcodeWriterPass(Out->os()));
85 // Before executing passes, print the final values of the LLVM options.
86 cl::PrintOptionValues();
88 // Now that we have all of the passes ready, run them.
92 if (OK != OK_NoOutput)