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


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

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


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

示例1: 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:emaste,项目名称:llvm,代码行数:17,代码来源:X86WinEHState.cpp

示例2: Visit

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

  Value* ptr_offset = builder.CreateGEP(ptr_, GetPtrOffset(s->GetOffset()));
  Value* input = builder.CreateCall(get_char_);

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

示例3: CreateArgumentAllocas

void PrototypeAST::CreateArgumentAllocas(Function *F)
{
  Function::arg_iterator AI = F->arg_begin();
  for (unsigned Idx = 0, e = Args.size(); Idx != e; ++Idx, ++AI)
  {
    AllocaInst* Alloca = CreateEntryBlockAlloca(Args[Idx]->getName(), Args[Idx]->getType());
    Builder.CreateStore(AI,Alloca);
    NamedValues[Args[Idx]->getName()] = Alloca;
    typeTab[Args[Idx]->getName()] = Args[Idx]->getType();
  }
}
开发者ID:JRWynneIII,项目名称:jLang,代码行数:11,代码来源:functions.cpp

示例4: compile_set_zero

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

示例5: codeGen

Value* VariableDef::codeGen(CodeGenContext &context) {

  IRBuilder<> *builder = context.currentBuilder();
  Value *alloc = builder->CreateAlloca(builder->getInt64Ty(), 0 , id.name.c_str());
  context.locals()[id.name] = alloc;
  if ( assExpr != NULL) {
    context.locals()[id.name] = alloc;
    Value *idValue = (*assExpr).codeGen(context);
    return builder->CreateStore(idValue, context.locals()[id.name]);
  }
  return alloc;
}
开发者ID:raincoat,项目名称:toy-llvm-frondend,代码行数:12,代码来源:codegen.cpp

示例6: compile_get

