本文整理汇总了C++中PassManager::add方法的典型用法代码示例。如果您正苦于以下问题:C++ PassManager::add方法的具体用法?C++ PassManager::add怎么用?C++ PassManager::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PassManager
的用法示例。
在下文中一共展示了PassManager::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addStaticGEPCheckingPass
static void addStaticGEPCheckingPass(PassManager & Passes) {
#if 0
switch (SCConfig.staticCheckType()) {
case SAFECodeConfiguration::ABC_CHECK_NONE:
Passes.add(new ArrayBoundsCheckDummy());
break;
case SAFECodeConfiguration::ABC_CHECK_LOCAL:
#if 0
if (SCConfig.getPAType() == SAFECodeConfiguration::PA_APA) {
Passes.add(new ArrayBoundsCheckStruct());
}
#endif
Passes.add(new ArrayBoundsCheckLocal());
break;
case SAFECodeConfiguration::ABC_CHECK_FULL:
#if 0
if (SCConfig.getPAType() == SAFECodeConfiguration::PA_APA) {
Passes.add(new ArrayBoundsCheckStruct());
}
#endif
#if 0
Passes.add(new ArrayBoundsCheck());
#else
assert (0 && "Omega pass is not working right now!");
#endif
break;
}
#endif
}
示例2: getGlobalContext
int
main (int argc, char **argv, const char **env) {
// This boilerplate provides convenient stack traces and clean LLVM exit
// handling. It also initializes the built in support for convenient
// command line option handling.
sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X{argc, argv};
llvm_shutdown_obj shutdown;
cl::ParseCommandLineOptions(argc, argv);
// Construct an IR file from the filename passed on the command line.
LLVMContext &context = getGlobalContext();
SMDiagnostic err;
unique_ptr<Module> module = parseIRFile(inPath.getValue(), err, context);
if (!module.get()) {
errs() << "Error reading bitcode file.\n";
err.print(argv[0], errs());
return -1;
}
// Build up all of the passes that we want to run on the module.
PassManager pm;
pm.add(new callgraphs::CallGraphPass);
pm.add(new callgraphs::WeightedCallGraphPass);
pm.add(new CallGraphPrinter<callgraphs::WeightedCallGraphPass>(outs()));
pm.run(*module);
return 0;
}
示例3: main
int main(int argc, char **argv) {
// Init LLVM, call llvm_shutdown() on exit, parse args, etc.
llvm::PrettyStackTraceProgram X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
llvm_shutdown_obj Y;
std::auto_ptr<Module> M(new Module("/tmp/autogen.bc", getGlobalContext()));
Function *F = GenEmptyFunction(M.get());
FillFunction(F);
IntroduceControlFlow(F);
// Figure out what stream we are supposed to write to...
OwningPtr<tool_output_file> Out;
// Default to standard output.
if (OutputFilename.empty())
OutputFilename = "-";
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
raw_fd_ostream::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
}
PassManager Passes;
Passes.add(createVerifierPass());
Passes.add(createPrintModulePass(&Out->os()));
Passes.run(*M.get());
Out->keep();
return 0;
}
示例4: AddTargetTranslationPass
static void AddTargetTranslationPass(PassManager &PM) {
ExpandVAArgPass *VAArgPass = NULL;
ReplaceUnwindHeaderSizePass *UnwindPass = NULL;
if (ArchName == "arm") {
VAArgPass = createARMExpandVAArgPass();
UnwindPass = createARMReplaceUnwindHeaderSizePass();
} else if (ArchName == "x86") {
VAArgPass = createX86ExpandVAArgPass();
UnwindPass = createX86ReplaceUnwindHeaderSizePass();
} else if (ArchName == "mips") {
VAArgPass = createMipsExpandVAArgPass();
UnwindPass = createMipsReplaceUnwindHeaderSizePass();
} else if (ArchName == "arm64") {
VAArgPass = createArm64ExpandVAArgPass();
UnwindPass = createX86ReplaceUnwindHeaderSizePass(); // the same as x86
} else if (ArchName == "x86_64") {
VAArgPass = createX86_64ExpandVAArgPass();
UnwindPass = createX86ReplaceUnwindHeaderSizePass(); // the same as x86
} else if (ArchName == "mips64") {
VAArgPass = createMips64ExpandVAArgPass();
UnwindPass = createX86ReplaceUnwindHeaderSizePass(); // the same as x86
} else {
errs() << "'" << ArchName << "' is not supported!\n";
exit(1);
}
// Add target specific pass
PM.add(new DataLayoutPass());
if (VAArgPass)
PM.add(VAArgPass);
if (UnwindPass)
PM.add(UnwindPass);
}
示例5: generateObjectFile
/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
bool DisableOpt,
bool DisableInline,
bool DisableGVNLoadPRE,
std::string &errMsg) {
if (!this->determineTarget(errMsg))
return false;
Module *mergedModule = Linker.getModule();
// Mark which symbols can not be internalized
this->applyScopeRestrictions();
// Instantiate the pass manager to organize the passes.
PassManager passes;
// Start off with a verification pass.
passes.add(createVerifierPass());
// Add an appropriate DataLayout instance for this module...
passes.add(new DataLayout(*TargetMach->getDataLayout()));
TargetMach->addAnalysisPasses(passes);
// Enabling internalize here would use its AllButMain variant. It
// keeps only main if it exists and does nothing for libraries. Instead
// we create the pass ourselves with the symbol list provided by the linker.
if (!DisableOpt)
PassManagerBuilder().populateLTOPassManager(passes,
/*Internalize=*/false,
!DisableInline,
DisableGVNLoadPRE);
// Make sure everything is still good.
passes.add(createVerifierPass());
PassManager codeGenPasses;
codeGenPasses.add(new DataLayout(*TargetMach->getDataLayout()));
TargetMach->addAnalysisPasses(codeGenPasses);
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: applyScopeRestrictions
void LTOCodeGenerator::applyScopeRestrictions() {
if (ScopeRestrictionsDone)
return;
Module *mergedModule = Linker.getModule();
// Start off with a verification pass.
PassManager passes;
passes.add(createVerifierPass());
// mark which symbols can not be internalized
Mangler Mangler(TargetMach);
std::vector<const char*> MustPreserveList;
SmallPtrSet<GlobalValue*, 8> AsmUsed;
std::vector<StringRef> Libcalls;
TargetLibraryInfo TLI(Triple(TargetMach->getTargetTriple()));
accumulateAndSortLibcalls(Libcalls, TLI, TargetMach->getTargetLowering());
for (Module::iterator f = mergedModule->begin(),
e = mergedModule->end(); f != e; ++f)
applyRestriction(*f, Libcalls, MustPreserveList, AsmUsed, Mangler);
for (Module::global_iterator v = mergedModule->global_begin(),
e = mergedModule->global_end(); v != e; ++v)
applyRestriction(*v, Libcalls, MustPreserveList, AsmUsed, Mangler);
for (Module::alias_iterator a = mergedModule->alias_begin(),
e = mergedModule->alias_end(); a != e; ++a)
applyRestriction(*a, Libcalls, MustPreserveList, AsmUsed, Mangler);
GlobalVariable *LLVMCompilerUsed =
mergedModule->getGlobalVariable("llvm.compiler.used");
findUsedValues(LLVMCompilerUsed, AsmUsed);
if (LLVMCompilerUsed)
LLVMCompilerUsed->eraseFromParent();
if (!AsmUsed.empty()) {
llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(Context);
std::vector<Constant*> asmUsed2;
for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = AsmUsed.begin(),
e = AsmUsed.end(); i !=e; ++i) {
GlobalValue *GV = *i;
Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
asmUsed2.push_back(c);
}
llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
LLVMCompilerUsed =
new llvm::GlobalVariable(*mergedModule, ATy, false,
llvm::GlobalValue::AppendingLinkage,
llvm::ConstantArray::get(ATy, asmUsed2),
"llvm.compiler.used");
LLVMCompilerUsed->setSection("llvm.metadata");
}
passes.add(createInternalizePass(MustPreserveList));
// apply scope restrictions
passes.run(*mergedModule);
ScopeRestrictionsDone = true;
}
示例7: addPasses
void MipsLinkingContext::addPasses(PassManager &pm) {
auto pass = createMipsRelocationPass(*this);
if (pass)
pm.add(std::move(pass));
ELFLinkingContext::addPasses(pm);
pm.add(llvm::make_unique<elf::MipsCtorsOrderPass>());
}
示例8: applyScopeRestrictions
void LTOCodeGenerator::applyScopeRestrictions() {
if (_scopeRestrictionsDone) return;
Module *mergedModule = _linker.getModule();
// Start off with a verification pass.
PassManager passes;
passes.add(createVerifierPass());
// mark which symbols can not be internalized
if (!_mustPreserveSymbols.empty()) {
MCContext Context(*_target->getMCAsmInfo(), NULL);
Mangler mangler(Context, *_target->getTargetData());
std::vector<const char*> mustPreserveList;
for (Module::iterator f = mergedModule->begin(),
e = mergedModule->end(); f != e; ++f) {
if (!f->isDeclaration() &&
_mustPreserveSymbols.count(mangler.getNameWithPrefix(f)))
mustPreserveList.push_back(::strdup(f->getNameStr().c_str()));
}
for (Module::global_iterator v = mergedModule->global_begin(),
e = mergedModule->global_end(); v != e; ++v) {
if (!v->isDeclaration() &&
_mustPreserveSymbols.count(mangler.getNameWithPrefix(v)))
mustPreserveList.push_back(::strdup(v->getNameStr().c_str()));
}
passes.add(createInternalizePass(mustPreserveList));
}
// apply scope restrictions
passes.run(*mergedModule);
_scopeRestrictionsDone = true;
}
示例9: applyScopeRestrictions
void LTOCodeGenerator::applyScopeRestrictions() {
if (_scopeRestrictionsDone) return;
Module *mergedModule = _linker.getModule();
// Start off with a verification pass.
PassManager passes;
passes.add(createVerifierPass());
// mark which symbols can not be internalized
MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL);
Mangler mangler(Context, *_target->getTargetData());
std::vector<const char*> mustPreserveList;
SmallPtrSet<GlobalValue*, 8> asmUsed;
for (Module::iterator f = mergedModule->begin(),
e = mergedModule->end(); f != e; ++f)
applyRestriction(*f, mustPreserveList, asmUsed, mangler);
for (Module::global_iterator v = mergedModule->global_begin(),
e = mergedModule->global_end(); v != e; ++v)
applyRestriction(*v, mustPreserveList, asmUsed, mangler);
for (Module::alias_iterator a = mergedModule->alias_begin(),
e = mergedModule->alias_end(); a != e; ++a)
applyRestriction(*a, mustPreserveList, asmUsed, mangler);
GlobalVariable *LLVMCompilerUsed =
mergedModule->getGlobalVariable("llvm.compiler.used");
findUsedValues(LLVMCompilerUsed, asmUsed);
if (LLVMCompilerUsed)
LLVMCompilerUsed->eraseFromParent();
llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
std::vector<Constant*> asmUsed2;
for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
e = asmUsed.end(); i !=e; ++i) {
GlobalValue *GV = *i;
Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
asmUsed2.push_back(c);
}
llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
LLVMCompilerUsed =
new llvm::GlobalVariable(*mergedModule, ATy, false,
llvm::GlobalValue::AppendingLinkage,
llvm::ConstantArray::get(ATy, asmUsed2),
"llvm.compiler.used");
LLVMCompilerUsed->setSection("llvm.metadata");
// Add prerequisite passes needed by SAFECode
PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false,
!DisableInline);
passes.add(createInternalizePass(mustPreserveList));
// apply scope restrictions
passes.run(*mergedModule);
_scopeRestrictionsDone = true;
}
示例10: generateAssemblyCode
/// 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
}
示例11: generateObjectFile
/// 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;
}
示例12: addPasses
void PECOFFLinkingContext::addPasses(PassManager &pm) {
pm.add(llvm::make_unique<pecoff::PDBPass>(*this));
pm.add(llvm::make_unique<pecoff::EdataPass>(*this));
pm.add(llvm::make_unique<pecoff::IdataPass>(*this));
pm.add(llvm::make_unique<pecoff::OrderPass>());
pm.add(llvm::make_unique<pecoff::LoadConfigPass>(*this));
pm.add(llvm::make_unique<pecoff::InferSubsystemPass>(*this));
}
示例13: StaticCountPrinter
static void
countStaticCalls(Module &m) {
// Build up all of the passes that we want to run on the module.
PassManager pm;
pm.add(new callcounter::StaticCallCounter());
pm.add(new StaticCountPrinter(outs()));
pm.run(m);
}
示例14: addPass
// A utility function that adds a pass to the pass manager but will also add
// a verifier pass after if we're supposed to verify.
static inline void addPass(PassManager &PM, Pass *P) {
// Add the pass to the pass manager...
PM.add(P);
// If we are verifying all of the intermediate steps, add the verifier...
if (VerifyEach)
PM.add(createVerifierPass());
}
示例15: Optimize
void Optimize(llvm::Module *M, int OptLevel, int SizeLevel, int Verify) {
// 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()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
Passes.add(TLI);
// Add an appropriate DataLayout instance for this module.
const DataLayout *DL = M->getDataLayout();
if (DL)
Passes.add(new DataLayoutPass());
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = nullptr;
if (ModuleTriple.getArch())
Machine = GetTargetMachine(Triple(ModuleTriple), OptLevel);
std::unique_ptr<TargetMachine> TM(Machine);
// Add internal analysis passes from the target machine.
if (TM.get())
TM->addAnalysisPasses(Passes);
std::unique_ptr<FunctionPassManager> FPasses;
if (OptLevel > 0 || SizeLevel > 0) {
FPasses.reset(new FunctionPassManager(M));
if (DL)
FPasses->add(new DataLayoutPass());
if (TM.get())
TM->addAnalysisPasses(*FPasses);
}
AddOptimizationPasses(Passes, *FPasses, OptLevel, SizeLevel);
if (OptLevel > 0 || SizeLevel > 0) {
FPasses->doInitialization();
for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
FPasses->run(*F);
FPasses->doFinalization();
}
// Check that the module is well formed on completion of optimization
if (Verify) {
Passes.add(createVerifierPass());
Passes.add(createDebugInfoVerifierPass());
}
// Now that we have all of the passes ready, run them.
Passes.run(*M);
}