本文整理汇总了C++中PassManager类的典型用法代码示例。如果您正苦于以下问题:C++ PassManager类的具体用法?C++ PassManager怎么用?C++ PassManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PassManager类的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: makeArrayRef
/* Compile the AST into a module */
void CodeGenContext::generateCode(NBlock& root)
{
//std::cout << "Generating code...\n";
/* Create the top level interpreter function to call as entry */
vector<Type*> argTypes;
FunctionType *ftype = FunctionType::get(Type::getVoidTy(getGlobalContext()), makeArrayRef(argTypes), false);
mainFunction = Function::Create(ftype, GlobalValue::InternalLinkage, "main", module);
BasicBlock *bblock = BasicBlock::Create(getGlobalContext(), "entry", mainFunction, 0);
currentFunction = mainFunction;
/* Push a new variable/block context */
pushBlock(bblock);
root.codeGen(*this); /* emit bytecode for the toplevel block */
ReturnInst::Create(getGlobalContext(), bblock);
popBlock();
/* Print the bytecode in a human-readable format
to see if our program compiled properly
*/
//std::cout << "Code is generated.\n";
PassManager pm;
pm.add(createPrintModulePass(outs()));
pm.run(*module);
}
示例3: llvmutil_emitobjfile
//adapted from LLVM's C interface "LLVMTargetMachineEmitToFile"
bool llvmutil_emitobjfile(Module * Mod, TargetMachine * TM, const char * Filename, std::string * ErrorMessage) {
PassManager pass;
llvmutil_addtargetspecificpasses(&pass, TM);
TargetMachine::CodeGenFileType ft = TargetMachine::CGFT_ObjectFile;
raw_fd_ostream dest(Filename, *ErrorMessage, raw_fd_ostream::F_Binary);
formatted_raw_ostream destf(dest);
if (!ErrorMessage->empty()) {
return true;
}
if (TM->addPassesToEmitFile(pass, destf, ft)) {
*ErrorMessage = "addPassesToEmitFile";
return true;
}
pass.run(*Mod);
destf.flush();
dest.flush();
return false;
}
示例4: run_pass
void SingleImplPass::run_pass(DexStoresVector& stores, ConfigFiles& cfg, PassManager& mgr) {
auto scope = build_class_scope(stores);
ClassHierarchy ch = build_type_hierarchy(scope);
int max_steps = 0;
size_t previous_invoke_intf_count = s_invoke_intf_count;
removed_count = 0;
while (true) {
DEBUG_ONLY size_t scope_size = scope.size();
TypeToTypes intfs_to_classes;
TypeSet intfs;
build_type_maps(scope, intfs_to_classes, intfs);
TypeMap single_impl;
collect_single_impl(intfs_to_classes, single_impl);
std::unique_ptr<SingleImplAnalysis> single_impls =
SingleImplAnalysis::analyze(
scope, stores, single_impl, intfs, m_pass_config);
auto optimized = optimize(
std::move(single_impls), ch, scope, m_pass_config);
if (optimized == 0 || ++max_steps >= MAX_PASSES) break;
removed_count += optimized;
assert(scope_size > scope.size());
}
TRACE(INTF, 1, "Removed interfaces %ld\n", removed_count);
TRACE(INTF, 1,
"Updated invoke-interface to invoke-virtual %ld\n",
s_invoke_intf_count - previous_invoke_intf_count);
mgr.incr_metric(METRIC_REMOVED_INTERFACES, removed_count);
mgr.incr_metric(METRIC_INVOKE_INT_TO_VIRT,
s_invoke_intf_count - previous_invoke_intf_count);
post_dexen_changes(scope, stores);
}
示例5: 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;
}
示例6: run_pass
void AccessMarkingPass::run_pass(DexStoresVector& stores,
ConfigFiles& /* conf */,
PassManager& pm) {
auto scope = build_class_scope(stores);
ClassHierarchy ch = build_type_hierarchy(scope);
SignatureMap sm = build_signature_map(ch);
if (m_finalize_classes) {
auto n_classes_final = mark_classes_final(scope, ch);
pm.incr_metric("finalized_classes", n_classes_final);
TRACE(ACCESS, 1, "Finalized %lu classes\n", n_classes_final);
}
if (m_finalize_methods) {
auto n_methods_final = mark_methods_final(scope, ch);
pm.incr_metric("finalized_methods", n_methods_final);
TRACE(ACCESS, 1, "Finalized %lu methods\n", n_methods_final);
}
if (m_finalize_fields) {
auto n_fields_final = mark_fields_final(scope);
pm.incr_metric("finalized_fields", n_fields_final);
TRACE(ACCESS, 1, "Finalized %lu fields\n", n_fields_final);
}
auto candidates = devirtualize(sm);
auto dmethods = direct_methods(scope);
candidates.insert(candidates.end(), dmethods.begin(), dmethods.end());
if (m_privatize_methods) {
auto privates = find_private_methods(scope, candidates);
fix_call_sites_private(scope, privates);
mark_methods_private(privates);
pm.incr_metric("privatized_methods", privates.size());
TRACE(ACCESS, 1, "Privatized %lu methods\n", privates.size());
}
}
示例7: makeArrayRef
void minipascal::CodeGenContext::generateCode(minipascal::Node* root)
{
vector<llvm::Type*> argTypes;
FunctionType *ftype = FunctionType::get(llvm::Type::getVoidTy(getGlobalContext()), makeArrayRef(argTypes), false);
Function* mainfunc = Function::Create(ftype, GlobalValue::InternalLinkage, "main", mmodule);
BasicBlock* mainblock = BasicBlock::Create(getGlobalContext(), "entry", mainfunc, 0);
pushFunction(mainfunc);
pushBlock(mainblock);
// root->print();
root->codeGen(*this);
// printConstVal();
// printTypeDefs();
// printVarTypes();
// printLocalVal();
ReturnInst::Create(getGlobalContext(), currentBlock());
popBlock();
mmodule->dump();
cout << "write to file out.ll start\n";
string errorstr("Can not open the file");
raw_fd_ostream outfile("out.ll", errorstr, 0);
verifyModule(*mmodule, PrintMessageAction);
PassManager passman;
passman.add(createPrintModulePass(&outfile));
passman.run(*mmodule);
// WriteBitcodeToFile(mmodule, outfile);
cout << "write to file out.ll end\n";
}
示例8: LLVMRustWriteOutputFile
extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
LLVMModuleRef M,
const char *triple,
const char *path,
TargetMachine::CodeGenFileType FileType,
CodeGenOpt::Level OptLevel) {
// Set compilation options.
llvm::NoFramePointerElim = true;
InitializeAllTargets();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
TargetMachine::setRelocationModel(Reloc::PIC_);
std::string Err;
const Target *TheTarget = TargetRegistry::lookupTarget(triple, Err);
std::string FeaturesStr;
std::string Trip(triple);
std::string CPUStr = llvm::sys::getHostCPUName();
TargetMachine *Target = TheTarget->createTargetMachine(Trip, CPUStr, FeaturesStr);
bool NoVerify = false;
PassManager *PM = unwrap<PassManager>(PMR);
std::string ErrorInfo;
raw_fd_ostream OS(path, ErrorInfo,
raw_fd_ostream::F_Binary);
formatted_raw_ostream FOS(OS);
bool foo = Target->addPassesToEmitFile(*PM, FOS, FileType, OptLevel,
NoVerify);
assert(!foo);
(void)foo;
PM->run(*unwrap(M));
delete Target;
}
示例9: resolveTask
/// This is where the link is actually performed.
bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) {
if (ctx.getNodes().empty())
return false;
for (std::unique_ptr<Node> &ie : ctx.getNodes())
if (FileNode *node = dyn_cast<FileNode>(ie.get()))
ctx.getTaskGroup().spawn([node] { node->getFile()->parse(); });
std::vector<std::unique_ptr<File>> internalFiles;
ctx.createInternalFiles(internalFiles);
for (auto i = internalFiles.rbegin(), e = internalFiles.rend(); i != e; ++i) {
auto &members = ctx.getNodes();
members.insert(members.begin(), llvm::make_unique<FileNode>(std::move(*i)));
}
// Give target a chance to add files.
std::vector<std::unique_ptr<File>> implicitFiles;
ctx.createImplicitFiles(implicitFiles);
for (auto i = implicitFiles.rbegin(), e = implicitFiles.rend(); i != e; ++i) {
auto &members = ctx.getNodes();
members.insert(members.begin(), llvm::make_unique<FileNode>(std::move(*i)));
}
// Give target a chance to postprocess input files.
// Mach-O uses this chance to move all object files before library files.
// ELF adds specific undefined symbols resolver.
ctx.finalizeInputFiles();
// Do core linking.
ScopedTask resolveTask(getDefaultDomain(), "Resolve");
Resolver resolver(ctx);
if (!resolver.resolve()) {
ctx.getTaskGroup().sync();
return false;
}
std::unique_ptr<SimpleFile> merged = resolver.resultFile();
resolveTask.end();
// Run passes on linked atoms.
ScopedTask passTask(getDefaultDomain(), "Passes");
PassManager pm;
ctx.addPasses(pm);
if (std::error_code ec = pm.runOnFile(*merged)) {
diagnostics << "Failed to write file '" << ctx.outputPath()
<< "': " << ec.message() << "\n";
return false;
}
passTask.end();
// Give linked atoms to Writer to generate output file.
ScopedTask writeTask(getDefaultDomain(), "Write");
if (std::error_code ec = ctx.writeFile(*merged)) {
diagnostics << "Failed to write file '" << ctx.outputPath()
<< "': " << ec.message() << "\n";
return false;
}
return true;
}
示例10: 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);
}
示例11: main
int main(int argc, char **argv) {
if (argc < 2) {
errs() << "Usage: " << argv[0] << " <IR file>\n";
return 1;
}
// Parse the input LLVM IR file into a module.
SMDiagnostic Err;
std::unique_ptr<Module> Mod(parseIRFile(argv[1], Err, getGlobalContext()));
if (!Mod) {
Err.print(argv[0], errs());
return 1;
}
// Create a function declarations for _tidx, _tidy, _tidz
FunctionType *TidFuncTy =
FunctionType::get(Type::getInt32Ty(Mod->getContext()), false);
Function *Tidx = Function::Create(TidFuncTy, GlobalValue::InternalLinkage,
"_tidx", Mod.get());
Function *Tidy = Function::Create(TidFuncTy, GlobalValue::InternalLinkage,
"_tidy", Mod.get());
Function *Tidz = Function::Create(TidFuncTy, GlobalValue::InternalLinkage,
"_tidz", Mod.get());
// Create a pass manager and fill it with the passes we want to run.
PassManager PM;
PM.add(new ReplaceThreadIdxRefs(Tidx, Tidy, Tidz));
PM.run(*Mod);
outs() << "Dumping the module after the pass has run:\n";
Mod->dump();
return 0;
}
示例12: 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>());
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}