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


C++ Module::getFunction方法代码示例

本文整理汇总了C++中llvm::Module::getFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ Module::getFunction方法的具体用法?C++ Module::getFunction怎么用?C++ Module::getFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在llvm::Module的用法示例。


在下文中一共展示了Module::getFunction方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleNonNullArgCall

  void NullDerefProtectionTransformer::handleNonNullArgCall(llvm::Module& M,
    const std::string& name, const std::bitset<32>& ArgIndexs) {

    // Get the function by the name.
    llvm::Function* func = M.getFunction(name);
    if (!func)
      return;

    // Find all the instructions that calls the function.
    std::vector<llvm::Instruction*> WorkList;
    for (llvm::Value::use_iterator I = func->use_begin(), E = func->use_end();
          I != E; ++I) {
      llvm::CallSite CS(*I);
      if (!CS || CS.getCalledValue() != func)
        continue;
      WorkList.push_back(CS.getInstruction());
    }

    // There is no call instructions that call the function and return.
    if (WorkList.empty())
      return;

    // Instrument all the call instructions that call the function.
    for (std::vector<llvm::Instruction*>::iterator I = WorkList.begin(),
           E = WorkList.end(); I != E; ++I) {
      Inst = *I;
      Builder->SetInsertPoint(Inst);
      instrumentCallInst(Inst, ArgIndexs);
    }
    return;
  }
开发者ID:agheorghiu,项目名称:root,代码行数:31,代码来源:NullDerefProtectionTransformer.cpp

示例2: runOnModule

bool TimeProfiler::runOnModule(llvm::Module &M)
{
  Function *Main = M.getFunction("main");
  if (Main == 0) {
    errs() << "WARNING: cannot insert edge profiling into a module"
           << " with no main function!\n";
    return false;  // No main, no instrumentation!
  }

  std::vector<CallInst*> Traped;
  Function* wtime = NULL;
  for(auto F = M.begin(), E = M.end(); F!=E; ++F){
     if((*F).getName() == "mpi_wtime_")
        wtime = &*F;
     for(auto I = inst_begin(*F), IE = inst_end(*F); I!=IE; ++I){
        CallInst* CI = dyn_cast<CallInst>(&*I);
        if(CI == NULL) continue;
        Value* CV = const_cast<CallInst*>(CI)->getCalledValue();
        Function* func = dyn_cast<Function>(castoff(CV));
        if(func == NULL)
          errs()<<"No func!\n";
        StringRef str = func->getName();
        if(str.startswith("mpi_"))
        {
           if(str.startswith("mpi_init_")||str.startswith("mpi_comm_rank_")||str.startswith("mpi_comm_size_"))
              continue;
           Traped.push_back(CI);
        }
     }
  }

  IRBuilder<> Builder(M.getContext());

  Type* DoubleTy = Type::getDoubleTy(M.getContext());

  Type*ATy = ArrayType::get(DoubleTy, Traped.size());
  GlobalVariable* Counters = new GlobalVariable(M, ATy, false,
        GlobalVariable::InternalLinkage, Constant::getNullValue(ATy),
        "TimeCounters");

  unsigned I=0;
  for(auto P : Traped){
     ArrayRef<Value*> args;
     CallInst* callTime = CallInst::Create(wtime, args, "", P);

     IncrementTimeCounter(callTime, wtime, I++, Counters, Builder, P);
  }

  InsertPredProfilingInitCall(Main, "llvm_start_time_profiling", Counters);
  return true;
}
开发者ID:wzzhang-HIT,项目名称:llvm-prof,代码行数:51,代码来源:TimeProfiling.cpp

示例3: vpc

bool
IRDynamicChecks::runOnModule(llvm::Module &M)
{
    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));

    llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str()));

    if (!function)
    {
        if (log)
            log->Printf("Couldn't find %s() in the module", m_func_name.c_str());

        return false;
    }

    if (m_checker_functions.m_valid_pointer_check)
    {
        ValidPointerChecker vpc(M, m_checker_functions);

        if (!vpc.Inspect(*function))
            return false;

        if (!vpc.Instrument())
            return false;
    }

    if (m_checker_functions.m_objc_object_check)
    {
        ObjcObjectChecker ooc(M, m_checker_functions);

        if (!ooc.Inspect(*function))
            return false;

        if (!ooc.Instrument())
            return false;
    }

    if (log && log->GetVerbose())
    {
        std::string s;
        raw_string_ostream oss(s);

        M.print(oss, nullptr);

        oss.flush();

        log->Printf ("Module after dynamic checks: \n%s", s.c_str());
    }

    return true;
}
开发者ID:Aj0Ay,项目名称:lldb,代码行数:51,代码来源:IRDynamicChecks.cpp

