本文整理汇总了C++中ModulePassManager类的典型用法代码示例。如果您正苦于以下问题:C++ ModulePassManager类的具体用法?C++ ModulePassManager怎么用?C++ ModulePassManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModulePassManager类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parsePassPipeline
// Primary pass pipeline description parsing routine.
// FIXME: Should this routine accept a TargetMachine or require the caller to
// pre-populate the analysis managers with target-specific stuff?
bool llvm::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
bool VerifyEachPass) {
// Look at the first entry to figure out which layer to start parsing at.
if (PipelineText.startswith("module("))
return parseModulePassPipeline(MPM, PipelineText, VerifyEachPass) &&
PipelineText.empty();
if (PipelineText.startswith("function(")) {
FunctionPassManager FPM;
if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass) ||
!PipelineText.empty())
return false;
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
return true;
}
// This isn't a direct pass manager name, look for the end of a pass name.
StringRef FirstName =
PipelineText.substr(0, PipelineText.find_first_of(",)"));
if (isModulePassName(FirstName))
return parseModulePassPipeline(MPM, PipelineText, VerifyEachPass) &&
PipelineText.empty();
if (isFunctionPassName(FirstName)) {
FunctionPassManager FPM;
if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass) ||
!PipelineText.empty())
return false;
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
return true;
}
return false;
}
示例2: parsePassPipeline
// Primary pass pipeline description parsing routine.
// FIXME: Should this routine accept a TargetMachine or require the caller to
// pre-populate the analysis managers with target-specific stuff?
bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
StringRef PipelineText, bool VerifyEachPass,
bool DebugLogging) {
// By default, try to parse the pipeline as-if it were within an implicit
// 'module(...)' pass pipeline. If this will parse at all, it needs to
// consume the entire string.
if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging))
return PipelineText.empty();
// This isn't parsable as a module pipeline, look for the end of a pass name
// and directly drop down to that layer.
StringRef FirstName =
PipelineText.substr(0, PipelineText.find_first_of(",)"));
assert(!isModulePassName(FirstName) &&
"Already handled all module pipeline options.");
// If this looks like a CGSCC pass, parse the whole thing as a CGSCC
// pipeline.
if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) {
CGSCCPassManager CGPM(DebugLogging);
if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass,
DebugLogging) ||
!PipelineText.empty())
return false;
MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
return true;
}
// Similarly, if this looks like a Function pass, parse the whole thing as
// a Function pipelien.
if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) {
FunctionPassManager FPM(DebugLogging);
if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass,
DebugLogging) ||
!PipelineText.empty())
return false;
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
return true;
}
// If this looks like a Loop pass, parse the whole thing as a Loop pipeline.
if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) {
LoopPassManager LPM(DebugLogging);
if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass,
DebugLogging) ||
!PipelineText.empty())
return false;
FunctionPassManager FPM(DebugLogging);
FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
return true;
}
return false;
}
示例3: parseModulePassPipeline
static bool parseModulePassPipeline(ModulePassManager &MPM,
StringRef &PipelineText,
bool VerifyEachPass) {
for (;;) {
// Parse nested pass managers by recursing.
if (PipelineText.startswith("module(")) {
ModulePassManager NestedMPM;
// Parse the inner pipeline into the nested manager.
PipelineText = PipelineText.substr(strlen("module("));
if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass) ||
PipelineText.empty())
return false;
assert(PipelineText[0] == ')');
PipelineText = PipelineText.substr(1);
// Now add the nested manager as a module pass.
MPM.addPass(std::move(NestedMPM));
} else if (PipelineText.startswith("function(")) {
FunctionPassManager NestedFPM;
// Parse the inner pipeline inte the nested manager.
PipelineText = PipelineText.substr(strlen("function("));
if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass) ||
PipelineText.empty())
return false;
assert(PipelineText[0] == ')');
PipelineText = PipelineText.substr(1);
// Add the nested pass manager with the appropriate adaptor.
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM)));
} else {
// Otherwise try to parse a pass name.
size_t End = PipelineText.find_first_of(",)");
if (!parseModulePassName(MPM, PipelineText.substr(0, End)))
return false;
if (VerifyEachPass)
MPM.addPass(VerifierPass());
PipelineText = PipelineText.substr(End);
}
if (PipelineText.empty() || PipelineText[0] == ')')
return true;
assert(PipelineText[0] == ',');
PipelineText = PipelineText.substr(1);
}
}
示例4: parseModulePassName
static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) {
if (Name == "no-op-module") {
MPM.addPass(NoOpModulePass());
return true;
}
if (Name == "print") {
MPM.addPass(PrintModulePass(dbgs()));
return true;
}
if (Name == "print-cg") {
MPM.addPass(LazyCallGraphPrinterPass(dbgs()));
return true;
}
return false;
}
示例5: addLTODefaultPipeline
void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM,
OptimizationLevel Level,
bool DebugLogging) {
// FIXME: Finish fleshing this out to match the legacy LTO pipelines.
FunctionPassManager LateFPM(DebugLogging);
LateFPM.addPass(InstCombinePass());
LateFPM.addPass(SimplifyCFGPass());
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
}
示例6: runNewCustomLtoPasses
static void runNewCustomLtoPasses(Module &M, TargetMachine &TM) {
PassBuilder PB(&TM);
AAManager AA;
// Parse a custom AA pipeline if asked to.
if (!PB.parseAAPipeline(AA, Config->LtoAAPipeline)) {
error("Unable to parse AA pipeline description: " + Config->LtoAAPipeline);
return;
}
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });
// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
ModulePassManager MPM;
if (!Config->DisableVerify)
MPM.addPass(VerifierPass());
// Now, add all the passes we've been requested to.
if (!PB.parsePassPipeline(MPM, Config->LtoNewPmPasses)) {
error("unable to parse pass pipeline description: " +
Config->LtoNewPmPasses);
return;
}
if (!Config->DisableVerify)
MPM.addPass(VerifierPass());
MPM.run(M, MAM);
}
示例7: addPerModuleDefaultPipeline
void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM,
OptimizationLevel Level,
bool DebugLogging) {
// FIXME: Finish fleshing this out to match the legacy pipelines.
FunctionPassManager EarlyFPM(DebugLogging);
EarlyFPM.addPass(SimplifyCFGPass());
EarlyFPM.addPass(SROA());
EarlyFPM.addPass(EarlyCSEPass());
EarlyFPM.addPass(LowerExpectIntrinsicPass());
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
}
示例8: runPassPipeline
bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
tool_output_file *Out, StringRef PassPipeline,
OutputKind OK, VerifierKind VK) {
FunctionAnalysisManager FAM;
ModuleAnalysisManager MAM;
// FIXME: Lift this registration of analysis passes into a .def file adjacent
// to the one used to associate names with passes.
MAM.registerPass(LazyCallGraphAnalysis());
// Cross register the analysis managers through their proxies.
MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
FAM.registerPass(ModuleAnalysisManagerFunctionProxy(MAM));
ModulePassManager MPM;
if (VK > VK_NoVerifier)
MPM.addPass(VerifierPass());
if (!parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass)) {
errs() << Arg0 << ": unable to parse pass pipeline description.\n";
return false;
}
if (VK > VK_NoVerifier)
MPM.addPass(VerifierPass());
// Add any relevant output pass at the end of the pipeline.
switch (OK) {
case OK_NoOutput:
break; // No output pass needed.
case OK_OutputAssembly:
MPM.addPass(PrintModulePass(Out->os()));
break;
case OK_OutputBitcode:
MPM.addPass(BitcodeWriterPass(Out->os()));
break;
}
// Before executing passes, print the final values of the LLVM options.
cl::PrintOptionValues();
// Now that we have all of the passes ready, run them.
MPM.run(&M, &MAM);
// Declare success.
if (OK != OK_NoOutput)
Out->keep();
return true;
}
示例9: Region
/// A clean version of `EmitAssembly` that uses the new pass manager.
///
/// Not all features are currently supported in this system, but where
/// necessary it falls back to the legacy pass manager to at least provide
/// basic functionality.
///
/// This API is planned to have its functionality finished and then to replace
/// `EmitAssembly` at some point in the future when the default switches.
void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) {
TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : nullptr);
setCommandLineOpts();
// The new pass manager always makes a target machine available to passes
// during construction.
CreateTargetMachine(/*MustCreateTM*/ true);
if (!TM)
// This will already be diagnosed, just bail.
return;
TheModule->setDataLayout(TM->createDataLayout());
PassBuilder PB(TM.get());
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); });
// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
ModulePassManager MPM;
if (!CodeGenOpts.DisableLLVMPasses) {
if (CodeGenOpts.OptimizationLevel == 0) {
// Build a minimal pipeline based on the semantics required by Clang,
// which is just that always inlining occurs.
MPM.addPass(AlwaysInlinerPass());
} else {
// Otherwise, use the default pass pipeline. We also have to map our
// optimization levels into one of the distinct levels used to configure
// the pipeline.
PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
MPM = PB.buildPerModuleDefaultPipeline(Level);
}
}
// FIXME: We still use the legacy pass manager to do code generation. We
// create that pass manager here and use it as needed below.
legacy::PassManager CodeGenPasses;
bool NeedCodeGen = false;
// Append any output we need to the pass manager.
switch (Action) {
case Backend_EmitNothing:
break;
case Backend_EmitBC:
MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
CodeGenOpts.EmitSummaryIndex,
CodeGenOpts.EmitSummaryIndex));
break;
case Backend_EmitLL:
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists));
break;
case Backend_EmitAssembly:
case Backend_EmitMCNull:
case Backend_EmitObj:
NeedCodeGen = true;
CodeGenPasses.add(
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
if (!AddEmitPasses(CodeGenPasses, Action, *OS))
// FIXME: Should we handle this error differently?
return;
break;
}
// Before executing passes, print the final values of the LLVM options.
cl::PrintOptionValues();
// Now that we have all of the passes ready, run them.
{
PrettyStackTraceString CrashInfo("Optimizer");
MPM.run(*TheModule, MAM);
}
// Now if needed, run the legacy PM for codegen.
if (NeedCodeGen) {
PrettyStackTraceString CrashInfo("Code generation");
CodeGenPasses.run(*TheModule);
//.........这里部分代码省略.........