-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spirv-ll] Attach names to values more often
We weren't doing a very thorough job at making use of OpNames when translating SPIR-V to LLVM IR. This is obviously fine as the names are purely decorative. However, they do have a use in making the translated LLVM IR easier to intuit. This is primarily because we were manually attaching names to the LLVM IR instructions (or blocks, functions, etc.) when creating them. If we forgot to do that, the names would be forgotten. Instead, if we attach names centrally, we can achieve a far higher coverage. We choose to do this in addID which is in practice called during the translation of almost every SPIR-V opcode. The name is only attached if one hasn't been given already. This means that, while by default the name will be attached to the "last" instruction in the translated sequence, this can be overridden if desired. That said, since names are decorative, this isn't hugely important and it's not often we translate opcodes using multiple instructions. We can fix up any specific cases later if they're particularly egregious. This gives us the opportunity to more cleanly prioritze the names of entry points over 'regular' functions. Previously we were doing this in a more convoluted two-step process. We can instead do it on the fly. This also fixes a bug where we could accidentally pick up GLSL functions called 'printf' as the C-style printf, and incorrectly make it variadic. A test has been added to cover it.
- Loading branch information
1 parent
5f7fb86
commit c2ab625
Showing
15 changed files
with
190 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) Codeplay Software Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
// Exceptions; you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
// RUN: %if online-glsl %{ glslangValidator -s -V -o %spv_file_s %s %} | ||
// RUN: %if online-glsl %{ spirv-val %spv_file_s %} | ||
// RUN: spirv-ll-tool -a Vulkan %spv_file_s | FileCheck %s | ||
|
||
#version 450 | ||
|
||
// Check that we don't pick up either of these functions called printf as "the" | ||
// printf, and give it the signature of printf (e.g., variadic). | ||
|
||
// CHECK: define private spir_func void @"printf("() {{(#0 )?}}{ | ||
void printf() { | ||
return; | ||
} | ||
|
||
// CHECK: define private spir_func void @"printf(u1;"(ptr %id) {{(#0 )?}}{ | ||
void printf(uint id) { | ||
return; | ||
} | ||
|
||
void main() { | ||
printf(); | ||
printf(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
modules/compiler/spirv-ll/test/spvasm/op_phi_forward_ref.spvasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
; Copyright (C) Codeplay Software Limited | ||
; | ||
; Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
; Exceptions; you may not use this file except in compliance with the License. | ||
; You may obtain a copy of the License at | ||
; | ||
; https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
; | ||
; Unless required by applicable law or agreed to in writing, software | ||
; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
; License for the specific language governing permissions and limitations | ||
; under the License. | ||
; | ||
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
; RUN: %if online-spirv-as %{ spirv-as --target-env %spv_tgt_env -o %spv_file_s %s %} | ||
; RUN: %if online-spirv-as %{ spirv-val %spv_file_s %} | ||
; RUN: spirv-ll-tool -a OpenCL -b 64 %spv_file_s | FileCheck %s | ||
|
||
OpCapability Addresses | ||
OpCapability Kernel | ||
OpCapability Int8 | ||
OpMemoryModel Physical64 OpenCL | ||
OpEntryPoint Kernel %testfn "testfn" | ||
|
||
OpName %entry "entry" | ||
OpName %for_cond "for.cond" | ||
OpName %for_body "for.body" | ||
OpName %exit_label "exit" | ||
|
||
OpName %input "input" | ||
OpName %output "output" | ||
OpName %add "add0" | ||
OpName %and26 "and26" | ||
OpName %shl10 "mask_next" | ||
OpName %mul1 "mul1" | ||
OpName %res "res" | ||
OpName %mask "mask" | ||
OpName %cmp0 "cmp0" | ||
OpName %cmp1 "cmp1" | ||
OpName %frombool "sel" | ||
OpName %52 "load" | ||
|
||
OpDecorate %output Alignment 1 | ||
%uint = OpTypeInt 32 0 | ||
%uchar = OpTypeInt 8 0 | ||
%uint_0 = OpConstant %uint 0 | ||
%uint_1 = OpConstant %uint 1 | ||
%uchar_0 = OpConstant %uchar 0 | ||
%uchar_1 = OpConstant %uchar 1 | ||
%void = OpTypeVoid | ||
%bool = OpTypeBool | ||
%ptr_uchar = OpTypePointer CrossWorkgroup %uchar | ||
%ptr_uint = OpTypePointer CrossWorkgroup %uint | ||
%fn_ty = OpTypeFunction %void %ptr_uchar %ptr_uint | ||
%true = OpConstantTrue %bool | ||
|
||
; CHECK: define spir_kernel void @testfn(ptr addrspace(1) %output, ptr addrspace(1) %input) | ||
%testfn = OpFunction %void None %fn_ty | ||
%output = OpFunctionParameter %ptr_uchar | ||
%input = OpFunctionParameter %ptr_uint | ||
|
||
; CHECK-LABEL: entry: | ||
; CHECK: %load = load i32, ptr addrspace(1) %input, align 4 | ||
; CHECK: %add0 = add i32 %load, 1 | ||
; CHECK: br label %for.cond | ||
%entry = OpLabel | ||
%52 = OpLoad %uint %input Aligned 4 | ||
%add = OpIAdd %uint %52 %uint_1 | ||
OpBranch %for_cond | ||
|
||
; CHECK-LABEL: for.cond: | ||
; CHECK: %res = phi i1 [ true, %entry ], [ %and26, %for.body ] | ||
; CHECK: %mask = phi i32 [ 1, %entry ], [ %mask_next, %for.body ] | ||
; CHECK: %cmp0 = icmp eq i32 %mask, 0 | ||
; CHECK: br i1 %cmp0, label %exit, label %for.body | ||
%for_cond = OpLabel | ||
%res = OpPhi %bool %true %entry %and26 %for_body | ||
%mask = OpPhi %uint %uint_1 %entry %shl10 %for_body | ||
%cmp0 = OpIEqual %bool %mask %uint_0 | ||
OpBranchConditional %cmp0 %exit_label %for_body | ||
|
||
; CHECK-LABEL: for.body: | ||
; CHECK: %mul1 = mul i32 %add0, %mask | ||
; CHECK: %cmp1 = icmp eq i32 %mul1, %add0 | ||
; CHECK: %and26 = and i1 %res, %cmp1 | ||
; CHECK: %mask_next = shl i32 %mask, 1 | ||
; CHECK: br label %for.cond | ||
%for_body = OpLabel | ||
%mul1 = OpIMul %uint %add %mask | ||
%cmp1 = OpIEqual %bool %mul1 %add | ||
%and26 = OpLogicalAnd %bool %res %cmp1 | ||
%shl10 = OpShiftLeftLogical %uint %mask %uint_1 | ||
OpBranch %for_cond | ||
|
||
; CHECK-LABEL: exit: | ||
; CHECK: %sel = select i1 %res, i8 1, i8 0 | ||
; CHECK: store i8 %sel, ptr addrspace(1) %output, align 1 | ||
; CHECK: ret void | ||
%exit_label = OpLabel | ||
%frombool = OpSelect %uchar %res %uchar_1 %uchar_0 | ||
OpStore %output %frombool Aligned 1 | ||
OpReturn | ||
|
||
OpFunctionEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters