Skip to content

Commit

Permalink
Merge pull request #1592 from Idclip/llvm15
Browse files Browse the repository at this point in the history
Added basic support for LLVM 15 in OpenVDB AX
  • Loading branch information
Idclip committed Jul 5, 2023
2 parents 19710c1 + 4a31d7f commit ffc71c3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ jobs:
matrix:
config:
- { cxx: 'clang++', build: 'Release', llvm: '14', dir: '@14' }
# Can't support LLVM >= 15
#- { cxx: 'clang++', build: 'Release', llvm: 'latest', dir: '' }
- { cxx: 'clang++', build: 'Release', llvm: 'latest', dir: '' }
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down
13 changes: 11 additions & 2 deletions openvdb_ax/openvdb_ax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ else()
set(LLVM_LIBS "${_llvm_libs}")
endif()

if(LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 15.0.0)
if(LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 16.0.0)
# https://llvm.org/docs/OpaquePointers.html
message(FATAL_ERROR "OpenVDB AX does not currently support LLVM versions >= 15 due to \
message(FATAL_ERROR "OpenVDB AX does not currently support LLVM versions >= 16 due to \
opaque pointer changes in LLVM. Found unsuitable LLVM version \"${LLVM_PACKAGE_VERSION}\"")
endif()

Expand Down Expand Up @@ -319,6 +319,11 @@ if(OPENVDB_AX_STATIC)
)

target_link_libraries(openvdb_ax_static PUBLIC ${OPENVDB_AX_CORE_DEPENDENT_LIBS})

# @todo fix opaque pointer requirements
if(LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 15.0.0)
target_compile_options(openvdb_ax_static PUBLIC "-Wno-error=deprecated-declarations")
endif()
endif()

# Configure shared build
Expand Down Expand Up @@ -351,6 +356,10 @@ if(OPENVDB_AX_SHARED)
)

target_link_libraries(openvdb_ax_shared PUBLIC ${OPENVDB_AX_CORE_DEPENDENT_LIBS})
# @todo fix opaque pointer requirements
if(LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 15.0.0)
target_compile_options(openvdb_ax_shared PUBLIC "-Wno-error=deprecated-declarations")
endif()
endif()

install(FILES ax.h Exceptions.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openvdb_ax/)
Expand Down
18 changes: 9 additions & 9 deletions openvdb_ax/openvdb_ax/compiler/Compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ initializeExecutionEngine(std::unique_ptr<llvm::Module> M, Logger& logger)

#ifndef USE_NEW_PASS_MANAGER

#if LLVM_VERSION_MAJOR < 15
void addStandardLinkPasses(llvm::legacy::PassManagerBase& passes)
{
llvm::PassManagerBuilder builder;
builder.VerifyInput = true;
builder.Inliner = llvm::createFunctionInliningPass();
builder.populateLTOPassManager(passes);
}
#endif

/// This routine adds optimization passes based on selected optimization level
///
Expand All @@ -129,7 +131,6 @@ void addOptimizationPasses(llvm::legacy::PassManagerBase& passes,
const unsigned optLevel,
const unsigned sizeLevel,
const bool disableInline = false,
const bool disableUnitAtATime = false,
const bool disableLoopUnrolling = false,
const bool disableLoopVectorization = false,
const bool disableSLPVectorization = false)
Expand All @@ -148,14 +149,6 @@ void addOptimizationPasses(llvm::legacy::PassManagerBase& passes,
builder.Inliner = llvm::createAlwaysInlinerLegacyPass();
}

#if LLVM_VERSION_MAJOR < 9
// Enable IPO. This corresponds to gcc's -funit-at-a-time
builder.DisableUnitAtATime = disableUnitAtATime;
#else
// unused from llvm 9
(void)(disableUnitAtATime);
#endif

