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


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

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


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

示例1: Visit

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

  Value* offset_ptr = builder.CreateGEP(ptr_, GetPtrOffset(s->GetOffset()));
  Value* set_val = GetDataOffset(s->GetAmt());
  builder.CreateStore(set_val, offset_ptr);
  VisitNextCNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:8,代码来源:codegen_canon.cpp

示例2: sizeof

Value*
code_emitter::emit_sizeof (Type *type)
{
    Value *size = builder->CreateGEP(ConstantPointerNull::get(PointerType::getUnqual(type)),
				     make_int_const(1));

    return builder->CreatePtrToInt(size, sizeof(gpointer) == 4 ? Type::Int32Ty : Type::Int64Ty);
}
开发者ID:WoodMath,项目名称:mathmap,代码行数:8,代码来源:llvm.cpp

示例3: if

Value*
code_emitter::emit_const_value_addr (value_t *value)
{
    g_assert(const_value_index_map.find(value) != const_value_index_map.end());

    int index = const_value_index_map[value];
    vector<Value*> indices;

    indices.push_back(make_int_const(0));
    indices.push_back(make_int_const(index));

    Value *const_var = NULL;

    if ((value->const_type | CONST_T) == (CONST_X | CONST_Y | CONST_T))
	const_var = xy_vars_var;
    else if ((value->const_type | CONST_T) == (CONST_X | CONST_T))
	const_var = x_vars_var;
    else if ((value->const_type | CONST_T) == (CONST_Y | CONST_T))
	const_var = y_vars_var;
    else
	g_assert_not_reached();

    return builder->CreateGEP(const_var, indices.begin(), indices.end());
}
开发者ID:WoodMath,项目名称:mathmap,代码行数:24,代码来源:llvm.cpp

示例4: Visit

void ASTCodeGenVisitor::Visit(DecrPtr* s) {
  IRBuilder<> builder = builders_.top();
  ptr_ = builder.CreateGEP(ptr_, neg_one);
  VisitNextASTNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:5,代码来源:codegen_ast.cpp

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


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