当前位置: 首页>>代码示例>>C++>>正文


C++ PassManager::add方法代码示例

本文整理汇总了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
}
开发者ID:otinn,项目名称:safecode,代码行数:29,代码来源:sc.cpp

示例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;
}
开发者ID:nsumner,项目名称:callgrapher-template,代码行数:30,代码来源:main.cpp

示例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;
}
开发者ID:bluemutedwisdom,项目名称:bhyve,代码行数:33,代码来源:llvm-stress.cpp

示例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);
}
开发者ID:crystax,项目名称:android-toolchain-llvm-3-6,代码行数:34,代码来源:ndk-translate.cpp

示例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;
}
开发者ID:hephaex,项目名称:llvm,代码行数:61,代码来源:LTOCodeGenerator.cpp

示例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;
}
开发者ID:c-ong,项目名称:llvm,代码行数:60,代码来源:LTOCodeGenerator.cpp

示例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>());
}
开发者ID:sas,项目名称:lld,代码行数:7,代码来源:MipsLinkingContext.cpp

示例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;
}
开发者ID:dmlap,项目名称:llvm-js-backend,代码行数:33,代码来源:LTOCodeGenerator.cpp

示例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;
}
开发者ID:otinn,项目名称:safecode,代码行数:59,代码来源:LTOCodeGenerator.cpp

示例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
}
开发者ID:dmlap,项目名称:llvm-js-backend,代码行数:60,代码来源:LTOCodeGenerator.cpp

示例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;
}
开发者ID:cschreiner,项目名称:llvm,代码行数:60,代码来源:LTOCodeGenerator.cpp

示例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));
}
开发者ID:Bigcheese,项目名称:lold,代码行数:8,代码来源:PECOFFLinkingContext.cpp

示例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);
}
开发者ID:pb2bee,项目名称:llvm-demo,代码行数:8,代码来源:main.cpp

示例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());
}
开发者ID:jirislaby,项目名称:klee,代码行数:10,代码来源:Optimize.cpp

示例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);
}
开发者ID:stuartarchibald,项目名称:libHLC,代码行数:58,代码来源:hlc.cpp


注:本文中的PassManager::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。