/// compile_get - Emit code for ','
void BrainFTraceRecorder::compile_get(BrainFTraceNode *node,
                                      IRBuilder<>& builder) {
  Value *Ret = builder.CreateCall(getchar_func);
  Value *Trunc =
    builder.CreateTrunc(Ret, IntegerType::get(Ret->getContext(), 8));
  builder.CreateStore(Ret, Trunc);
  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

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

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

示例9: promote

void
code_emitter::commit_set_const_value (value_t *value, Value *llvm_value)
{
    Value *addr = emit_const_value_addr(value);
    llvm_value = promote(llvm_value, value->compvar->type);

#ifdef DEBUG_OUTPUT
    printf("storing value ");
    compiler_print_value(value);
    printf(" with llvm value ");
    llvm_value->dump();
    printf(" at addr ");
    addr->dump();
#endif

    builder->CreateStore(llvm_value, addr);
    set_value_name(llvm_value, value);
}
开发者ID:WoodMath,项目名称:mathmap,代码行数:18,代码来源:llvm.cpp

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

示例11: IncrementTimeCounter

static void IncrementTimeCounter(Value* Inc, Value* calle, unsigned Index, GlobalVariable* Counters, IRBuilder<>& Builder, Value* Point)
{
   LLVMContext &Context = Inc->getContext();
   //In order to insert instruction after Point, we use the nextIns function.
   Value* nextIns = getNextIns(Point);
   Builder.SetInsertPoint(dyn_cast<Instruction>(nextIns));

   // Create the getelementptr constant expression
   std::vector<Constant*> Indices(2);
   Indices[0] = Constant::getNullValue(Type::getInt32Ty(Context));
   Indices[1] = ConstantInt::get(Type::getInt32Ty(Context), Index);
   Constant *ElementPtr =
      ConstantExpr::getGetElementPtr(Counters, Indices);

   // Load, increment and store the value back.
   // Use this formula: a = a + end_time - start_time
   ArrayRef<Value*> args;
   CallInst* Inc_end = Builder.CreateCall(calle, args, "");
   Value* OldVal = Builder.CreateLoad(ElementPtr, "OldTimeCounter");
   Value* TmpVal = Builder.CreateFSub(OldVal, Inc, "TmpTimeCounter");
   Value* NewVal = Builder.CreateFAdd(TmpVal, Inc_end, "NewTimeCounter");
   Builder.CreateStore(NewVal, ElementPtr);
}
开发者ID:wzzhang-HIT,项目名称:llvm-prof,代码行数:23,代码来源:TimeProfiling.cpp

示例12: CreatePassManager

JITFunction* 
CompilePipeline(Pipeline *pipeline, Thread *thread) {
    size_t i = 0;
    size_t size = 0;
    std::unique_ptr<Module> owner = make_unique<Module>("PipelineFunction", thread->context);
    Module *module = owner.get();
    std::string fname = std::string("PipelineFunction") + std::to_string(thread->functions++);
    size_t input_count = pipeline->inputData->objects.size();
    size_t output_count = pipeline->outputData->objects.size();
    size_t function_arg_count = 6;
    size_t arg_count = input_count + output_count + (function_arg_count - 2);
    size_t start_addr = input_count + output_count;
    size_t end_addr = start_addr + 1;
    size_t result_sizes_addr = end_addr + 1;
    size_t thread_nr_addr = result_sizes_addr + 1;
    IRBuilder<> *builder = &thread->builder;
    auto passmanager = CreatePassManager(module, thread->jit.get());

    module->setDataLayout(thread->jit->getTargetMachine().createDataLayout());

    Type *int8_tpe = Type::getInt8Ty(thread->context);
    Type *int8ptr_tpe = PointerType::get(int8_tpe, 0);
    Type *int8ptrptr_tpe = PointerType::get(int8ptr_tpe, 0);
    Type *int64_tpe = Type::getInt64Ty(thread->context);
    Type *int64ptr_tpe = PointerType::get(int64_tpe, 0);

    JITInformation info;

    // arguments of the function
    // the arguments are (void **result, void** inputs, size_t start, size_t end);
    // note that we don't actually use void**, we use int8**, because LLVM does not support void pointers
    std::vector<Type*> arguments(function_arg_count);
    i = 0;
    arguments[i++] = int8ptrptr_tpe;  // void** results
    arguments[i++] = int8ptrptr_tpe;  // void** inputs
    arguments[i++] = int64_tpe;       // size_t start
    arguments[i++] = int64_tpe;       // size_t end
    arguments[i++] = int64ptr_tpe;  // size_t* result_sizes
    arguments[i++] = int64_tpe;  // size_t thread_nr
    assert(i == function_arg_count);

    /*for(auto inputs = pipeline->inputData->objects.begin(); inputs != pipeline->inputData->objects.end(); inputs++, i++) {
        arguments[i] = PointerType::get(getLLVMType(thread->context, inputs->type), 0);
    }
    for(auto outputs = pipeline->outputData->objects.begin(); outputs != pipeline->outputData->objects.end(); outputs++, i++) {
        arguments[i] = PointerType::get(getLLVMType(thread->context, outputs->type), 0);
    }*/

    // create the LLVM function
    FunctionType *prototype = FunctionType::get(int64_tpe, arguments, false);
    Function *function = Function::Create(prototype, GlobalValue::ExternalLinkage, fname, module);
    function->setCallingConv(CallingConv::C);

    // create the basic blocks
    BasicBlock *loop_entry = BasicBlock::Create(thread->context, "entry", function, 0);
    BasicBlock *loop_cond  = BasicBlock::Create(thread->context, "for.cond", function, 0);
    BasicBlock *loop_body  = BasicBlock::Create(thread->context, "for.body", function, 0);
    BasicBlock *loop_inc   = BasicBlock::Create(thread->context, "for.inc", function, 0);
    BasicBlock *loop_end   = BasicBlock::Create(thread->context, "for.end", function, 0);

    info.builder = &thread->builder;
    info.context = &thread->context;
    info.function = function;
    info.loop_entry = loop_entry;
    info.loop_cond = loop_cond;
    info.loop_body = loop_body;
    info.loop_inc = loop_inc;
    info.loop_end = loop_end;
    info.current = loop_body;

#ifndef _NOTDEBUG
    // argument names (for debug purposes only)
    std::vector<std::string> argument_names(arg_count);
    i = 0;
    for(auto inputs = pipeline->inputData->objects.begin(); inputs != pipeline->inputData->objects.end(); inputs++, i++) {
        argument_names[i] = std::string("inputs") + std::to_string(i);
    }
    for(auto outputs = pipeline->outputData->objects.begin(); outputs != pipeline->outputData->objects.end(); outputs++, i++) {
        argument_names[i] = std::string("outputs") + std::to_string(i - input_count);
    }
    argument_names[i++] = "start";
    argument_names[i++] = "end";
    argument_names[i++] = "result_sizes";
    argument_names[i++] = "thread_nr";
#endif

    std::vector<AllocaInst*> argument_addresses(arg_count);
    builder->SetInsertPoint(loop_entry);
    {
        // allocate space for the arguments
        auto args = function->arg_begin();
        i = 0;
        for(auto outputs = pipeline->outputData->objects.begin(); outputs != pipeline->outputData->objects.end(); outputs++, i++) {
            Type *column_type = PointerType::get(getLLVMType(thread->context, outputs->source->type), 0);
            Value *voidptrptr = builder->CreateGEP(int8ptr_tpe, &*args, ConstantInt::get(int64_tpe, i, true));
            Value *voidptr = builder->CreateLoad(voidptrptr, "voidptr");
            Value *columnptr = builder->CreatePointerCast(voidptr, column_type);
            argument_addresses[i] = builder->CreateAlloca(column_type, nullptr, argument_names[i]);
            builder->CreateStore(columnptr, argument_addresses[i]);
            outputs->alloca_address = (void*) argument_addresses[i];
//.........这里部分代码省略.........
开发者ID:Mytherin,项目名称:numpyllvm,代码行数:101,代码来源:compiler.cpp

示例13: compile_if

/// compile_if - Emit code for '['
void BrainFTraceRecorder::compile_if(BrainFTraceNode *node,
                                     IRBuilder<>& builder) {
  BasicBlock *ZeroChild = 0;
  BasicBlock *NonZeroChild = 0;
  BasicBlock *Parent = builder.GetInsertBlock();
  
  LLVMContext &Context = Header->getContext();
  
  // If both directions of the branch go back to the trace-head, just
  // jump there directly.
  if (node->left == (BrainFTraceNode*)~0ULL &&
      node->right == (BrainFTraceNode*)~0ULL) {
    HeaderPHI->addIncoming(DataPtr, builder.GetInsertBlock());
    builder.CreateBr(Header);
    return;
  }
  
  // Otherwise, there are two cases to handle for each direction:
  //   ~0ULL - A branch back to the trace head
  //   0 - A branch out of the trace
  //   * - A branch to a node we haven't compiled yet.
  // Go ahead and generate code for both targets.
  
  if (node->left == (BrainFTraceNode*)~0ULL) {
    NonZeroChild = Header;
    HeaderPHI->addIncoming(DataPtr, Parent);
  } else if (node->left == 0) {
    NonZeroChild = BasicBlock::Create(Context,
                                   "exit_left_"+utostr(node->pc),
                                   Header->getParent());
    builder.SetInsertPoint(NonZeroChild);
    
    // Set the extension leaf, which is a pointer to the leaf of the trace
    // tree from which we are side exiting.
    ConstantInt *ExtLeaf = ConstantInt::get(int_type, (intptr_t)node);
    builder.CreateStore(ExtLeaf, ext_leaf);
    
    ConstantInt *NewPc = ConstantInt::get(int_type, node->pc+1);
    Value *BytecodeIndex =
      builder.CreateConstInBoundsGEP1_32(bytecode_array, node->pc+1);
    Value *Target = builder.CreateLoad(BytecodeIndex);
    CallInst *Call =cast<CallInst>(builder.CreateCall2(Target, NewPc, DataPtr));
    Call->setTailCall();
    builder.CreateRetVoid();
  } else {
    NonZeroChild = BasicBlock::Create(Context, 
                                      utostr(node->left->pc), 
                                      Header->getParent());
    builder.SetInsertPoint(NonZeroChild);
    compile_opcode(node->left, builder);
  }
  
  if (node->right == (BrainFTraceNode*)~0ULL) {
    ZeroChild = Header;
    HeaderPHI->addIncoming(DataPtr, Parent);
  } else if (node->right == 0) {
    ZeroChild = BasicBlock::Create(Context,
                                   "exit_right_"+utostr(node->pc),
                                   Header->getParent());
    builder.SetInsertPoint(ZeroChild);
    
    // Set the extension leaf, which is a pointer to the leaf of the trace
    // tree from which we are side exiting.
    ConstantInt *ExtLeaf = ConstantInt::get(int_type, (intptr_t)node);
    builder.CreateStore(ExtLeaf, ext_leaf);
    
    ConstantInt *NewPc = ConstantInt::get(int_type, JumpMap[node->pc]+1);
    Value *BytecodeIndex =
      builder.CreateConstInBoundsGEP1_32(bytecode_array, JumpMap[node->pc]+1);
    Value *Target = builder.CreateLoad(BytecodeIndex);
    CallInst *Call =cast<CallInst>(builder.CreateCall2(Target, NewPc, DataPtr));
    Call->setTailCall();
    builder.CreateRetVoid();
  } else {
    ZeroChild = BasicBlock::Create(Context, 
                                      utostr(node->right->pc), 
                                      Header->getParent());
    builder.SetInsertPoint(ZeroChild);
    compile_opcode(node->right, builder);
  }
  
  // Generate the test and branch to select between the targets.
  builder.SetInsertPoint(Parent);
  Value *Loaded = builder.CreateLoad(DataPtr);
  Value *Cmp = builder.CreateICmpEQ(Loaded, 
                                       ConstantInt::get(Loaded->getType(), 0));
  builder.CreateCondBr(Cmp, ZeroChild, NonZeroChild);
}
开发者ID:resistor,项目名称:BrainFTracing,代码行数:89,代码来源:BrainFCodeGen.cpp

示例14: emit_primary

Value*
code_emitter::emit_rhs (rhs_t *rhs)
{
    switch (rhs->kind) {
	case RHS_PRIMARY :
	    return emit_primary(&rhs->v.primary);
	case RHS_INTERNAL :
	    return lookup_internal(rhs->v.internal);
	case RHS_OP :
	    {
		operation_t *op = rhs->v.op.op;
		type_t promotion_type = TYPE_NIL;
		char *function_name = compiler_function_name_for_op_rhs(rhs, &promotion_type);

		if (promotion_type == TYPE_NIL)
		    assert(op->type_prop == TYPE_PROP_CONST);
		if (op->type_prop != TYPE_PROP_CONST)
		    assert(promotion_type != TYPE_NIL);

		Function *func = module->getFunction(string(function_name));
		g_assert(func);
		vector<Value*> args;
		args.push_back(invocation_arg);
		args.push_back(closure_arg);
		args.push_back(pools_arg);
		for (int i = 0; i < rhs->v.op.op->num_args; ++i) {
		    type_t type = promotion_type == TYPE_NIL ? op->arg_types[i] : promotion_type;
		    Value *val = emit_primary(&rhs->v.op.args[i], type == TYPE_FLOAT);
		    val = promote(val, type);

#ifndef __MINGW32__
		    if (sizeof(gpointer) == 4 && val->getType() == llvm_type_for_type(module, TYPE_COMPLEX))
		    {
			Value *copy = builder->CreateAlloca(llvm_type_for_type(module, TYPE_COMPLEX));
			builder->CreateStore(val, copy);
			val = copy;
		    }
#endif

#ifdef DEBUG_OUTPUT
		    val->dump();
#endif
		    args.push_back(val);
		}
#ifdef DEBUG_OUTPUT
		func->dump();
#endif
		Value *result = builder->CreateCall(func, args.begin(), args.end());
		/* FIXME: this is ugly - we should check for the type
		   of the operation or resulting value */
		if (is_complex_return_type(result->getType()))
		    result = convert_complex_return_value(result);
		return result;
	    }

	case RHS_FILTER :
	    {
		int num_args = compiler_num_filter_args(rhs->v.filter.filter);
		Value *closure = emit_closure(rhs->v.filter.filter, rhs->v.filter.args);
		Function *func = lookup_filter_function(module, rhs->v.filter.filter);
		vector<Value*> args;

		args.push_back(invocation_arg);
		args.push_back(closure);
		args.push_back(emit_primary(&rhs->v.filter.args[num_args - 3]));
		args.push_back(emit_primary(&rhs->v.filter.args[num_args - 2]));
		args.push_back(emit_primary(&rhs->v.filter.args[num_args - 1]));
		args.push_back(pools_arg);

		return builder->CreateCall(func, args.begin(), args.end());
	    }

	case RHS_CLOSURE :
	    return emit_closure(rhs->v.closure.filter, rhs->v.closure.args);

	case RHS_TUPLE :
	case RHS_TREE_VECTOR :
	    {
		Function *set_func = module->getFunction(string("tuple_set"));
		Value *tuple = builder->CreateCall2(module->getFunction(string("alloc_tuple")),
						    pools_arg,
						    make_int_const(rhs->v.tuple.length));
		int i;

		for (i = 0; i < rhs->v.tuple.length; ++i)
		{
		    Value *val = emit_primary(&rhs->v.tuple.args[i], true);
		    builder->CreateCall3(set_func, tuple, make_int_const(i), val);
		}

		if (rhs->kind == RHS_TREE_VECTOR)
		{
		    return builder->CreateCall3(module->getFunction(string("alloc_tree_vector")),
						pools_arg,
						make_int_const(rhs->v.tuple.length),
						tuple);
		}
		else
		    return tuple;
	    }
//.........这里部分代码省略.........
开发者ID:WoodMath,项目名称:mathmap,代码行数:101,代码来源:llvm.cpp

示例15: Visit

void ASTCodeGenVisitor::Visit(GetInput* s) {
  IRBuilder<> builder = builders_.top();
  Value* input = builder.CreateCall(get_char_);
  builder.CreateStore(input, ptr_);
  VisitNextASTNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:6,代码来源:codegen_ast.cpp


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