本文整理汇总了C++中LLVMGetUndef函数的典型用法代码示例。如果您正苦于以下问题:C++ LLVMGetUndef函数的具体用法?C++ LLVMGetUndef怎么用?C++ LLVMGetUndef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LLVMGetUndef函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lp_build_swizzle_aos_n
/**
* Swizzle a vector consisting of an array of XYZW structs.
*
* This fills a vector of dst_len length with the swizzled channels from src.
*
* e.g. with swizzles = { 2, 1, 0 } and swizzle_count = 6 results in
* RGBA RGBA = BGR BGR BG
*
* @param swizzles the swizzle array
* @param num_swizzles the number of elements in swizzles
* @param dst_len the length of the result
*/
LLVMValueRef
lp_build_swizzle_aos_n(struct gallivm_state* gallivm,
LLVMValueRef src,
const unsigned char* swizzles,
unsigned num_swizzles,
unsigned dst_len)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef shuffles[LP_MAX_VECTOR_WIDTH];
unsigned i;
assert(dst_len < LP_MAX_VECTOR_WIDTH);
for (i = 0; i < dst_len; ++i) {
int swizzle = swizzles[i % num_swizzles];
if (swizzle == LP_BLD_SWIZZLE_DONTCARE) {
shuffles[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
} else {
shuffles[i] = lp_build_const_int32(gallivm, swizzle);
}
}
return LLVMBuildShuffleVector(builder, src, LLVMGetUndef(LLVMTypeOf(src)), LLVMConstVector(shuffles, dst_len), "");
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: lp_build_pack_aos_scalars
/**
* Pack first element of aos values,
* pad out to destination size.
* i.e. x1 _ _ _ x2 _ _ _ will become x1 x2 _ _
*/
LLVMValueRef
lp_build_pack_aos_scalars(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef src)
{
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef undef = LLVMGetUndef(i32t);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
unsigned num_src = src_type.length / 4;
unsigned num_dst = dst_type.length;
unsigned i;
assert(num_src <= num_dst);
for (i = 0; i < num_src; i++) {
shuffles[i] = LLVMConstInt(i32t, i * 4, 0);
}
for (i = num_src; i < num_dst; i++) {
shuffles[i] = undef;
}
if (num_dst == 1) {
return LLVMBuildExtractElement(gallivm->builder, src, shuffles[0], "");
}
else {
return LLVMBuildShuffleVector(gallivm->builder, src, src,
LLVMConstVector(shuffles, num_dst), "");
}
}
示例6: emit_array_fetch
static LLVMValueRef
emit_array_fetch(
struct lp_build_tgsi_context *bld_base,
unsigned File, enum tgsi_opcode_type type,
struct tgsi_declaration_range range,
unsigned swizzle)
{
struct lp_build_tgsi_soa_context *bld = lp_soa_context(bld_base);
struct gallivm_state * gallivm = bld->bld_base.base.gallivm;
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
unsigned i, size = range.Last - range.First + 1;
LLVMTypeRef vec = LLVMVectorType(tgsi2llvmtype(bld_base, type), size);
LLVMValueRef result = LLVMGetUndef(vec);
struct tgsi_full_src_register tmp_reg = {};
tmp_reg.Register.File = File;
for (i = 0; i < size; ++i) {
tmp_reg.Register.Index = i + range.First;
LLVMValueRef temp = emit_fetch(bld_base, &tmp_reg, type, swizzle);
result = LLVMBuildInsertElement(builder, result, temp,
lp_build_const_int32(gallivm, i), "");
}
return result;
}
示例7: lp_build_context_init
void
lp_build_context_init(struct lp_build_context *bld,
struct gallivm_state *gallivm,
struct lp_type type)
{
bld->gallivm = gallivm;
bld->type = type;
bld->int_elem_type = lp_build_int_elem_type(gallivm, type);
if (type.floating)
bld->elem_type = lp_build_elem_type(gallivm, type);
else
bld->elem_type = bld->int_elem_type;
if (type.length == 1) {
bld->int_vec_type = bld->int_elem_type;
bld->vec_type = bld->elem_type;
}
else {
bld->int_vec_type = LLVMVectorType(bld->int_elem_type, type.length);
bld->vec_type = LLVMVectorType(bld->elem_type, type.length);
}
bld->undef = LLVMGetUndef(bld->vec_type);
bld->zero = LLVMConstNull(bld->vec_type);
bld->one = lp_build_one(gallivm, type);
}
示例8: lp_build_gather
/**
* Gather elements from scatter positions in memory into a single vector.
* Use for fetching texels from a texture.
* For SSE, typical values are length=4, src_width=32, dst_width=32.
*
* @param length length of the offsets
* @param src_width src element width in bits
* @param dst_width result element width in bits (src will be expanded to fit)
* @param base_ptr base pointer, should be a i8 pointer type.
* @param offsets vector with offsets
*/
LLVMValueRef
lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
LLVMValueRef base_ptr,
LLVMValueRef offsets)
{
LLVMValueRef res;
if (length == 1) {
/* Scalar */
return lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, 0);
} else {
/* Vector */
LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMTypeRef dst_vec_type = LLVMVectorType(dst_elem_type, length);
unsigned i;
res = LLVMGetUndef(dst_vec_type);
for (i = 0; i < length; ++i) {
LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef elem;
elem = lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, i);
res = LLVMBuildInsertElement(gallivm->builder, res, elem, index, "");
}
}
return res;
}
示例9: 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;
}
示例10: lp_build_intrinsic_map
LLVMValueRef
lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
unsigned num_args)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef ret_elem_type = LLVMGetElementType(ret_type);
unsigned n = LLVMGetVectorSize(ret_type);
unsigned i, j;
LLVMValueRef res;
assert(num_args <= LP_MAX_FUNC_ARGS);
res = LLVMGetUndef(ret_type);
for(i = 0; i < n; ++i) {
LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef arg_elems[LP_MAX_FUNC_ARGS];
LLVMValueRef res_elem;
for(j = 0; j < num_args; ++j)
arg_elems[j] = LLVMBuildExtractElement(builder, args[j], index, "");
res_elem = lp_build_intrinsic(builder, name, ret_elem_type, arg_elems, num_args, 0);
res = LLVMBuildInsertElement(builder, res, res_elem, index, "");
}
return res;
}
示例11: lp_build_pad_vector
/**
* Expands src vector from src.length to dst_length
*/
LLVMValueRef
lp_build_pad_vector(struct gallivm_state *gallivm,
LLVMValueRef src,
struct lp_type src_type,
unsigned dst_length)
{
LLVMValueRef undef = LLVMGetUndef(lp_build_vec_type(gallivm, src_type));
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
assert(dst_length <= Elements(elems));
assert(dst_length > src_type.length);
if (src_type.length == dst_length)
return src;
/* If its a single scalar type, no need to reinvent the wheel */
if (src_type.length == 1) {
return lp_build_broadcast(gallivm, LLVMVectorType(lp_build_elem_type(gallivm, src_type), dst_length), src);
}
/* All elements from src vector */
for (i = 0; i < src_type.length; ++i)
elems[i] = lp_build_const_int32(gallivm, i);
/* Undef fill remaining space */
for (i = src_type.length; i < dst_length; ++i)
elems[i] = lp_build_const_int32(gallivm, src_type.length);
/* Combine the two vectors */
return LLVMBuildShuffleVector(gallivm->builder, src, undef, LLVMConstVector(elems, dst_length), "");
}
示例12: lp_build_extract_broadcast
/**
* Combined extract and broadcast (mere shuffle in most cases)
*/
LLVMValueRef
lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,
LLVMValueRef index)
{
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef res;
assert(src_type.floating == dst_type.floating);
assert(src_type.width == dst_type.width);
assert(lp_check_value(src_type, vector));
assert(LLVMTypeOf(index) == i32t);
if (src_type.length == 1) {
if (dst_type.length == 1) {
/*
* Trivial scalar -> scalar.
*/
res = vector;
}
else {
/*
* Broadcast scalar -> vector.
*/
res = lp_build_broadcast(gallivm,
lp_build_vec_type(gallivm, dst_type),
vector);
}
}
else {
if (dst_type.length > 1) {
/*
* shuffle - result can be of different length.
*/
LLVMValueRef shuffle;
shuffle = lp_build_broadcast(gallivm,
LLVMVectorType(i32t, dst_type.length),
index);
res = LLVMBuildShuffleVector(gallivm->builder, vector,
LLVMGetUndef(lp_build_vec_type(gallivm, src_type)),
shuffle, "");
}
else {
/*
* Trivial extract scalar from vector.
*/
res = LLVMBuildExtractElement(gallivm->builder, vector, index, "");
}
}
return res;
}
示例13: gen_tuple
LLVMValueRef gen_tuple(compile_t* c, ast_t* ast)
{
ast_t* child = ast_child(ast);
if(ast_sibling(child) == NULL)
return gen_expr(c, child);
deferred_reification_t* reify = c->frame->reify;
ast_t* type = deferred_reify(reify, ast_type(ast), c->opt);
// If we contain '_', we have no usable value.
if(contains_dontcare(type))
{
ast_free_unattached(type);
return GEN_NOTNEEDED;
}
reach_type_t* t = reach_type(c->reach, type);
compile_type_t* c_t = (compile_type_t*)t->c_type;
int count = LLVMCountStructElementTypes(c_t->primitive);
size_t buf_size = count * sizeof(LLVMTypeRef);
LLVMTypeRef* elements = (LLVMTypeRef*)ponyint_pool_alloc_size(buf_size);
LLVMGetStructElementTypes(c_t->primitive, elements);
LLVMValueRef tuple = LLVMGetUndef(c_t->primitive);
int i = 0;
while(child != NULL)
{
LLVMValueRef value = gen_expr(c, child);
if(value == NULL)
{
ponyint_pool_free_size(buf_size, elements);
return NULL;
}
// We'll have an undefined element if one of our source elements is a
// variable declaration. This is ok, since the tuple value will never be
// used.
if(value == GEN_NOVALUE || value == GEN_NOTNEEDED)
{
ponyint_pool_free_size(buf_size, elements);
return value;
}
ast_t* child_type = deferred_reify(reify, ast_type(child), c->opt);
value = gen_assign_cast(c, elements[i], value, child_type);
ast_free_unattached(child_type);
tuple = LLVMBuildInsertValue(c->builder, tuple, value, i++, "");
child = ast_sibling(child);
}
ponyint_pool_free_size(buf_size, elements);
return tuple;
}
示例14: emit_fetch
static LLVMValueRef
emit_fetch(
struct lp_build_tgsi_context *bld_base,
const struct tgsi_full_src_register *reg,
enum tgsi_opcode_type type,
unsigned swizzle)
{
struct radeon_llvm_context * ctx = radeon_llvm_context(bld_base);
struct lp_build_tgsi_soa_context *bld = lp_soa_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMValueRef result, ptr;
if (swizzle == ~0) {
LLVMValueRef values[TGSI_NUM_CHANNELS];
unsigned chan;
for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
values[chan] = emit_fetch(bld_base, reg, type, chan);
}
return lp_build_gather_values(bld_base->base.gallivm, values,
TGSI_NUM_CHANNELS);
}
if (reg->Register.Indirect) {
struct tgsi_declaration_range range = get_array_range(bld_base,
reg->Register.File, ®->Indirect);
return LLVMBuildExtractElement(builder,
emit_array_fetch(bld_base, reg->Register.File, type, range, swizzle),
emit_array_index(bld, ®->Indirect, reg->Register.Index - range.First),
"");
}
switch(reg->Register.File) {
case TGSI_FILE_IMMEDIATE: {
LLVMTypeRef ctype = tgsi2llvmtype(bld_base, type);
return LLVMConstBitCast(bld->immediates[reg->Register.Index][swizzle], ctype);
}
case TGSI_FILE_INPUT:
result = ctx->inputs[radeon_llvm_reg_index_soa(reg->Register.Index, swizzle)];
break;
case TGSI_FILE_TEMPORARY:
ptr = lp_get_temp_ptr_soa(bld, reg->Register.Index, swizzle);
result = LLVMBuildLoad(builder, ptr, "");
break;
case TGSI_FILE_OUTPUT:
ptr = lp_get_output_ptr(bld, reg->Register.Index, swizzle);
result = LLVMBuildLoad(builder, ptr, "");
break;
default:
return LLVMGetUndef(tgsi2llvmtype(bld_base, type));
}
return bitcast(bld_base, type, result);
}
示例15: lp_build_pad_vector
/**
* Expands src vector from src.length to dst_length
*/
LLVMValueRef
lp_build_pad_vector(struct gallivm_state *gallivm,
LLVMValueRef src,
unsigned dst_length)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
LLVMValueRef undef;
LLVMTypeRef type;
unsigned i, src_length;
type = LLVMTypeOf(src);
if (LLVMGetTypeKind(type) != LLVMVectorTypeKind) {
/* Can't use ShuffleVector on non-vector type */
undef = LLVMGetUndef(LLVMVectorType(type, dst_length));
return LLVMBuildInsertElement(gallivm->builder, undef, src, lp_build_const_int32(gallivm, 0), "");
}
undef = LLVMGetUndef(type);
src_length = LLVMGetVectorSize(type);
assert(dst_length <= Elements(elems));
assert(dst_length >= src_length);
if (src_length == dst_length)
return src;
/* All elements from src vector */
for (i = 0; i < src_length; ++i)
elems[i] = lp_build_const_int32(gallivm, i);
/* Undef fill remaining space */
for (i = src_length; i < dst_length; ++i)
elems[i] = lp_build_const_int32(gallivm, src_length);
/* Combine the two vectors */
return LLVMBuildShuffleVector(gallivm->builder, src, undef, LLVMConstVector(elems, dst_length), "");
}