Skip to content

Commit 1d436e3

Browse files
committed
Changes to work with LLVM 13 (#1420)
And a few places to let it compile with clang 13's new warnings. Signed-off-by: Larry Gritz <[email protected]>
1 parent eb67611 commit 1d436e3

File tree

4 files changed

+62
-15
lines changed

4 files changed

+62
-15
lines changed

INSTALL.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ NEW or CHANGED dependencies since the last major release are **bold**.
1515
* Build system: [CMake](https://cmake.org/) 3.12 or newer (tested through 3.21)
1616

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

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

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

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

5353
* [Boost](https://www.boost.org) 1.55 or newer (tested through boost 1.76)
5454
* [Ilmbase or Imath](http://openexr.com/downloads.html) 2.0 or newer (tested through 3.1)
55-
* [Flex](https://github.com/westes/flex) and
56-
[GNU Bison](https://www.gnu.org/software/bison/)
55+
* [Flex](https://github.com/westes/flex) 2.5.35 or newer and
56+
[GNU Bison](https://www.gnu.org/software/bison/) 2.7 or newer.
57+
Note that on some MacOS/xcode releases, the system-installed Bison is too
58+
old, and it's better to install a newer Bison (via Homebrew is one way to
59+
do this easily).
5760
* [PugiXML](http://pugixml.org/)
5861
* (optional) [Partio](https://www.disneyanimation.com/technology/partio.html)
5962
If it is not found at build time, the OSL `pointcloud` functions will not

src/include/OSL/llvm_util.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ class OSLEXECPUBLIC LLVM_Util {
577577
llvm::Value *src, int srcalign, int len);
578578

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

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

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

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

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

605616
// Arithmetic ops. It auto-detects the type (int vs float).

src/liboslexec/llvm_util.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,10 +2591,18 @@ LLVM_Util::op_memcpy (llvm::Value *dst, int dstalign,
25912591

25922592

25932593

2594+
llvm::Value *
2595+
LLVM_Util::op_load (llvm::Type* type, llvm::Value* ptr)
2596+
{
2597+
return builder().CreateLoad (type, ptr);
2598+
}
2599+
2600+
2601+
25942602
llvm::Value *
25952603
LLVM_Util::op_load (llvm::Value *ptr)
25962604
{
2597-
return builder().CreateLoad (ptr);
2605+
return op_load(ptr->getType()->getPointerElementType(), ptr);
25982606
}
25992607

26002608

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

26082616

26092617

2618+
llvm::Value *
2619+
LLVM_Util::GEP (llvm::Type* type, llvm::Value* ptr, llvm::Value* elem)
2620+
{
2621+
return builder().CreateGEP(type, ptr, elem);
2622+
}
2623+
2624+
2625+
26102626
llvm::Value *
26112627
LLVM_Util::GEP (llvm::Value *ptr, llvm::Value *elem)
26122628
{
2613-
return builder().CreateGEP (ptr, elem);
2629+
return GEP(ptr->getType()->getScalarType()->getPointerElementType(), ptr,
2630+
elem);
2631+
}
2632+
2633+
2634+
2635+
llvm::Value *
2636+
LLVM_Util::GEP (llvm::Type* type, llvm::Value* ptr, int elem)
2637+
{
2638+
return builder().CreateConstGEP1_32(type, ptr, elem);
26142639
}
26152640

26162641

26172642

26182643
llvm::Value *
26192644
LLVM_Util::GEP (llvm::Value *ptr, int elem)
26202645
{
2621-
return builder().CreateConstGEP1_32 (ptr, elem);
2646+
return GEP(ptr->getType()->getScalarType()->getPointerElementType(), ptr,
2647+
elem);
2648+
}
2649+
2650+
2651+
2652+
llvm::Value *
2653+
LLVM_Util::GEP(llvm::Type* type, llvm::Value* ptr, int elem1, int elem2)
2654+
{
2655+
return builder().CreateConstGEP2_32 (type, ptr, elem1, elem2);
26222656
}
26232657

26242658

26252659

26262660
llvm::Value *
26272661
LLVM_Util::GEP (llvm::Value *ptr, int elem1, int elem2)
26282662
{
2629-
return builder().CreateConstGEP2_32 (nullptr, ptr, elem1, elem2);
2663+
return GEP(ptr->getType()->getScalarType()->getPointerElementType(), ptr,
2664+
elem1, elem2);
26302665
}
26312666

26322667

src/liboslexec/runtimeoptimize.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,6 @@ RuntimeOptimizer::optimize_instance ()
23012301
// passes, but we have a hard cutoff just to be sure we don't
23022302
// ever get into an infinite loop from an unforseen cycle where we
23032303
// end up inadvertently transforming A => B => A => etc.
2304-
int totalchanged = 0;
23052304
int reallydone = 0; // Force a few passes after we think we're done
23062305
int npasses = shadingsys().opt_passes();
23072306
for (m_pass = 0; m_pass < npasses; ++m_pass) {
@@ -2362,7 +2361,6 @@ RuntimeOptimizer::optimize_instance ()
23622361
// If nothing changed, we're done optimizing. But wait, it may be
23632362
// that after re-tracking variable lifetimes, we can notice new
23642363
// optimizations! So force another pass, then we're really done.
2365-
totalchanged += changed;
23662364
if (changed < 1) {
23672365
if (++reallydone > 3)
23682366
break;

0 commit comments

Comments
 (0)