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


C++ IRBuilder::CreateLoad方法代码示例

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


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

示例1: Visit

void ASTCodeGenVisitor::Visit(DecrData* s) {
  IRBuilder<> builder = builders_.top();
  Value* ptr_val = builder.CreateLoad(ptr_);
  Value* result = builder.CreateAdd(ptr_val, neg_one);
  builder.CreateStore(result, ptr_);
  VisitNextASTNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:7,代码来源:codegen_ast.cpp

示例2: codeGen

Value* Id::codeGen(CodeGenContext &context) {
  if (context.locals().find(name) == context.locals().end()) {
    return NULL;
  }

  IRBuilder<> *builder = context.currentBuilder();
  return builder->CreateLoad(context.locals()[name], name);
}
开发者ID:raincoat,项目名称:toy-llvm-frondend,代码行数:8,代码来源:codegen.cpp

示例3: main

int main(int argc, char **argv)
{
    InitializeNativeTarget();
    LLVMContext &Context = getGlobalContext();
    Module *m = new Module("test", Context);
    Type *intTy  = Type::getInt64Ty(Context);

    StructType* structTy = StructType::create(Context, "struct.list");
    std::vector<Type*> fields;
    fields.push_back(intTy);
    fields.push_back(PointerType::get(structTy, 0));
    if (structTy->isOpaque()) {
        structTy->setBody(fields, false);
    }

    /*
     * int f1(struct x *p) { return p->next->l1; }
     */
    std::vector<Type*> args_type;
    args_type.push_back(PointerType::get(structTy, 0));

    FunctionType *fnTy = FunctionType::get(intTy, args_type, false);
    Function *func = Function::Create(fnTy,
            GlobalValue::ExternalLinkage, "f1", m);
    Value *v = func->arg_begin();
    BasicBlock *bb = BasicBlock::Create(Context, "EntryBlock", func);
    IRBuilder<> *builder = new IRBuilder<>(bb);
    v = builder->CreateStructGEP(v, 1);
    v = builder->CreateLoad(v, "load0");
    v = builder->CreateStructGEP(v, 0);
    v = builder->CreateLoad(v, "load1");
    builder->CreateRet(v);

    (*m).dump();
    {
        ExecutionEngine *ee = EngineBuilder(m). 
            setEngineKind(EngineKind::JIT).create();
        void *f = ee->getPointerToFunction(func);
        typedef int (*func_t) (struct x *);
        struct x o = {10, NULL}, v = {};
        v.next = &o;
        std::cout << ((func_t)f)(&v) << std::endl;
    }
    return 0;
}
开发者ID:NariyoshiChida,项目名称:llvm-sample,代码行数:45,代码来源:list.cpp

示例4: Visit

void CNodeCodeGenVisitor::Visit(COutput* s) {
  IRBuilder<> builder = builders_.top();

  Value* offset_ptr = builder.CreateGEP(ptr_, GetPtrOffset(s->GetOffset()));
  Value* ptr_value = builder.CreateLoad(offset_ptr);

  builder.CreateCall(put_char_, ptr_value);
  VisitNextCNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:9,代码来源:codegen_canon.cpp

示例5: Name

vector<Value*> AssertionSiteInstrumenter::CollectArgs(
    Instruction *Before, const Automaton& A,
    Module& Mod, IRBuilder<>& Builder) {

  // Find named values to be passed to instrumentation.
  std::map<string,Value*> ValuesInScope;
  for (auto G = Mod.global_begin(); G != Mod.global_end(); G++)
    ValuesInScope[G->getName()] = G;

  auto *Fn = Before->getParent()->getParent();
  for (auto& Arg : Fn->getArgumentList())
    ValuesInScope[Arg.getName()] = &Arg;

  auto& EntryBlock(*Fn->begin());
  for (auto& I : EntryBlock) {
    auto *Inst = dyn_cast<AllocaInst>(&I);
    if (!Inst)
      break;

    ValuesInScope[Inst->getName()] = Builder.CreateLoad(Inst);
  }

  int ArgSize = 0;
  for (auto& Arg : A.getAssertion().argument())
    if (!Arg.free())
      ArgSize = std::max(ArgSize + 1, Arg.index());

  vector<Value*> Args(ArgSize, NULL);

  for (auto& Arg : A.getAssertion().argument()) {
    if (Arg.free())
      continue;

    string Name(BaseName(Arg));

    if (ValuesInScope.find(Name) == ValuesInScope.end()) {
      string s;
      raw_string_ostream Out(s);

      for (auto v : ValuesInScope) {
        Out << "  \"" << v.first << "\": ";
        v.second->getType()->print(Out);
        Out << "\n";
      }

      panic("assertion references non-existent variable '" + BaseName(Arg)
         + "'; was it defined under '#ifdef TESLA'?\n\n"
           "Variables in scope are:\n" + Out.str());
    }

    Args[Arg.index()] =
      GetArgumentValue(ValuesInScope[Name], Arg, Builder, true);
  }

  return Args;
}
开发者ID:cadets,项目名称:tesla-static-analysis,代码行数:56,代码来源:Assertion.cpp

示例6:

Value*
code_emitter::lookup_value (value_t *value)
{
    g_assert(value->index >= 0);

    if (value_map.find(value) != value_map.end())
	return value_map[value];

    g_assert(compiler_is_permanent_const_value(value));
    return builder->CreateLoad(emit_const_value_addr(value));
}
开发者ID:WoodMath,项目名称:mathmap,代码行数:11,代码来源:llvm.cpp

示例7: getNamedValue

Value* WyvernFunction::getNamedValue (string name)
{
    Value* value;
    
    value = namedValues[name];
    
    if (dynamic_cast<AllocaInst*> (value) == NULL)
        return value;
        
    return Builder.CreateLoad (value);
}
开发者ID:semitie,项目名称:wyvern,代码行数:11,代码来源:WyvernFunction.cpp

示例8: CodeGenLexicalScope

CodeGenBlock::CodeGenBlock(int args, int locals, CodeGenLexicalScope
		*enclosingScope, CodeGenModule *Mod) 
	: CodeGenLexicalScope(Mod), parentScope(enclosingScope) 
{
	Value *enclosingContext = enclosingScope->getContext();
	// Define the layout of a block
	BlockTy = StructType::get(
		Mod->Context,
		IdTy,                          // 0 - isa.
		IMPTy,                         // 1 - Function pointer.
		Type::getInt32Ty(Mod->Context),// 2 - Number of args.
		enclosingContext->getType(),   // 3 - Context.
		NULL);
	std::vector<const Type*> argTy;
	argTy.push_back(PointerType::getUnqual(BlockTy));

	// FIXME: Broken on Etoile runtime - _cmd needs to be a GEP on _call
	argTy.push_back(SelTy);
	for (int i=0 ; i<args ; ++i) 
	{
		argTy.push_back(IdTy);
	}
	FunctionType *BlockFunctionTy = FunctionType::get(IdTy, argTy, false);

	IRBuilder<> *MethodBuilder = enclosingScope->getBuilder();

	// Create the block object
	
	// The NewBlock function gets a block from a pool.  It should really be
	// inlined.
	Block = MethodBuilder->CreateAlloca(BlockTy);

	Module *TheModule = CGM->getModule();
	// Create the block function
	CurrentFunction = Function::Create(BlockFunctionTy,
		GlobalValue::InternalLinkage, "BlockFunction", TheModule);
	InitialiseFunction(Args, Locals, locals);

	// Set the isa pointer
	Value *isa = MethodBuilder->CreateLoad(
		TheModule->getGlobalVariable(".smalltalk_block_stack_class", true));
	storeInStruct(MethodBuilder, Block, isa, 0);

	// Store the block function in the object
	storeInStruct(MethodBuilder, Block,
		MethodBuilder->CreateBitCast(CurrentFunction, IMPTy), 1);
	// Store the number of arguments
	storeInStruct(MethodBuilder, Block, 
			ConstantInt::get(Type::getInt32Ty(Mod->Context), args), 2);
	// Set the context
	storeInStruct(MethodBuilder, Block, enclosingScope->getContext(), 3);


}
开发者ID:johndpope,项目名称:etoile,代码行数:54,代码来源:CodeGenBlock.cpp

示例9: getValue

Value* ColExpression::getValue() {
    IRBuilder<>* builder = codegen::getBuilder();
    DataType dt = codegen::getAttType(index);
    Value* tupleptr = codegen::getTupleptr();

    Value *indices[1];
    indices[0] = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), (uint64_t) index);
    ArrayRef<Value*> indicesRef(indices);

    Value *dataptr = builder->CreateInBoundsGEP(tupleptr, indicesRef);

    switch(dt){
        case DOUBLE:
            return builder->CreateLoad(
                    builder->CreateBitCast(dataptr, Type::getDoublePtrTy(getGlobalContext()))
            );
        case LONG:
        case STRING:
        case DATE:
            return builder->CreateLoad(dataptr);
    }
}
开发者ID:Legacy25,项目名称:ValkyrieDB,代码行数:22,代码来源:Expression.cpp

