This adds a legalization pass to convert zero size arrays to legal types for common cases. It doesn't handle all cases, but if we see real use cases for other cases, we can add them in the future. For globals, and their initializers, we generally replace `[0 x T]` with `ptr`. For instructions, we either replace `[0 x T]` with `poision`, for `alloca` we just allocate `T`. This is motivated by IR generated by the OpenMP front end. Issue: https://github.com/llvm/llvm-project/issues/170150 --------- Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
24 lines
794 B
LLVM
24 lines
794 B
LLVM
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute < %s | FileCheck %s
|
|
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
|
|
|
|
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown < %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
|
|
|
|
; For compute, nothing is generated, but compilation doesn't crash.
|
|
; CHECK: OpName %[[#FOO:]] "foo"
|
|
; CHECK: %[[#FOO]] = OpFunction
|
|
; CHECK-NEXT: = OpLabel
|
|
; CHECK-NEXT: OpReturn
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
|
|
|
|
; For non-compute, error.
|
|
; CHECK-ERR: LLVM ERROR: Runtime arrays are not allowed in non-shader SPIR-V modules
|
|
|
|
%struct.with_zero = type { i32, [0 x i32], i64 }
|
|
|
|
define spir_func void @foo() {
|
|
entry:
|
|
%i = alloca %struct.with_zero, align 64
|
|
ret void
|
|
}
|