本文整理汇总了C++中PassManagerBuilder类的典型用法代码示例。如果您正苦于以下问题:C++ PassManagerBuilder类的具体用法?C++ PassManagerBuilder怎么用?C++ PassManagerBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PassManagerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LLVMPassManagerBuilderPopulateModulePassManager
void
LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
LLVMPassManagerRef PM) {
PassManagerBuilder *Builder = unwrap(PMB);
legacy::PassManagerBase *MPM = unwrap(PM);
Builder->populateModulePassManager(*MPM);
}
示例2: LLVMPassManagerBuilderPopulateFunctionPassManager
void
LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB,
LLVMPassManagerRef PM) {
PassManagerBuilder *Builder = unwrap(PMB);
legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
Builder->populateFunctionPassManager(*FPM);
}
示例3: AddOptimizationPasses
/// AddOptimizationPasses - This routine adds optimization passes
/// based on selected optimization level, OptLevel. This routine
/// duplicates llvm-gcc behaviour.
///
/// OptLevel - Optimization Level
static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
unsigned OptLevel, unsigned SizeLevel) {
FPM.add(createVerifierPass()); // Verify that input is correct
PassManagerBuilder Builder;
Builder.OptLevel = OptLevel;
Builder.SizeLevel = SizeLevel;
if (DisableInline) {
// No inlining pass
} else if (OptLevel > 1) {
unsigned Threshold = 225;
if (SizeLevel == 1) // -Os
Threshold = 75;
else if (SizeLevel == 2) // -Oz
Threshold = 25;
if (OptLevel > 2)
Threshold = 275;
Builder.Inliner = createFunctionInliningPass(Threshold);
} else {
Builder.Inliner = createAlwaysInlinerPass();
}
Builder.DisableUnitAtATime = !UnitAtATime;
Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ?
DisableLoopUnrolling : OptLevel == 0;
Builder.LoopVectorize =
DisableLoopVectorization ? false : OptLevel > 1 && SizeLevel < 2;
Builder.SLPVectorize =
DisableSLPVectorization ? false : OptLevel > 1 && SizeLevel < 2;
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
示例4: AddOptimizationPasses
/// This routine adds optimization passes based on selected optimization level,
/// OptLevel.
///
/// OptLevel - Optimization Level
static void AddOptimizationPasses(legacy::PassManagerBase &MPM,
legacy::FunctionPassManager &FPM,
unsigned OptLevel, unsigned SizeLevel) {
if (!NoVerify || VerifyEach)
FPM.add(createVerifierPass()); // Verify that input is correct
PassManagerBuilder Builder;
Builder.OptLevel = OptLevel;
Builder.SizeLevel = SizeLevel;
if (DisableInline) {
// No inlining pass
} else if (OptLevel > 1) {
Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel);
} else {
Builder.Inliner = createAlwaysInlinerPass();
}
Builder.DisableUnitAtATime = !UnitAtATime;
Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ?
DisableLoopUnrolling : OptLevel == 0;
// This is final, unless there is a #pragma vectorize enable
if (DisableLoopVectorization)
Builder.LoopVectorize = false;
// If option wasn't forced via cmd line (-vectorize-loops, -loop-vectorize)
else if (!Builder.LoopVectorize)
Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2;
// When #pragma vectorize is on for SLP, do the same as above
Builder.SLPVectorize =
DisableSLPVectorization ? false : OptLevel > 1 && SizeLevel < 2;
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
示例5: TargetTriple
/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
bool DisableOpt,
bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization,
std::string &errMsg) {
if (!this->determineTarget(errMsg))
return false;
Module *mergedModule = IRLinker.getModule();
// Mark which symbols can not be internalized
this->applyScopeRestrictions();
// Instantiate the pass manager to organize the passes.
PassManager passes;
// Add an appropriate DataLayout instance for this module...
mergedModule->setDataLayout(TargetMach->getSubtargetImpl()->getDataLayout());
Triple TargetTriple(TargetMach->getTargetTriple());
PassManagerBuilder PMB;
PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
PMB.LoopVectorize = !DisableVectorization;
PMB.SLPVectorize = !DisableVectorization;
if (!DisableInline)
PMB.Inliner = createFunctionInliningPass();
PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple);
if (DisableOpt)
PMB.OptLevel = 0;
PMB.VerifyInput = true;
PMB.VerifyOutput = true;
PMB.populateLTOPassManager(passes, TargetMach);
PassManager codeGenPasses;
codeGenPasses.add(new DataLayoutPass());
formatted_raw_ostream Out(out);
// If the bitcode files contain ARC code and were compiled with optimization,
// the ObjCARCContractPass must be run, so do it unconditionally here.
codeGenPasses.add(createObjCARCContractPass());
if (TargetMach->addPassesToEmitFile(codeGenPasses, Out,
TargetMachine::CGFT_ObjectFile)) {
errMsg = "target file type not supported";
return false;
}
// Run our queue of passes all at once now, efficiently.
passes.run(*mergedModule);
// Run the code generator, and write assembly file
codeGenPasses.run(*mergedModule);
return true;
}
示例6: getOptLevel
void AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
Builder.DivergentTarget = true;
bool EnableOpt = getOptLevel() > CodeGenOpt::None;
bool Internalize = InternalizeSymbols;
bool EarlyInline = EarlyInlineAll && EnableOpt && !EnableFunctionCalls;
bool AMDGPUAA = EnableAMDGPUAliasAnalysis && EnableOpt;
bool LibCallSimplify = EnableLibCallSimplify && EnableOpt;
if (EnableFunctionCalls) {
delete Builder.Inliner;
Builder.Inliner = createAMDGPUFunctionInliningPass();
}
Builder.addExtension(
PassManagerBuilder::EP_ModuleOptimizerEarly,
[Internalize, EarlyInline, AMDGPUAA](const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
if (AMDGPUAA) {
PM.add(createAMDGPUAAWrapperPass());
PM.add(createAMDGPUExternalAAWrapperPass());
}
PM.add(createAMDGPUUnifyMetadataPass());
if (Internalize) {
PM.add(createInternalizePass(mustPreserveGV));
PM.add(createGlobalDCEPass());
}
if (EarlyInline)
PM.add(createAMDGPUAlwaysInlinePass(false));
});
const auto &Opt = Options;
Builder.addExtension(
PassManagerBuilder::EP_EarlyAsPossible,
[AMDGPUAA, LibCallSimplify, &Opt](const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
if (AMDGPUAA) {
PM.add(createAMDGPUAAWrapperPass());
PM.add(createAMDGPUExternalAAWrapperPass());
}
PM.add(llvm::createAMDGPUUseNativeCallsPass());
if (LibCallSimplify)
PM.add(llvm::createAMDGPUSimplifyLibCallsPass(Opt));
});
Builder.addExtension(
PassManagerBuilder::EP_CGSCCOptimizerLate,
[](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
// Add infer address spaces pass to the opt pipeline after inlining
// but before SROA to increase SROA opportunities.
PM.add(createInferAddressSpacesPass());
// This should run after inlining to have any chance of doing anything,
// and before other cleanup optimizations.
PM.add(createAMDGPULowerKernelAttributesPass());
});
}
示例7: AddStandardLinkPasses
static void AddStandardLinkPasses(legacy::PassManagerBase &PM) {
PassManagerBuilder Builder;
Builder.VerifyInput = true;
if (DisableOptimizations)
Builder.OptLevel = 0;
if (!DisableInline)
Builder.Inliner = createFunctionInliningPass();
Builder.populateLTOPassManager(PM);
}
示例8: runLTOPasses
static void runLTOPasses(Module &M, TargetMachine &TM) {
PassManager passes;
PassManagerBuilder PMB;
PMB.LibraryInfo = new TargetLibraryInfo(Triple(TM.getTargetTriple()));
PMB.Inliner = createFunctionInliningPass();
PMB.VerifyInput = true;
PMB.VerifyOutput = true;
PMB.populateLTOPassManager(passes, &TM);
passes.run(M);
}
示例9: LLVMZigOptimizeModule
void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref) {
TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref);
Module* module = unwrap(module_ref);
TargetLibraryInfoImpl tlii(Triple(module->getTargetTriple()));
PassManagerBuilder *PMBuilder = new PassManagerBuilder();
PMBuilder->OptLevel = target_machine->getOptLevel();
PMBuilder->SizeLevel = 0;
PMBuilder->BBVectorize = true;
PMBuilder->SLPVectorize = true;
PMBuilder->LoopVectorize = true;
PMBuilder->DisableUnitAtATime = false;
PMBuilder->DisableUnrollLoops = false;
PMBuilder->MergeFunctions = true;
PMBuilder->PrepareForLTO = true;
PMBuilder->RerollLoops = true;
PMBuilder->addExtension(PassManagerBuilder::EP_EarlyAsPossible, addAddDiscriminatorsPass);
PMBuilder->LibraryInfo = &tlii;
PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel);
// Set up the per-function pass manager.
legacy::FunctionPassManager *FPM = new legacy::FunctionPassManager(module);
FPM->add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis()));
#ifndef NDEBUG
bool verify_module = true;
#else
bool verify_module = false;
#endif
if (verify_module) {
FPM->add(createVerifierPass());
}
PMBuilder->populateFunctionPassManager(*FPM);
// Set up the per-module pass manager.
legacy::PassManager *MPM = new legacy::PassManager();
MPM->add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis()));
PMBuilder->populateModulePassManager(*MPM);
// run per function optimization passes
FPM->doInitialization();
for (Function &F : *module)
if (!F.isDeclaration())
FPM->run(F);
FPM->doFinalization();
// run per module optimization passes
MPM->run(*module);
}
示例10: getBuilder
static PassManagerBuilder getBuilder() {
PassManagerBuilder Builder;
Builder.VerifyInput = false;
Builder.VerifyOutput = false;
Builder.OptLevel = 3;
Builder.addGlobalExtension(PassManagerBuilder::EP_EarlyAsPossible,
registerPolly);
return Builder;
}
示例11: llvmutil_extractmodule
Module * llvmutil_extractmodule(Module * OrigMod, TargetMachine * TM, std::vector<llvm::GlobalValue*> * livevalues, std::vector<std::string> * symbolnames, bool internalizeandoptimize) {
assert(symbolnames == NULL || livevalues->size() == symbolnames->size());
ValueToValueMapTy VMap;
#if LLVM_VERSION >= 34
Module * M = llvmutil_extractmodulewithproperties(OrigMod->getModuleIdentifier(), OrigMod, (llvm::GlobalValue **)&(*livevalues)[0], livevalues->size(), AlwaysCopy, NULL, VMap);
#else
Module * M = CloneModule(OrigMod, VMap);
internalizeandoptimize = true; //we need to do this regardless of the input because it is the only way we can extract just the needed functions from the module
#endif
//rename values to symbolsnames
std::vector<const char *> names;
for(size_t i = 0; i < livevalues->size(); i++) {
GlobalValue * fn = cast<GlobalValue>(VMap[(*livevalues)[i]]);
const std::string & name = (*symbolnames)[i];
GlobalValue * gv = M->getNamedValue(name);
if(gv) { //if there is already a symbol with this name, rename it
gv->setName(Twine((*symbolnames)[i],"_renamed"));
}
fn->setName(name); //and set our function to this name
assert(fn->getName() == name);
names.push_back(name.c_str()); //internalize pass has weird interface, so we need to copy the names here
}
if (!internalizeandoptimize)
return M;
//at this point we run optimizations on the module
//first internalize all functions not mentioned in "names" using an internalize pass and then perform
//standard optimizations
PassManager MPM;
llvmutil_addtargetspecificpasses(&MPM, TM);
MPM.add(createVerifierPass()); //make sure we haven't messed stuff up yet
MPM.add(createInternalizePass(names));
MPM.add(createGlobalDCEPass()); //run this early since anything not in the table of exported functions is still in this module
//this will remove dead functions
PassManagerBuilder PMB;
PMB.OptLevel = 3;
PMB.SizeLevel = 0;
#if LLVM_VERSION >= 35
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
#endif
PMB.populateModulePassManager(MPM);
MPM.run(*M);
return M;
}
示例12: addCoroutinePassesToExtensionPoints
void llvm::addCoroutinePassesToExtensionPoints(PassManagerBuilder &Builder) {
Builder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
addCoroutineEarlyPasses);
Builder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
addCoroutineOpt0Passes);
Builder.addExtension(PassManagerBuilder::EP_CGSCCOptimizerLate,
addCoroutineSCCPasses);
Builder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
addCoroutineScalarOptimizerPasses);
Builder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addCoroutineOptimizerLastPasses);
}
示例13: getDebugBuilder
static PassManagerBuilder getDebugBuilder() {
PassManagerBuilder Builder;
Builder.VerifyInput = true;
Builder.VerifyOutput = true;
Builder.OptLevel = 0;
Builder.DisableUnrollLoops = true;
Builder.DisableTailCalls = true;
Builder.addGlobalExtension(PassManagerBuilder::EP_EarlyAsPossible,
registerPolly);
return Builder;
}
示例14: AddStandardLinkPasses
static void AddStandardLinkPasses(PassManagerBase &PM) {
PM.add(createVerifierPass()); // Verify that input is correct
// If the -strip-debug command line option was specified, do it.
if (StripDebug)
addPass(PM, createStripSymbolsPass(true));
if (DisableOptimizations) return;
PassManagerBuilder Builder;
Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
/*RunInliner=*/ !DisableInline);
}
示例15: errs
/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization) {
if (!this->determineTarget())
return false;
auto DiagFileOrErr = lto::setupOptimizationRemarks(
Context, LTORemarksFilename, LTOPassRemarksWithHotness);
if (!DiagFileOrErr) {
errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
report_fatal_error("Can't get an output file for the remarks");
}
DiagnosticOutputFile = std::move(*DiagFileOrErr);
// We always run the verifier once on the merged module, the `DisableVerify`
// parameter only applies to subsequent verify.
verifyMergedModuleOnce();
// Mark which symbols can not be internalized
this->applyScopeRestrictions();
// Instantiate the pass manager to organize the passes.
legacy::PassManager passes;
// Add an appropriate DataLayout instance for this module...
MergedModule->setDataLayout(TargetMach->createDataLayout());
passes.add(
createTargetTransformInfoWrapperPass(TargetMach->getTargetIRAnalysis()));
Triple TargetTriple(TargetMach->getTargetTriple());
PassManagerBuilder PMB;
PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
PMB.LoopVectorize = !DisableVectorization;
PMB.SLPVectorize = !DisableVectorization;
if (!DisableInline)
PMB.Inliner = createFunctionInliningPass();
PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple);
if (Freestanding)
PMB.LibraryInfo->disableAllFunctions();
PMB.OptLevel = OptLevel;
PMB.VerifyInput = !DisableVerify;
PMB.VerifyOutput = !DisableVerify;
PMB.populateLTOPassManager(passes);
// Run our queue of passes all at once now, efficiently.
passes.run(*MergedModule);
return true;
}