示例4: runOnModule

bool DeclareAssumePass::runOnModule(llvm::Module &M){
  bool modified_M = false;
  CheckModule::check_assume(&M);
  llvm::Function *F_assume = M.getFunction("__VERIFIER_assume");
  if(!F_assume){
    llvm::FunctionType *assumeTy;
    {
      llvm::Type *voidTy = llvm::Type::getVoidTy(M.getContext());
      llvm::Type *i1Ty = llvm::Type::getInt1Ty(M.getContext());
      assumeTy = llvm::FunctionType::get(voidTy,{i1Ty},false);
    }
    llvm::AttributeSet assumeAttrs =
      llvm::AttributeSet::get(M.getContext(),llvm::AttributeSet::FunctionIndex,
                              std::vector<llvm::Attribute::AttrKind>({llvm::Attribute::NoUnwind}));
    F_assume = llvm::dyn_cast<llvm::Function>(M.getOrInsertFunction("__VERIFIER_assume",assumeTy,assumeAttrs));
    assert(F_assume);
    modified_M = true;
  }
  return modified_M;
}
开发者ID:kostis,项目名称:nidhugg,代码行数:20,代码来源:SpinAssumePass.cpp

示例5: doInitialization

bool UnsafeTypeCastingCheck::doInitialization(llvm::Module &mod) { 
  errs() << "initialization... \n"; 
  
  for (Module::global_iterator git = mod.global_begin() ;
       git != mod.global_end() ; 
       git++) {
    GlobalValue *gv = dyn_cast<GlobalValue>(git);
    string gv_name = gv->getName().str(); 
    if (gv_name.compare("blockDim") == 0 || 
	gv_name.compare("gridDim") == 0 || 
	gv_name.compare("blockIdx") == 0 || 
	gv_name.compare("threadIdx") == 0) {
      setPointedType(gv, UINT_UT); 
    }
  }

  // get utcc_assert function call (assertion) 
  code_modified = false; 
  assert_func = mod.getFunction("utcc_assert"); 
  assert(assert_func != NULL); 

  return false; 
}
开发者ID:wfchiang,项目名称:llvm-utcc,代码行数:23,代码来源:UnsafeTypeCastingCheck.cpp

示例6: deleteAsmBodies

void Prepare::deleteAsmBodies(llvm::Module &M) {
  static const char *toDelete[] = {
    "atomic_inc", "atomic_dec", "atomic_add", "atomic_sub",
    "atomic_dec_and_test", "atomic_add_return",
    "atomic64_inc", "atomic64_dec", "atomic64_add", "atomic64_sub",
    "local_inc", "local_dec",
    "__fswab16", "__fswab32", "__fswab64",
    "__xchg", "__cmpxchg",
    "__set_bit", "__clear_bit", "set_bit", "clear_bit",
    "variable_test_bit",
    "__test_and_set_bit", "__test_and_clear_bit",
    "test_and_set_bit", "test_and_clear_bit",
    "__fls", "fls", "__ffs", "ffs", "ffz",
    "inb", "inw", "inl",
    "insb", "insw", "insl",
    "inb_p", "inw_p", "inl_p",
    "readb", "readw", "readl", "readq",
    "__readb", "__readw", "__readl", "__readq",

    "___arch__swab32", "___arch__swab64" // generates false positives in stats
  };
  static const char *_makeNop[] = {
    "pagefault_disable",
    "__raw_local_save_flags", "raw_local_irq_restore",
    "raw_local_irq_enable", "raw_local_irq_disable",
    "__raw_spin_is_contended",
    "local_bh_enable", "local_bh_disable",
    "schedule", "schedule_timeout", "schedule_timeout_interruptible",
    "schedule_timeout_uninterruptible",
    "preempt_schedule",
    "msleep", "msleep_interruptible", "__udelay", "__const_udelay",
    "printk_ratelimit", "warn_slowpath", "warn_on_slowpath", "dump_stack",
    "printk", "vprintk", "snd_verbose_printk",
    "rep_nop",
    "outb", "outw", "outl",
    "outsb", "outsw", "outsl",
    "outb_p", "outw_p", "outl_p",
    "writeb", "writew", "writel", "writeq",
    "__writeb", "__writew", "__writel", "__writeq",

    "mod_timer", "__mod_timer", "del_timer", "del_timer_sync",
    "complete", "wait_for_completion",
    "interruptible_sleep_on",
    "add_wait_queue", "remove_wait_queue", "prepare_to_wait", "finish_wait",
    "__tasklet_schedule",
    "queue_work", "schedule_work", "flush_scheduled_work",
    "schedule_delayed_work",
    "__wake_up", "wake_up_process", "wake_up_state", "kill_fasync"
  };
  unsigned int i;

  for (i = 0; i < ARRAY_SIZE(toDelete); i++) {
    Function *F = M.getFunction(toDelete[i]);
    if (F)
      F->deleteBody();
  }
  for (i = 0; i < ARRAY_SIZE(_makeNop); i++) {
    Function *F = M.getFunction(_makeNop[i]);
    if (F)
      makeNop(F);
  }
}
开发者ID:RedlineResearch,项目名称:LLVMSlicer,代码行数:62,代码来源:Prepare.cpp

