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


C++ llvm::Module类代码示例

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


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

示例1: replaceModuleFlagsEntry

static bool replaceModuleFlagsEntry(llvm::LLVMContext &Ctx,
                                    llvm::Module &Module, StringRef EntryName,
                                    llvm::Module::ModFlagBehavior Behavior,
                                    llvm::Metadata *Val) {
  auto *ModuleFlags = Module.getModuleFlagsMetadata();

  for (unsigned I = 0, E = ModuleFlags->getNumOperands(); I != E; ++I) {
    llvm::MDNode *Op = ModuleFlags->getOperand(I);
    llvm::MDString *ID = cast<llvm::MDString>(Op->getOperand(1));

    if (ID->getString().equals(EntryName)) {

      // Create the new entry.
      llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx);
      llvm::Metadata *Ops[3] = {llvm::ConstantAsMetadata::get(
                                    llvm::ConstantInt::get(Int32Ty, Behavior)),
                                llvm::MDString::get(Ctx, EntryName), Val};

      ModuleFlags->setOperand(I, llvm::MDNode::get(Ctx, Ops));
      return true;
    }
  }
  llvm_unreachable("Could not replace old linker options entry?");
}
开发者ID:antonvmironov,项目名称:swift,代码行数:24,代码来源:IRGenModule.cpp

示例2: 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

示例3: printLLVMModule

 void ClangInternalState::printLLVMModule(llvm::raw_ostream& Out,
                                          llvm::Module& M,
                                          CodeGenerator& CG) {
   M.print(Out, /*AssemblyAnnotationWriter*/ 0);
   CG.print(Out);
 }
开发者ID:CristinaCristescu,项目名称:root,代码行数:6,代码来源:ClangInternalState.cpp

示例4: Context

CodeGenASTVisitor::CodeGenASTVisitor(llvm::Module& targetModule)
    : Context(targetModule.getContext())
    , TargetModule(targetModule)
    , Builder(TargetModule.getContext())
{ }
开发者ID:mfurquim,项目名称:simple-llvm-lang,代码行数:5,代码来源:codegen.cpp

示例5: buildMemModel

/*!
 *  This method identify which is value sym and which is object sym
 */
