Skip to content

Commit b87cceb

Browse files
committed
Add full LLVM 18 support (#1803)
Some methods and enums got renamed from LLVM 17 -> 18, etc. Also some adjustment to warning messages about version mixing between clang and llvm. Signed-off-by: Larry Gritz <[email protected]>
1 parent 9b3ed78 commit b87cceb

File tree

5 files changed

+61
-28
lines changed

5 files changed

+61
-28
lines changed

INSTALL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ NEW or CHANGED dependencies since the last major release are **bold**.
4747
$OpenImageIO_ROOT/lib to be in your LD_LIBRARY_PATH (or
4848
DYLD_LIBRARY_PATH on OS X).
4949

50-
* [LLVM](http://www.llvm.org) 9, 10, 11, 12, 13, 14, 15, 16, or 17, including
50+
* [LLVM](http://www.llvm.org) 9, 10, 11, 12, 13, 14, 15, 16, 17, or 18, including
5151
clang libraries.
5252

5353
* (optional) For GPU rendering on NVIDIA GPUs:
@@ -71,7 +71,7 @@ NEW or CHANGED dependencies since the last major release are **bold**.
7171
be operative.
7272
* (optional) Python: If you are building the Python bindings or running the
7373
testsuite:
74-
* Python >= 2.7 (tested against 2.7, 3.7, 3.8, 3.9, 3.10, 3.11)
74+
* Python >= 2.7 (tested against 2.7, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12)
7575
NOTE: It is likely that 1.13 is the last release that will support
7676
Python 2.7.
7777
* pybind11 >= 2.4.2 (Tested through 2.11. Note that pybind11 v2.10+ does

src/cmake/compiler.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER MATCHES "[Cc]lan
5959
set (CMAKE_CXX_COMPILER_ID "AppleClang")
6060
set (CMAKE_COMPILER_IS_APPLECLANG 1)
6161
string (REGEX REPLACE ".* version ([0-9]+\\.[0-9]+).*" "\\1" APPLECLANG_VERSION_STRING ${clang_full_version_string})
62+
set (ANY_CLANG_VERSION_STRING ${APPLECLANG_VERSION_STRING})
6263
message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${APPLECLANG_VERSION_STRING}")
6364
elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
6465
set (CMAKE_COMPILER_IS_INTELCLANG 1)
6566
string (REGEX MATCH "[0-9]+(\\.[0-9]+)+" INTELCLANG_VERSION_STRING ${clang_full_version_string})
67+
set (ANY_CLANG_VERSION_STRING ${INTELCLANG_VERSION_STRING})
6668
message (VERBOSE "The compiler is Intel Clang: ${CMAKE_CXX_COMPILER_ID} version ${INTELCLANG_VERSION_STRING}")
6769
else ()
70+
set (CMAKE_COMPILER_IS_GENERICCLANG 1)
6871
string (REGEX REPLACE ".* version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
72+
set (ANY_CLANG_VERSION_STRING ${CLANG_VERSION_STRING})
6973
message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${CLANG_VERSION_STRING}")
7074
endif ()
7175
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")

src/cmake/externalpackages.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ checked_find_package (pugixml REQUIRED
117117
# LLVM library setup
118118
checked_find_package (LLVM REQUIRED
119119
VERSION_MIN 9.0
120-
VERSION_MAX 17.9
120+
VERSION_MAX 18.9
121121
PRINT LLVM_SYSTEM_LIBRARIES CLANG_LIBRARIES)
122122
# ensure include directory is added (in case of non-standard locations
123123
include_directories (BEFORE SYSTEM "${LLVM_INCLUDES}")
@@ -139,9 +139,8 @@ if (APPLE AND LLVM_VERSION VERSION_EQUAL 10.0.1 AND EXISTS "/usr/local/Cellar/ll
139139
" brew upgrade llvm \n"
140140
"${ColorReset}\n")
141141
endif ()
142-
if (LLVM_VERSION VERSION_GREATER_EQUAL 15.0
143-
AND ( (CMAKE_COMPILER_IS_APPLECLANG AND APPLECLANG_VERSION_STRING VERSION_LESS 15.0)
144-
OR (CMAKE_COMPILER_IS_CLANG AND CLANG_VERSION_STRING VERSION_LESS 15.0)))
142+
if (LLVM_VERSION VERSION_GREATER_EQUAL 15.0 AND CMAKE_COMPILER_IS_CLANG
143+
AND ANY_CLANG_VERSION_STRING VERSION_LESS 15.0)
145144
message (WARNING
146145
"${ColorYellow}"
147146
"If you are using LLVM 15 or higher, you should also use clang version "
@@ -155,7 +154,8 @@ if (LLVM_VERSION VERSION_GREATER_EQUAL 16.0)
155154
if (CMAKE_COMPILER_IS_GNUCC AND (GCC_VERSION VERSION_LESS 7.0))
156155
message (WARNING "${ColorYellow}LLVM 16+ requires gcc 7.0 or higher.${ColorReset}\n")
157156
endif ()
158-
if (CMAKE_COMPILER_IS_CLANG AND (CLANG_VERSION_STRING VERSION_LESS 5.0))
157+
if (CMAKE_COMPILER_IS_CLANG AND (CLANG_VERSION_STRING VERSION_LESS 5.0
158+
OR APPLE_CLANG_VERSION_STRING VERSION_LESS 5.0))
159159
message (WARNING "${ColorYellow}LLVM 16+ requires clang 5.0 or higher.${ColorReset}\n")
160160
endif ()
161161
endif ()

src/liboslexec/llvm_instance.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ BackendLLVM::build_offsets_of_ShaderGlobals(
482482
offset_by_index.push_back(offsetof(ShaderGlobals, flipHandedness));
483483
offset_by_index.push_back(offsetof(ShaderGlobals, backfacing));
484484
}
485+
486+
487+
485488
void
486489
BackendLLVM::llvm_assign_initial_value(const Symbol& sym, bool force)
487490
{
@@ -1626,7 +1629,13 @@ BackendLLVM::prepare_module_for_cuda_jit()
16261629
for (llvm::Function& fn : *ll.module()) {
16271630
if (fn.hasFnAttribute("osl-lib-function")) {
16281631
fn.setLinkage(llvm::GlobalValue::ExternalLinkage);
1629-
} else if (fn.getName().startswith(group().name().c_str())) {
1632+
}
1633+
#if OSL_LLVM_VERSION >= 180
1634+
else if (fn.getName().starts_with(group().name().c_str()))
1635+
#else
1636+
else if (fn.getName().startswith(group().name().c_str()))
1637+
#endif
1638+
{
16301639
fn.setLinkage(llvm::GlobalValue::PrivateLinkage);
16311640
}
16321641
}
@@ -1638,9 +1647,15 @@ BackendLLVM::prepare_module_for_cuda_jit()
16381647
// Don't modify the inlining attribute for:
16391648
// * group entry functions
16401649
// * llvm library functions
1650+
#if OSL_LLVM_VERSION >= 180
1651+
if (fn.getName().starts_with("__direct_callable__")
1652+
|| fn.getName().starts_with("llvm."))
1653+
continue;
1654+
#else
16411655
if (fn.getName().startswith("__direct_callable__")
16421656
|| fn.getName().startswith("llvm."))
16431657
continue;
1658+
#endif
16441659

16451660
// Merge layer functions which are only called from one place
16461661
if (merge_layer_funcs && !fn.hasFnAttribute("osl-lib-function")

src/liboslexec/llvm_util.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -490,26 +490,20 @@ LLVM_Util::LLVM_Util(const PerThreadInfo& per_thread_info, int debuglevel,
490490
else
491491
m_llvm_type_addrint = (llvm::Type*)llvm::Type::getInt64Ty(
492492
*m_llvm_context);
493-
m_llvm_type_int_ptr = (llvm::PointerType*)llvm::Type::getInt32PtrTy(
494-
*m_llvm_context);
495-
m_llvm_type_int8_ptr = (llvm::PointerType*)llvm::Type::getInt8PtrTy(
496-
*m_llvm_context);
497-
m_llvm_type_int64_ptr = (llvm::PointerType*)llvm::Type::getInt64PtrTy(
498-
*m_llvm_context);
499493
m_llvm_type_bool = (llvm::Type*)llvm::Type::getInt1Ty(*m_llvm_context);
500-
m_llvm_type_bool_ptr = (llvm::PointerType*)llvm::Type::getInt1PtrTy(
501-
*m_llvm_context);
502494
m_llvm_type_char = (llvm::Type*)llvm::Type::getInt8Ty(*m_llvm_context);
503495
m_llvm_type_longlong = (llvm::Type*)llvm::Type::getInt64Ty(*m_llvm_context);
504496
m_llvm_type_void = (llvm::Type*)llvm::Type::getVoidTy(*m_llvm_context);
505-
m_llvm_type_char_ptr = (llvm::PointerType*)llvm::Type::getInt8PtrTy(
506-
*m_llvm_context);
507-
m_llvm_type_float_ptr = (llvm::PointerType*)llvm::Type::getFloatPtrTy(
508-
*m_llvm_context);
509-
m_llvm_type_longlong_ptr = (llvm::PointerType*)llvm::Type::getInt64PtrTy(
510-
*m_llvm_context);
511-
m_llvm_type_void_ptr = m_llvm_type_char_ptr;
512-
m_llvm_type_double_ptr = llvm::Type::getDoublePtrTy(*m_llvm_context);
497+
498+
m_llvm_type_int_ptr = llvm::PointerType::get(m_llvm_type_int, 0);
499+
m_llvm_type_int8_ptr = llvm::PointerType::get(m_llvm_type_int8, 0);
500+
m_llvm_type_int64_ptr = llvm::PointerType::get(m_llvm_type_int64, 0);
501+
m_llvm_type_bool_ptr = llvm::PointerType::get(m_llvm_type_bool, 0);
502+
m_llvm_type_char_ptr = llvm::PointerType::get(m_llvm_type_char, 0);
503+
m_llvm_type_void_ptr = m_llvm_type_char_ptr;
504+
m_llvm_type_float_ptr = llvm::PointerType::get(m_llvm_type_float, 0);
505+
m_llvm_type_longlong_ptr = llvm::PointerType::get(m_llvm_type_int64, 0);
506+
m_llvm_type_double_ptr = llvm::PointerType::get(m_llvm_type_double, 0);
513507

514508
// A triple is a struct composed of 3 floats
515509
std::vector<llvm::Type*> triplefields(3, m_llvm_type_float);
@@ -563,7 +557,7 @@ void
563557
LLVM_Util::ustring_rep(UstringRep rep)
564558
{
565559
m_ustring_rep = rep;
566-
m_llvm_type_ustring = llvm::Type::getInt8PtrTy(*m_llvm_context);
560+
m_llvm_type_ustring = m_llvm_type_int8_ptr;
567561
// ^^ When m_ustring_rep != UstringRep::charptr, we'd ideally want to make
568562
// it a uint directly, but that is wreaking havoc with function
569563
// signatures, so continue to disguise it as a pointer.
@@ -1514,8 +1508,14 @@ LLVM_Util::make_jit_execengine(std::string* err, TargetISA requestedISA,
15141508
std::unique_ptr<llvm::RTDyldMemoryManager>(
15151509
new MemoryManager(m_llvm_jitmm)));
15161510

1511+
#if OSL_LLVM_VERSION >= 180
1512+
engine_builder.setOptLevel(jit_aggressive()
1513+
? llvm::CodeGenOptLevel::Aggressive
1514+
: llvm::CodeGenOptLevel::Default);
1515+
#else
15171516
engine_builder.setOptLevel(jit_aggressive() ? llvm::CodeGenOpt::Aggressive
15181517
: llvm::CodeGenOpt::Default);
1518+
#endif
15191519

15201520
llvm::TargetOptions options;
15211521
// Enables FMA's in IR generation.
@@ -1817,7 +1817,12 @@ LLVM_Util::nvptx_target_machine()
18171817
m_nvptx_target_machine = llvm_target->createTargetMachine(
18181818
ModuleTriple.str(), CUDA_TARGET_ARCH, "+ptx50", options,
18191819
llvm::Reloc::Static, llvm::CodeModel::Small,
1820-
llvm::CodeGenOpt::Default);
1820+
#if OSL_LLVM_VERSION >= 180
1821+
llvm::CodeGenOptLevel::Default
1822+
#else
1823+
llvm::CodeGenOpt::Default
1824+
#endif
1825+
);
18211826

18221827
OSL_ASSERT(m_nvptx_target_machine
18231828
&& "Unable to create TargetMachine for NVPTX");
@@ -2957,7 +2962,12 @@ LLVM_Util::prune_and_internalize_module(
29572962
|| llvm::cast<llvm::GlobalValue>(val)
29582963
->hasLocalLinkage()) {
29592964
if (!debug()
2960-
|| !val->getName().startswith("llvm.dbg")) {
2965+
#if OSL_LLVM_VERSION >= 180
2966+
|| !val->getName().starts_with("llvm.dbg")
2967+
#else
2968+
|| !val->getName().startswith("llvm.dbg")
2969+
#endif
2970+
) {
29612971
__OSL_PRUNE_ONLY(
29622972
std::cout
29632973
<< "remove symbol table for value: "
@@ -6486,7 +6496,11 @@ LLVM_Util::ptx_compile_group(llvm::Module*, const std::string& name,
64866496
llvm::raw_svector_ostream assembly_stream(assembly);
64876497

64886498
// TODO: Make sure rounding modes, etc., are set correctly
6489-
# if OSL_LLVM_VERSION >= 100
6499+
# if OSL_LLVM_VERSION >= 180
6500+
target_machine->addPassesToEmitFile(mpm, assembly_stream,
6501+
nullptr, // FIXME: Correct?
6502+
llvm::CodeGenFileType::AssemblyFile);
6503+
# elif OSL_LLVM_VERSION >= 100
64906504
target_machine->addPassesToEmitFile(mpm, assembly_stream,
64916505
nullptr, // FIXME: Correct?
64926506
llvm::CGFT_AssemblyFile);

0 commit comments

Comments
 (0)