diff options
-rw-r--r-- | lib/SPIRV/SPRVWriter.cpp | 6 | ||||
-rw-r--r-- | lib/SPIRV/libSPIRV/SPRVModule.cpp | 16 | ||||
-rw-r--r-- | test/image-unoptimized.ll | 76 | ||||
-rw-r--r-- | test/store.ll | 4 | ||||
-rw-r--r-- | tools/llvm-spirv/CMakeLists.txt | 1 |
5 files changed, 93 insertions, 10 deletions
diff --git a/lib/SPIRV/SPRVWriter.cpp b/lib/SPIRV/SPRVWriter.cpp index ca0e1b6..44ed346 100644 --- a/lib/SPIRV/SPRVWriter.cpp +++ b/lib/SPIRV/SPRVWriter.cpp @@ -86,6 +86,10 @@ using namespace llvm; using namespace SPRV;
using namespace OCLUtil;
+namespace llvm { + FunctionPass *createPromoteMemoryToRegisterPass(); +} + namespace SPRV{
bool SPRVDbgSaveRegularizedModule = false;
@@ -2140,10 +2144,10 @@ LLVMToSPRV::dumpUsers(Value* V) { SPRVDBG(dbgs() << " " << **UI << '\n');
}
-
void
LLVMToSPRV::oclRegularize() {
PassManager PassMgr;
+ PassMgr.add(createPromoteMemoryToRegisterPass()); PassMgr.add(createSPRVRegularizeOCL20());
PassMgr.add(createSPRVLowerOCLBlocks());
PassMgr.add(createSPRVLowerBool());
diff --git a/lib/SPIRV/libSPIRV/SPRVModule.cpp b/lib/SPIRV/libSPIRV/SPRVModule.cpp index 87880a2..ec86627 100644 --- a/lib/SPIRV/libSPIRV/SPRVModule.cpp +++ b/lib/SPIRV/libSPIRV/SPRVModule.cpp @@ -376,14 +376,14 @@ SPRVModuleImpl::optimizeDecorates() { continue;
}
SPRVDBG(bildbgs() << " add deco group. erase equal range\n");
- auto G = new SPRVDecorationGroup(this, getId());
- std::vector<SPRVId> Targets;
- Targets.push_back(D->getTargetId());
- const_cast<SPRVDecorateGeneric*>(D)->setTargetId(G->getId());
- G->getDecorations().insert(D);
- for (I = ER.first; I != ER.second; ++I) {
- auto E = *I;
- if (*E == *D)
+ auto G = new SPRVDecorationGroup(this, getId()); + std::vector<SPRVId> Targets; + Targets.push_back(D->getTargetId()); + const_cast<SPRVDecorateGeneric*>(D)->setTargetId(G->getId()); + G->getDecorations().insert(D); + for (I = ER.first; I != ER.second; ++I) { + auto E = *I; + if (*E == *D) continue;
Targets.push_back(E->getTargetId());
}
diff --git a/test/image-unoptimized.ll b/test/image-unoptimized.ll new file mode 100644 index 0000000..f3c1be4 --- /dev/null +++ b/test/image-unoptimized.ll @@ -0,0 +1,76 @@ +; RUN: llvm-as < %s | llvm-spirv -spirv-text -o %t +; RUN: FileCheck < %t %s +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_t = type opaque + +; Function Attrs: nounwind +; CHECK: {{[0-9]*}} Store +; CHECK-NEXT: 1 Return +define spir_kernel void @test_fn(%opencl.image2d_t addrspace(1)* %srcimg, i32 %sampler, <4 x float> addrspace(1)* %results) #0 { +entry: + %srcimg.addr = alloca %opencl.image2d_t addrspace(1)*, align 4 + %sampler.addr = alloca i32, align 4 + %results.addr = alloca <4 x float> addrspace(1)*, align 4 + %tid_x = alloca i32, align 4 + %tid_y = alloca i32, align 4 + %.compoundliteral = alloca <2 x i32>, align 8 + store %opencl.image2d_t addrspace(1)* %srcimg, %opencl.image2d_t addrspace(1)** %srcimg.addr, align 4 + store i32 %sampler, i32* %sampler.addr, align 4 + store <4 x float> addrspace(1)* %results, <4 x float> addrspace(1)** %results.addr, align 4 + %call = call spir_func i32 @_Z13get_global_idj(i32 0) #2 + store i32 %call, i32* %tid_x, align 4 + %call1 = call spir_func i32 @_Z13get_global_idj(i32 1) #2 + store i32 %call1, i32* %tid_y, align 4 + %0 = load %opencl.image2d_t addrspace(1)** %srcimg.addr, align 4 + %1 = load i32* %sampler.addr, align 4 + %2 = load i32* %tid_x, align 4 + %vecinit = insertelement <2 x i32> undef, i32 %2, i32 0 + %3 = load i32* %tid_y, align 4 + %vecinit2 = insertelement <2 x i32> %vecinit, i32 %3, i32 1 + store <2 x i32> %vecinit2, <2 x i32>* %.compoundliteral + %4 = load <2 x i32>* %.compoundliteral + %call3 = call spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(%opencl.image2d_t addrspace(1)* %0, i32 %1, <2 x i32> %4) #2 + %5 = load i32* %tid_y, align 4 + %6 = load %opencl.image2d_t addrspace(1)** %srcimg.addr, align 4 + %call4 = call spir_func i32 @_Z15get_image_width11ocl_image2d(%opencl.image2d_t addrspace(1)* %6) #2 + %mul = mul nsw i32 %5, %call4 + %7 = load i32* %tid_x, align 4 + %add = add nsw i32 %mul, %7 + %8 = load <4 x float> addrspace(1)** %results.addr, align 4 + %arrayidx = getelementptr inbounds <4 x float> addrspace(1)* %8, i32 %add + store <4 x float> %call3, <4 x float> addrspace(1)* %arrayidx, align 16 + ret void +} + +; Function Attrs: nounwind readnone +declare spir_func i32 @_Z13get_global_idj(i32) #1 + +; Function Attrs: nounwind readnone +declare spir_func <4 x float> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(%opencl.image2d_t addrspace(1)*, i32, <2 x i32>) #1 + +; Function Attrs: nounwind readnone +declare spir_func i32 @_Z15get_image_width11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1 + +attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind readnone } + +!opencl.kernels = !{!0} +!opencl.enable.FP_CONTRACT = !{} +!opencl.spir.version = !{!6} +!opencl.ocl.version = !{!6} +!opencl.used.extensions = !{!7} +!opencl.used.optional.core.features = !{!8} +!opencl.compiler.options = !{!7} + +!0 = !{void (%opencl.image2d_t addrspace(1)*, i32, <4 x float> addrspace(1)*)* @test_fn, !1, !2, !3, !4, !5} +!1 = !{!"kernel_arg_addr_space", i32 1, i32 0, i32 1} +!2 = !{!"kernel_arg_access_qual", !"read_only", !"none", !"none"} +!3 = !{!"kernel_arg_type", !"image2d_t", !"sampler_t", !"float4*"} +!4 = !{!"kernel_arg_base_type", !"image2d_t", !"sampler_t", !"float4*"} +!5 = !{!"kernel_arg_type_qual", !"", !"", !""} +!6 = !{i32 1, i32 2} +!7 = !{} +!8 = !{!"cl_images"} diff --git a/test/store.ll b/test/store.ll index 3c4b328..7da3cc4 100644 --- a/test/store.ll +++ b/test/store.ll @@ -8,8 +8,10 @@ target triple = "spir-unknown-unknown" define spir_kernel void @foo(i32 addrspace(1)* %a) #0 { entry: %a.addr = alloca i32 addrspace(1)*, align 4 -; CHECK: 5 Store {{[0-9]+}} {{[0-9]+}} 2 4 store i32 addrspace(1)* %a, i32 addrspace(1)** %a.addr, align 4 + %0 = load i32 addrspace(1)** %a.addr, align 4 +; CHECK: 5 Store {{[0-9]+}} {{[0-9]+}} 2 4 + store i32 0, i32 addrspace(1)* %0, align 4 ret void } diff --git a/tools/llvm-spirv/CMakeLists.txt b/tools/llvm-spirv/CMakeLists.txt index eec7607..d868689 100644 --- a/tools/llvm-spirv/CMakeLists.txt +++ b/tools/llvm-spirv/CMakeLists.txt @@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS SPIRVLib
Core
Support
+ TransformUtils )
add_llvm_tool(llvm-spirv
|