
This PR is to thoroughly rework duplicate tracker implementation and tracking of IR entities and types. These are legacy parts of the project resulting in an extremely bloated intermediate representation and computational delays due to inefficient data flow and structure choices. Main results of the rework: 1) Improved compile-time performance. The reference binary LLVM IR used to measure speed gains in https://github.com/llvm/llvm-project/pull/120415 shows ~x5 speed up also after this PR. The timing before this PR is ~42s and after this PR it's ~7.5s. In total this PR and the previous overhaul of the module analysis in https://github.com/llvm/llvm-project/pull/120415 results in ~x25 speed improvement. ``` $ time llc -O0 -mtriple=spirv64v1.6-unknown-unknown _group_barrier_phi.bc -o 1 --filetype=obj real 0m7.545s user 0m6.685s sys 0m0.859s ``` 2) Less bloated intermediate representation of internal translation steps. Elimination of `spv_track_constant` intrinsic usage for scalar constants, rework of `spv_assign_name`, removal of the gMIR `GET_XXX` pseudo code and a smaller number of generated `ASSIGN_TYPE` pseudo codes substantially decrease volume of data generated during translation. 3) Simpler code and easier maintenance. The duplicate tracker implementation is simplified, as well as other features. 4) Numerous fixes of issues and logical flaws in different passes. The main achievement is rework of the duplicate tracker itself that had never guaranteed a correct caching of LLVM IR entities, rarely and randomly returning stale/incorrect records (like, remove an instruction from gMIR but still refer to it). Other fixes comprise consistent generation of OpConstantNull, assigning types to newly created registers, creation of integer/bool types, and other minor fixes. 5) Numerous fixes of LIT tests: mainly CHECK-DAG to properly reflect SPIR-V spec guarantees, `{{$}}` at the end of constants to avoid matching of substrings, and XFAILS for `SPV_INTEL_long_composites` test cases, because the feature is not completed in full yet and doesn't generate a requested by the extension sequence of instructions. 6) New test cases are added.
82 lines
3.8 KiB
LLVM
82 lines
3.8 KiB
LLVM
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
|
|
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
|
|
|
|
;; This test checks that the backend is capable to correctly translate
|
|
;; barrier OpenCL C 1.2 built-in function [1] into corresponding SPIR-V
|
|
;; instruction.
|
|
|
|
;; FIXME: Strictly speaking, this flag is not supported by barrier in OpenCL 1.2
|
|
;; #define CLK_IMAGE_MEM_FENCE 0x04
|
|
;;
|
|
;; void __attribute__((overloadable)) __attribute__((convergent)) barrier(cl_mem_fence_flags);
|
|
;;
|
|
;; __kernel void test_barrier_const_flags() {
|
|
;; barrier(CLK_LOCAL_MEM_FENCE);
|
|
;; barrier(CLK_GLOBAL_MEM_FENCE);
|
|
;; barrier(CLK_IMAGE_MEM_FENCE);
|
|
;;
|
|
;; barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
|
|
;; barrier(CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
|
|
;; barrier(CLK_GLOBAL_MEM_FENCE | CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
|
|
;; }
|
|
;;
|
|
;; __kernel void test_barrier_non_const_flags(cl_mem_fence_flags flags) {
|
|
;; FIXME: OpenCL spec doesn't require flags to be compile-time known
|
|
;; barrier(flags);
|
|
;; }
|
|
|
|
; CHECK-SPIRV-DAG: OpName %[[#TEST_CONST_FLAGS:]] "test_barrier_const_flags"
|
|
; CHECK-SPIRV-DAG: %[[#UINT:]] = OpTypeInt 32 0
|
|
|
|
;; In SPIR-V, barrier is represented as OpControlBarrier [3] and OpenCL
|
|
;; cl_mem_fence_flags are represented as part of Memory Semantics [2], which
|
|
;; also includes memory order constraints. The backend applies some default
|
|
;; memory order for OpControlBarrier and therefore, constants below include a
|
|
;; bit more information than original source
|
|
|
|
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory
|
|
; CHECK-SPIRV-DAG: %[[#LOCAL:]] = OpConstant %[[#UINT]] 272{{$}}
|
|
;; 0x2 Workgroup
|
|
; CHECK-SPIRV-DAG: %[[#WG:]] = OpConstant %[[#UINT]] 2{{$}}
|
|
;; 0x10 SequentiallyConsistent + 0x200 CrossWorkgroupMemory
|
|
; CHECK-SPIRV-DAG: %[[#GLOBAL:]] = OpConstant %[[#UINT]] 528{{$}}
|
|
;; 0x10 SequentiallyConsistent + 0x800 ImageMemory
|
|
; CHECK-SPIRV-DAG: %[[#IMAGE:]] = OpConstant %[[#UINT]] 2064{{$}}
|
|
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory
|
|
; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL:]] = OpConstant %[[#UINT]] 784{{$}}
|
|
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x800 ImageMemory
|
|
; CHECK-SPIRV-DAG: %[[#LOCAL_IMAGE:]] = OpConstant %[[#UINT]] 2320{{$}}
|
|
;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory + 0x800 ImageMemory
|
|
; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL_IMAGE:]] = OpConstant %[[#UINT]] 2832{{$}}
|
|
|
|
; CHECK-SPIRV: %[[#TEST_CONST_FLAGS]] = OpFunction %[[#]]
|
|
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL]]
|
|
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#GLOBAL]]
|
|
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#IMAGE]]
|
|
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_GLOBAL]]
|
|
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_IMAGE]]
|
|
; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_GLOBAL_IMAGE]]
|
|
|
|
define dso_local spir_kernel void @test_barrier_const_flags() local_unnamed_addr {
|
|
entry:
|
|
tail call spir_func void @_Z7barrierj(i32 noundef 1)
|
|
tail call spir_func void @_Z7barrierj(i32 noundef 2)
|
|
tail call spir_func void @_Z7barrierj(i32 noundef 4)
|
|
tail call spir_func void @_Z7barrierj(i32 noundef 3)
|
|
tail call spir_func void @_Z7barrierj(i32 noundef 5)
|
|
tail call spir_func void @_Z7barrierj(i32 noundef 7)
|
|
ret void
|
|
}
|
|
|
|
declare spir_func void @_Z7barrierj(i32 noundef) local_unnamed_addr
|
|
|
|
define dso_local spir_kernel void @test_barrier_non_const_flags(i32 noundef %flags) local_unnamed_addr {
|
|
entry:
|
|
ret void
|
|
}
|
|
|
|
;; References:
|
|
;; [1]: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
|
|
;; [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_memory_semantics__id_a_memory_semantics_lt_id_gt
|
|
;; [3]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpControlBarrier
|