示例7: AllLinkLibraries

bool swift::immediate::IRGenImportedModules(
    CompilerInstance &CI,
    llvm::Module &Module,
    llvm::SmallPtrSet<swift::Module *, 8> &ImportedModules,
    SmallVectorImpl<llvm::Function*> &InitFns,
    IRGenOptions &IRGenOpts,
    const SILOptions &SILOpts) {
  swift::Module *M = CI.getMainModule();

  // Perform autolinking.
  SmallVector<LinkLibrary, 4> AllLinkLibraries(IRGenOpts.LinkLibraries);
  auto addLinkLibrary = [&](LinkLibrary linkLib) {
    AllLinkLibraries.push_back(linkLib);
  };

  M->forAllVisibleModules({}, /*includePrivateTopLevel=*/true,
                          [&](Module::ImportedModule import) {
    import.second->collectLinkLibraries(addLinkLibrary);
  });

  // Hack to handle thunks eagerly synthesized by the Clang importer.
  swift::Module *prev = nullptr;
  for (auto external : CI.getASTContext().ExternalDefinitions) {
    swift::Module *next = external->getModuleContext();
    if (next == prev)
      continue;
    next->collectLinkLibraries(addLinkLibrary);
    prev = next;
  }

  tryLoadLibraries(AllLinkLibraries, CI.getASTContext().SearchPathOpts,
                   CI.getDiags());

  ImportedModules.insert(M);
  if (!CI.hasSourceImport())
    return false;

  // IRGen the modules this module depends on. This is only really necessary
  // for imported source, but that's a very convenient thing to do in -i mode.
  // FIXME: Crawling all loaded modules is a hack.
  // FIXME: And re-doing SILGen, SIL-linking, SIL diagnostics, and IRGen is
  // expensive, because it's not properly being limited to new things right now.
  bool hadError = false;
  for (auto &entry : CI.getASTContext().LoadedModules) {
    swift::Module *import = entry.second;
    if (!ImportedModules.insert(import).second)
      continue;

    std::unique_ptr<SILModule> SILMod = performSILGeneration(import,
                                                             CI.getSILOptions());
    performSILLinking(SILMod.get());
    if (runSILDiagnosticPasses(*SILMod)) {
      hadError = true;
      break;
    }

    // FIXME: We shouldn't need to use the global context here, but
    // something is persisting across calls to performIRGeneration.
    auto SubModule = performIRGeneration(IRGenOpts, import, SILMod.get(),
                                         import->getName().str(),
                                         llvm::getGlobalContext());

    if (CI.getASTContext().hadError()) {
      hadError = true;
      break;
    }

    if (!linkLLVMModules(&Module, std::move(SubModule)
                         // TODO: reactivate the linker mode if it is
                         // supported in llvm again. Otherwise remove the
                         // commented code completely.
                         /*, llvm::Linker::DestroySource */)) {
      hadError = true;
      break;
    }

    // FIXME: This is an ugly hack; need to figure out how this should
    // actually work.
    SmallVector<char, 20> NameBuf;
    StringRef InitFnName = (import->getName().str() + ".init").toStringRef(NameBuf);
    llvm::Function *InitFn = Module.getFunction(InitFnName);
    if (InitFn)
      InitFns.push_back(InitFn);
  }

  return hadError;
}
开发者ID:jxyang,项目名称:swift,代码行数:87,代码来源:Immediate.cpp