示例10: compile_put

/// compile_put - Emit code for '.'                                                                                                                                                         
void BrainFTraceRecorder::compile_put(BrainFTraceNode *node,
                                      IRBuilder<>& builder) {
  Value *Loaded = builder.CreateLoad(DataPtr);
  Value *Print =
    builder.CreateSExt(Loaded, IntegerType::get(Loaded->getContext(), 32));
  builder.CreateCall(putchar_func, Print);
  if (node->left != (BrainFTraceNode*)~0ULL)
    compile_opcode(node->left, builder);
  else {
    HeaderPHI->addIncoming(DataPtr, builder.GetInsertBlock());
    builder.CreateBr(Header);
  }
}
开发者ID:resistor,项目名称:BrainFTracing,代码行数:14,代码来源:BrainFCodeGen.cpp

示例11: unlinkExceptionRegistration

void WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder) {
  // Clone Link into the current BB for better address mode folding.
  if (auto *GEP = dyn_cast<GetElementPtrInst>(Link)) {
    GEP = cast<GetElementPtrInst>(GEP->clone());
    Builder.Insert(GEP);
    Link = GEP;
  }
  Type *LinkTy = getEHLinkRegistrationType();
  // [fs:00] = Link->Next
  Value *Next =
      Builder.CreateLoad(Builder.CreateStructGEP(LinkTy, Link, 0));
  Constant *FSZero =
      Constant::getNullValue(LinkTy->getPointerTo()->getPointerTo(257));
  Builder.CreateStore(Next, FSZero);
}
开发者ID:realdelta,项目名称:delta-llvm,代码行数:15,代码来源:X86WinEHState.cpp

