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


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

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


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

示例1: codeGen

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

  //Value* conditionValue = condition.codeGen(context);

  IRBuilder<> *builder = context.currentBuilder();
  Function *mainFunction = builder->GetInsertBlock()->getParent();

  BasicBlock *condBb = BasicBlock::Create(getGlobalContext(), "whilecond",
      mainFunction);
  BasicBlock *doBb = BasicBlock::Create(getGlobalContext(), "whiledo");
  BasicBlock *afterWhileBb = BasicBlock::Create(getGlobalContext(), "afterWhile");


  builder->CreateBr(condBb);
  builder->SetInsertPoint(condBb);
  Value* conditionValue = condition.codeGen(context);
  builder->CreateCondBr(conditionValue, doBb, afterWhileBb);
  condBb = builder->GetInsertBlock();

  mainFunction->getBasicBlockList().push_back(doBb);
  builder->SetInsertPoint(doBb);
  Value *doValue = (*doStmt).codeGen(context);
  builder->CreateBr(condBb);
  doBb = builder->GetInsertBlock();

  mainFunction->getBasicBlockList().push_back(afterWhileBb);
  builder->SetInsertPoint(afterWhileBb);
  return NULL;

}
开发者ID:raincoat,项目名称:toy-llvm-frondend,代码行数:30,代码来源:codegen.cpp

示例2: handleFinalSuspend

// Rewrite final suspend point handling. We do not use suspend index to
// represent the final suspend point. Instead we zero-out ResumeFnAddr in the
// coroutine frame, since it is undefined behavior to resume a coroutine
// suspended at the final suspend point. Thus, in the resume function, we can
// simply remove the last case (when coro::Shape is built, the final suspend
// point (if present) is always the last element of CoroSuspends array).
// In the destroy function, we add a code sequence to check if ResumeFnAddress
// is Null, and if so, jump to the appropriate label to handle cleanup from the
// final suspend point.
static void handleFinalSuspend(IRBuilder<> &Builder, Value *FramePtr,
                               coro::Shape &Shape, SwitchInst *Switch,
                               bool IsDestroy) {
  assert(Shape.HasFinalSuspend);
  auto FinalCaseIt = std::prev(Switch->case_end());
  BasicBlock *ResumeBB = FinalCaseIt->getCaseSuccessor();
  Switch->removeCase(FinalCaseIt);
  if (IsDestroy) {
    BasicBlock *OldSwitchBB = Switch->getParent();
    auto *NewSwitchBB = OldSwitchBB->splitBasicBlock(Switch, "Switch");
    Builder.SetInsertPoint(OldSwitchBB->getTerminator());
    auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(Shape.FrameTy, FramePtr,
                                                        0, 0, "ResumeFn.addr");
    auto *Load = Builder.CreateLoad(GepIndex);
    auto *NullPtr =
        ConstantPointerNull::get(cast<PointerType>(Load->getType()));
    auto *Cond = Builder.CreateICmpEQ(Load, NullPtr);
    Builder.CreateCondBr(Cond, ResumeBB, NewSwitchBB);
    OldSwitchBB->getTerminator()->eraseFromParent();
  }
}
开发者ID:a565109863,项目名称:src,代码行数:30,代码来源:CoroSplit.cpp

示例3: BitCastInst

void GNUstep::IMPCacher::SpeculativelyInline(Instruction *call, Function
        *function) {
    BasicBlock *beforeCallBB = call->getParent();
    BasicBlock *callBB = SplitBlock(beforeCallBB, call, Owner);
    BasicBlock *inlineBB = BasicBlock::Create(Context, "inline",
                           callBB->getParent());


    BasicBlock::iterator iter = call;
    iter++;

    BasicBlock *afterCallBB = SplitBlock(iter->getParent(), iter, Owner);

    removeTerminator(beforeCallBB);

    // Put a branch before the call, testing whether the callee really is the
    // function
    IRBuilder<> B = IRBuilder<>(beforeCallBB);
    Value *callee = isa<CallInst>(call) ? cast<CallInst>(call)->getCalledValue()
                    : cast<InvokeInst>(call)->getCalledValue();

    const FunctionType *FTy = function->getFunctionType();
    const FunctionType *calleeTy = cast<FunctionType>(
                                       cast<PointerType>(callee->getType())->getElementType());
    if (calleeTy != FTy) {
        callee = B.CreateBitCast(callee, function->getType());
    }

    Value *isInlineValid = B.CreateICmpEQ(callee, function);
    B.CreateCondBr(isInlineValid, inlineBB, callBB);

    // In the inline BB, add a copy of the call, but this time calling the real
    // version.
    Instruction *inlineCall = call->clone();
    Value *inlineResult= inlineCall;
    inlineBB->getInstList().push_back(inlineCall);

    B.SetInsertPoint(inlineBB);

    if (calleeTy != FTy) {
        for (unsigned i=0 ; i<FTy->getNumParams() ; i++) {
            LLVMType *callType = calleeTy->getParamType(i);
            LLVMType *argType = FTy->getParamType(i);
            if (callType != argType) {
                inlineCall->setOperand(i, new
                                       BitCastInst(inlineCall->getOperand(i), argType, "", inlineCall));
            }
        }
        if (FTy->getReturnType() != calleeTy->getReturnType()) {
            if (FTy->getReturnType() == Type::getVoidTy(Context)) {
                inlineResult = Constant::getNullValue(calleeTy->getReturnType());
            } else {
                inlineResult =
                    new BitCastInst(inlineCall, calleeTy->getReturnType(), "", inlineBB);
            }
        }
    }

    B.CreateBr(afterCallBB);

    // Unify the return values
    if (call->getType() != Type::getVoidTy(Context)) {
        PHINode *phi = CreatePHI(call->getType(), 2, "", afterCallBB->begin());
        call->replaceAllUsesWith(phi);
        phi->addIncoming(call, callBB);
        phi->addIncoming(inlineResult, inlineBB);
    }

    // Really do the real inlining
    InlineFunctionInfo IFI(0, 0);
    if (CallInst *c = dyn_cast<CallInst>(inlineCall)) {
        c->setCalledFunction(function);
        InlineFunction(c, IFI);
    } else if (InvokeInst *c = dyn_cast<InvokeInst>(inlineCall)) {
        c->setCalledFunction(function);
        InlineFunction(c, IFI);
    }
}
开发者ID:andyvand,项目名称:darwin-sdk,代码行数:78,代码来源:IMPCacher.cpp

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

示例5: if