void SymbolTableInfo::buildMemModel(llvm::Module& module) {
    analysisUtil::increaseStackSize();

    prePassSchedule(module);

    mod = &module;

    maxFieldLimit = maxFieldNumLimit;

    // Object #0 is black hole the object that may point to any object
    assert(totalSymNum == BlackHole && "Something changed!");
    symTyMap.insert(std::make_pair(totalSymNum++, BlackHole));
    createBlkOrConstantObj(BlackHole);

    // Object #1 always represents the constant
    assert(totalSymNum == ConstantObj && "Something changed!");
    symTyMap.insert(std::make_pair(totalSymNum++, ConstantObj));
    createBlkOrConstantObj(ConstantObj);

    // Pointer #2 always represents the pointer points-to black hole.
    assert(totalSymNum == BlkPtr && "Something changed!");
    symTyMap.insert(std::make_pair(totalSymNum++, BlkPtr));

    // Pointer #3 always represents the null pointer.
    assert(totalSymNum == NullPtr && "Something changed!");
    symTyMap.insert(std::make_pair(totalSymNum, NullPtr));

    // Add symbols for all the globals .
    for (Module::global_iterator I = module.global_begin(), E =
                module.global_end(); I != E; ++I) {
        collectSym(&*I);
    }

    // Add symbols for all the global aliases
    for (Module::alias_iterator I = module.alias_begin(), E =
                module.alias_end(); I != E; I++) {
        collectSym(&*I);
    }

    // Add symbols for all of the functions and the instructions in them.
    for (Module::iterator F = module.begin(), E = module.end(); F != E; ++F) {
        collectSym(&*F);
        collectRet(&*F);
        if (F->getFunctionType()->isVarArg())
            collectVararg(&*F);

        // Add symbols for all formal parameters.
        for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
                I != E; ++I) {
            collectSym(&*I);
        }

        // collect and create symbols inside the function body
        for (inst_iterator II = inst_begin(&*F), E = inst_end(&*F); II != E; ++II) {
            const Instruction *inst = &*II;
            collectSym(inst);

            // initialization for some special instructions
            //{@
            if (const StoreInst *st = dyn_cast<StoreInst>(inst)) {
                collectSym(st->getPointerOperand());
                collectSym(st->getValueOperand());
            }

            else if (const LoadInst *ld = dyn_cast<LoadInst>(inst)) {
                collectSym(ld->getPointerOperand());
            }

            else if (const PHINode *phi = dyn_cast<PHINode>(inst)) {
                for (u32_t i = 0; i < phi->getNumIncomingValues(); ++i) {
                    collectSym(phi->getIncomingValue(i));
                }
            }

            else if (const GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(
                    inst)) {
                collectSym(gep->getPointerOperand());
            }

            else if (const SelectInst *sel = dyn_cast<SelectInst>(inst)) {
                collectSym(sel->getTrueValue());
                collectSym(sel->getFalseValue());
            }

            else if (const CastInst *cast = dyn_cast<CastInst>(inst)) {
                collectSym(cast->getOperand(0));
            }
            else if (const ReturnInst *ret = dyn_cast<ReturnInst>(inst)) {
                if(ret->getReturnValue())
                    collectSym(ret->getReturnValue());
            }
            else if (isCallSite(inst) && isInstrinsicDbgInst(inst)==false) {

                CallSite cs = analysisUtil::getLLVMCallSite(inst);
                callSiteSet.insert(cs);
                for (CallSite::arg_iterator it = cs.arg_begin();
                        it != cs.arg_end(); ++it) {
//.........这里部分代码省略.........
开发者ID:melbcat,项目名称:SVF,代码行数:101,代码来源:MemModel.cpp

示例6: generateProgram

void SmackModuleGenerator::generateProgram(llvm::Module& M) {

  Naming naming;
  SmackRep rep(M.getDataLayout(), naming, program, getAnalysis<Regions>());
  std::list<Decl*>& decls = program.getDeclarations();

  DEBUG(errs() << "Analyzing globals...\n");

  for (auto& G : M.globals()) {
    auto ds = rep.globalDecl(&G);
    decls.insert(decls.end(), ds.begin(), ds.end());
  }

  DEBUG(errs() << "Analyzing functions...\n");

  for (auto& F : M) {

    // Reset the counters for per-function names
    naming.reset();

    DEBUG(errs() << "Analyzing function: " << naming.get(F) << "\n");

    auto ds = rep.globalDecl(&F);
    decls.insert(decls.end(), ds.begin(), ds.end());

    auto procs = rep.procedure(&F);
    assert(procs.size() > 0);

    if (naming.get(F) != Naming::DECLARATIONS_PROC)
      decls.insert(decls.end(), procs.begin(), procs.end());

    if (F.isDeclaration())
      continue;

    if (!F.empty() && !F.getEntryBlock().empty()) {
      DEBUG(errs() << "Analyzing function body: " << naming.get(F) << "\n");

      for (auto P : procs) {
        SmackInstGenerator igen(getAnalysis<LoopInfo>(F), rep, *P, naming);
        DEBUG(errs() << "Generating body for " << naming.get(F) << "\n");
        igen.visit(F);
        DEBUG(errs() << "\n");

        // First execute static initializers, in the main procedure.
        if (F.hasName() && SmackOptions::isEntryPoint(F.getName())) {
          P->insert(Stmt::call(Naming::INITIALIZE_PROC));

        } else if (naming.get(F).find(Naming::INIT_FUNC_PREFIX) == 0)
          rep.addInitFunc(&F);
      }
      DEBUG(errs() << "Finished analyzing function: " << naming.get(F) << "\n\n");
    }

    // MODIFIES
    // ... to do below, after memory splitting is determined.
  }

  auto ds = rep.auxiliaryDeclarations();
  decls.insert(decls.end(), ds.begin(), ds.end());
  decls.insert(decls.end(), rep.getInitFuncs());

  // NOTE we must do this after instruction generation, since we would not
  // otherwise know how many regions to declare.
  program.appendPrelude(rep.getPrelude());

  std::list<Decl*> kill_list;
  for (auto D : program) {
    if (auto P = dyn_cast<ProcDecl>(D)) {
      if (D->getName().find(Naming::CONTRACT_EXPR) != std::string::npos) {
        decls.insert(decls.end(), Decl::code(P));
        kill_list.push_back(P);
      }
    }
  }
  for (auto D : kill_list)
    decls.erase(std::remove(decls.begin(), decls.end(), D), decls.end());
}
开发者ID:Guoanshisb,项目名称:smack,代码行数:77,代码来源:SmackModuleGenerator.cpp

示例7: CheckCandidateMap

bool CheckCandidateMap(llvm::Module &Mod, CandidateMap &M, Solver *S,
                       InstContext &IC) {
  if (!S) {
    llvm::errs() << "Solver required in -check mode\n";
    return false;
  }

  unsigned ExpectedID = Mod.getContext().getMDKindID("expected");

  bool OK = true;
  for (auto &Cand : M) {
    Inst *RHS;
    if (std::error_code EC =
            S->infer(Cand.PCs, Cand.Mapping.LHS, RHS, &Cand.Origin, IC)) {
      llvm::errs() << "Unable to query solver: " << EC.message() << '\n';
      return false;
    }
    if (RHS) {
      Cand.Mapping.RHS = RHS;
      if (Cand.Mapping.RHS->K != Inst::Const) {
        llvm::errs() << "found replacement:\n";
        Cand.printFunction(llvm::errs());
        Cand.print(llvm::errs());
        llvm::errs() << "but cannot yet analyze non-constant replacements\n";
        OK = false;
        continue;
      }
      llvm::APInt ActualVal = Cand.Mapping.RHS->Val;

      llvm::Instruction *Inst = Cand.Origin.getInstruction();
      llvm::MDNode *ExpectedMD = Inst->getMetadata(ExpectedID);
      if (!ExpectedMD) {
        llvm::errs() << "instruction:\n";
        Inst->dump();
        llvm::errs() << "unexpected simplification:\n";
        Cand.printFunction(llvm::errs());
        Cand.print(llvm::errs());
        OK = false;
        continue;
      }
      if (ExpectedMD->getNumOperands() != 1 ||
          !isa<llvm::ConstantInt>(ExpectedMD->getOperand(0))) {
        llvm::errs() << "instruction:\n";
        Inst->dump();
        llvm::errs() << "invalid metadata\n";
        OK = false;
        continue;
      }
      llvm::APInt ExpectedVal =
        cast<llvm::ConstantInt>(ExpectedMD->getOperand(0))->getValue();
      Inst->setMetadata(ExpectedID, 0);
      if (ExpectedVal != ActualVal) {
        llvm::errs() << "instruction:\n";
        Inst->dump();
        llvm::errs() << "unexpected simplification, wanted " << ExpectedVal
                     << ":\n";
        Cand.printFunction(llvm::errs());
        Cand.print(llvm::errs());
        OK = false;
        continue;
      }
    }
  }

  for (const auto &F : Mod) {
    for (const auto &BB : F) {
      for (const auto &Inst : BB) {
        llvm::MDNode *ExpectedMD = Inst.getMetadata(ExpectedID);
        if (ExpectedMD) {
          llvm::errs() << "instruction:\n";
          Inst.dump();
          llvm::errs() << "expected simplification, none found\n";
          OK = false;
          continue;
        }
      }
    }
  }

  return OK;
}
开发者ID:pcc,项目名称:souper,代码行数:81,代码来源:CandidateMapUtils.cpp

示例8: Compiler

 Compiler(llvm::Module& module_) :
   module(module_),
   builder(module_.getContext()),
   endLoopBlock(nullptr),
   result(nullptr)
 {}
开发者ID:boardwalk,项目名称:xra,代码行数:6,代码来源:compiler.hpp

示例9: HasMDString

/// ValueEnumerator - Enumerate module-level information.
ValueEnumerator::ValueEnumerator(const llvm::Module &M,
                                 bool ShouldPreserveUseListOrder)
    : HasMDString(false), HasDILocation(false),
    ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
  assert(!ShouldPreserveUseListOrder &&
         "not supported UseListOrders = predictUseListOrder(M)");

  // Enumerate the global variables.
  for (llvm::Module::const_global_iterator I = M.global_begin(), E = M.global_end();
       I != E; ++I)
    EnumerateValue(I);

  // Enumerate the functions.
  for (llvm::Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
    EnumerateValue(I);
    EnumerateAttributes(cast<Function>(I)->getAttributes());
  }

  // Enumerate the aliases.
  for (llvm::Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
       I != E; ++I)
    EnumerateValue(I);

  // Remember what is the cutoff between globalvalue's and other constants.
  unsigned FirstConstant = Values.size();

  // Enumerate the global variable initializers.
  for (llvm::Module::const_global_iterator I = M.global_begin(), E = M.global_end();
       I != E; ++I)
    if (I->hasInitializer())
      EnumerateValue(I->getInitializer());

  // Enumerate the aliasees.
  for (llvm::Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
       I != E; ++I)
    EnumerateValue(I->getAliasee());

  // Enumerate the metadata type.
  //
  // TODO: Move this to ValueEnumerator::EnumerateOperandType() once bitcode
  // only encodes the metadata type when it's used as a value.
  EnumerateType(Type::getMetadataTy(M.getContext()));

  // Insert constants and metadata that are named at module level into the slot
  // pool so that the module symbol table can refer to them...
  EnumerateValueSymbolTable(M.getValueSymbolTable());
  EnumerateNamedMetadata(M);

  SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;

  // Enumerate types used by function bodies and argument lists.
  for (const Function &F : M) {
    for (const Argument &A : F.args())
      EnumerateType(A.getType());

    for (const BasicBlock &BB : F)
      for (const Instruction &I : BB) {
        for (const Use &Op : I.operands()) {
          auto *MD = dyn_cast<MetadataAsValue>(&Op);
          if (!MD) {
            EnumerateOperandType(Op);
            continue;
          }

          // Local metadata is enumerated during function-incorporation.
          if (isa<LocalAsMetadata>(MD->getMetadata()))
            continue;

          EnumerateMetadata(MD->getMetadata());
        }
        EnumerateType(I.getType());
        if (const CallInst *CI = dyn_cast<CallInst>(&I))
          EnumerateAttributes(CI->getAttributes());
        else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I))
          EnumerateAttributes(II->getAttributes());

        // Enumerate metadata attached with this instruction.
        MDs.clear();
        I.getAllMetadataOtherThanDebugLoc(MDs);
        for (unsigned i = 0, e = MDs.size(); i != e; ++i)
          EnumerateMetadata(MDs[i].second);

#if LLVM_VERSION >= 37
        if (I.getDebugLoc()) {
          MDNode* Scope = I.getDebugLoc().getScope();
          if (Scope) EnumerateMetadata(Scope);
          DILocation *IA = I.getDebugLoc().getInlinedAt();
          if (IA) EnumerateMetadata(IA);
        }
#else
        if (!I.getDebugLoc().isUnknown()) {
          MDNode *Scope, *IA;
          I.getDebugLoc().getScopeAndInlinedAt(Scope, IA, I.getContext());
          if (Scope) EnumerateMetadata(Scope);
          if (IA) EnumerateMetadata(IA);
        }
#endif
      }
  }
//.........这里部分代码省略.........
开发者ID:LilliamGonzalez-Alayon,项目名称:Halide,代码行数:101,代码来源:ValueEnumerator.cpp

示例10: EnumerateNamedMetadata

/// EnumerateNamedMetadata - Insert all of the values referenced by
/// named metadata in the specified module.
void ValueEnumerator::EnumerateNamedMetadata(const llvm::Module &M) {
  for (llvm::Module::const_named_metadata_iterator I = M.named_metadata_begin(),
                                             E = M.named_metadata_end();
       I != E; ++I)
    EnumerateNamedMDNode(I);
}
开发者ID:LilliamGonzalez-Alayon,项目名称:Halide,代码行数:8,代码来源:ValueEnumerator.cpp

示例11: assert

bool
RenderScriptRuntimeModulePass::runOnModule(llvm::Module &module)
{
    bool changed_module = false;
    Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE | LIBLLDB_LOG_EXPRESSIONS));

    std::string err;
    llvm::StringRef real_triple = m_process_ptr->GetTarget().GetArchitecture().GetTriple().getTriple();
    const llvm::Target *target_info = llvm::TargetRegistry::lookupTarget(real_triple, err);
    if (!target_info)
    {
        if (log)
            log->Warning("couldn't determine real target architecture: '%s'", err.c_str());
        return false;
    }

    llvm::Optional<llvm::Reloc::Model> reloc_model = llvm::None;
    assert(m_process_ptr && "no available lldb process");
    switch (m_process_ptr->GetTarget().GetArchitecture().GetMachine())
    {
        case llvm::Triple::ArchType::x86:
            changed_module |= fixupX86FunctionCalls(module);
            // For some reason this triple gets totally missed by the backend, and must be set manually.
            // There a reference in bcc/Main.cpp about auto feature-detection being removed from LLVM3.5, but I can't
            // see that discussion anywhere public.
            real_triple = "i686--linux-android";
            break;
        case llvm::Triple::ArchType::x86_64:
            changed_module |= fixupX86_64FunctionCalls(module);
            break;
        case llvm::Triple::ArchType::mipsel:
        case llvm::Triple::ArchType::mips64el:
            // No actual IR fixup pass is needed on MIPS, but the datalayout
            // and targetmachine do need to be explicitly set.

            // bcc explicitly compiles MIPS code to use the static relocation
            // model due to an issue with relocations in mclinker.
            // see libbcc/support/CompilerConfig.cpp for details
            reloc_model = llvm::Reloc::Static;
            changed_module = true;
            break;
        case llvm::Triple::ArchType::arm:
        case llvm::Triple::ArchType::aarch64:
            // ARM subtargets need no fixup passes as they are the initial target as generated by the
            // slang compiler frontend.
            break;
        default:
            if (log)
                log->Warning("Ignoring unknown renderscript target");
            return false;
    }

    if (changed_module)
    {
        llvm::TargetOptions options;
        llvm::TargetMachine *target_machine =
            target_info->createTargetMachine(real_triple, "", "", options, reloc_model);
        assert(target_machine && "failed to identify RenderScriptRuntime target machine");
        // We've been using a triple and datalayout of some ARM variant all along, so
        // we need to let the backend know that this is no longer the case.
        if (log)
        {
            log->Printf("%s - Changing RS target triple to '%s'", __FUNCTION__, real_triple.str().c_str());
            log->Printf("%s - Changing RS datalayout to '%s'", __FUNCTION__,
                        target_machine->createDataLayout().getStringRepresentation().c_str());
        }
        module.setTargetTriple(real_triple);
        module.setDataLayout(target_machine->createDataLayout());
    }
    return changed_module;
}
开发者ID:Aj0Ay,项目名称:lldb,代码行数:71,代码来源:RenderScriptExpressionOpts.cpp