示例12: compile_minus

/// compile_minus - Emit code for '-'   
void BrainFTraceRecorder::compile_minus(BrainFTraceNode *node,
                                        IRBuilder<>& builder) {
  Value *CellValue = builder.CreateLoad(DataPtr);
  Constant *One =
    ConstantInt::get(IntegerType::getInt8Ty(Header->getContext()), 1);
  Value *UpdatedValue = builder.CreateSub(CellValue, One);
  builder.CreateStore(UpdatedValue, DataPtr);
  
  if (node->left != (BrainFTraceNode*)~0ULL)
    compile_opcode(node->left, builder);
  else {
    HeaderPHI->addIncoming(DataPtr, builder.GetInsertBlock());
    builder.CreateBr(Header);
  }
}
开发者ID:resistor,项目名称:BrainFTracing,代码行数:16,代码来源:BrainFCodeGen.cpp

示例13: linkExceptionRegistration

void WinEHStatePass::linkExceptionRegistration(IRBuilder<> &Builder,
                                               Function *Handler) {
  // Emit the .safeseh directive for this function.
  Handler->addFnAttr("safeseh");

  Type *LinkTy = getEHLinkRegistrationType();
  // Handler = Handler
  Value *HandlerI8 = Builder.CreateBitCast(Handler, Builder.getInt8PtrTy());
  Builder.CreateStore(HandlerI8, Builder.CreateStructGEP(LinkTy, Link, 1));
  // Next = [fs:00]
  Constant *FSZero =
      Constant::getNullValue(LinkTy->getPointerTo()->getPointerTo(257));
  Value *Next = Builder.CreateLoad(FSZero);
  Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0));
  // [fs:00] = Link
  Builder.CreateStore(Link, FSZero);
}
开发者ID:realdelta,项目名称:delta-llvm,代码行数:17,代码来源:X86WinEHState.cpp

