本文整理汇总了C++中LLVMTypeOf函数的典型用法代码示例。如果您正苦于以下问题:C++ LLVMTypeOf函数的具体用法?C++ LLVMTypeOf怎么用?C++ LLVMTypeOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LLVMTypeOf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lp_build_print_args
/**
* Generates LLVM IR to call debug_printf.
*/
static LLVMValueRef
lp_build_print_args(struct gallivm_state* gallivm,
int argcount,
LLVMValueRef* args)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMContextRef context = gallivm->context;
LLVMValueRef func_printf;
LLVMTypeRef printf_type;
int i;
assert(args);
assert(argcount > 0);
assert(LLVMTypeOf(args[0]) == LLVMPointerType(LLVMInt8TypeInContext(context), 0));
/* Cast any float arguments to doubles as printf expects */
for (i = 1; i < argcount; i++) {
LLVMTypeRef type = LLVMTypeOf(args[i]);
if (LLVMGetTypeKind(type) == LLVMFloatTypeKind)
args[i] = LLVMBuildFPExt(builder, args[i], LLVMDoubleTypeInContext(context), "");
}
printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1);
func_printf = lp_build_const_int_pointer(gallivm, func_to_pointer((func_pointer)debug_printf));
func_printf = LLVMBuildBitCast(builder, func_printf, LLVMPointerType(printf_type, 0), "debug_printf");
return LLVMBuildCall(builder, func_printf, args, argcount, "");
}
示例2: lp_build_broadcast
LLVMValueRef
lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar)
{
LLVMValueRef res;
if (LLVMGetTypeKind(vec_type) != LLVMVectorTypeKind) {
/* scalar */
assert(vec_type == LLVMTypeOf(scalar));
res = scalar;
} else {
LLVMBuilderRef builder = gallivm->builder;
const unsigned length = LLVMGetVectorSize(vec_type);
LLVMValueRef undef = LLVMGetUndef(vec_type);
/* The shuffle vector is always made of int32 elements */
LLVMTypeRef i32_type = LLVMInt32TypeInContext(gallivm->context);
LLVMTypeRef i32_vec_type = LLVMVectorType(i32_type, length);
assert(LLVMGetElementType(vec_type) == LLVMTypeOf(scalar));
res = LLVMBuildInsertElement(builder, undef, scalar, LLVMConstNull(i32_type), "");
res = LLVMBuildShuffleVector(builder, res, undef, LLVMConstNull(i32_vec_type), "");
}
return res;
}
示例3: gen_name
LLVMValueRef gen_name(struct node *ast)
{
LLVMValueRef func, ptr, val;
LLVMTypeRef type;
ptr = lvalue(ast);
type = LLVMTypeOf(ptr);
if (LLVMGetTypeKind(type) == LLVMLabelTypeKind) {
func = LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder));
return LLVMBuildPtrToInt(builder,
LLVMBlockAddress(func, (LLVMBasicBlockRef)ptr),
TYPE_INT,
"");
}
type = LLVMGetElementType(LLVMTypeOf(ptr));
switch (LLVMGetTypeKind(type)) {
case LLVMIntegerTypeKind:
val = LLVMBuildLoad(builder, ptr, ast->val);
if (LLVMIsAGlobalValue(ptr))
val = LLVMBuildLShr(builder, val, CONST(WORDPOW), "");
return val;
default:
generror("unexpected type '%s'", LLVMPrintTypeToString(type));
return NULL;
}
}
示例4: translateBinOp
static LLVMValueRef
translateBinOp(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) {
ASTNode *NodeE1 = (ASTNode*) ptrVectorGet(&(Node->Child), 0),
*NodeE2 = (ASTNode*) ptrVectorGet(&(Node->Child), 1);
LLVMValueRef ValueE1Ptr = translateExpr(TyTable, ValTable, NodeE1),
ValueE2Ptr = translateExpr(TyTable, ValTable, NodeE2);
LLVMValueRef ValueE1 = LLVMBuildLoad(Builder, ValueE1Ptr, "binop.ld.e1."),
ValueE2 = LLVMBuildLoad(Builder, ValueE2Ptr, "binop.ld.e2.");
LLVMValueRef ResultVal = NULL;
switch (LLVMGetTypeKind(LLVMTypeOf(ValueE1))) {
case LLVMIntegerTypeKind: ResultVal = translateIntBinOp (Node->Kind, ValueE1, ValueE2); break;
case LLVMFloatTypeKind: ResultVal = translateFloatBinOp (Node->Kind, ValueE1, ValueE2); break;
case LLVMStructTypeKind: ResultVal = translateStructBinOp(Node->Kind, ValueE1Ptr, ValueE2Ptr); break;
case LLVMPointerTypeKind: ResultVal = translateStringBinOp(Node->Kind, ValueE1, ValueE2); break;
default: return NULL;
}
switch (LLVMGetTypeKind(LLVMTypeOf(ResultVal))) {
case LLVMIntegerTypeKind: ResultVal = LLVMBuildZExt(Builder, ResultVal, LLVMInt32Type(), ""); break;
default: break;
}
return wrapValue(ResultVal);
}
示例5: 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);
}
示例6: build_cube_intrinsic
static LLVMValueRef build_cube_intrinsic(struct gallivm_state *gallivm,
LLVMValueRef in[3])
{
if (HAVE_LLVM >= 0x0309) {
LLVMTypeRef f32 = LLVMTypeOf(in[0]);
LLVMValueRef out[4];
out[0] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubetc",
f32, in, 3, LLVMReadNoneAttribute);
out[1] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubesc",
f32, in, 3, LLVMReadNoneAttribute);
out[2] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubema",
f32, in, 3, LLVMReadNoneAttribute);
out[3] = lp_build_intrinsic(gallivm->builder, "llvm.amdgcn.cubeid",
f32, in, 3, LLVMReadNoneAttribute);
return lp_build_gather_values(gallivm, out, 4);
} else {
LLVMValueRef c[4] = {
in[0],
in[1],
in[2],
LLVMGetUndef(LLVMTypeOf(in[0]))
};
LLVMValueRef vec = lp_build_gather_values(gallivm, c, 4);
return lp_build_intrinsic(gallivm->builder, "llvm.AMDGPU.cube",
LLVMTypeOf(vec), &vec, 1,
LLVMReadNoneAttribute);
}
}
示例7: translateFunCallExpr
static LLVMValueRef
translateFunCallExpr(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) {
PtrVector *V = &(Node->Child);
ASTNode *ExprNode = (ASTNode*) ptrVectorGet(V, 0),
*ParamsNode = (ASTNode*) ptrVectorGet(V, 1);
LLVMTypeRef ReturnType = toTransitionType(getLLVMTypeFromType(TyTable, Node->Value)),
*ParamsType = NULL, FunctionType;
LLVMValueRef *ParamsValue = NULL;
unsigned Count = 0;
if (ParamsNode) {
ParamsValue = (LLVMValueRef*) malloc(sizeof(LLVMValueRef) * ParamsNode->Child.Size);
for (Count = 0; Count < ParamsNode->Child.Size; ++Count) {
LLVMValueRef ExprVal = translateExpr(TyTable, ValTable, ptrVectorGet(&(ParamsNode->Child), Count));
LLVMTypeRef ExprType = LLVMGetElementType(LLVMTypeOf(ExprVal));
switch (LLVMGetTypeKind(ExprType)) {
case LLVMIntegerTypeKind:
case LLVMFloatTypeKind:
case LLVMPointerTypeKind: ExprVal = LLVMBuildLoad(Builder, ExprVal, "load.4.call"); break;
default: break;
}
ParamsValue[Count] = ExprVal;
if (!ParamsType)
ParamsType = (LLVMTypeRef*) malloc(sizeof(LLVMTypeRef) * ParamsNode->Child.Size);
ParamsType[Count] = LLVMTypeOf(ExprVal);
}
}
FunctionType = LLVMFunctionType(ReturnType, ParamsType, Count, 0);
FunctionType = LLVMPointerType(FunctionType, 0);
LLVMValueRef Closure = translateExpr(TyTable, ValTable, ExprNode);
LLVMValueRef CallValue = callClosure(FunctionType, Closure, ParamsValue, Count);
switch (getLLVMValueTypeKind(CallValue)) {
case LLVMIntegerTypeKind:
case LLVMFloatTypeKind:
case LLVMPointerTypeKind:
{
if (getLLVMValueTypeKind(CallValue) == LLVMPointerTypeKind &&
getLLVMElementTypeKind(CallValue) == LLVMStructTypeKind)
break;
LLVMValueRef PtrMem = LLVMBuildAlloca(Builder, LLVMTypeOf(CallValue), "");
LLVMBuildStore(Builder, CallValue, PtrMem);
return PtrMem;
}
}
return CallValue;
}
示例8: lp_build_array_set
void
lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value)
{
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
LLVMBuildStore(gallivm->builder, value, element_ptr);
}
示例9: translateIfThenExpr
static LLVMValueRef
translateIfThenExpr(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) {
ASTNode *CondNode = (ASTNode*) ptrVectorGet(&(Node->Child), 0),
*ThenNode = (ASTNode*) ptrVectorGet(&(Node->Child), 1),
*ElseNode = (ASTNode*) ptrVectorGet(&(Node->Child), 2);
LLVMBasicBlockRef ThisBB = LLVMGetInsertBlock(Builder);
LLVMValueRef ThisFn = LLVMGetBasicBlockParent(ThisBB);
// Creating the BasicBlocks that will be used.
LLVMBasicBlockRef TrueBB, FalseBB, EndBB;
TrueBB = LLVMAppendBasicBlock(ThisFn, "if.then");
EndBB = LLVMAppendBasicBlock(ThisFn, "if.end");
if (ElseNode) FalseBB = LLVMAppendBasicBlock(ThisFn, "if.else");
else FalseBB = EndBB;
// Creating the conditional branch.
LLVMValueRef CondValue = translateExpr(TyTable, ValTable, CondNode);
LLVMValueRef CondLoad = LLVMBuildLoad(Builder, CondValue, "");
LLVMValueRef CalcTrueFalse = LLVMBuildICmp(Builder, LLVMIntNE, CondLoad, getSConstInt(0), "");
LLVMBuildCondBr(Builder, CalcTrueFalse, TrueBB, FalseBB);
// Filling the BasicBlocks.
LLVMValueRef TrueValue, FalseValue;
LLVMPositionBuilderAtEnd(Builder, TrueBB);
TrueValue = translateExpr(TyTable, ValTable, ThenNode);
LLVMBuildBr(Builder, EndBB);
if (ElseNode) {
LLVMPositionBuilderAtEnd(Builder, FalseBB);
FalseValue = translateExpr(TyTable, ValTable, ElseNode);
LLVMBuildBr(Builder, EndBB);
}
FalseBB = LLVMGetInsertBlock(Builder);
LLVMPositionBuilderAtEnd(Builder, EndBB);
if (ElseNode && LLVMGetTypeKind(LLVMTypeOf(TrueValue)) != LLVMVoidTypeKind) {
LLVMValueRef PhiNode = LLVMBuildPhi(Builder, LLVMTypeOf(TrueValue), "");
// Adding incoming to phi-node.
LLVMValueRef Values[] = { TrueValue, FalseValue };
LLVMBasicBlockRef Blocks[] = { TrueBB, FalseBB };
LLVMAddIncoming(PhiNode, Values, Blocks, 2);
return PhiNode;
}
return NULL;
}
示例10: lp_build_struct_get
LLVMValueRef
lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
{
LLVMValueRef member_ptr;
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name);
res = LLVMBuildLoad(gallivm->builder, member_ptr, "");
lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
return res;
}
示例11: 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;
}
示例12: 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;
}
示例13: ac_build_gather_values_extended
LLVMValueRef
ac_build_gather_values_extended(struct ac_llvm_context *ctx,
LLVMValueRef *values,
unsigned value_count,
unsigned value_stride,
bool load)
{
LLVMBuilderRef builder = ctx->builder;
LLVMValueRef vec = NULL;
unsigned i;
if (value_count == 1) {
if (load)
return LLVMBuildLoad(builder, values[0], "");
return values[0];
} else if (!value_count)
unreachable("value_count is 0");
for (i = 0; i < value_count; i++) {
LLVMValueRef value = values[i * value_stride];
if (load)
value = LLVMBuildLoad(builder, value, "");
if (!i)
vec = LLVMGetUndef( LLVMVectorType(LLVMTypeOf(value), value_count));
LLVMValueRef index = LLVMConstInt(ctx->i32, i, false);
vec = LLVMBuildInsertElement(builder, vec, value, index, "");
}
return vec;
}
示例14: lp_build_array_get
LLVMValueRef
lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
LLVMValueRef element_ptr;
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
res = LLVMBuildLoad(gallivm->builder, element_ptr, "");
#ifdef DEBUG
lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
#endif
return res;
}
示例15: lp_build_struct_get_ptr
LLVMValueRef
lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
{
LLVMValueRef indices[2];
LLVMValueRef member_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
indices[0] = lp_build_const_int32(gallivm, 0);
indices[1] = lp_build_const_int32(gallivm, member);
member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name);
return member_ptr;
}