Changeset View
Changeset View
Standalone View
Standalone View
llvm/tools/opt/opt.cpp
Show All 33 Lines | |||||
#include "llvm/IR/ModuleSummaryIndex.h" | #include "llvm/IR/ModuleSummaryIndex.h" | ||||
#include "llvm/IR/Verifier.h" | #include "llvm/IR/Verifier.h" | ||||
#include "llvm/IRReader/IRReader.h" | #include "llvm/IRReader/IRReader.h" | ||||
#include "llvm/InitializePasses.h" | #include "llvm/InitializePasses.h" | ||||
#include "llvm/LinkAllIR.h" | #include "llvm/LinkAllIR.h" | ||||
#include "llvm/LinkAllPasses.h" | #include "llvm/LinkAllPasses.h" | ||||
#include "llvm/MC/SubtargetFeature.h" | #include "llvm/MC/SubtargetFeature.h" | ||||
#include "llvm/MC/TargetRegistry.h" | #include "llvm/MC/TargetRegistry.h" | ||||
#include "llvm/Passes/PassPlugin.h" | #include "llvm/Passes/PassPluginLoader.h" | ||||
#include "llvm/Passes/PassPluginRegistry.h" | |||||
#include "llvm/Remarks/HotnessThresholdParser.h" | #include "llvm/Remarks/HotnessThresholdParser.h" | ||||
#include "llvm/Support/Debug.h" | #include "llvm/Support/Debug.h" | ||||
#include "llvm/Support/FileSystem.h" | #include "llvm/Support/FileSystem.h" | ||||
#include "llvm/Support/Host.h" | #include "llvm/Support/Host.h" | ||||
#include "llvm/Support/InitLLVM.h" | #include "llvm/Support/InitLLVM.h" | ||||
#include "llvm/Support/PluginLoader.h" | #include "llvm/Support/PluginLoader.h" | ||||
#include "llvm/Support/SourceMgr.h" | #include "llvm/Support/SourceMgr.h" | ||||
#include "llvm/Support/SystemUtils.h" | #include "llvm/Support/SystemUtils.h" | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | RemarksPasses("pass-remarks-filter", | ||||
"names match the given regular expression"), | "names match the given regular expression"), | ||||
cl::value_desc("regex")); | cl::value_desc("regex")); | ||||
static cl::opt<std::string> RemarksFormat( | static cl::opt<std::string> RemarksFormat( | ||||
"pass-remarks-format", | "pass-remarks-format", | ||||
cl::desc("The format used for serializing remarks (default: YAML)"), | cl::desc("The format used for serializing remarks (default: YAML)"), | ||||
cl::value_desc("format"), cl::init("yaml")); | cl::value_desc("format"), cl::init("yaml")); | ||||
static cl::list<std::string> | |||||
PassPlugins("load-pass-plugin", | |||||
cl::desc("Load passes from plugin library")); | |||||
namespace llvm { | namespace llvm { | ||||
cl::opt<PGOKind> | cl::opt<PGOKind> | ||||
PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden, | PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden, | ||||
cl::desc("The kind of profile guided optimization"), | cl::desc("The kind of profile guided optimization"), | ||||
cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."), | cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."), | ||||
clEnumValN(InstrGen, "pgo-instr-gen-pipeline", | clEnumValN(InstrGen, "pgo-instr-gen-pipeline", | ||||
"Instrument the IR to generate profile."), | "Instrument the IR to generate profile."), | ||||
clEnumValN(InstrUse, "pgo-instr-use-pipeline", | clEnumValN(InstrUse, "pgo-instr-use-pipeline", | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | int main(int argc, char **argv) { | ||||
initializeTypePromotionPass(Registry); | initializeTypePromotionPass(Registry); | ||||
initializeReplaceWithVeclibLegacyPass(Registry); | initializeReplaceWithVeclibLegacyPass(Registry); | ||||
initializeJMCInstrumenterPass(Registry); | initializeJMCInstrumenterPass(Registry); | ||||
#ifdef BUILD_EXAMPLES | #ifdef BUILD_EXAMPLES | ||||
initializeExampleIRTransforms(Registry); | initializeExampleIRTransforms(Registry); | ||||
#endif | #endif | ||||
SmallVector<PassPlugin, 1> PluginList; | |||||
PassPlugins.setCallback([&](const std::string &PluginPath) { | |||||
auto Plugin = PassPlugin::Load(PluginPath); | |||||
if (!Plugin) { | |||||
errs() << "Failed to load passes from '" << PluginPath | |||||
<< "'. Request ignored.\n"; | |||||
return; | |||||
} | |||||
PluginList.emplace_back(Plugin.get()); | |||||
}); | |||||
cl::ParseCommandLineOptions(argc, argv, | cl::ParseCommandLineOptions(argc, argv, | ||||
"llvm .bc -> .bc modular optimizer and analysis printer\n"); | "llvm .bc -> .bc modular optimizer and analysis printer\n"); | ||||
LLVMContext Context; | LLVMContext Context; | ||||
// If `-passes=` is specified, use NPM. | // If `-passes=` is specified, use NPM. | ||||
// If `-enable-new-pm` is specified and there are no codegen passes, use NPM. | // If `-enable-new-pm` is specified and there are no codegen passes, use NPM. | ||||
// e.g. `-enable-new-pm -sroa` will use NPM. | // e.g. `-enable-new-pm -sroa` will use NPM. | ||||
// but `-enable-new-pm -codegenprepare` will still revert to legacy PM. | // but `-enable-new-pm -codegenprepare` will still revert to legacy PM. | ||||
const bool UseNPM = (EnableNewPassManager && !shouldForceLegacyPM()) || | const bool UseNPM = (EnableNewPassManager && !shouldForceLegacyPM()) || | ||||
PassPipeline.getNumOccurrences() > 0; | PassPipeline.getNumOccurrences() > 0; | ||||
if (!UseNPM && PluginList.size()) { | if (!UseNPM && PassPluginRegistry::getPlugins().size()) { | ||||
errs() << argv[0] << ": " << PassPlugins.ArgStr | errs() << argv[0] << ": " << PassPlugins.ArgStr | ||||
<< " specified with legacy PM.\n"; | << " specified with legacy PM.\n"; | ||||
return 1; | return 1; | ||||
} | } | ||||
// FIXME: once the legacy PM code is deleted, move runPassPipeline() here and | // FIXME: once the legacy PM code is deleted, move runPassPipeline() here and | ||||
// construct the PassBuilder before parsing IR so we can reuse the same | // construct the PassBuilder before parsing IR so we can reuse the same | ||||
// PassBuilder for print passes. | // PassBuilder for print passes. | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | if (UseNPM) { | ||||
else if (VerifyEach) | else if (VerifyEach) | ||||
VK = VK_VerifyEachPass; | VK = VK_VerifyEachPass; | ||||
// The user has asked to use the new pass manager and provided a pipeline | // The user has asked to use the new pass manager and provided a pipeline | ||||
// string. Hand off the rest of the functionality to the new code for that | // string. Hand off the rest of the functionality to the new code for that | ||||
// layer. | // layer. | ||||
return runPassPipeline(argv[0], *M, TM.get(), &TLII, Out.get(), | return runPassPipeline(argv[0], *M, TM.get(), &TLII, Out.get(), | ||||
ThinLinkOut.get(), RemarksFile.get(), Pipeline, | ThinLinkOut.get(), RemarksFile.get(), Pipeline, | ||||
Passes, PluginList, OK, VK, PreserveAssemblyUseListOrder, | Passes, OK, VK, PreserveAssemblyUseListOrder, | ||||
PreserveBitcodeUseListOrder, EmitSummaryIndex, | PreserveBitcodeUseListOrder, EmitSummaryIndex, | ||||
EmitModuleHash, EnableDebugify, | EmitModuleHash, EnableDebugify, | ||||
VerifyDebugInfoPreserve) | VerifyDebugInfoPreserve) | ||||
? 0 | ? 0 | ||||
: 1; | : 1; | ||||
} | } | ||||
// Create a PassManager to hold and optimize the collection of passes we are | // Create a PassManager to hold and optimize the collection of passes we are | ||||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |