本文整理汇总了C++中LLVMPositionBuilderAtEnd函数的典型用法代码示例。如果您正苦于以下问题:C++ LLVMPositionBuilderAtEnd函数的具体用法?C++ LLVMPositionBuilderAtEnd怎么用?C++ LLVMPositionBuilderAtEnd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LLVMPositionBuilderAtEnd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createPushHeapFunction
static void createPushHeapFunction() {
// Saving last BasicBlock;
LLVMBasicBlockRef OldBB = LLVMGetInsertBlock(Builder);
LLVMTypeRef ParamType = LLVMPointerType(RAType, 0);
LLVMTypeRef FunctionType = LLVMFunctionType(LLVMVoidType(), &ParamType, 1, 0);
LLVMValueRef Function = LLVMAddFunction(Module, "push.heap", FunctionType);
LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "entry");
LLVMPositionBuilderAtEnd(Builder, Entry);
// Function Body
LLVMValueRef HeapMalloc = LLVMBuildMalloc(Builder, HeapType, "heap.malloc");
LLVMValueRef ExPtrIdx[] = { getSConstInt(0), getSConstInt(0) };
LLVMValueRef LastPtrIdx[] = { getSConstInt(0), getSConstInt(1) };
LLVMValueRef ExPtr = LLVMBuildInBoundsGEP(Builder, HeapMalloc, ExPtrIdx, 2, "heap.exec");
LLVMValueRef LastPtr = LLVMBuildInBoundsGEP(Builder, HeapMalloc, LastPtrIdx, 2, "heap.last");
LLVMBuildStore(Builder, LLVMGetParam(Function, 0), ExPtr);
LLVMBuildStore(Builder, LLVMBuildLoad(Builder, HeapHead, "ld.heap.head"), LastPtr);
LLVMBuildStore(Builder, HeapMalloc, HeapHead);
LLVMBuildRetVoid(Builder);
// Restoring last BasicBlock
LLVMPositionBuilderAtEnd(Builder, OldBB);
}
示例2: raw_is_box
static LLVMValueRef raw_is_box(compile_t* c, ast_t* left_type,
LLVMValueRef l_value, LLVMValueRef r_value)
{
pony_assert(LLVMGetTypeKind(LLVMTypeOf(r_value)) == LLVMPointerTypeKind);
LLVMValueRef r_desc = gendesc_fetch(c, r_value);
LLVMValueRef same_type = gendesc_isentity(c, r_desc, left_type);
pony_assert(same_type != GEN_NOVALUE);
LLVMBasicBlockRef this_block = LLVMGetInsertBlock(c->builder);
LLVMBasicBlockRef value_block = codegen_block(c, "is_value");
LLVMBasicBlockRef post_block = codegen_block(c, "is_post");
LLVMBuildCondBr(c->builder, same_type, value_block, post_block);
LLVMPositionBuilderAtEnd(c->builder, value_block);
r_value = gen_unbox(c, left_type, r_value);
LLVMValueRef is_value = gen_is_value(c, left_type, left_type, l_value,
r_value);
LLVMBuildBr(c->builder, post_block);
value_block = LLVMGetInsertBlock(c->builder);
LLVMPositionBuilderAtEnd(c->builder, post_block);
LLVMValueRef phi = LLVMBuildPhi(c->builder, c->i1, "");
LLVMValueRef zero = LLVMConstInt(c->i1, 0, false);
LLVMAddIncoming(phi, &is_value, &value_block, 1);
LLVMAddIncoming(phi, &zero, &this_block, 1);
return phi;
}
示例3: check_union
static bool check_union(compile_t* c, LLVMValueRef ptr, LLVMValueRef desc,
ast_t* pattern_type, LLVMBasicBlockRef next_block)
{
// We have to match some component type.
LLVMBasicBlockRef continue_block = codegen_block(c, "pattern_continue");
ast_t* child = ast_child(pattern_type);
while(child != NULL)
{
// If we don't match, try the next type if there is one. If there is
// no next type, jump to the next case.
ast_t* next_type = ast_sibling(child);
LLVMBasicBlockRef nomatch_block;
if(next_type != NULL)
nomatch_block = codegen_block(c, "pattern_next");
else
nomatch_block = next_block;
if(!check_type(c, ptr, desc, child, nomatch_block))
return false;
// If we do match, jump to the continue block.
LLVMBuildBr(c->builder, continue_block);
// Put the next union check, if there is one, in the nomatch block.
LLVMPositionBuilderAtEnd(c->builder, nomatch_block);
child = next_type;
}
// Continue codegen in the continue block, not in the next block.
LLVMPositionBuilderAtEnd(c->builder, continue_block);
return true;
}
示例4: lp_build_endif
/**
* End a conditional.
*/
void
lp_build_endif(struct lp_build_if_state *ifthen)
{
LLVMBuilderRef builder = ifthen->gallivm->builder;
/* Insert branch to the merge block from current block */
LLVMBuildBr(builder, ifthen->merge_block);
/*
* Now patch in the various branch instructions.
*/
/* Insert the conditional branch instruction at the end of entry_block */
LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
if (ifthen->false_block) {
/* we have an else clause */
LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->false_block);
}
else {
/* no else clause */
LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->merge_block);
}
/* Resume building code at end of the ifthen->merge_block */
LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
}
示例5: gen_localdecl
LLVMValueRef gen_localdecl(compile_t* c, ast_t* ast)
{
ast_t* id = ast_child(ast);
ast_t* type = ast_type(id);
gentype_t g;
if(!gentype(c, type, &g))
return NULL;
// All alloca should happen in the entry block of a function.
LLVMBasicBlockRef this_block = LLVMGetInsertBlock(c->builder);
LLVMBasicBlockRef entry_block = LLVMGetEntryBasicBlock(codegen_fun(c));
LLVMValueRef inst = LLVMGetFirstInstruction(entry_block);
if(inst != NULL)
LLVMPositionBuilderBefore(c->builder, inst);
else
LLVMPositionBuilderAtEnd(c->builder, entry_block);
const char* name = ast_name(id);
LLVMValueRef l_value = LLVMBuildAlloca(c->builder, g.use_type, name);
// Store the alloca to use when we reference this local.
codegen_setlocal(c, name, l_value);
// Emit debug info for local variable declaration.
dwarf_local(&c->dwarf, ast, g.type_name, entry_block, inst, l_value);
// Put the builder back where it was.
LLVMPositionBuilderAtEnd(c->builder, this_block);
return GEN_NOVALUE;
}
示例6: gen_switch
LLVMValueRef gen_switch(struct node *ast)
{
LLVMValueRef func, switch_;
LLVMBasicBlockRef this_block, switch_first_block, switch_last_block, end_block;
int i;
this_block = LLVMGetInsertBlock(builder);
func = LLVMGetBasicBlockParent(this_block);
switch_first_block = LLVMAppendBasicBlock(func, "");
LLVMPositionBuilderAtEnd(builder, switch_first_block);
case_count = 0;
codegen(ast->two);
switch_last_block = LLVMGetLastBasicBlock(func);
end_block = LLVMAppendBasicBlock(func, "");
LLVMPositionBuilderAtEnd(builder, switch_last_block);
LLVMBuildBr(builder, end_block);
LLVMPositionBuilderAtEnd(builder, this_block);
switch_ = LLVMBuildSwitch(builder, codegen(ast->one), end_block, case_count);
for (i = 0; i < case_count; i++)
LLVMAddCase(switch_, case_vals[i], case_blocks[i]);
LLVMPositionBuilderAtEnd(builder, end_block);
return NULL;
}
示例7: lp_build_for_loop_begin
/**
* Creates a c-style for loop,
* contrasts lp_build_loop as this checks condition on entry
* e.g. for(i = start; i cmp_op end; i += step)
* \param state the for loop state, initialized here
* \param gallivm the gallivm state
* \param start starting value of iterator
* \param cmp_op comparison operator used for comparing current value with end value
* \param end value used to compare against iterator
* \param step value added to iterator at end of each loop
*/
void
lp_build_for_loop_begin(struct lp_build_for_loop_state *state,
struct gallivm_state *gallivm,
LLVMValueRef start,
LLVMIntPredicate cmp_op,
LLVMValueRef end,
LLVMValueRef step)
{
LLVMBuilderRef builder = gallivm->builder;
assert(LLVMTypeOf(start) == LLVMTypeOf(end));
assert(LLVMTypeOf(start) == LLVMTypeOf(step));
state->begin = lp_build_insert_new_block(gallivm, "loop_begin");
state->step = step;
state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter");
state->gallivm = gallivm;
state->cond = cmp_op;
state->end = end;
LLVMBuildStore(builder, start, state->counter_var);
LLVMBuildBr(builder, state->begin);
LLVMPositionBuilderAtEnd(builder, state->begin);
state->counter = LLVMBuildLoad(builder, state->counter_var, "");
state->body = lp_build_insert_new_block(gallivm, "loop_body");
LLVMPositionBuilderAtEnd(builder, state->body);
}
示例8: vm_state_destroy
void
vm_state_destroy(struct vm_state *vm)
{
LLVMBasicBlockRef current_block, return_block;
char *error;
current_block = LLVMGetInsertBlock(vm->builder);
return_block = LLVMInsertBasicBlock(current_block, "ret");
LLVMPositionBuilderAtEnd(vm->builder, current_block);
LLVMBuildBr(vm->builder, return_block);
LLVMPositionBuilderAtEnd(vm->builder, return_block);
LLVMBuildRetVoid(vm->builder);
LLVMMoveBasicBlockAfter(return_block, current_block);
LLVMDumpModule(vm->module);
error = NULL;
LLVMVerifyModule(vm->module, LLVMAbortProcessAction, &error);
LLVMDisposeMessage(error);
LLVMDisposeBuilder(vm->builder);
LLVMDisposeModule(vm->module);
symbol_table_destroy(vm->symtab);
}
示例9: if
LLVMBasicBlockRef JITImpl::getOrCreateMemoryCheckBailoutBlock(unsigned index)
{
if (index == 0) {
if (interpretOneBB) {
return interpretOneBB;
}
} else if (endTraceBB) {
return endTraceBB;
}
LLVMBasicBlockRef savedInsertPoint = LLVMGetInsertBlock(builder);
LLVMBasicBlockRef bailoutBB = LLVMAppendBasicBlock(getCurrentFunction(), "");
LLVMPositionBuilderAtEnd(builder, bailoutBB);
if (index == 0) {
LLVMValueRef args[] = {
threadParam
};
LLVMValueRef call = emitCallToBeInlined(functions.jitInterpretOne, args, 1);
LLVMBuildRet(builder, call);
interpretOneBB = bailoutBB;
} else {
ensureEarlyReturnBB(LLVMGetReturnType(jitFunctionType));
earlyReturnIncomingValues.push_back(
LLVMConstInt(LLVMGetReturnType(jitFunctionType),
JIT_RETURN_END_TRACE, false));
earlyReturnIncomingBlocks.push_back(LLVMGetInsertBlock(builder));
LLVMBuildBr(builder, earlyReturnBB);
endTraceBB = bailoutBB;
}
LLVMPositionBuilderAtEnd(builder, savedInsertPoint);
return bailoutBB;
}
示例10: emitJumpToNextFragment
bool JITImpl::
emitJumpToNextFragment(InstructionOpcode opc, const Operands &operands,
JITCoreInfo &coreInfo, uint32_t nextPc,
JITFunctionInfo *caller)
{
std::set<uint32_t> successors;
if (!getSuccessors(opc, operands, nextPc, successors))
return false;
unsigned numSuccessors = successors.size();
if (numSuccessors == 0)
return false;
std::set<uint32_t>::iterator it = successors.begin();
++it;
if (it != successors.end()) {
LLVMValueRef args[] = {
threadParam
};
LLVMValueRef nextPc = emitCallToBeInlined(functions.jitGetPc, args, 1);
for (;it != successors.end(); ++it) {
LLVMValueRef cmp =
LLVMBuildICmp(builder, LLVMIntEQ, nextPc,
LLVMConstInt(LLVMTypeOf(nextPc), *it, false), "");
LLVMBasicBlockRef trueBB = appendBBToCurrentFunction(builder, "");
LLVMBasicBlockRef afterBB = appendBBToCurrentFunction(builder, "");
LLVMBuildCondBr(builder, cmp, trueBB, afterBB);
LLVMPositionBuilderAtEnd(builder, trueBB);
emitJumpToNextFragment(coreInfo, *it, caller);
LLVMPositionBuilderAtEnd(builder, afterBB);
}
}
emitJumpToNextFragment(coreInfo, *successors.begin(), caller);
return true;
}
示例11: getJITFunctionOrStubImpl
JITFunctionInfo *JITImpl::
getJITFunctionOrStubImpl(JITCoreInfo &coreInfo, uint32_t pc)
{
JITFunctionInfo *&info = coreInfo.functionMap[pc];
if (info)
return info;
LLVMBasicBlockRef savedInsertPoint = LLVMGetInsertBlock(builder);
LLVMValueRef f = LLVMAddFunction(module, "", jitFunctionType);
LLVMSetFunctionCallConv(f, LLVMFastCallConv);
LLVMBasicBlockRef entryBB = LLVMAppendBasicBlock(f, "entry");
LLVMPositionBuilderAtEnd(builder, entryBB);
LLVMValueRef args[] = {
LLVMGetParam(f, 0)
};
LLVMValueRef call =
LLVMBuildCall(builder, functions.jitStubImpl, args, 1, "");
LLVMBuildRet(builder, call);
if (DEBUG_JIT) {
LLVMDumpValue(f);
LLVMVerifyFunction(f, LLVMAbortProcessAction);
}
JITInstructionFunction_t code =
reinterpret_cast<JITInstructionFunction_t>(
LLVMGetPointerToGlobal(executionEngine, f));
info = new JITFunctionInfo(pc, f, code, true);
LLVMPositionBuilderAtEnd(builder, savedInsertPoint);
return info;
}
示例12: gen_if
LLVMValueRef gen_if(struct node *ast)
{
LLVMValueRef condition, func;
LLVMBasicBlockRef then_block, else_block, end;
condition = codegen(ast->one);
condition = LLVMBuildICmp(builder, LLVMIntNE, condition, CONST(0), "");
func = LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder));
then_block = LLVMAppendBasicBlock(func, "");
else_block = LLVMAppendBasicBlock(func, "");
end = LLVMAppendBasicBlock(func, "");
LLVMBuildCondBr(builder, condition, then_block, else_block);
LLVMPositionBuilderAtEnd(builder, then_block);
codegen(ast->two);
LLVMBuildBr(builder, end);
LLVMPositionBuilderAtEnd(builder, else_block);
if (ast->three)
codegen(ast->three);
LLVMBuildBr(builder, end);
LLVMPositionBuilderAtEnd(builder, end);
return NULL;
}
示例13: trace_dynamic_nominal
static void trace_dynamic_nominal(compile_t* c, LLVMValueRef ctx,
LLVMValueRef object, ast_t* type, ast_t* orig, ast_t* tuple,
LLVMBasicBlockRef next_block)
{
// Skip if a primitive.
ast_t* def = (ast_t*)ast_data(type);
if(ast_id(def) == TK_PRIMITIVE)
return;
// If it's not possible to use match or as to extract this type from the
// original type, there's no need to trace as this type.
if(tuple != NULL)
{
// We are a tuple element. Our type is in the correct position in the
// tuple, everything else is TK_DONTCARE.
if(is_matchtype(orig, tuple) != MATCHTYPE_ACCEPT)
return;
} else {
// We aren't a tuple element.
if(is_matchtype(orig, type) != MATCHTYPE_ACCEPT)
return;
}
// We aren't always this type. We need to check dynamically.
LLVMValueRef desc = gendesc_fetch(c, object);
LLVMValueRef test = gendesc_isnominal(c, desc, type);
LLVMBasicBlockRef is_true = codegen_block(c, "");
LLVMBasicBlockRef is_false = codegen_block(c, "");
LLVMBuildCondBr(c->builder, test, is_true, is_false);
// Trace as this type.
LLVMPositionBuilderAtEnd(c->builder, is_true);
gentrace(c, ctx, object, type);
// If we have traced as known, unknown or actor, we're done with this
// element. Otherwise, continue tracing this as if the match had been
// unsuccessful.
switch(trace_type(type))
{
case TRACE_KNOWN:
case TRACE_UNKNOWN:
case TRACE_KNOWN_VAL:
case TRACE_UNKNOWN_VAL:
case TRACE_ACTOR:
LLVMBuildBr(c->builder, next_block);
break;
default:
LLVMBuildBr(c->builder, is_false);
break;
}
// Carry on, whether we have traced or not.
LLVMPositionBuilderAtEnd(c->builder, is_false);
}
示例14: gen_localdecl
LLVMValueRef gen_localdecl(compile_t* c, ast_t* ast)
{
ast_t* id = ast_child(ast);
const char* name = ast_name(id);
// If this local has already been generated, don't create another copy. This
// can happen when the same ast node is generated more than once, such as
// the condition block of a while expression.
LLVMValueRef value = codegen_getlocal(c, name);
if(value != NULL)
return GEN_NOVALUE;
ast_t* type = deferred_reify(c->frame->reify, ast_type(id), c->opt);
reach_type_t* t = reach_type(c->reach, type);
ast_free_unattached(type);
compile_type_t* c_t = (compile_type_t*)t->c_type;
// All alloca should happen in the entry block of a function.
LLVMBasicBlockRef this_block = LLVMGetInsertBlock(c->builder);
LLVMBasicBlockRef entry_block = LLVMGetEntryBasicBlock(codegen_fun(c));
LLVMValueRef inst = LLVMGetFirstInstruction(entry_block);
if(inst != NULL)
LLVMPositionBuilderBefore(c->builder, inst);
else
LLVMPositionBuilderAtEnd(c->builder, entry_block);
LLVMValueRef alloc = LLVMBuildAlloca(c->builder, c_t->mem_type, name);
// Store the alloca to use when we reference this local.
codegen_setlocal(c, name, alloc);
LLVMMetadataRef file = codegen_difile(c);
LLVMMetadataRef scope = codegen_discope(c);
#if PONY_LLVM >= 700
uint32_t align_bytes = LLVMABIAlignmentOfType(c->target_data, c_t->mem_type);
LLVMMetadataRef info = LLVMDIBuilderCreateAutoVariable(c->di, scope,
name, strlen(name), file, (unsigned)ast_line(ast), c_t->di_type,
true, LLVMDIFlagZero, align_bytes * 8);
#else
LLVMMetadataRef info = LLVMDIBuilderCreateAutoVariable(c->di, scope, name,
file, (unsigned)ast_line(ast), c_t->di_type);
#endif
LLVMMetadataRef expr = LLVMDIBuilderCreateExpression(c->di, NULL, 0);
LLVMDIBuilderInsertDeclare(c->di, alloc, info, expr,
(unsigned)ast_line(ast), (unsigned)ast_pos(ast), scope,
LLVMGetInsertBlock(c->builder));
// Put the builder back where it was.
LLVMPositionBuilderAtEnd(c->builder, this_block);
return GEN_NOTNEEDED;
}
示例15: main
int main (void) {
LLVMModuleRef module = LLVMModuleCreateWithName("kal");
LLVMBuilderRef builder = LLVMCreateBuilder();
// LLVMInitializeNativeTarget();
LLVMTypeRef funcType = LLVMFunctionType(LLVMVoidType(), NULL, 0, 0);
LLVMValueRef func = LLVMAddFunction(module, "main", funcType);
LLVMSetLinkage(func, LLVMExternalLinkage);
LLVMBasicBlockRef block = LLVMAppendBasicBlock(func, "entry");
LLVMPositionBuilderAtEnd(builder, block);
LLVMValueRef cond = LLVMBuildICmp(builder, LLVMIntNE, LLVMConstInt(LLVMInt32Type(), 2, 0), LLVMConstInt(LLVMInt32Type(), 1, 0), "ifcond");
LLVMValueRef owning_block = LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)); //TODO: WRONG??
//LLVMValueRef owning_block = LLVMBasicBlockAsValue(LLVMGetPreviousBasicBlock(LLVMGetInsertBlock(builder)));
// 2. Generate new blocks for cases.
LLVMBasicBlockRef then_ref = LLVMAppendBasicBlock(owning_block, "then");
LLVMBasicBlockRef else_ref = LLVMAppendBasicBlock(owning_block, "else");
LLVMBasicBlockRef merge_ref = LLVMAppendBasicBlock(owning_block, "ifmerge");
// 3. Branch conditionally on then or else.
LLVMBuildCondBr(builder, cond, then_ref, else_ref);
// 4. Build then branch prologue.
LLVMPositionBuilderAtEnd(builder, then_ref);
LLVMValueRef hi1 = LLVMBuildXor(builder, LLVMGetUndef(LLVMInt32Type()), LLVMGetUndef(LLVMInt32Type()), "subtmp");
// 5. Connect then branch to merge block.
LLVMBuildBr(builder, merge_ref);
then_ref = LLVMGetInsertBlock(builder);
// 6. Build else branch prologue.
LLVMPositionBuilderAtEnd(builder, else_ref);
LLVMValueRef hi2 = LLVMBuildXor(builder, LLVMGetUndef(LLVMInt32Type()), LLVMGetUndef(LLVMInt32Type()), "subtmp2");
// 7. Connect else branch to merge block.
LLVMBuildBr(builder, merge_ref);
else_ref = LLVMGetInsertBlock(builder);
// 8. Position ourselves after the merge block.
LLVMPositionBuilderAtEnd(builder, merge_ref);
// 9. Build the phi node.
// LLVMValueRef phi = LLVMBuildPhi(builder, LLVMDoubleType(), "phi");
// 10. Add incoming edges.
// LLVMAddIncoming(phi, &hi1, &then_ref, 1);
// LLVMAddIncoming(phi, &hi2, &else_ref, 1);
LLVMDumpModule(module);
LLVMDisposeBuilder(builder);
LLVMDisposeModule(module);
return 0;
}