summaryrefslogtreecommitdiffstats
path: root/src/amd/common/ac_llvm_build.c
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2017-12-11 12:54:47 +1100
committerTimothy Arceri <[email protected]>2018-01-05 11:58:55 +1100
commitb99ebaa4fd7ab1f4b1f3ff5b965d422f67a8cb40 (patch)
treee6b1a1cef02a226c1b2c26ea3494000363f92db7 /src/amd/common/ac_llvm_build.c
parent2deb82207572d47ab1b35fc47768536ad34a875e (diff)
ac: move some helpers to ac_llvm_build.c
We will call these from the radeonsi NIR backend. Reviewed-by: Nicolai Hähnle <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/amd/common/ac_llvm_build.c')
-rw-r--r--src/amd/common/ac_llvm_build.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index c74a47a7998..0ea5e7f4caa 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -99,6 +99,30 @@ ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context,
ctx->empty_md = LLVMMDNodeInContext(ctx->context, NULL, 0);
}
+int
+ac_get_llvm_num_components(LLVMValueRef value)
+{
+ LLVMTypeRef type = LLVMTypeOf(value);
+ unsigned num_components = LLVMGetTypeKind(type) == LLVMVectorTypeKind
+ ? LLVMGetVectorSize(type)
+ : 1;
+ return num_components;
+}
+
+LLVMValueRef
+ac_llvm_extract_elem(struct ac_llvm_context *ac,
+ LLVMValueRef value,
+ int index)
+{
+ int count = ac_get_llvm_num_components(value);
+
+ if (count == 1)
+ return value;
+
+ return LLVMBuildExtractElement(ac->builder, value,
+ LLVMConstInt(ac->i32, index, false), "");
+}
+
unsigned
ac_get_type_size(LLVMTypeRef type)
{