Skip to content

Commit

Permalink
Merge pull request #1424 from franz/llvm_18_support
Browse files Browse the repository at this point in the history
LLVM 18 support
  • Loading branch information
pjaaskel committed Mar 5, 2024
2 parents 7ac781d + 944c7d9 commit 368454b
Show file tree
Hide file tree
Showing 36 changed files with 691 additions and 430 deletions.
45 changes: 26 additions & 19 deletions .github/workflows/build_cmake.yml
Expand Up @@ -35,22 +35,27 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: [16, 17]
llvm: [17, 18]
# basic = simplest pthread build
# devel = with devel options
# cts_spirv = cts with SPIR-V
# tier1 = includes CTS without SPIR-V
# asan, tsan, ubsan = sanitizers
# chipstar 1.1 only supports LLVM up to 17
config: [basic, devel, asan, tsan, ubsan, cts_spirv, tier1, chipstar]
include:
- llvm: 14
config: basic
config: OpenMP
- llvm: 15
config: TBB
- llvm: 16
config: basic
- llvm: 18
config: static
exclude:
- llvm: 16
- llvm: 18
config: cts_spirv
- llvm: 16
- llvm: 18
config: chipstar

steps:
Expand All @@ -76,14 +81,14 @@ jobs:
runCMake -DENABLE_TSAN=1 -DENABLE_ICD=0 -DENABLE_LOADABLE_DRIVERS=0
elif [ "${{ matrix.config }}" == "ubsan" ]; then
runCMake -DENABLE_UBSAN=1 -DENABLE_LATEST_CXX_STD=ON -DENABLE_ICD=0 -DENABLE_LOADABLE_DRIVERS=0
elif [ "${{ matrix.config }}" == "OpenMP" ]; then
runCMake -DENABLE_ICD=1 -DENABLE_HOST_CPU_DEVICES_OPENMP=1
elif [ "${{ matrix.config }}" == "TBB" ]; then
runCMake -DENABLE_ICD=1 -DENABLE_TBB_DEVICE=1
elif [ "${{ matrix.config }}" == "basic" ]; then
if [ "${{ matrix.llvm }}" == "14" ]; then
runCMake -DENABLE_ICD=1 -DENABLE_HOST_CPU_DEVICES_OPENMP=1
elif [ "${{ matrix.llvm }}" == "15" ]; then
runCMake -DENABLE_ICD=1 -DENABLE_TBB_DEVICE=1
else
runCMake -DENABLE_ICD=1
fi
runCMake -DENABLE_ICD=1
elif [ "${{ matrix.config }}" == "static" ]; then
runCMake -DENABLE_ICD=1 -DSTATIC_LLVM=1
elif [ "${{ matrix.config }}" == "devel" ]; then
runCMake -DENABLE_RELOCATION=0 -DENABLE_VALGRIND=1 -DENABLE_EXTRA_VALIDITY_CHECKS=1
elif [ "${{ matrix.config }}" == "cts_spirv" ]; then
Expand Down Expand Up @@ -127,8 +132,14 @@ jobs:
runCTest -L "internal|tsan" -E "clCreateSubDevices"
elif [ "${{ matrix.config }}" == "ubsan" ]; then
runCTest -L "internal|ubsan"
elif [ "${{ matrix.config }}" == "OpenMP" ]; then
runCTest -L internal
elif [ "${{ matrix.config }}" == "TBB" ]; then
runCTest -L internal
elif [ "${{ matrix.config }}" == "basic" ]; then
runCTest -L internal
elif [ "${{ matrix.config }}" == "static" ]; then
runCTest -L internal
elif [ "${{ matrix.config }}" == "devel" ]; then
runCTest -L internal
elif [ "${{ matrix.config }}" == "cts_spirv" ]; then
Expand Down Expand Up @@ -280,7 +291,7 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: [16, 17]
llvm: [17, 18]
config: [cuda]

steps:
Expand Down Expand Up @@ -322,7 +333,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# only 16 is enabled, but 15 should also work
# only 16 is enabled, but 15 & 17 should also work
llvm: [16]
config: [openasip]

Expand Down Expand Up @@ -408,7 +419,7 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: [16, 17]
llvm: [17, 18]
config: [basic]

