本文整理汇总了C++中PassManagerBuilder::populateModulePassManager方法的典型用法代码示例。如果您正苦于以下问题:C++ PassManagerBuilder::populateModulePassManager方法的具体用法?C++ PassManagerBuilder::populateModulePassManager怎么用?C++ PassManagerBuilder::populateModulePassManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PassManagerBuilder
的用法示例。
在下文中一共展示了PassManagerBuilder::populateModulePassManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddOptimizationPasses
/// This routine adds optimization passes based on selected optimization level,
/// OptLevel.
///
/// OptLevel - Optimization Level
static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
unsigned OptLevel, unsigned SizeLevel) {
FPM.add(createVerifierPass()); // Verify that input is correct
MPM.add(createDebugInfoVerifierPass()); // Verify that debug info 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);
}
示例2: 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 = OptLevel == 0;
Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
示例3: LLVMOptimizeModule
bool LLVMOptimizeModule(LLVMModuleRef Mod) {
Module* M = unwrap(Mod);
// Create a PassManager to hold and optimize the collection of passes we are
// about to build.
PassManager Passes;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// Add an appropriate DataLayout instance for this module.
// const std::string &ModuleDataLayout = M->getDataLayout();
// if (!ModuleDataLayout.empty()) {
// DataLayout *TD = NULL; // new DataLayout(ModuleDataLayout);
// Passes.add(TD);
// }
Passes.add(createVerifierPass()); // Verify that input is correct
// -std-compile-opts adds the same module passes as -O3.
PassManagerBuilder Builder;
Builder.Inliner = createFunctionInliningPass();
Builder.OptLevel = 3;
Builder.populateModulePassManager(Passes);
// Now that we have all of the passes ready, run them.
bool change = Passes.run(*M);
return change;
}
示例4: unwrap
void
LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB,
LLVMPassManagerRef PM) {
PassManagerBuilder *Builder = unwrap(PMB);
legacy::PassManagerBase *MPM = unwrap(PM);
Builder->populateModulePassManager(*MPM);
}
示例5: assert
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;
}
示例6: 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);
}
示例7: getDebugBuilder
Function &OptimizeForRuntime(Function &F) {
#ifdef DEBUG
static PassManagerBuilder Builder = getDebugBuilder();
#else
static PassManagerBuilder Builder = getBuilder();
#endif
Module *M = F.getParent();
opt::GenerateOutput = true;
polly::opt::PollyParallel = true;
FunctionPassManager PM = FunctionPassManager(M);
Builder.populateFunctionPassManager(PM);
PM.doInitialization();
PM.run(F);
PM.doFinalization();
if (opt::havePapi()) {
PassManager MPM;
Builder.populateModulePassManager(MPM);
MPM.add(polli::createTraceMarkerPass());
MPM.run(*M);
}
if (opt::haveLikwid()) {
PassManager MPM;
Builder.populateModulePassManager(MPM);
MPM.add(polli::createLikwidMarkerPass());
MPM.run(*M);
}
DEBUG(
StoreModule(*M, M->getModuleIdentifier() + ".after.polly.ll")
);
opt::GenerateOutput = false;
return F;
}
示例8: assert
Module * llvmutil_extractmodule(Module * OrigMod, TargetMachine * TM, std::vector<Function*> * livefns, std::vector<std::string> * symbolnames) {
assert(symbolnames == NULL || livefns->size() == symbolnames->size());
ValueToValueMapTy VMap;
Module * M = CloneModule(OrigMod, VMap);
PassManager * MPM = new PassManager();
llvmutil_addtargetspecificpasses(MPM, TM);
std::vector<const char *> names;
for(size_t i = 0; i < livefns->size(); i++) {
Function * fn = cast<Function>(VMap[(*livefns)[i]]);
const char * name;
if(symbolnames) {
GlobalAlias * ga = new GlobalAlias(fn->getType(), Function::ExternalLinkage, (*symbolnames)[i], fn, M);
name = copyName(ga->getName());
} else {
name = copyName(fn->getName());
}
names.push_back(name); //internalize pass has weird interface, so we need to copy the names here
}
//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
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
//clean up the name list
for(size_t i = 0; i < names.size(); i++) {
free((char*)names[i]);
names[i] = NULL;
}
PassManagerBuilder PMB;
PMB.OptLevel = 3;
PMB.DisableUnrollLoops = true;
PMB.populateModulePassManager(*MPM);
//PMB.populateLTOPassManager(*MPM, false, false); //no need to re-internalize, we already did it
MPM->run(*M);
delete MPM;
MPM = NULL;
return M;
}
示例9: llvmutil_addoptimizationpasses
void llvmutil_addoptimizationpasses(PassManagerBase * fpm) {
PassManagerBuilder PMB;
PMB.OptLevel = 3;
PMB.SizeLevel = 0;
PMB.DisableUnitAtATime = true;
#if LLVM_VERSION <= 34 && LLVM_VERSION >= 32
PMB.LoopVectorize = false;
#elif LLVM_VERSION >= 35
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
#endif
PassManagerWrapper W(fpm);
PMB.populateModulePassManager(W);
}
示例10: AddStandardCompilePasses
static void AddStandardCompilePasses(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;
// -std-compile-opts adds the same module passes as -O3.
PassManagerBuilder Builder;
if (!DisableInline)
Builder.Inliner = createFunctionInliningPass();
Builder.OptLevel = 3;
Builder.populateModulePassManager(PM);
}
示例11: addOptimizationPasses
/**
* Adds a set of optimization passes to the given module/function pass
* managers based on the given optimization and size reduction levels.
*
* The selection mirrors Clang behavior and is based on LLVM's
* PassManagerBuilder.
*/
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 (willInline()) {
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.DisableSimplifyLibCalls = disableSimplifyLibCalls;
builder.DisableUnitAtATime = !unitAtATime;
builder.DisableUnrollLoops = optLevel == 0;
/* builder.Vectorize is set in ctor from command line switch */
if (!disableLangSpecificPasses) {
if (!disableSimplifyDruntimeCalls)
builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd, addSimplifyDRuntimeCallsPass);
#if USE_METADATA
if (!disableGCToStack)
builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd, addGarbageCollect2StackPass);
#endif // USE_METADATA
}
#if LDC_LLVM_VER >= 301
// EP_OptimizerLast does not exist in LLVM 3.0, add it manually below.
builder.addExtension(PassManagerBuilder::EP_OptimizerLast, addStripExternalsPass);
#endif
builder.populateFunctionPassManager(fpm);
builder.populateModulePassManager(mpm);
#if LDC_LLVM_VER < 301
addStripExternalsPass(builder, mpm);
#endif
}
示例12: AddOptimizationPasses
/// This routine adds optimization passes based on selected optimization level,
/// OptLevel.
///
/// OptLevel - Optimization Level
static void AddOptimizationPasses(legacy::PassManagerBase &MPM,
legacy::FunctionPassManager &FPM,
TargetMachine *TM, 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 = createAlwaysInlinerLegacyPass();
}
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;
// Add target-specific passes that need to run as early as possible.
if (TM)
Builder.addExtension(
PassManagerBuilder::EP_EarlyAsPossible,
[&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
TM->addEarlyAsPossiblePasses(PM);
});
if (Coroutines)
addCoroutinePassesToExtensionPoints(Builder);
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
示例13: llvmutil_optimizemodule
void llvmutil_optimizemodule(Module * M, TargetMachine * TM) {
PassManager MPM;
llvmutil_addtargetspecificpasses(&MPM, TM);
MPM.add(createVerifierPass()); //make sure we haven't messed stuff up yet
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;
PMB.Inliner = createFunctionInliningPass(PMB.OptLevel, 0);
#if LLVM_VERSION >= 35
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
#endif
PMB.populateModulePassManager(MPM);
MPM.run(*M);
}
示例14: 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) {
PassManagerBuilder Builder;
Builder.OptLevel = OptLevel;
if (DisableInline) {
// No inlining pass
} else if (OptLevel > 1) {
unsigned Threshold = 225;
if (OptLevel > 2)
Threshold = 275;
Builder.Inliner = createFunctionInliningPass(Threshold);
} else {
Builder.Inliner = createAlwaysInlinerPass();
}
Builder.DisableUnitAtATime = !UnitAtATime;
Builder.DisableUnrollLoops = OptLevel == 0;
Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
示例15: CreatePasses
void EmitAssemblyHelper::CreatePasses() {
unsigned OptLevel = CodeGenOpts.OptimizationLevel;
CodeGenOptions::InliningMethod Inlining = CodeGenOpts.Inlining;
// Handle disabling of LLVM optimization, where we want to preserve the
// internal module before any optimization.
if (CodeGenOpts.DisableLLVMOpts) {
OptLevel = 0;
Inlining = CodeGenOpts.NoInlining;
}
PassManagerBuilder PMBuilder;
PMBuilder.OptLevel = OptLevel;
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
PMBuilder.DisableSimplifyLibCalls = !CodeGenOpts.SimplifyLibCalls;
PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime;
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
// In ObjC ARC mode, add the main ARC optimization passes.
if (LangOpts.ObjCAutoRefCount) {
PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
addObjCARCExpandPass);
PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
addObjCARCOptPass);
}
if (LangOpts.AddressSanitizer) {
PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
addAddressSanitizerPass);
PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
addAddressSanitizerPass);
}
// Figure out TargetLibraryInfo.
Triple TargetTriple(TheModule->getTargetTriple());
PMBuilder.LibraryInfo = new TargetLibraryInfo(TargetTriple);
if (!CodeGenOpts.SimplifyLibCalls)
PMBuilder.LibraryInfo->disableAllFunctions();
switch (Inlining) {
case CodeGenOptions::NoInlining: break;
case CodeGenOptions::NormalInlining: {
// FIXME: Derive these constants in a principled fashion.
unsigned Threshold = 225;
if (CodeGenOpts.OptimizeSize == 1) // -Os
Threshold = 75;
else if (CodeGenOpts.OptimizeSize == 2) // -Oz
Threshold = 25;
else if (OptLevel > 2)
Threshold = 275;
PMBuilder.Inliner = createFunctionInliningPass(Threshold);
break;
}
case CodeGenOptions::OnlyAlwaysInlining:
// Respect always_inline.
PMBuilder.Inliner = createAlwaysInlinerPass();
break;
}
// Set up the per-function pass manager.
FunctionPassManager *FPM = getPerFunctionPasses();
if (CodeGenOpts.VerifyModule)
FPM->add(createVerifierPass());
PMBuilder.populateFunctionPassManager(*FPM);
// Set up the per-module pass manager.
PassManager *MPM = getPerModulePasses();
if (CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes) {
MPM->add(createGCOVProfilerPass(CodeGenOpts.EmitGcovNotes,
CodeGenOpts.EmitGcovArcs,
TargetTriple.isMacOSX()));
if (!CodeGenOpts.DebugInfo)
MPM->add(createStripSymbolsPass(true));
}
PMBuilder.populateModulePassManager(*MPM);
}