Skip to content

Commit a006665

Browse files
linehillpvelesko
authored andcommitted
Make adjustments for LLVM-19
* Fixed LLVM passes for LLVM-19. * Changed chipStar configuration to prefer llvm-spirv with version suffix which matches to the chosen LLVM (e.g. `llvm-spirv-19`). * Update README and scripts/configure_llvm.sh. * New in clang-19: clang's SPIR-V and HIPSPV toolchain picks `llvm-spirv-XX` (when found in PATH or installed alongside the clang binary) where XX matches to the clang's major version. This should resolve the llvm-spirv issue reported in #824.
1 parent ab44488 commit a006665

16 files changed

+47
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ For this you can use a script included in the chipStar repository:
4545
```bash
4646
./scripts/configure_llvm.sh
4747
Usage: ./configure_llvm.sh --version <version> --install-dir <dir> --link-type static(default)/dynamic --only-necessary-spirv-exts <on|off> --binutils-header-location <path>
48-
--version: LLVM version 15, 16, 17, 18
48+
--version: LLVM version 15, 16, 17, 18, 19
4949
--install-dir: installation directory
5050
--link-type: static or dynamic (default: static)
5151
--only-necessary-spirv-exts: on or off (default: off)

cmake/FindLLVM.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ else() # if it was not defined, look for it
4141
endif()
4242
message(STATUS "Using llvm-config: ${LLVM_CONFIG_BIN}")
4343

44-
get_filename_component(LLVM_CONFIG_BINARY_NAME ${LLVM_CONFIG_BIN} NAME)
45-
get_filename_component(LLVM_CONFIG_DIR ${LLVM_CONFIG_BIN} DIRECTORY)
46-
string(REGEX MATCH "[0-9]+" LLVM_VERSION_MAJOR "${LLVM_CONFIG_BINARY_NAME}")
47-
4844
execute_process(COMMAND "${LLVM_CONFIG_BIN}" "--obj-root"
4945
RESULT_VARIABLE RES
5046
OUTPUT_VARIABLE CLANG_ROOT_PATH
@@ -57,6 +53,7 @@ execute_process(COMMAND "${LLVM_CONFIG_BIN}" "--version"
5753
OUTPUT_VARIABLE LLVM_VERSION
5854
OUTPUT_STRIP_TRAILING_WHITESPACE)
5955
message(STATUS "Using LLVM_VERSION: ${LLVM_VERSION}")
56+
string(REGEX MATCH "[0-9]+" LLVM_VERSION_MAJOR "${LLVM_VERSION}")
6057

6158
# Check if the LLVM_INCLUDE_DIR is already cached
6259
if(NOT LLVM_INCLUDE_DIRS)
@@ -105,8 +102,10 @@ if(NOT DEFINED LLVM_LINK)
105102
endif()
106103
message(STATUS "Using llvm-link: ${LLVM_LINK}")
107104

105+
message(STATUS "XXX LLVM-version-major: ${LLVM_VERSION_MAJOR}") # DEBUG
106+
108107
if(NOT DEFINED LLVM_SPIRV)
109-
find_program(LLVM_SPIRV NAMES llvm-spirv llvm-spirv-${LLVM_VERSION_MAJOR} FIND_TARGET NO_DEFAULT_PATH PATHS ${CLANG_ROOT_PATH_BIN} ENV PATH)
108+
find_program(LLVM_SPIRV NAMES llvm-spirv-${LLVM_VERSION_MAJOR} llvm-spirv FIND_TARGET NO_DEFAULT_PATH PATHS ${CLANG_ROOT_PATH_BIN} ENV PATH)
110109
if(NOT LLVM_SPIRV)
111110
message(FATAL_ERROR "Can't find llvm-spirv. Please provide CMake argument -DLLVM_SPIRV=/path/to/llvm-spirv<-version>")
112111
endif()
@@ -140,4 +139,4 @@ endif()
140139
enable_language(C CXX)
141140
# required by ROCm-Device-Libs, must be after project() call
142141
find_package(LLVM REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${CLANG_ROOT_PATH}/lib/cmake/llvm)
143-
find_package(Clang REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${CLANG_ROOT_PATH}/lib/cmake/clang)
142+
find_package(Clang REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${CLANG_ROOT_PATH}/lib/cmake/clang)

llvm_passes/HipAbort.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
#include "../src/common.hh"
5050

51+
#include "llvm/IR/Module.h"
52+
5153
#include <set>
5254
#include <iostream>
5355

llvm_passes/HipEmitLoweredNames.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "HipEmitLoweredNames.h"
3131

32+
#include "llvm/IR/Module.h"
3233
#include "llvm/Passes/PassBuilder.h"
3334
#include "llvm/Passes/PassPlugin.h"
3435
#include "llvm/Support/CommandLine.h"

llvm_passes/HipGlobalVariables.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/IR/Function.h"
4646
#include "llvm/IR/IRBuilder.h"
4747
#include "llvm/IR/Instructions.h"
48+
#include "llvm/IR/Module.h"
4849
#include "llvm/Passes/PassBuilder.h"
4950
#include "llvm/Passes/PassPlugin.h"
5051

@@ -308,7 +309,11 @@ static void emitGlobalVarInitShadowKernel(Module &M, GlobalVariable *GVar,
308309
static bool shouldLower(const GlobalVariable &GVar) {
309310
if (!GVar.hasName()) return false;
310311

312+
#if LLVM_VERSION_MAJOR < 19
311313
if (GVar.getName().startswith(ChipVarPrefix))
314+
#else
315+
if (GVar.getName().starts_with(ChipVarPrefix))
316+
#endif
312317
return false; // Already lowered.
313318

314319
// All host accessible global device variables are marked to be externally

llvm_passes/HipIGBADetector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include <llvm/IR/Function.h>
4141
#include <llvm/IR/Instructions.h>
42+
#include "llvm/IR/Module.h"
4243
#include <llvm/Passes/PassBuilder.h>
4344
#include <llvm/Passes/PassPlugin.h>
4445

llvm_passes/HipKernelArgSpiller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/ADT/SmallPtrSet.h"
5050
#include "llvm/ADT/STLExtras.h"
5151
#include "llvm/IR/IRBuilder.h"
52+
#include "llvm/IR/Module.h"
5253
#include "llvm/Passes/PassBuilder.h"
5354
#include "llvm/Passes/PassPlugin.h"
5455
#include "llvm/Support/CommandLine.h"
@@ -107,7 +108,11 @@ bool isSpecial(const Argument &Arg) {
107108
// Only consider OpenCL and SPIR-V types - leave user defined opaque
108109
// structures alone (they are just plain pointers).
109110
StringRef Name = STy->getName();
111+
#if LLVM_VERSION_MAJOR < 19
110112
return (Name.startswith("opencl.") || Name.startswith("__spirv_"));
113+
#else
114+
return (Name.starts_with("opencl.") || Name.starts_with("__spirv_"));
115+
#endif
111116
#endif
112117
}
113118

llvm_passes/HipLowerZeroLengthArrays.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/SmallPtrSet.h"
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/IR/IRBuilder.h"
20+
#include "llvm/IR/Module.h"
2021
#include "llvm/Passes/PassBuilder.h"
2122
#include "llvm/Passes/PassPlugin.h"
2223
#include "llvm/Support/CommandLine.h"

llvm_passes/HipPasses.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "HipLowerMemset.h"
3131
#include "HipIGBADetector.h"
3232

33+
#include "llvm/IR/Module.h"
3334
#include "llvm/Passes/PassBuilder.h"
3435
#include "llvm/Passes/PassPlugin.h"
3536
#include "llvm/Transforms/IPO/Inliner.h"

llvm_passes/HipPrintf.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/IR/Constants.h"
5151
#include "llvm/IR/Function.h"
5252
#include "llvm/IR/Instructions.h"
53+
#include "llvm/IR/Module.h"
5354
#include "llvm/Pass.h"
5455
#include "llvm/Passes/PassBuilder.h"
5556
#include "llvm/Passes/PassPlugin.h"

llvm_passes/HipSanityChecks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include "HipSanityChecks.h"
1414

1515
#include "llvm/IR/Instructions.h"
16+
#include "llvm/IR/Module.h"
1617
#include "llvm/ADT/BitVector.h"
18+
#include "llvm/Support/Debug.h"
1719

1820
using namespace llvm;
1921

@@ -78,7 +80,11 @@ static void checkCallInst(CallInst *CI, BitVector &CaughtChecks) {
7880
const auto &Name = Callee->getName();
7981
// Catch use of unexpected atomic built-ins. All HIP atomic operations
8082
// should be mapped to corresponding OpenCL built-ins.
83+
#if LLVM_VERSION_MAJOR < 19
8184
if (Name.startswith("__atomic_") || Name.startswith("__hip_atomic_")) {
85+
#else
86+
if (Name.starts_with("__atomic_") || Name.starts_with("__hip_atomic_")) {
87+
#endif
8288
dbgs() << "Warning: Use of unsupported built-in atomic function: "
8389
<< Callee->getName() << "\n";
8490

llvm_passes/HipStripUsedIntrinsics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "HipStripUsedIntrinsics.h"
2525

26+
#include "llvm/IR/Module.h"
2627
#if LLVM_VERSION_MAJOR >= 14
2728
#include "llvm/Pass.h"
2829
#endif

llvm_passes/HipTextureLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/Function.h"
2323
#include "llvm/IR/IRBuilder.h"
2424
#include "llvm/IR/Instructions.h"
25+
#include "llvm/IR/Module.h"
2526
#include "llvm/Passes/PassBuilder.h"
2627
#include "llvm/Passes/PassPlugin.h"
2728
#include "llvm/Support/Compiler.h"

llvm_passes/HipWarps.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "HipWarps.h"
2626

2727
#include <llvm/IR/Metadata.h>
28+
#include "llvm/IR/Module.h"
2829
#include <llvm/IR/Constants.h>
2930

3031
#include "chipStarConfig.hh"

llvm_passes/SPIRVImageType.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ llvm::Type *getSPIRVImageType(llvm::LLVMContext &Ctx, llvm::StringRef BaseType,
3131

3232
// Choose the dimension of the image--this corresponds to the Dim enum in
3333
// SPIR-V (first integer parameter of OpTypeImage).
34+
#if LLVM_VERSION_MAJOR < 19
3435
if (OpenCLName.startswith("image2d"))
3536
IntParams[0] = 1; // 1D
3637
else if (OpenCLName.startswith("image3d"))
@@ -39,6 +40,16 @@ llvm::Type *getSPIRVImageType(llvm::LLVMContext &Ctx, llvm::StringRef BaseType,
3940
IntParams[0] = 5; // Buffer
4041
else
4142
assert(OpenCLName.startswith("image1d") && "Unknown image type");
43+
#else
44+
if (OpenCLName.starts_with("image2d"))
45+
IntParams[0] = 1; // 1D
46+
else if (OpenCLName.starts_with("image3d"))
47+
IntParams[0] = 2; // 2D
48+
else if (OpenCLName == "image1d_buffer")
49+
IntParams[0] = 5; // Buffer
50+
else
51+
assert(OpenCLName.starts_with("image1d") && "Unknown image type");
52+
#endif
4253

4354
// Set the other integer parameters of OpTypeImage if necessary. Note that the
4455
// OpenCL image types don't provide any information for the Sampled or

scripts/configure_llvm.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ done
4141
# check mandatory argument version
4242
if [ -z "$VERSION" ]; then
4343
echo "Usage: $0 --version <version> --install-dir <dir> --link-type static(default)/dynamic --only-necessary-spirv-exts <on|off> --binutils-header-location <path>"
44-
echo "--version: LLVM version 15, 16, 17, 18"
44+
echo "--version: LLVM version 15, 16, 17, 18, 19"
4545
echo "--install-dir: installation directory"
4646
echo "--link-type: static or dynamic (default: static)"
4747
echo "--only-necessary-spirv-exts: on or off (default: off)"
@@ -55,8 +55,9 @@ if [ -z "$INSTALL_DIR" ]; then
5555
fi
5656

5757
# validate version argument
58-
if [ "$VERSION" != "15" ] && [ "$VERSION" != "16" ] && [ "$VERSION" != "17" ] && [ "$VERSION" != "18" ]; then
59-
echo "Invalid version. Must be 15, 16, 17 or 18."
58+
if [ "$VERSION" != "15" ] && [ "$VERSION" != "16" ] && [ "$VERSION" != "17" ] \
59+
&& [ "$VERSION" != "18" ] && [ "$VERSION" != "19" ]; then
60+
echo "Invalid version. Must be 15, 16, 17, 18 or 19."
6061
exit 1
6162
fi
6263

0 commit comments

Comments
 (0)