summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Churaev <echuraev@users.noreply.github.com>2016-10-20 00:21:52 +0300
committerYaxun (Sam) Liu <yaxun.liu@amd.com>2016-10-19 17:21:52 -0400
commitfdf62322cd2bb30c051d128c8dc5797771578128 (patch)
tree44fbd2c8f4bc39f679f7c4e99ed36b91b5815563
parent04cadadc09de600daacc57c1b332005d8e4478ed (diff)
Implemented method for mapping function arguments without metadata. (#194)
-rw-r--r--lib/SPIRV/OCLTypeToSPIRV.cpp32
-rw-r--r--lib/SPIRV/OCLTypeToSPIRV.h1
-rw-r--r--test/image_decl_func_arg.ll60
3 files changed, 93 insertions, 0 deletions
diff --git a/lib/SPIRV/OCLTypeToSPIRV.cpp b/lib/SPIRV/OCLTypeToSPIRV.cpp
index be58ff1..f088620 100644
--- a/lib/SPIRV/OCLTypeToSPIRV.cpp
+++ b/lib/SPIRV/OCLTypeToSPIRV.cpp
@@ -82,6 +82,9 @@ OCLTypeToSPIRV::runOnModule(Module& Module) {
for (auto &F:Module.functions())
adaptArgumentsByMetadata(&F);
+ for (auto &F:Module.functions())
+ adaptFunctionArguments(&F);
+
adaptArgumentsBySamplerUse(Module);
while (!WorkSet.empty()) {
@@ -274,6 +277,35 @@ void OCLTypeToSPIRV::adaptArgumentsBySamplerUse(Module &M) {
}
}
+void
+OCLTypeToSPIRV::adaptFunctionArguments(Function* F) {
+ auto TypeMD = getArgBaseTypeMetadata(F);
+ if (TypeMD)
+ return;
+ bool Changed = false;
+ auto FT = F->getFunctionType();
+ auto PI = FT->param_begin();
+ auto Arg = F->arg_begin();
+ for (unsigned I = 0; I < F->getArgumentList().size(); ++I, ++PI, ++Arg) {
+ auto NewTy = *PI;
+ if (isPointerToOpaqueStructType(NewTy)) {
+ auto STName = NewTy->getPointerElementType()->getStructName();
+ if (!hasAccessQualifiedName(STName))
+ continue;
+ if (STName.startswith(kSPR2TypeName::ImagePrefix) ||
+ STName == kSPR2TypeName::Pipe) {
+ auto Ty = STName.str();
+ auto AccStr = getAccessQualifier(Ty);
+ addAdaptedType(Arg, getOrCreateOpaquePtrType(M,
+ mapOCLTypeNameToSPIRV(Ty, AccStr)));
+ Changed = true;
+ }
+ }
+ }
+ if (Changed)
+ addWork(F);
+}
+
/// Go through all kernel functions, get access qualifier for image and pipe
/// types and use them to map the function arguments to the SPIR-V type.
/// ToDo: Map other OpenCL opaque types to SPIR-V types.
diff --git a/lib/SPIRV/OCLTypeToSPIRV.h b/lib/SPIRV/OCLTypeToSPIRV.h
index f6302f8..bb66d6a 100644
--- a/lib/SPIRV/OCLTypeToSPIRV.h
+++ b/lib/SPIRV/OCLTypeToSPIRV.h
@@ -74,6 +74,7 @@ private:
MDNode *getArgAccessQualifierMetadata(Function *);
MDNode *getArgMetadata(Function *, const std::string& MDName);
MDNode *getKernelMetadata(Function *F);
+ void adaptFunctionArguments(Function* F);
void adaptArgumentsByMetadata(Function* F);
void adaptArgumentsBySamplerUse(Module &M);
void adaptFunction(Function *F);
diff --git a/test/image_decl_func_arg.ll b/test/image_decl_func_arg.ll
new file mode 100644
index 0000000..748b560
--- /dev/null
+++ b/test/image_decl_func_arg.ll
@@ -0,0 +1,60 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
+; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
+
+; CHECK-SPIRV: {{[0-9]*}} TypeImage [[TypeImage:[0-9]+]]
+; CHECK-SPIRV-NOT: {{[0-9]*}} TypeImage
+; CHECK-SPIRV: {{[0-9]*}} TypeFunction {{[0-9]*}} {{[0-9]*}} [[TypeImage]]
+; CHECK-SPIRV: {{[0-9]*}} TypeFunction {{[0-9]*}} {{[0-9]*}} [[TypeImage]]
+; CHECK-SPIRV: {{[0-9]*}} FunctionParameter [[TypeImage]] {{[0-9]*}}
+; CHECK-SPIRV: {{[0-9]*}} FunctionParameter [[TypeImage]] {{[0-9]*}}
+; CHECK-SPIRV: {{[0-9]*}} FunctionParameter [[TypeImage]] [[ParamID:[0-9]+]]
+; CHECK-SPIRV: {{[0-9]*}} FunctionCall {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} [[ParamID]]
+
+; ModuleID = 'test.cl.bc'
+target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
+target triple = "spir-unknown-unknown"
+
+%opencl.image2d_ro_t = type opaque
+
+; Function Attrs: nounwind
+define spir_func void @f0(%opencl.image2d_ro_t addrspace(1)* %v2, <2 x float> %v3) #0 {
+entry:
+ ret void
+}
+
+; Function Attrs: nounwind
+define spir_func void @f1(%opencl.image2d_ro_t addrspace(1)* %v2, <2 x float> %v3) #0 {
+entry:
+ ret void
+}
+
+; Function Attrs: nounwind
+define spir_kernel void @test(%opencl.image2d_ro_t addrspace(1)* %v1) #0 {
+entry:
+ call spir_func void @f0(%opencl.image2d_ro_t addrspace(1)* %v1, <2 x float> <float 1.000000e+00, float 5.000000e+00>) #0
+ ret void
+}
+
+attributes #0 = { nounwind }
+
+!opencl.kernels = !{!0}
+!opencl.enable.FP_CONTRACT = !{}
+!spirv.Source = !{!6}
+!opencl.spir.version = !{!7}
+!opencl.ocl.version = !{!7}
+!opencl.used.extensions = !{!8}
+!opencl.used.optional.core.features = !{!9}
+!spirv.Generator = !{!10}
+
+!0 = !{void (%opencl.image2d_ro_t addrspace(1)*)* @test, !1, !2, !3, !4, !5}
+!1 = !{!"kernel_arg_addr_space", i32 1}
+!2 = !{!"kernel_arg_access_qual", !"read_only"}
+!3 = !{!"kernel_arg_type", !"image2d_t"}
+!4 = !{!"kernel_arg_type_qual", !""}
+!5 = !{!"kernel_arg_base_type", !"image2d_t"}
+!6 = !{i32 3, i32 200000}
+!7 = !{i32 2, i32 0}
+!8 = !{}
+!9 = !{!"cl_images"}
+!10 = !{i16 6, i16 14}