Skip to content

Commit ca34f97

Browse files
committed
Merge from 'sycl' to 'sycl-web' (#1)
Ignored the revert 1a8a660 (cherry-pick of 0c28a7c). It was done for sycl-web => sycl pulldown. The revert has already happened once in sycl-web (as 0c28a7c), followed by a re-commit 4c4093e. The conflict was because 1a8a660 was trying to apply on top of the re-commit 4c4093e. CONFLICT (modify/delete): llvm/test/Transforms/InstCombine/fpclass.ll deleted in 9f41bf6 and modified in HEAD. Version HEAD of llvm/test/Transforms/InstCombine/fpclass.ll left in tree. CONFLICT (modify/delete): llvm/test/CodeGen/PowerPC/ppc-fpclass.ll deleted in 9f41bf6 and modified in HEAD. Version HEAD of llvm/test/CodeGen/PowerPC/ppc-fpclass.ll left in tree. CONFLICT (content): Merge conflict in llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp CONFLICT (content): Merge conflict in llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
2 parents b4e8fee + 9f41bf6 commit ca34f97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+774
-2887
lines changed

clang/test/Driver/sycl-offload-intelfpga.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
/// -fintelfpga implies -g and -MMD
1414
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -Xshardware %s 2>&1 \
1515
// RUN: | FileCheck -check-prefix=CHK-TOOLS-INTELFPGA %s
16-
// CHK-TOOLS-INTELFPGA: clang{{.*}} "-debug-info-kind=limited" {{.*}} "-dependency-file"
16+
// CHK-TOOLS-INTELFPGA: clang{{.*}} "-debug-info-kind=constructor" {{.*}} "-dependency-file"
1717
// CHK-TOOLS-INTELFPGA: aoc{{.*}} "-dep-files={{.*}}"
1818

1919
/// -fintelfpga implies -g but -g0 should override
2020
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -g0 -fsycl -fintelfpga %s 2>&1 \
2121
// RUN: | FileCheck -check-prefix=CHK-TOOLS-INTELFPGA-G0 %s
22-
// CHK-TOOLS-INTELFPGA-G0-NOT: clang{{.*}} "-debug-info-kind=limited"
22+
// CHK-TOOLS-INTELFPGA-G0-NOT: clang{{.*}} "-debug-info-kind=constructor"
2323

2424
/// FPGA target implies -fsycl-disable-range-rounding
2525
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %s 2>&1 \

clang/test/Driver/sycl-offload-nvptx.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// CHK-ACTIONS: "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}} "-fsycl-is-device"{{.*}} "-Wno-sycl-strict"{{.*}} "-sycl-std=2020" {{.*}} "-emit-llvm-bc" {{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libspirv.bc"{{.*}} "-mlink-builtin-bitcode" "{{.*}}libdevice{{.*}}.10.bc"{{.*}} "-target-feature" "+ptx42"{{.*}} "-target-sdk-version=[[CUDA_VERSION:[0-9.]+]]"{{.*}} "-target-cpu" "sm_50"{{.*}} "-std=c++11"{{.*}}
1313
// CHK-ACTIONS: sycl-post-link{{.*}} "-split=auto"
1414
// CHK-ACTIONS: file-table-tform" "-extract=Code" "-drop_titles"
15-
// CHK-ACTIONS: llvm-foreach" {{.*}} "--" "{{.*}}clang-13"
15+
// CHK-ACTIONS: llvm-foreach" {{.*}} "--" "{{.*}}clang-{{[0-9]+}}"
1616
// CHK-ACTIONS: llvm-foreach" {{.*}} "--" "{{.*}}ptxas"
1717
// CHK-ACTIONS: llvm-foreach" {{.*}} "--" "{{.*}}fatbinary"
1818
// CHK-ACTIONS: file-table-tform" "-replace=Code,Code"

llvm-spirv/.github/workflows/check-code-style.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ env:
2424
# We need compile command database in order to perform clang-tidy check. So,
2525
# in order to perform configure step we need to setup llvm-dev package. This
2626
# env variable used to specify desired version of it
27-
LLVM_VERSION: 13
27+
LLVM_VERSION: 14
2828

2929
jobs:
3030
clang-format-and-tidy:

llvm-spirv/.github/workflows/check-in-tree-build.yml

+31-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ on:
3232
- cron: 0 0 * * *
3333

3434
env:
35-
LLVM_VERSION: 13
35+
LLVM_VERSION: 14
3636

3737
jobs:
3838
build_and_test_linux:
@@ -70,6 +70,16 @@ jobs:
7070
uses: actions/checkout@v2
7171
with:
7272
path: llvm-project/llvm/projects/SPIRV-LLVM-Translator
73+
- name: Get tag for SPIR-V Headers
74+
id: spirv-headers-tag
75+
run: |
76+
echo "spirv_headers_tag=$(cat llvm-project/llvm/projects/SPIRV-LLVM-Translator/spirv-headers-tag.conf)" >> $GITHUB_ENV
77+
- name: Checkout SPIR-V Headers
78+
uses: actions/checkout@v2
79+
with:
80+
repository: KhronosGroup/SPIRV-Headers
81+
ref: ${{ env.spirv_headers_tag }}
82+
path: llvm-project/llvm/projects/SPIRV-Headers
7383
- name: Configure
7484
run: |
7585
mkdir build && cd build
@@ -115,6 +125,16 @@ jobs:
115125
uses: actions/checkout@v2
116126
with:
117127
path: llvm-project\\llvm\\projects\\SPIRV-LLVM-Translator
128+
- name: Get tag for SPIR-V Headers
129+
id: spirv-headers-tag
130+
run: |
131+
echo "spirv_headers_tag=$(type llvm-project\\llvm\\projects\\SPIRV-LLVM-Translator\\spirv-headers-tag.conf)" >> $GITHUB_ENV
132+
- name: Checkout SPIR-V Headers
133+
uses: actions/checkout@v2
134+
with:
135+
repository: KhronosGroup/SPIRV-Headers
136+
ref: ${{ env.spirv_headers_tag }}
137+
path: llvm-project\\llvm\\projects\\SPIRV-Headers
118138
- name: Configure
119139
shell: bash
120140
run: |
@@ -157,6 +177,16 @@ jobs:
157177
uses: actions/checkout@v2
158178
with:
159179
path: llvm-project/llvm/projects/SPIRV-LLVM-Translator
180+
- name: Get tag for SPIR-V Headers
181+
id: spirv-headers-tag
182+
run: |
183+
echo "spirv_headers_tag=$(cat llvm-project/llvm/projects/SPIRV-LLVM-Translator/spirv-headers-tag.conf)" >> $GITHUB_ENV
184+
- name: Checkout SPIR-V Headers
185+
uses: actions/checkout@v2
186+
with:
187+
repository: KhronosGroup/SPIRV-Headers
188+
ref: ${{ env.spirv_headers_tag }}
189+
path: llvm-project/llvm/projects/SPIRV-Headers
160190
- name: Configure
161191
run: |
162192
mkdir build && cd build

llvm-spirv/.github/workflows/check-out-of-tree-build.yml

+16-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ on:
2929
- cron: 0 0 * * *
3030

3131
env:
32-
LLVM_VERSION: 13
32+
LLVM_VERSION: 14
3333

3434
jobs:
3535
build_and_test:
@@ -58,14 +58,28 @@ jobs:
5858
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${{ env.LLVM_VERSION }} 1000
5959
- name: Checkout the translator sources
6060
uses: actions/checkout@v2
61+
with:
62+
path: SPIRV-LLVM-Translator
63+
- name: Get tag for SPIR-V Headers
64+
id: spirv-headers-tag
65+
run: |
66+
echo "spirv_headers_tag=$(cat SPIRV-LLVM-Translator/spirv-headers-tag.conf)" >> $GITHUB_ENV
67+
- name: Checkout SPIR-V Headers
68+
uses: actions/checkout@v2
69+
with:
70+
repository: KhronosGroup/SPIRV-Headers
71+
ref: ${{ env.spirv_headers_tag }}
72+
path: SPIRV-Headers
6173
- name: Configure
6274
run: |
6375
mkdir build && cd build
64-
cmake ${{ github.workspace }} \
76+
cmake ${{ github.workspace }}/SPIRV-LLVM-Translator \
6577
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
6678
-DCMAKE_CXX_FLAGS="-Werror" \
6779
-DLLVM_INCLUDE_TESTS=ON \
6880
-DLLVM_EXTERNAL_LIT="/usr/lib/llvm-${{ env.LLVM_VERSION }}/build/utils/lit/lit.py" \
81+
-DLLVM_EXTERNAL_PROJECTS="SPIRV-Headers" \
82+
-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=${{ github.workspace }}/SPIRV-Headers \
6983
-G "Unix Makefiles"
7084
- name: Build
7185
run: |

llvm-spirv/.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ compiler:
4242
env:
4343
global:
4444
- MAKEFLAGS="-j2"
45-
- LLVM_VERSION=13
45+
- LLVM_VERSION=14
4646
matrix:
4747
- BUILD_TYPE=Release BUILD_EXTERNAL=1 SHARED_LIBS=ON MAKE_TARGETS="" MAKE_TEST_TARGET="test"
4848
- BUILD_TYPE=Debug BUILD_EXTERNAL=1 SHARED_LIBS=ON MAKE_TARGETS="" MAKE_TEST_TARGET="test"

llvm-spirv/CMakeLists.txt

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
cmake_minimum_required(VERSION 3.3)
1+
cmake_minimum_required(VERSION 3.13.4)
22

3-
set (BASE_LLVM_VERSION 13.0.0)
3+
set (BASE_LLVM_VERSION 14.0.0)
44
set(LLVM_SPIRV_VERSION ${BASE_LLVM_VERSION}.0)
55

6+
include(FetchContent)
7+
68
option(LLVM_SPIRV_INCLUDE_TESTS
79
"Generate build targets for the llvm-spirv lit tests."
810
${LLVM_INCLUDE_TESTS})
@@ -14,6 +16,42 @@ if (NOT DEFINED LLVM_SPIRV_BUILD_EXTERNAL)
1416
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1517
endif (NOT DEFINED LLVM_SPIRV_BUILD_EXTERNAL)
1618

19+
# Download spirv.hpp from the official SPIRV-Headers repository.
20+
# One can skip this step by manually setting
21+
# LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR path.
22+
if(NOT DEFINED LLVM_TOOL_SPIRV_HEADERS_BUILD AND
23+
NOT DEFINED LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR)
24+
set(LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR
25+
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Headers")
26+
message(STATUS "SPIR-V Headers location is not specified. Will try to download
27+
spirv.hpp from https://github.com/KhronosGroup/SPIRV-Headers into
28+
${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}")
29+
file(READ spirv-headers-tag.conf SPIRV_HEADERS_TAG)
30+
# Strip the potential trailing newline from tag
31+
string(STRIP "${SPIRV_HEADERS_TAG}" SPIRV_HEADERS_TAG)
32+
FetchContent_Declare(spirv-headers
33+
GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Headers.git
34+
GIT_TAG ${SPIRV_HEADERS_TAG}
35+
SOURCE_DIR ${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}
36+
)
37+
FetchContent_MakeAvailable(spirv-headers)
38+
else()
39+
if(NOT DEFINED LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR)
40+
# This means LLVM_TOOL_SPIRV_HEADERS_BUILD is defined, therefore
41+
# SPIRV-Headers exist as a subproject.
42+
set(LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR
43+
"${CMAKE_SOURCE_DIR}/projects/SPIRV-Headers")
44+
if(NOT EXISTS ${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR})
45+
message(FATAL_ERROR "No location specified for SPIRV-Headers.
46+
Try setting the LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR
47+
path or put the project into the llvm/projects folder
48+
under the name 'SPIRV-Headers'")
49+
endif()
50+
endif()
51+
message(STATUS "Using SPIR-V Headers from
52+
${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}")
53+
endif()
54+
1755
if(LLVM_SPIRV_BUILD_EXTERNAL)
1856
project(LLVM_SPIRV
1957
VERSION

llvm-spirv/CONTRIBUTING.md

+28
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ Coding Standards]. Compliance of your code is checked automatically using
3636
Travis CI. See [clang-format] and [clang-tidy] configs for more details about
3737
coding standards.
3838

39+
## How to add an extension
40+
41+
First of all please make sure you have added a link to the
42+
specification for the extension in your PR. Then to add definitions of
43+
new Op Codes you shall modify [spirv.hpp], which is an external
44+
dependency for this project. To do so, you should add new definitions
45+
to [json grammar file], rebuild the header following the
46+
[instructions] in [SPIR-V Headers repository] and push your changes
47+
for review, i.e. make a PR. Once the PR is merged, a new spirv.hpp
48+
will have to be downloaded during build of the translator; make sure
49+
to update the hash for SPIRV-Headers in [spirv-headers-tag.conf]
50+
so that tokens from your extension can be visible to the translator
51+
build.
52+
53+
It's highly recommended to add the definitions to [SPIR-V Headers repository]
54+
first, but if you don't want to bring it there yet, you can define new Op Codes
55+
in the [internal SPIR-V header file].
56+
57+
For local testing you can copy your spirv.hpp variant to
58+
`<PATH_TO_SPIRV_HEADERS>/include/spirv/unified1` and/or modify it
59+
there. See [README.md](README.md#configuring-spir-v-headers) for build
60+
instructions that should be employed with such modifications.
61+
3962
### Conditions to merge a PR
4063

4164
In order to get your PR merged, the following conditions must be met:
@@ -79,5 +102,10 @@ it can be merged:
79102
[LLVM Coding Standards]: https://llvm.org/docs/CodingStandards.html
80103
[clang-format]: [.clang-format]
81104
[clang-tidy]: [.clang-tidy]
105+
[spirv.hpp]: https://github.com/KhronosGroup/SPIRV-Headers/blob/master/include/spirv/unified1/spirv.hpp
106+
[json grammar file]: https://github.com/KhronosGroup/SPIRV-Headers/blob/master/include/spirv/unified1/spirv.core.grammar.json
107+
[instructions]: https://github.com/KhronosGroup/SPIRV-Headers#generating-headers-from-the-json-grammar-for-the-spir-v-core-instruction-set
108+
[SPIR-V Headers repository]: https://github.com/KhronosGroup/SPIRV-Headers
109+
[internal SPIR-V header file]: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/master/lib/SPIRV/libSPIRV/spirv_internal.hpp
82110
[Contributor License Agreement]: https://cla-assistant.io/KhronosGroup/SPIRV-LLVM-Translator
83111
[Travis CI testing]: https://travis-ci.org/KhronosGroup/SPIRV-LLVM-Translator

llvm-spirv/README.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The translator can be built with the latest(nightly) package of LLVM. For Ubuntu
2929
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
3030
sudo add-apt-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main"
3131
sudo apt-get update
32-
sudo apt-get install llvm-13-dev llvm-13-tools clang-13 libclang-13-dev
32+
sudo apt-get install llvm-14-dev llvm-14-tools clang-14 libclang-14-dev
3333
```
3434
The installed version of LLVM will be used by default for out-of-tree build of the translator.
3535
```
@@ -93,6 +93,26 @@ Building clang from sources takes time and resources and it can be avoided:
9393
moment, see [KhronosGroup/SPIRV-LLVM-Translator#477](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/477)
9494
to track progress, discuss and contribute.
9595

96+
## Configuring SPIR-V Headers
97+
98+
The translator build is dependent on the official Khronos header file
99+
`spirv.hpp` that maps SPIR-V extensions, decorations, instructions,
100+
etc. onto numeric tokens. The official header version is available at
101+
[KhronosGroup/SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers).
102+
There are several options for accessing the header file:
103+
- By default, the header file repository will be downloaded from
104+
Khronos Group GitHub and put into `<build_dir>/SPIRV-Headers`.
105+
- If you are building the translator in-tree, you can manually
106+
download the SPIR-V Headers repo into `llvm/projects` - this
107+
location will be automatically picked up by the LLVM build
108+
scripts. Make sure the folder retains its default naming in
109+
that of `SPIRV-Headers`.
110+
- Any build type can also use an external installation of SPIR-V
111+
Headers - if you have the headers downloaded somewhere in your
112+
system and want to use that version, simply extend your CMake
113+
command with `-DLLVM_EXTERNAL_PROJECTS="SPIRV-Headers"
114+
-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=</path/to/headers_dir>`.
115+
96116
## Test instructions
97117

98118
All tests related to the translator are placed in the [test](test) directory. A number of the tests require spirv-as (part of SPIR-V Tools) to run, but the remainder of the tests can still be run without this. Optionally the tests can make use of spirv-val (part of SPIRV-Tools) in order to validate the generated SPIR-V against the official SPIR-V specification.
@@ -105,7 +125,7 @@ make test
105125
```
106126
This requires that the `-DLLVM_SPIRV_INCLUDE_TESTS=ON` argument is
107127
passed to CMake during the build step. Additionally,
108-
`-DLLVM_EXTERNAL_LIT="/usr/lib/llvm-13/build/utils/lit/lit.py"` is
128+
`-DLLVM_EXTERNAL_LIT="/usr/lib/llvm-14/build/utils/lit/lit.py"` is
109129
needed when building with a pre-installed version of LLVM.
110130

111131
The translator test suite can be disabled by passing

llvm-spirv/lib/SPIRV/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ target_include_directories(LLVMSPIRVLib
5151
PRIVATE
5252
${LLVM_INCLUDE_DIRS}
5353
${LLVM_SPIRV_INCLUDE_DIRS}
54+
# TODO: Consider using SPIRV-Headers' as a header-only INTERFACE
55+
# instead. Right now this runs into exporting issues with
56+
# the LLVM in-tree builds.
57+
${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}/include
5458
${CMAKE_CURRENT_SOURCE_DIR}
5559
${CMAKE_CURRENT_SOURCE_DIR}/libSPIRV
5660
${CMAKE_CURRENT_SOURCE_DIR}/Mangler

llvm-spirv/lib/SPIRV/OCLToSPIRV.cpp

+6-60
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ class OCLToSPIRVBase : public InstVisitor<OCLToSPIRVBase> {
108108
/// Transform OCL builtin function to SPIR-V builtin function.
109109
void transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info);
110110

111-
/// Transform OCL work item builtin functions to SPIR-V builtin variables.
112-
void transWorkItemBuiltinsToVariables();
113-
114111
/// Transform atomic_work_item_fence/mem_fence to __spirv_MemoryBarrier.
115112
/// func(flag, order, scope) =>
116113
/// __spirv_MemoryBarrier(map(scope), map(flag)|map(order))
@@ -367,8 +364,6 @@ bool OCLToSPIRVBase::runOCLToSPIRV(Module &Module) {
367364

368365
LLVM_DEBUG(dbgs() << "Enter OCLToSPIRV:\n");
369366

370-
transWorkItemBuiltinsToVariables();
371-
372367
visit(*M);
373368

374369
for (auto &I : ValuesToDelete)
@@ -1061,6 +1056,7 @@ void OCLToSPIRVBase::transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
10611056
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
10621057
Op OC = OpNop;
10631058
unsigned ExtOp = ~0U;
1059+
SPIRVBuiltinVariableKind BVKind = BuiltInMax;
10641060
if (StringRef(Info.UniqName).startswith(kSPIRVName::Prefix))
10651061
return;
10661062
if (OCLSPIRVBuiltinMap::find(Info.UniqName, &OC)) {
@@ -1081,7 +1077,11 @@ void OCLToSPIRVBase::transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
10811077
}
10821078
} else if ((ExtOp = getExtOp(Info.MangledName, Info.UniqName)) != ~0U)
10831079
Info.UniqName = getSPIRVExtFuncName(SPIRVEIS_OpenCL, ExtOp);
1084-
else
1080+
else if (SPIRSPIRVBuiltinVariableMap::find(Info.UniqName, &BVKind)) {
1081+
// Map OCL work item builtins to SPV-IR work item builtins.
1082+
// e.g. get_global_id() --> __spirv_BuiltinGlobalInvocationId()
1083+
Info.UniqName = getSPIRVFuncName(BVKind);
1084+
} else
10851085
return;
10861086
if (!Info.RetTy)
10871087
mutateCallInstSPIRV(
@@ -1273,60 +1273,6 @@ void OCLToSPIRVBase::visitCallBuiltinSimple(CallInst *CI, StringRef MangledName,
12731273
transBuiltin(CI, Info);
12741274
}
12751275

1276-
/// Translates OCL work-item builtin functions to SPIRV builtin variables.
1277-
/// Function like get_global_id(i) -> x = load GlobalInvocationId; extract x, i
1278-
/// Function like get_work_dim() -> load WorkDim
1279-
void OCLToSPIRVBase::transWorkItemBuiltinsToVariables() {
1280-
LLVM_DEBUG(dbgs() << "Enter transWorkItemBuiltinsToVariables\n");
1281-
std::vector<Function *> WorkList;
1282-
for (auto &I : *M) {
1283-
StringRef DemangledName;
1284-
if (!oclIsBuiltin(I.getName(), DemangledName))
1285-
continue;
1286-
LLVM_DEBUG(dbgs() << "Function demangled name: " << DemangledName << '\n');
1287-
std::string BuiltinVarName;
1288-
SPIRVBuiltinVariableKind BVKind;
1289-
if (!SPIRSPIRVBuiltinVariableMap::find(DemangledName.str(), &BVKind))
1290-
continue;
1291-
BuiltinVarName =
1292-
std::string(kSPIRVName::Prefix) + SPIRVBuiltInNameMap::map(BVKind);
1293-
LLVM_DEBUG(dbgs() << "builtin variable name: " << BuiltinVarName << '\n');
1294-
bool IsVec = I.getFunctionType()->getNumParams() > 0;
1295-
Type *GVType =
1296-
IsVec ? FixedVectorType::get(I.getReturnType(), 3) : I.getReturnType();
1297-
auto BV = new GlobalVariable(*M, GVType, true, GlobalValue::ExternalLinkage,
1298-
nullptr, BuiltinVarName, 0,
1299-
GlobalVariable::NotThreadLocal, SPIRAS_Input);
1300-
std::vector<Instruction *> InstList;
1301-
for (auto UI = I.user_begin(), UE = I.user_end(); UI != UE; ++UI) {
1302-
auto CI = dyn_cast<CallInst>(*UI);
1303-
assert(CI && "invalid instruction");
1304-
const DebugLoc &DLoc = CI->getDebugLoc();
1305-
Instruction *NewValue = new LoadInst(GVType, BV, "", CI);
1306-
if (DLoc)
1307-
NewValue->setDebugLoc(DLoc);
1308-
LLVM_DEBUG(dbgs() << "Transform: " << *CI << " => " << *NewValue << '\n');
1309-
if (IsVec) {
1310-
NewValue =
1311-
ExtractElementInst::Create(NewValue, CI->getArgOperand(0), "", CI);
1312-
if (DLoc)
1313-
NewValue->setDebugLoc(DLoc);
1314-
LLVM_DEBUG(dbgs() << *NewValue << '\n');
1315-
}
1316-
NewValue->takeName(CI);
1317-
CI->replaceAllUsesWith(NewValue);
1318-
InstList.push_back(CI);
1319-
}
1320-
for (auto &Inst : InstList) {
1321-
Inst->eraseFromParent();
1322-
}
1323-
WorkList.push_back(&I);
1324-
}
1325-
for (auto &I : WorkList) {
1326-
I->eraseFromParent();
1327-
}
1328-
}
1329-
13301276
void OCLToSPIRVBase::visitCallReadWriteImage(CallInst *CI,
13311277
StringRef DemangledName) {
13321278
OCLBuiltinTransInfo Info;

0 commit comments

Comments
 (0)