xref: /freebsd/contrib/llvm-project/llvm/tools/opt/NewPMDriver.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 //===- NewPMDriver.h - Function to drive opt with the new PM ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// A single function which is called to drive the opt behavior for the new
11 /// PassManager.
12 ///
13 /// This is only in a separate TU with a header to avoid including all of the
14 /// old pass manager headers and the new pass manager headers into the same
15 /// file. Eventually all of the routines here will get folded back into
16 /// opt.cpp.
17 ///
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLVM_TOOLS_OPT_NEWPMDRIVER_H
21 #define LLVM_TOOLS_OPT_NEWPMDRIVER_H
22 
23 #include "llvm/Support/CommandLine.h"
24 
25 namespace llvm {
26 class PassBuilder;
27 class StringRef;
28 class Module;
29 class PassPlugin;
30 class TargetMachine;
31 class ToolOutputFile;
32 class TargetLibraryInfoImpl;
33 
34 extern cl::opt<bool> DebugifyEach;
35 extern cl::opt<std::string> DebugifyExport;
36 
37 extern cl::opt<bool> VerifyEachDebugInfoPreserve;
38 extern cl::opt<std::string> VerifyDIPreserveExport;
39 
40 namespace opt_tool {
41 enum OutputKind {
42   OK_NoOutput,
43   OK_OutputAssembly,
44   OK_OutputBitcode,
45   OK_OutputThinLTOBitcode,
46 };
47 enum VerifierKind { VK_NoVerifier, VK_VerifyOut, VK_VerifyEachPass };
48 enum PGOKind {
49   NoPGO,
50   InstrGen,
51   InstrUse,
52   SampleUse
53 };
54 enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
55 }
56 
57 void printPasses(raw_ostream &OS);
58 
59 /// Driver function to run the new pass manager over a module.
60 ///
61 /// This function only exists factored away from opt.cpp in order to prevent
62 /// inclusion of the new pass manager headers and the old headers into the same
63 /// file. It's interface is consequentially somewhat ad-hoc, but will go away
64 /// when the transition finishes.
65 ///
66 /// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
67 /// nullptr.
68 bool runPassPipeline(
69     StringRef Arg0, Module &M, TargetMachine *TM, TargetLibraryInfoImpl *TLII,
70     ToolOutputFile *Out, ToolOutputFile *ThinLinkOut,
71     ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
72     ArrayRef<PassPlugin> PassPlugins,
73     ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks,
74     opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
75     bool ShouldPreserveAssemblyUseListOrder,
76     bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
77     bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
78     bool UnifiedLTO = false);
79 } // namespace llvm
80 
81 #endif
82