// Disable loop unrolling in all relevant passes
builder.DisableUnrollLoops =
disableLoopUnrolling ? disableLoopUnrolling : optLevel == 0;
Expand Down Expand Up @@ -198,7 +191,9 @@ void LLVMoptimise(llvm::Module& module,
else functionPasses.add(llvm::createTargetTransformInfoWrapperPass(llvm::TargetIRAnalysis()));


#if LLVM_VERSION_MAJOR < 15
addStandardLinkPasses(passes);
#endif
addOptimizationPasses(passes, functionPasses, TM, optLevel, sizeLevel);

functionPasses.doInitialization();
Expand Down Expand Up @@ -663,6 +658,11 @@ Compiler::Compiler(const CompilerOptions& options)
, mFunctionRegistry()
{
mContext.reset(new llvm::LLVMContext);
#if LLVM_VERSION_MAJOR >= 15
// This will not work from LLVM 16. We'll need to fix this
// https://llvm.org/docs/OpaquePointers.html
mContext->setOpaquePointers(false);
#endif
mFunctionRegistry = codegen::createDefaultRegistry(&options.mFunctionOptions);
}

Expand Down
5 changes: 5 additions & 0 deletions openvdb_ax/openvdb_ax/test/backend/TestCodecs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ void TestCodecs::testRegisteredCodecs()
// enforced as part of the API but the majority of the setup code is internal.

llvm::LLVMContext C;
#if LLVM_VERSION_MAJOR >= 15
// This will not work from LLVM 16. We'll need to fix this
// https://llvm.org/docs/OpaquePointers.html
C.setOpaquePointers(false);
#endif

// Get all unique registered codecs
std::set<const Codec*> codecs;
Expand Down
8 changes: 7 additions & 1 deletion openvdb_ax/openvdb_ax/test/backend/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ namespace unittest_util
struct LLVMState
{
LLVMState(const std::string& name = "__test_module")
: mCtx(new llvm::LLVMContext), mModule(new llvm::Module(name, *mCtx)) {}
: mCtx(new llvm::LLVMContext), mModule(new llvm::Module(name, *mCtx)) {
#if LLVM_VERSION_MAJOR >= 15
// This will not work from LLVM 16. We'll need to fix this
// https://llvm.org/docs/OpaquePointers.html
mCtx->setOpaquePointers(false);
#endif
}

llvm::LLVMContext& context() { return *mCtx; }
llvm::Module& module() { return *mModule; }
Expand Down
6 changes: 6 additions & 0 deletions openvdb_ax/openvdb_ax/test/compiler/TestVolumeExecutable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ TestVolumeExecutable::testConstructionDestruction()
CPPUNIT_ASSERT(openvdb::ax::isInitialized());

std::shared_ptr<llvm::LLVMContext> C(new llvm::LLVMContext);
#if LLVM_VERSION_MAJOR >= 15
// This will not work from LLVM 16. We'll need to fix this
// https://llvm.org/docs/OpaquePointers.html
C->setOpaquePointers(false);
#endif

std::unique_ptr<llvm::Module> M(new llvm::Module("test_module", *C));
std::shared_ptr<const llvm::ExecutionEngine> E(llvm::EngineBuilder(std::move(M))
.setEngineKind(llvm::EngineKind::JIT)
Expand Down
6 changes: 6 additions & 0 deletions openvdb_ax/openvdb_ax/test/integration/TestVDBFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ void
TestVDBFunctions::testValidContext()
{
std::shared_ptr<llvm::LLVMContext> C(new llvm::LLVMContext);
#if LLVM_VERSION_MAJOR >= 15
// This will not work from LLVM 16. We'll need to fix this
// https://llvm.org/docs/OpaquePointers.html
C->setOpaquePointers(false);
#endif

openvdb::ax::Compiler compiler;
openvdb::ax::FunctionOptions ops;
ops.mLazyFunctions = false;
Expand Down
3 changes: 3 additions & 0 deletions pendingchanges/vdb_ax.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
AX:
- Improvements:
Added support for LLVM 15

- Bug Fix:
Fixed an incorrect option in the `vdb_ax` command line tool where the default
optimization level was set to NONE instead of O3 (issue introduced in 10.0.0).

0 comments on commit ffc71c3

Please sign in to comment.