void
code_emitter::emit_stmts (statement_t *stmt, unsigned int slice_flag)
{
    for (; stmt != NULL; stmt = stmt->next)
    {
	if (!must_emit_stmt(stmt, slice_flag))
	    continue;

	switch (stmt->kind)
	{
	    case STMT_NIL :
		g_assert(slice_flag == SLICE_IGNORE);
		break;

	    case STMT_ASSIGN :
#ifdef DEBUG_OUTPUT
		compiler_print_assign_statement(stmt);
		printf("\n");
#endif
		if (stmt->v.assign.rhs->kind == RHS_OP
		    && stmt->v.assign.rhs->v.op.op->index == OP_OUTPUT_TUPLE)
		    builder->CreateRet(emit_primary(&stmt->v.assign.rhs->v.op.args[0]));
		else
		    set_value(stmt->v.assign.lhs, emit_rhs(stmt->v.assign.rhs));
		break;

	    case STMT_IF_COND :
		{
		    Value *condition_number = emit_rhs(stmt->v.if_cond.condition);
		    Value *condition;
		    map<rhs_t*, Value*> rhs_map;

		    if (condition_number->getType() == Type::Int32Ty)
			condition = builder->CreateICmpNE(condition_number, make_int_const(0));
		    else if (condition_number->getType() == Type::FloatTy)
			condition = builder->CreateFCmpONE(condition_number, make_float_const(0.0));
		    else
			g_assert_not_reached();

		    BasicBlock *then_bb = BasicBlock::Create("then", current_function);
		    BasicBlock *else_bb = BasicBlock::Create("else");
		    BasicBlock *merge_bb = BasicBlock::Create("ifcont");

		    builder->CreateCondBr(condition, then_bb, else_bb);

		    builder->SetInsertPoint(then_bb);
		    emit_stmts(stmt->v.if_cond.consequent, slice_flag);
		    emit_phi_rhss(stmt->v.if_cond.exit, true, &rhs_map, slice_flag);
		    builder->CreateBr(merge_bb);
		    then_bb = builder->GetInsertBlock();

		    current_function->getBasicBlockList().push_back(else_bb);
		    builder->SetInsertPoint(else_bb);
		    emit_stmts(stmt->v.if_cond.alternative, slice_flag);
		    emit_phi_rhss(stmt->v.if_cond.exit, false, &rhs_map, slice_flag);
		    builder->CreateBr(merge_bb);
		    else_bb = builder->GetInsertBlock();

		    current_function->getBasicBlockList().push_back(merge_bb);
		    builder->SetInsertPoint(merge_bb);

		    emit_phis(stmt->v.if_cond.exit, then_bb, else_bb, rhs_map, slice_flag);
		}
		break;

	    case STMT_WHILE_LOOP:
		{
		    BasicBlock *start_bb = builder->GetInsertBlock();
		    BasicBlock *entry_bb = BasicBlock::Create("entry", current_function);
		    BasicBlock *body_bb = BasicBlock::Create("body");
		    BasicBlock *exit_bb = BasicBlock::Create("exit");
		    map<rhs_t*, Value*> rhs_map;

		    emit_phi_rhss(stmt->v.while_loop.entry, true, &rhs_map, slice_flag);

		    builder->CreateBr(entry_bb);

		    builder->SetInsertPoint(entry_bb);

		    emit_phis(stmt->v.while_loop.entry, start_bb, NULL, rhs_map, slice_flag);

		    Value *invariant_number = emit_rhs(stmt->v.while_loop.invariant);
		    Value *invariant;

		    if (invariant_number->getType() == Type::Int32Ty)
			invariant = builder->CreateICmpNE(invariant_number, make_int_const(0));
		    else if (invariant_number->getType() == Type::FloatTy)
			invariant = builder->CreateFCmpONE(invariant_number, make_float_const(0.0));
		    else
			g_assert_not_reached();

		    builder->CreateCondBr(invariant, body_bb, exit_bb);

		    current_function->getBasicBlockList().push_back(body_bb);
		    builder->SetInsertPoint(body_bb);
		    emit_stmts(stmt->v.while_loop.body, slice_flag);
		    body_bb = builder->GetInsertBlock();
		    emit_phi_rhss(stmt->v.while_loop.entry, false, &rhs_map, slice_flag);
		    emit_phis(stmt->v.while_loop.entry, NULL, body_bb, rhs_map, slice_flag);
		    builder->CreateBr(entry_bb);
//.........这里部分代码省略.........
开发者ID:WoodMath,项目名称:mathmap,代码行数:101,代码来源:llvm.cpp

示例6: CreatePassManager


//.........这里部分代码省略.........
                size = inputs->source->size;
            }
            assert(size == inputs->source->size || inputs->source->size == 1);
        }
        args++;
        argument_addresses[i] = builder->CreateAlloca(arguments[2], nullptr, argument_names[i]);
        builder->CreateStore(&*args, argument_addresses[i]);
        args++; i++;
        argument_addresses[i] = builder->CreateAlloca(arguments[3], nullptr, argument_names[i]);
        builder->CreateStore(&*args, argument_addresses[i]);
        args++; i++;
        argument_addresses[i] = builder->CreateAlloca(arguments[4], nullptr, argument_names[i]);
        builder->CreateStore(&*args, argument_addresses[i]);
        args++; i++;
        argument_addresses[i] = builder->CreateAlloca(arguments[5], nullptr, argument_names[i]);
        builder->CreateStore(&*args, argument_addresses[i]);
        args++; i++;
        assert(args == function->arg_end());
        assert(i == arg_count);
        info.index_addr = argument_addresses[start_addr];
        info.thread_addr = argument_addresses[thread_nr_addr];

        PerformInitialization(info, pipeline->operation);

        builder->CreateBr(loop_cond);
    }

    // for loop condition: index < end
    builder->SetInsertPoint(loop_cond);
    {
        LoadInst *index = builder->CreateLoad(argument_addresses[start_addr], "index");
        LoadInst *end = builder->CreateLoad(argument_addresses[end_addr], "end");
        Value *condition = builder->CreateICmpSLT(index, end, "index < end");
        builder->CreateCondBr(condition, loop_body, loop_end);
    }

    // loop body: perform the computation
    builder->SetInsertPoint(loop_body);
    {
        LoadInst *index = builder->CreateLoad(argument_addresses[start_addr], "index");
        info.index = index;
        info.index_addr = argument_addresses[start_addr];
        // perform the computation over the given index
        // we don't use the return value because the final assignment has already taken place
        Value *v = PerformOperation(info, thread->builder, thread->context, pipeline->operation, pipeline->inputData, pipeline->outputData);
        if (v == NULL) {
            // failed to perform operation
            printf("Failed to compile pipeline %s\n", pipeline->name);
            return NULL;
        }

        builder->CreateBr(loop_inc);
    }

    // loop increment: index++
    builder->SetInsertPoint(loop_inc);
    {
        LoadInst *index = builder->CreateLoad(argument_addresses[start_addr], "index");
        Value *incremented_index = builder->CreateAdd(index, ConstantInt::get(int64_tpe, 1, true), "index++");
        builder->CreateStore(incremented_index, argument_addresses[start_addr]);

        builder->CreateBr(loop_cond);
    }

    // loop end: return; (nothing happens here because we have no return value)
    builder->SetInsertPoint(loop_end);
开发者ID:Mytherin,项目名称:numpyllvm,代码行数:67,代码来源:compiler.cpp


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