示例14: instrumentAddress

void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
                                         IRBuilder<> &IRB, Value *Addr,
                                         uint32_t TypeSize, bool IsWrite) {
  Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);

  Type *ShadowTy  = IntegerType::get(
      *C, std::max(8U, TypeSize >> MappingScale));
  Type *ShadowPtrTy = PointerType::get(ShadowTy, 0);
  Value *ShadowPtr = memToShadow(AddrLong, IRB);
  Value *CmpVal = Constant::getNullValue(ShadowTy);
  Value *ShadowValue = IRB.CreateLoad(
      IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));

  Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal);

  Instruction *CheckTerm = splitBlockAndInsertIfThen(
      cast<Instruction>(Cmp)->getNextNode(), Cmp);
  IRBuilder<> IRB2(CheckTerm);

  size_t Granularity = 1 << MappingScale;
  if (TypeSize < 8 * Granularity) {
    // Addr & (Granularity - 1)
    Value *Lower3Bits = IRB2.CreateAnd(
        AddrLong, ConstantInt::get(IntptrTy, Granularity - 1));
    // (Addr & (Granularity - 1)) + size - 1
    Value *LastAccessedByte = IRB2.CreateAdd(
        Lower3Bits, ConstantInt::get(IntptrTy, TypeSize / 8 - 1));
    // (uint8_t) ((Addr & (Granularity-1)) + size - 1)
    LastAccessedByte = IRB2.CreateIntCast(
        LastAccessedByte, IRB.getInt8Ty(), false);
    // ((uint8_t) ((Addr & (Granularity-1)) + size - 1)) >= ShadowValue
    Value *Cmp2 = IRB2.CreateICmpSGE(LastAccessedByte, ShadowValue);

    CheckTerm = splitBlockAndInsertIfThen(CheckTerm, Cmp2);
  }

  IRBuilder<> IRB1(CheckTerm);
  Instruction *Crash = generateCrashCode(IRB1, AddrLong, IsWrite, TypeSize);
  Crash->setDebugLoc(OrigIns->getDebugLoc());
  ReplaceInstWithInst(CheckTerm, new UnreachableInst(*C));
}
开发者ID:xncm,项目名称:xncm-llvm,代码行数:41,代码来源:AddressSanitizer.cpp

示例15: if

Value*
code_emitter::convert_complex_return_value (Value *result)
{
    /* The result is complex, whose representation
       differs between archs, and we need to transform
       it into another arch-dependent
       representation. */
    if (sizeof(gpointer) == 4)
    {
	Value *local = complex_copy_var;
	Value *local_ptr = builder->CreateBitCast(local, PointerType::getUnqual(Type::Int64Ty));
	builder->CreateStore(result, local_ptr);
	result = builder->CreateLoad(local);
    }
    else if (sizeof(gpointer) == 8)
	result = builder->CreateExtractValue(result, 0);
    else
	g_assert_not_reached();

    return result;
}
开发者ID:WoodMath,项目名称:mathmap,代码行数:21,代码来源:llvm.cpp


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