Skip to content

Commit

Permalink
Changes to work with LLVM 13 (#1420)
Browse files Browse the repository at this point in the history
And a few places to let it compile with clang 13's new warnings.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Oct 24, 2021
1 parent eb67611 commit 1d436e3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
15 changes: 9 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ NEW or CHANGED dependencies since the last major release are **bold**.
* Build system: [CMake](https://cmake.org/) 3.12 or newer (tested through 3.21)

* A suitable C++11 compiler to build OSL itself, which may be any of:
- GCC 4.8.5 or newer (tested through gcc 11)
- Clang 3.4 or newer (tested through clang 12)
- GCC 4.8.5 or newer (tested through gcc 11.2)
- Clang 3.4 or newer (tested through clang 13)
- Microsoft Visual Studio 2015 or newer
- Intel C++ compiler icc version 13 (?) or newer

Expand All @@ -43,17 +43,20 @@ NEW or CHANGED dependencies since the last major release are **bold**.
DYLD_LIBRARY_PATH on OS X) and then OSL's build scripts will be able
to find it.

* **[LLVM](http://www.llvm.org) 7, 8, 9, 10, 11, or 12**, including
clang libraries.
* **[LLVM](http://www.llvm.org) 7, 8, 9, 10, 11, 12, or 13**, including clang
libraries.

Note that LLVM 10+ is not compatible with C++11, and requires C++14 or
later. If you *must* build OSL with C++11, you need to use an LLVM that
is LLVM 9 or earlier.

* [Boost](https://www.boost.org) 1.55 or newer (tested through boost 1.76)
* [Ilmbase or Imath](http://openexr.com/downloads.html) 2.0 or newer (tested through 3.1)
* [Flex](https://github.com/westes/flex) and
[GNU Bison](https://www.gnu.org/software/bison/)
* [Flex](https://github.com/westes/flex) 2.5.35 or newer and
[GNU Bison](https://www.gnu.org/software/bison/) 2.7 or newer.
Note that on some MacOS/xcode releases, the system-installed Bison is too
old, and it's better to install a newer Bison (via Homebrew is one way to
do this easily).
* [PugiXML](http://pugixml.org/)
* (optional) [Partio](https://www.disneyanimation.com/technology/partio.html)
If it is not found at build time, the OSL `pointcloud` functions will not
Expand Down
17 changes: 14 additions & 3 deletions src/include/OSL/llvm_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ class OSLEXECPUBLIC LLVM_Util {
llvm::Value *src, int srcalign, int len);

/// Dereference a pointer: return *ptr
/// type is the type of the thing being pointed to.
llvm::Value *op_load (llvm::Type* type, llvm::Value *ptr);
// Blind pointer version that's deprecated as of LLVM13:
llvm::Value *op_load (llvm::Value *ptr);

/// Store to a dereferenced pointer: *ptr = val
Expand All @@ -589,17 +592,25 @@ class OSLEXECPUBLIC LLVM_Util {

/// Generate a GEP (get element pointer) where the element index is an
/// llvm::Value, which can be generated from either a constant or a
/// runtime-computed integer element index.
/// runtime-computed integer element index. `type` is the type of the data
/// we're retrieving.
llvm::Value *GEP (llvm::Type* type, llvm::Value *ptr, llvm::Value *elem);
// Blind pointer version that's deprecated as of LLVM13:
llvm::Value *GEP (llvm::Value *ptr, llvm::Value *elem);

/// Generate a GEP (get element pointer) with an integer element
/// offset.
/// offset. `type` is the type of the data we're retrieving.
llvm::Value *GEP (llvm::Type* type, llvm::Value *ptr, int elem);
// Blind pointer version that's deprecated as of LLVM13:
llvm::Value *GEP (llvm::Value *ptr, int elem);

/// Generate a GEP (get element pointer) with two integer element
/// offsets. This is just a special (and common) case of GEP where
/// we have a 2-level hierarchy and we have fixed element indices
/// that are known at compile time.
/// that are known at compile time. `type` is the type of the data we're
/// retrieving.
llvm::Value *GEP (llvm::Type* type, llvm::Value *ptr, int elem1, int elem2);
// Blind pointer version that's deprecated as of LLVM13:
llvm::Value *GEP (llvm::Value *ptr, int elem1, int elem2);

// Arithmetic ops. It auto-detects the type (int vs float).
Expand Down
43 changes: 39 additions & 4 deletions src/liboslexec/llvm_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2591,10 +2591,18 @@ LLVM_Util::op_memcpy (llvm::Value *dst, int dstalign,



llvm::Value *
LLVM_Util::op_load (llvm::Type* type, llvm::Value* ptr)
{
return builder().CreateLoad (type, ptr);
}



llvm::Value *
LLVM_Util::op_load (llvm::Value *ptr)
{
return builder().CreateLoad (ptr);
return op_load(ptr->getType()->getPointerElementType(), ptr);
}


Expand All @@ -2607,26 +2615,53 @@ LLVM_Util::op_store (llvm::Value *val, llvm::Value *ptr)



llvm::Value *
LLVM_Util::GEP (llvm::Type* type, llvm::Value* ptr, llvm::Value* elem)
{
return builder().CreateGEP(type, ptr, elem);
}



llvm::Value *
LLVM_Util::GEP (llvm::Value *ptr, llvm::Value *elem)
{
return builder().CreateGEP (ptr, elem);
return GEP(ptr->getType()->getScalarType()->getPointerElementType(), ptr,
elem);
}



llvm::Value *
LLVM_Util::GEP (llvm::Type* type, llvm::Value* ptr, int elem)
{
return builder().CreateConstGEP1_32(type, ptr, elem);
}



llvm::Value *
LLVM_Util::GEP (llvm::Value *ptr, int elem)
{
return builder().CreateConstGEP1_32 (ptr, elem);
return GEP(ptr->getType()->getScalarType()->getPointerElementType(), ptr,
elem);
}



llvm::Value *
LLVM_Util::GEP(llvm::Type* type, llvm::Value* ptr, int elem1, int elem2)
{
return builder().CreateConstGEP2_32 (type, ptr, elem1, elem2);
}



llvm::Value *
LLVM_Util::GEP (llvm::Value *ptr, int elem1, int elem2)
{
return builder().CreateConstGEP2_32 (nullptr, ptr, elem1, elem2);
return GEP(ptr->getType()->getScalarType()->getPointerElementType(), ptr,
elem1, elem2);
}


Expand Down
2 changes: 0 additions & 2 deletions src/liboslexec/runtimeoptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,6 @@ RuntimeOptimizer::optimize_instance ()
// passes, but we have a hard cutoff just to be sure we don't
// ever get into an infinite loop from an unforseen cycle where we
// end up inadvertently transforming A => B => A => etc.
int totalchanged = 0;
int reallydone = 0; // Force a few passes after we think we're done
int npasses = shadingsys().opt_passes();
for (m_pass = 0; m_pass < npasses; ++m_pass) {
Expand Down Expand Up @@ -2362,7 +2361,6 @@ RuntimeOptimizer::optimize_instance ()
// If nothing changed, we're done optimizing. But wait, it may be
// that after re-tracking variable lifetimes, we can notice new
// optimizations! So force another pass, then we're really done.
totalchanged += changed;
if (changed < 1) {
if (++reallydone > 3)
break;
Expand Down

0 comments on commit 1d436e3

Please sign in to comment.