本文整理汇总了C++中FunctionPassManager类的典型用法代码示例。如果您正苦于以下问题:C++ FunctionPassManager类的具体用法?C++ FunctionPassManager怎么用?C++ FunctionPassManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FunctionPassManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: llvm_init
static void llvm_init(){
ExecutionEngine *ee = tcg_llvm_ctx->getExecutionEngine();
FunctionPassManager *fpm = tcg_llvm_ctx->getFunctionPassManager();
Module *mod = tcg_llvm_ctx->getModule();
LLVMContext &ctx = mod->getContext();
// Link logging function in with JIT
Function *logFunc;
std::vector<Type*> argTypes;
// DynValBuffer*
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(uintptr_t)));
// DynValEntryType
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(DynValEntryType)));
// LogOp
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(LogOp)));
// Dynamic value
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(uintptr_t)));
logFunc = Function::Create(
FunctionType::get(Type::getVoidTy(ctx), argTypes, false),
Function::ExternalLinkage, "log_dynval", mod);
logFunc->addFnAttr(Attribute::AlwaysInline);
ee->addGlobalMapping(logFunc, (void*) &log_dynval);
// Create instrumentation pass and add to function pass manager
llvm::FunctionPass *instfp = createPandaInstrFunctionPass(mod);
fpm->add(instfp);
PIFP = static_cast<PandaInstrFunctionPass*>(instfp);
}
示例2: TargetData
/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
std::string& errMsg)
{
if ( this->determineTarget(errMsg) )
return true;
// mark which symbols can not be internalized
this->applyScopeRestrictions();
Module* mergedModule = _linker.getModule();
// if options were requested, set them
if ( !_codegenOptions.empty() )
cl::ParseCommandLineOptions(_codegenOptions.size(),
const_cast<char **>(&_codegenOptions[0]));
// Instantiate the pass manager to organize the passes.
PassManager passes;
// Start off with a verification pass.
passes.add(createVerifierPass());
// Add an appropriate TargetData instance for this module...
passes.add(new TargetData(*_target->getTargetData()));
createStandardLTOPasses(&passes, /*Internalize=*/ false, !DisableInline,
/*VerifyEach=*/ false);
// Make sure everything is still good.
passes.add(createVerifierPass());
FunctionPassManager* codeGenPasses = new FunctionPassManager(mergedModule);
codeGenPasses->add(new TargetData(*_target->getTargetData()));
formatted_raw_ostream Out(out);
if (_target->addPassesToEmitFile(*codeGenPasses, Out,
TargetMachine::CGFT_AssemblyFile,
CodeGenOpt::Aggressive)) {
errMsg = "target file type not supported";
return true;
}
// Run our queue of passes all at once now, efficiently.
passes.run(*mergedModule);
// Run the code generator, and write assembly file
codeGenPasses->doInitialization();
for (Module::iterator
it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it)
if (!it->isDeclaration())
codeGenPasses->run(*it);
codeGenPasses->doFinalization();
return false; // success
}
示例3: LLVMRustRunFunctionPassManager
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
// all the functions in a module, so we do that manually here. You'll find
// similar code in clang's BackendUtil.cpp file.
extern "C" void
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
FunctionPassManager *P = unwrap<FunctionPassManager>(PM);
P->doInitialization();
for (Module::iterator I = unwrap(M)->begin(),
E = unwrap(M)->end(); I != E; ++I)
if (!I->isDeclaration())
P->run(*I);
P->doFinalization();
}
示例4: parseFunctionPassName
static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
if (Name == "no-op-function") {
FPM.addPass(NoOpFunctionPass());
return true;
}
if (Name == "print") {
FPM.addPass(PrintFunctionPass(dbgs()));
return true;
}
return false;
}
示例5: optimize
void
optimize(cpu_t *cpu)
{
FunctionPassManager pm = FunctionPassManager(cpu->mod);
pm.add(createPromoteMemoryToRegisterPass());
pm.add(createInstructionCombiningPass());
pm.add(createConstantPropagationPass());
pm.add(createDeadCodeEliminationPass());
pm.run(*cpu->cur_func);
}
示例6: NestedFPM
bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
StringRef &PipelineText,
bool VerifyEachPass,
bool DebugLogging) {
for (;;) {
// Parse nested pass managers by recursing.
if (PipelineText.startswith("function(")) {
FunctionPassManager NestedFPM(DebugLogging);
// Parse the inner pipeline inte the nested manager.
PipelineText = PipelineText.substr(strlen("function("));
if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass,
DebugLogging) ||
PipelineText.empty())
return false;
assert(PipelineText[0] == ')');
PipelineText = PipelineText.substr(1);
// Add the nested pass manager with the appropriate adaptor.
FPM.addPass(std::move(NestedFPM));
} else if (PipelineText.startswith("loop(")) {
LoopPassManager NestedLPM(DebugLogging);
// Parse the inner pipeline inte the nested manager.
PipelineText = PipelineText.substr(strlen("loop("));
if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass,
DebugLogging) ||
PipelineText.empty())
return false;
assert(PipelineText[0] == ')');
PipelineText = PipelineText.substr(1);
// Add the nested pass manager with the appropriate adaptor.
FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM)));
} else {
// Otherwise try to parse a pass name.
size_t End = PipelineText.find_first_of(",)");
if (!parseFunctionPassName(FPM, PipelineText.substr(0, End)))
return false;
if (VerifyEachPass)
FPM.addPass(VerifierPass());
PipelineText = PipelineText.substr(End);
}
if (PipelineText.empty() || PipelineText[0] == ')')
return true;
assert(PipelineText[0] == ',');
PipelineText = PipelineText.substr(1);
}
}
示例7: closeCurrentModule
ExecutionEngine *MCJITHelper::compileModule(Module *M) {
if (M == OpenModule)
closeCurrentModule();
std::string ErrStr;
ExecutionEngine *NewEngine = EngineBuilder(M)
.setErrorStr(&ErrStr)
.setMCJITMemoryManager(new HelpingMemoryManager(this))
.create();
if (!NewEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
}
// Create a function pass manager for this engine
FunctionPassManager *FPM = new FunctionPassManager(M);
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
FPM->add(new DataLayout(*NewEngine->getDataLayout()));
// Provide basic AliasAnalysis support for GVN.
FPM->add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
FPM->add(createPromoteMemoryToRegisterPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
FPM->add(createInstructionCombiningPass());
// Reassociate expressions.
FPM->add(createReassociatePass());
// Eliminate Common SubExpressions.
FPM->add(createGVNPass());
// Simplify the control flow graph (deleting unreachable blocks, etc).
FPM->add(createCFGSimplificationPass());
FPM->doInitialization();
// For each function in the module
Module::iterator it;
Module::iterator end = M->end();
for (it = M->begin(); it != end; ++it) {
// Run the FPM on this function
FPM->run(*it);
}
// We don't need this anymore
delete FPM;
// Store this engine
EngineMap[M] = NewEngine;
NewEngine->finalizeObject();
return NewEngine;
}
示例8: 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);
}
示例9: 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);
}
示例10: 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;
}
示例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: FunctionPassManager
FunctionPassManager* Builder::getStandardOptimizer() {
FunctionPassManager* optimizer = new FunctionPassManager(this->_mod);
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
if (this->_jit) {
optimizer->add(new DataLayoutPass(*this->_jit->getDataLayout()));
}
// Provide basic AliasAnalysis support for GVN.
optimizer->add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
optimizer->add(createInstructionCombiningPass());
// Reassociate expressions.
optimizer->add(createReassociatePass());
// Eliminate Common SubExpressions.
optimizer->add(createGVNPass());
// Simplify the control flow graph (deleting unreachable blocks, etc).
optimizer->add(createCFGSimplificationPass());
optimizer->doInitialization();
return optimizer;
}
示例13: optimize
void
optimize(cpu_t *cpu)
{
dyncom_engine_t* de = cpu->dyncom_engine;
FunctionPassManager pm = FunctionPassManager(de->mod);
std::string data_layout = de->exec_engine->getTargetData()->getStringRepresentation();
TargetData *TD = new TargetData(data_layout);
pm.add(TD);
pm.add(createPromoteMemoryToRegisterPass());
pm.add(createInstructionCombiningPass());
pm.add(createConstantPropagationPass());
pm.add(createDeadCodeEliminationPass());
pm.run(*de->cur_func);
}
示例14: EngineBuilder
void *MCJITHelper::getPointerToFunction(Function* F) {
// See if an existing instance of MCJIT has this function.
EngineVector::iterator begin = Engines.begin();
EngineVector::iterator end = Engines.end();
EngineVector::iterator it;
for (it = begin; it != end; ++it) {
void *P = (*it)->getPointerToFunction(F);
if (P)
return P;
}
// If we didn't find the function, see if we can generate it.
if (OpenModule) {
std::string ErrStr;
ExecutionEngine *NewEngine = EngineBuilder(OpenModule)
.setErrorStr(&ErrStr)
.setMCJITMemoryManager(new HelpingMemoryManager(this))
.create();
if (!NewEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
}
// Create a function pass manager for this engine
FunctionPassManager *FPM = new FunctionPassManager(OpenModule);
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
FPM->add(new DataLayout(*NewEngine->getDataLayout()));
// Provide basic AliasAnalysis support for GVN.
FPM->add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
FPM->add(createPromoteMemoryToRegisterPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
FPM->add(createInstructionCombiningPass());
// Reassociate expressions.
FPM->add(createReassociatePass());
// Eliminate Common SubExpressions.
FPM->add(createGVNPass());
// Simplify the control flow graph (deleting unreachable blocks, etc).
FPM->add(createCFGSimplificationPass());
FPM->doInitialization();
// For each function in the module
Module::iterator it;
Module::iterator end = OpenModule->end();
for (it = OpenModule->begin(); it != end; ++it) {
// Run the FPM on this function
FPM->run(*it);
}
// We don't need this anymore
delete FPM;
OpenModule = NULL;
Engines.push_back(NewEngine);
NewEngine->finalizeObject();
return NewEngine->getPointerToFunction(F);
}
return NULL;
}
示例15: assert
ExecutionEngine *MCJITHelper::compileModule(Module *M) {
assert(EngineMap.find(M) == EngineMap.end());
if (M == CurrentModule)
closeCurrentModule();
std::string ErrStr;
ExecutionEngine *EE = EngineBuilder(M)
.setErrorStr(&ErrStr)
.setMCJITMemoryManager(new HelpingMemoryManager(this))
.create();
if (!EE) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
}
if (UseObjectCache)
EE->setObjectCache(&OurObjectCache);
// Get the ModuleID so we can identify IR input files
const std::string ModuleID = M->getModuleIdentifier();
// If we've flagged this as an IR file, it doesn't need function passes run.
if (0 != ModuleID.compare(0, 3, "IR:")) {
FunctionPassManager *FPM = 0;
// Create a FPM for this module
FPM = new FunctionPassManager(M);
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
FPM->add(new DataLayout(*EE->getDataLayout()));
// Provide basic AliasAnalysis support for GVN.
FPM->add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
FPM->add(createPromoteMemoryToRegisterPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
FPM->add(createInstructionCombiningPass());
// Reassociate expressions.
FPM->add(createReassociatePass());
// Eliminate Common SubExpressions.
FPM->add(createGVNPass());
// Simplify the control flow graph (deleting unreachable blocks, etc).
FPM->add(createCFGSimplificationPass());
FPM->doInitialization();
// For each function in the module
Module::iterator it;
Module::iterator end = M->end();
for (it = M->begin(); it != end; ++it) {
// Run the FPM on this function
FPM->run(*it);
}
delete FPM;
}
EE->finalizeObject();
// Store this engine
EngineMap[M] = EE;
return EE;
}