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
25namespace llvm {
26class LLVMContext;
27class PassBuilder;
28class StringRef;
29struct PassPluginLibraryInfo;
30class Module;
31class TargetMachine;
32class ToolOutputFile;
33class TargetLibraryInfoImpl;
34
35extern cl::opt<bool> DebugifyEach;
36extern cl::opt<std::string> DebugifyExport;
37
38extern cl::opt<bool> VerifyEachDebugInfoPreserve;
39extern cl::opt<std::string> VerifyDIPreserveExport;
40
41namespace opt_tool {
42enum OutputKind {
43 OK_NoOutput,
44 OK_OutputAssembly,
45 OK_OutputBitcode,
46 OK_OutputThinLTOBitcode,
47};
48enum class VerifierKind { None, InputOutput, EachPass };
49enum PGOKind {
50 NoPGO,
51 InstrGen,
52 InstrUse,
53 SampleUse
54};
55enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
56} // namespace opt_tool
57
58void printPasses(LLVMContext &Context, raw_ostream &OS);
59
60/// Driver function to run the new pass manager over a module.
61///
62/// This function only exists factored away from opt.cpp in order to prevent
63/// inclusion of the new pass manager headers and the old headers into the same
64/// file. It's interface is consequentially somewhat ad-hoc, but will go away
65/// when the transition finishes.
66///
67/// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
68/// nullptr.
69bool runPassPipeline(
70 StringRef Arg0, Module &M, TargetMachine *TM, TargetLibraryInfoImpl *TLII,
71 ToolOutputFile *Out, ToolOutputFile *ThinLinkOut,
72 ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
73 ArrayRef<PassPluginLibraryInfo> Extensions,
74 ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks,
75 opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
76 bool ShouldPreserveAssemblyUseListOrder,
77 bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
78 bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
79 bool EnableProfcheck, bool UnifiedLTO = false);
80} // namespace llvm
81
82#endif
83