示例8: Simulate

void Simulator::Simulate()
{
  llvm::SMDiagnostic error;
  //std::unique_ptr<llvm::Module> M = llvm::ParseIRFile("Behavior.bc", error, context);
  //MyModule = M.get();
  MyModule = llvm::ParseIRFile("Behavior.bc", error, context);
  string err_str;
/*
    OwningPtr<MemoryBuffer> result;
    MemoryBuffer *mb;
    llvm::error_code ec = MemoryBuffer::getFile("Behavior.bc", result);
    mb = result.take();
    err_str = ec.message();
    if (!mb) {
      error() <<"Cannot open \"" <<bitcode_file() <<"\": " <<err_str <<endl;
      exit(1);
    }
    MyModule = llvm::ParseBitcodeFile(mb,context,&err_str);
    if (!MyModule) {
      error() <<"Failed to load module from bitcode file: " <<err_str <<endl;
      exit(1);
    }
    delete mb;
*/
/*
    for (llvm::Module::iterator f = MyModule->begin(), ef = MyModule->end(); f!=ef; ++f) 
    {
      f->addFnAttr(Attributes::AlwaysInline);
    }
*/
    for (int32_t i = 0; i < (int32_t)OPCODE::INVALID; i++) {
      OPCODE op = (OPCODE) i;
      llvm::Function *func = MyModule->getFunction(GetFuncName(op));
      func->addFnAttr(llvm::Attribute::AlwaysInline);
      OpFunctionMap[op] = func; 
    }
    test_type = MyModule->getFunction("test")->getFunctionType();


    std::string ErrStr;
    passManager = new llvm::PassManager();
    passManager->add(llvm::createAlwaysInlinerPass());
    fPassManager = new llvm::FunctionPassManager(MyModule);
    //fPassManager->add(new DataLayout(*EE->getDataLayout()));
    //fPassManager->add(new DataLayout(*EE->getDataLayout()));
    fPassManager->add(llvm::createGVNPass());
    fPassManager->add(llvm::createInstructionCombiningPass());
    fPassManager->add(llvm::createCFGSimplificationPass());
    fPassManager->add(llvm::createDeadStoreEliminationPass());

/*
    llvm::EngineBuilder builder(MyModule);
    builder.setErrorStr(&ErrStr);
    builder.setEngineKind(llvm::EngineKind::JIT);
    builder.setOptLevel(llvm::CodeGenOpt::Default); // None/Less/Default/Aggressive
    //llvm::TargetOptions options;
    //options.JITExceptionHandling = 1;
    //builder.setTargetOptions(options);
    EE = builder.create();
*/
  //StringRef MCPU = llvm::sys::getHostCPUName()
  EE = llvm::EngineBuilder(MyModule).create(); 
/*
    EE =
      llvm::EngineBuilder(std::move(M))
          .setErrorStr(&ErrStr)
          .setMCJITMemoryManager(llvm::make_unique<llvm::SectionMemoryManager>())
          .create();
*/
/*
    EE = llvm::EngineBuilder(M)
                .setErrorStr(&ErrStr)
                .setMCJITMemoryManager(llvm::SectionMemoryManager())
                .create();
    EE = llvm::EngineBuilder(std::move(M)).setErrorStr(&ErrStr).create();

*/
    if (!EE) {
      fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
      exit(1);
    }
    EE->DisableLazyCompilation(true);


/*
    //atexit(llvm_shutdown);  // Call llvm_shutdown() on exit.
    //llvm::EngineBuilder builder(MyModule);
    llvm::EngineBuilder builder(std::move(M));
    //llvm::EngineBuilder builder(MyModule);
    builder.setErrorStr(&err_str);
    builder.setEngineKind(llvm::EngineKind::JIT);
    builder.setOptLevel(llvm::CodeGenOpt::Default); // None/Less/Default/Aggressive
    //TargetOptions options;
    //options.JITExceptionHandling = 1;
    //builder.setTargetOptions(options);
    EE = builder.create();
    if (!EE) {
      std::cout <<"failed to create execution engine: " <<err_str <<"\n";
      exit(1);
    }
//.........这里部分代码省略.........
开发者ID:Rahul3527,项目名称:iss,代码行数:101,代码来源:Simulator.cpp


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