steps:
Expand Down Expand Up @@ -461,11 +472,7 @@ jobs:
run: |
runCMake() {
BUILD_FLAGS="-O1 -march=native -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable"
if [ ${{ matrix.llvm }} -lt 16 ]; then
LLVM_FLAGS="-DSTATIC_LLVM=0 -DWITH_LLVM_CONFIG=/home/LLVM_${{ matrix.llvm }}/bin/llvm-config"
else
LLVM_FLAGS="-DSTATIC_LLVM=1 -DWITH_LLVM_CONFIG=/usr/bin/llvm-config-${{ matrix.llvm }} -DLLVM_SPIRV=/home/LLVM_${{ matrix.llvm }}/bin/llvm-spirv"
fi
LLVM_FLAGS="-DSTATIC_LLVM=1 -DWITH_LLVM_CONFIG=/usr/bin/llvm-config-${{ matrix.llvm }} -DLLVM_SPIRV=/home/LLVM_${{ matrix.llvm }}/bin/llvm-spirv"
cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DDEVELOPER_MODE=ON \
-DCMAKE_BUILD_TYPE=Release "-DCMAKE_C_FLAGS_RELEASE=$BUILD_FLAGS" "-DCMAKE_CXX_FLAGS_RELEASE=$BUILD_FLAGS" \
$LLVM_FLAGS "$@" -B ${{ github.workspace }}/build ${{ github.workspace }}
Expand Down
9 changes: 6 additions & 3 deletions CMakeLists.txt
Expand Up @@ -905,9 +905,12 @@ endif()
# constant addrspace variables, and stack protector likely slows
# down the kernels, so it needs to be determined whether it's worth
# the trouble.
set(DEFAULT_KERNEL_CL_FLAGS "-xcl -fno-stack-protector -fPIC ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(DEFAULT_KERNEL_C_FLAGS "-xc -std=c11 -D__CBUILD__ -fno-math-errno -fno-stack-protector -fPIC ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(DEFAULT_KERNEL_CXX_FLAGS "-xc++ -std=c++11 -fno-stack-protector -fPIC ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
#
# no-jump-tables is to avoid LLVM optimization passes introducing switch tables,
# which the variable uniformity analysis cannot analyze
set(DEFAULT_KERNEL_CL_FLAGS "-xcl -fno-stack-protector -fPIC -fno-jump-tables ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(DEFAULT_KERNEL_C_FLAGS "-xc -std=c11 -D__CBUILD__ -fno-math-errno -fno-stack-protector -fPIC -fno-jump-tables ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(DEFAULT_KERNEL_CXX_FLAGS "-xc++ -std=c++11 -fno-stack-protector -fPIC -fno-jump-tables ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")


set(EXTRA_KERNEL_FLAGS "" CACHE STRING "Extra arguments to all kernel compilation commands (defaults to empty)")
Expand Down
100 changes: 7 additions & 93 deletions cmake/LLVM.cmake
Expand Up @@ -241,6 +241,10 @@ if(STATIC_LLVM)
if(LLVM_MAJOR GREATER 14)
list(APPEND CLANG_LIBNAMES clangSupport)
endif()
# must come after clangFrontend
if(LLVM_MAJOR GREATER 17)
list(INSERT CLANG_LIBNAMES 4 clangAPINotes)
endif()
else()
# For non-static builds, link against a single shared library
# instead of multiple component shared libraries.
Expand Down Expand Up @@ -712,33 +716,7 @@ if(NOT LLVM_LINK_TEST)

message(STATUS "Running LLVM link test")

set(LLVM_LINK_TEST_SOURCE "
#include <stdio.h>
#include \"llvm/IR/LLVMContext.h\"
#include \"llvm/Support/SourceMgr.h\"
#include \"llvm/IR/Module.h\"
#include \"llvm/IRReader/IRReader.h\"
int main( int argc, char* argv[] )
{
if( argc < 2 )
exit(2);
llvm::LLVMContext context;
llvm::SMDiagnostic err;
std::unique_ptr<llvm::Module> module = llvm::parseIRFile( argv[1], err, context );
if( !module )
exit(1);
else
printf(\"DataLayout = %s\\n\", module->getDataLayoutStr().c_str());
return 0;
}")

string(RANDOM RNDNAME)
set(LLVM_LINK_TEST_FILENAME "${CMAKE_BINARY_DIR}/llvm_link_test_${RNDNAME}.cc")
file(WRITE "${LLVM_LINK_TEST_FILENAME}" "${LLVM_LINK_TEST_SOURCE}")
set(LLVM_LINK_TEST_FILENAME "${CMAKE_SOURCE_DIR}/cmake/LinkTestLLVM.cc")

try_compile(LLVM_LINK_TEST ${CMAKE_BINARY_DIR} "${LLVM_LINK_TEST_FILENAME}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${LLVM_INCLUDE_DIRS}"
Expand All @@ -765,77 +743,13 @@ if(NOT CLANG_LINK_TEST)

message(STATUS "Running Clang link test")

set(CLANG_LINK_TEST_SOURCE "
#include <stdio.h>
#include <clang/Lex/PreprocessorOptions.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/LangOptions.h>
#include <clang/CodeGen/CodeGenAction.h>
#include <clang/Driver/Compilation.h>
#include <clang/Driver/Driver.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/CompilerInvocation.h>
#include <clang/Frontend/FrontendActions.h>
using namespace clang;
using namespace llvm;
int main( int argc, char* argv[] )
{
if( argc < 2 )
exit(2);
CompilerInstance CI;
CompilerInvocation &pocl_build = CI.getInvocation();
LangOptions *la = pocl_build.getLangOpts();
PreprocessorOptions &po = pocl_build.getPreprocessorOpts();
po.Includes.push_back(\"/usr/include/test/path.h\");
la->OpenCLVersion = 300;
la->FakeAddressSpaceMap = false;
la->Blocks = true; //-fblocks
la->MathErrno = false; // -fno-math-errno
la->NoBuiltin = true; // -fno-builtin
la->AsmBlocks = true; // -fasm (?)
la->setStackProtector(LangOptions::StackProtectorMode::SSPOff);
la->PICLevel = PICLevel::BigPIC;
la->PIE = 0;
clang::TargetOptions &ta = pocl_build.getTargetOpts();
ta.Triple = \"x86_64-pc-linux-gnu\";
ta.CPU = \"haswell\";
FrontendOptions &fe = pocl_build.getFrontendOpts();
fe.Inputs.clear();
fe.Inputs.push_back(
FrontendInputFile(argv[1],
clang::InputKind(clang::Language::OpenCL)));
CodeGenOptions &cg = pocl_build.getCodeGenOpts();
cg.EmitOpenCLArgMetadata = true;
cg.StackRealignment = true;
cg.VerifyModule = true;
bool success = true;
clang::PrintPreprocessedAction Preprocess;
success = CI.ExecuteAction(Preprocess);
return (success ? 0 : 11);
}")

string(RANDOM RNDNAME)
set(CLANG_LINK_TEST_FILENAME "${CMAKE_BINARY_DIR}/clang_link_test_${RNDNAME}.cc")
file(WRITE "${CLANG_LINK_TEST_FILENAME}" "${CLANG_LINK_TEST_SOURCE}")
set(CLANG_LINK_TEST_FILENAME "${CMAKE_SOURCE_DIR}/cmake/LinkTestClang.cc")

try_compile(CLANG_LINK_TEST ${CMAKE_BINARY_DIR} "${CLANG_LINK_TEST_FILENAME}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${LLVM_INCLUDE_DIRS}"
CMAKE_FLAGS "-DLINK_DIRECTORIES:STRING=${LLVM_LIBDIR}"
LINK_LIBRARIES "${LLVM_LDFLAGS} ${CLANG_LIBS} ${LLVM_LIBS} ${LLVM_SYSLIBS}"
COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS}"
COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS} -DLLVM_MAJOR=${LLVM_MAJOR}"
OUTPUT_VARIABLE _TRY_COMPILE_OUTPUT)

if(CLANG_LINK_TEST)
Expand Down
85 changes: 85 additions & 0 deletions cmake/LinkTestClang.cc
@@ -0,0 +1,85 @@
/* PoCL CMake build system: LinkTestClang.cc
Copyright (c) 2023 Michal Babej / Intel Finland Oy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/LangOptions.h>
#include <clang/CodeGen/CodeGenAction.h>
#include <clang/Driver/Compilation.h>
#include <clang/Driver/Driver.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/CompilerInvocation.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Lex/PreprocessorOptions.h>
#include <stdio.h>

using namespace clang;
using namespace llvm;

int main(int argc, char *argv[]) {
if (argc < 2)
exit(2);

CompilerInstance CI;
CompilerInvocation &pocl_build = CI.getInvocation();
#if (LLVM_MAJOR < 18)
LangOptions *la = pocl_build.getLangOpts();
#else
LangOptions L = pocl_build.getLangOpts();
LangOptions *la = &L;
#endif
PreprocessorOptions &po = pocl_build.getPreprocessorOpts();
po.Includes.push_back("/usr/include/test/path.h");

la->OpenCLVersion = 300;
la->FakeAddressSpaceMap = false;
la->Blocks = true; //-fblocks
la->MathErrno = false; // -fno-math-errno
la->NoBuiltin = true; // -fno-builtin
la->AsmBlocks = true; // -fasm (?)

la->setStackProtector(LangOptions::StackProtectorMode::SSPOff);

la->PICLevel = PICLevel::BigPIC;
la->PIE = 0;

clang::TargetOptions &ta = pocl_build.getTargetOpts();
ta.Triple = "x86_64-pc-linux-gnu";
ta.CPU = "haswell";

FrontendOptions &fe = pocl_build.getFrontendOpts();
fe.Inputs.clear();

fe.Inputs.push_back(
FrontendInputFile(argv[1], clang::InputKind(clang::Language::OpenCL)));

CodeGenOptions &cg = pocl_build.getCodeGenOpts();
cg.EmitOpenCLArgMetadata = true;
cg.StackRealignment = true;
cg.VerifyModule = true;

bool success = true;
clang::PrintPreprocessedAction Preprocess;
success = CI.ExecuteAction(Preprocess);

return (success ? 0 : 11);
}
45 changes: 45 additions & 0 deletions cmake/LinkTestLLVM.cc
@@ -0,0 +1,45 @@
/* PoCL CMake build system: LinkTestLLVM.cc
Copyright (c) 2016 Michal Babej / Tampere University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IRReader/IRReader.h>
#include <llvm/Support/SourceMgr.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
if (argc < 2)
exit(2);

llvm::LLVMContext context;
llvm::SMDiagnostic err;
std::unique_ptr<llvm::Module> module =
llvm::parseIRFile(argv[1], err, context);

if (!module)
exit(1);
else
printf("DataLayout = %s\n", module->getDataLayoutStr().c_str());

return 0;
}

0 comments on commit 368454b

Please sign in to comment.