示例12: get_aa_type_name

std::string Aa::get_aa_type_name(const llvm::Type* ptr, llvm::Module& tst)
{

	if(ptr->isVoidTy())
		return("$void");
	std::string ret_string = tst.getTypeName(ptr);
	if(ret_string != "")
		return(to_aa(ret_string));



	if(isa<PointerType>(ptr))
	{
		ret_string = "$pointer< ";
		const llvm::PointerType *ptr_pointer = dyn_cast<llvm::PointerType>(ptr);
		const llvm::Type* el_type = ptr_pointer->getElementType();
		ret_string += get_aa_type_name(el_type,tst);
		ret_string += " >"; 
	}
	else if(isa<ArrayType>(ptr) || isa<VectorType>(ptr))
	{

		const llvm::SequentialType *ptr_seq = dyn_cast<llvm::SequentialType>(ptr);
		const llvm::Type* el_type = ptr_seq->getElementType();

		int dim = 0;
		const llvm::ArrayType* ptr_array = dyn_cast<llvm::ArrayType>(ptr);
		if(ptr_array != NULL)
			dim = ptr_array->getNumElements();
		else
		{
			const llvm::VectorType* ptr_vec = dyn_cast<llvm::VectorType>(ptr);
			dim = ptr_vec->getNumElements();
		}

		ret_string = "$array [" + int_to_str(dim) + "] $of ";
		ret_string += get_aa_type_name(el_type,tst);
	}
	else if(isa<StructType>(ptr))
	{
		const llvm::StructType *ptr_struct = dyn_cast<llvm::StructType>(ptr);
		ret_string = "$record ";
		for(int idx = 0; idx < ptr_struct->getNumElements(); idx++)
		{
			ret_string += "< " ;
			ret_string += get_aa_type_name(ptr_struct->getElementType(idx),tst);
			ret_string += " > ";
		}
	}
	else if(isa<IntegerType>(ptr))
	{
		ret_string = "$uint<";
		const llvm::IntegerType*   ptr_int = dyn_cast<llvm::IntegerType>(ptr);
		ret_string += int_to_str(ptr_int->getBitWidth()) + ">";
	}
	else if(ptr->isFloatTy())
	{
		ret_string = "$float<8,23>";
	}
	else if(ptr->isDoubleTy())
	{
		ret_string = "$float<11,52>";
	}
	else if(ptr->isVoidTy())
	{
		ret_string = "$void";
	}
	else if(ptr->isFunctionTy())
	{
		std::cerr << "Warning: function type converted to void*" << std::endl;
		ret_string = "$pointer < $void > ";
	} 
	else
	{
		std::cerr << "Error: unsupported type" << std::endl;
		ret_string = "Unsupported_Type";
	}
	return(ret_string);
}
开发者ID:madhavPdesai,项目名称:ahir,代码行数:79,代码来源:Utils.cpp

示例13: compile_llvm_module_to_llvm_assembly

void compile_llvm_module_to_llvm_assembly(llvm::Module &module, Internal::LLVMOStream& out) {
    module.print(out, nullptr);
}
开发者ID:alinas,项目名称:Halide,代码行数:3,代码来源:LLVM_Output.cpp

示例14: error

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

示例15: doInitialization

bool TargetInfo::doInitialization(llvm::Module &m)
{
	dl = &m.getDataLayout();
	return ImmutablePass::doInitialization(m);
}
开发者ID:hoke-t,项目名称:fcd,代码行数:5,代码来源:pass_targetinfo.cpp


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