Skip to content

Commit 4dff00b

Browse files
committed
LLVM12 support
1 parent b571bfa commit 4dff00b

25 files changed

+2834
-60
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: |
2020
#sudo apt-get remove -y llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools
2121
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
22-
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${{ matrix.llvm }} main"
22+
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${{ matrix.llvm }} main" || true
2323
sudo apt-get install -y autoconf cmake gcc g++ libtool gfortran libblas-dev llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools clang-${{ matrix.llvm }} libeigen3-dev libboost-dev
2424
sudo touch /usr/lib/llvm-${{ matrix.llvm }}/bin/yaml-bench
2525
- uses: actions/checkout@v1

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: |
2121
#sudo apt-get remove -y llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools
2222
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
23-
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${{ matrix.llvm }} main"
23+
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${{ matrix.llvm }} main" || true
2424
sudo apt-get install -y autoconf cmake gcc g++ libtool gfortran llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools clang-${{ matrix.llvm }} libeigen3-dev libboost-dev
2525
sudo touch /usr/lib/llvm-${{ matrix.llvm }}/bin/yaml-bench
2626
- uses: actions/checkout@v1

.github/workflows/enzyme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: |
2121
#sudo apt-get remove -y llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools
2222
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
23-
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${{ matrix.llvm }} main"
23+
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${{ matrix.llvm }} main" || true
2424
sudo apt-get install -y autoconf cmake gcc g++ libtool gfortran llvm-${{ matrix.llvm }}-dev llvm-${{ matrix.llvm }}-tools
2525
sudo touch /usr/lib/llvm-${{ matrix.llvm }}/bin/yaml-bench
2626
- uses: actions/checkout@v1

enzyme/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ endif()
7070

7171
string(REPLACE "#define LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H" "#define LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H\n#include \"SCEV/ScalarEvolution.h\"" INPUT_TEXT "${INPUT_TEXT}")
7272
string(REPLACE "LLVM_ANALYSIS" "FAKELLVM_ANALYSIS" INPUT_TEXT "${INPUT_TEXT}")
73-
string(REPLACE "class SCEVExpander" "namespace fake {\n class SCEVExpander" INPUT_TEXT "${INPUT_TEXT}")
73+
string(REPLACE "class SCEVExpander " "namespace fake {\n class SCEVExpander " INPUT_TEXT "${INPUT_TEXT}")
74+
string(REPLACE "struct SCEVOperand " "namespace fake {\n struct SCEVOperand " INPUT_TEXT "${INPUT_TEXT}")
7475
string(REPLACE "};\n}" "};\n}}" INPUT_TEXT "${INPUT_TEXT}")
76+
string(REPLACE "const SCEV* S;\n};\n" "const SCEV* S;\n};\n}\n" INPUT_TEXT "${INPUT_TEXT}")
77+
7578
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/SCEV/ScalarEvolutionExpander.h" "${INPUT_TEXT}")
7679

7780
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")

enzyme/Enzyme/AdjointGenerator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,9 +1821,14 @@ class DerivativeMaker
18211821
TR.query(orig->getArgOperand(i)).Data0()[{}].isPossiblePointer()) {
18221822
DIFFE_TYPE ty = DIFFE_TYPE::DUP_ARG;
18231823
if (argType->isPointerTy()) {
1824+
#if LLVM_VERSION_MAJOR >= 12
1825+
auto at = getUnderlyingObject(
1826+
orig->getArgOperand(i), 100);
1827+
#else
18241828
auto at = GetUnderlyingObject(
18251829
orig->getArgOperand(i),
18261830
gutils->oldFunc->getParent()->getDataLayout(), 100);
1831+
#endif
18271832
if (auto arg = dyn_cast<Argument>(at)) {
18281833
if (constant_args[arg->getArgNo()] == DIFFE_TYPE::DUP_NONEED) {
18291834
ty = DIFFE_TYPE::DUP_NONEED;

enzyme/Enzyme/Enzyme.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#include <llvm/Config/llvm-config.h>
1313

1414
#include "llvm/ADT/SmallVector.h"
15+
#include "llvm/ADT/ArrayRef.h"
1516

1617
#include "llvm/IR/BasicBlock.h"
1718
#include "llvm/IR/Constants.h"
18-
#include "llvm/IR/DebugInfoMetadata.h"
19+
//#include "llvm/IR/DebugInfoMetadata.h"
1920
#include "llvm/IR/Function.h"
2021
#include "llvm/IR/IRBuilder.h"
2122
#include "llvm/IR/InstrTypes.h"

enzyme/Enzyme/EnzymeLogic.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ bool is_load_uncacheable(
139139

140140
// Find the underlying object for the pointer operand of the load instruction.
141141
auto obj =
142+
#if LLVM_VERSION_MAJOR >= 12
143+
getUnderlyingObject(li.getPointerOperand(), 100);
144+
#else
142145
GetUnderlyingObject(li.getPointerOperand(),
143146
gutils->oldFunc->getParent()->getDataLayout(), 100);
147+
#endif
144148

145149
bool can_modref = is_value_mustcache_from_origin(
146150
obj, AA, gutils, TLI, unnecessaryInstructions, uncacheable_args);
@@ -228,9 +232,14 @@ std::map<Argument *, bool> compute_uncacheable_args_for_one_callsite(
228232

229233
// If the UnderlyingObject is from one of this function's arguments, then we
230234
// need to propagate the volatility.
235+
#if LLVM_VERSION_MAJOR >= 12
236+
Value *obj = getUnderlyingObject(
237+
callsite_op->getArgOperand(i), 100);
238+
#else
231239
Value *obj = GetUnderlyingObject(
232240
callsite_op->getArgOperand(i),
233241
callsite_op->getParent()->getModule()->getDataLayout(), 100);
242+
#endif
234243

235244
bool init_safe = !is_value_mustcache_from_origin(
236245
obj, AA, gutils, TLI, unnecessaryInstructions, parent_uncacheable_args);
@@ -367,9 +376,14 @@ void calculateUnusedValuesInFunction(Function& func, llvm::SmallPtrSetImpl<const
367376
if (auto si = dyn_cast<StoreInst>(inst)) {
368377
if (isa<UndefValue>(si->getValueOperand()))
369378
return false;
379+
#if LLVM_VERSION_MAJOR >= 12
380+
auto at = getUnderlyingObject(
381+
si->getPointerOperand(), 100);
382+
#else
370383
auto at = GetUnderlyingObject(
371384
si->getPointerOperand(),
372385
gutils->oldFunc->getParent()->getDataLayout(), 100);
386+
#endif
373387
if (auto arg = dyn_cast<Argument>(at)) {
374388
if (constant_args[arg->getArgNo()] == DIFFE_TYPE::DUP_NONEED) {
375389
return false;
@@ -378,9 +392,14 @@ void calculateUnusedValuesInFunction(Function& func, llvm::SmallPtrSetImpl<const
378392
}
379393

380394
if (auto mti = dyn_cast<MemTransferInst>(inst)) {
395+
#if LLVM_VERSION_MAJOR >= 12
396+
auto at = getUnderlyingObject(
397+
mti->getArgOperand(1), 100);
398+
#else
381399
auto at = GetUnderlyingObject(
382400
mti->getArgOperand(1),
383401
gutils->oldFunc->getParent()->getDataLayout(), 100);
402+
#endif
384403
if (auto arg = dyn_cast<Argument>(at)) {
385404
if (constant_args[arg->getArgNo()] == DIFFE_TYPE::DUP_NONEED) {
386405
return false;
@@ -426,9 +445,14 @@ void calculateUnusedStoresInFunction(Function& func, llvm::SmallPtrSetImpl<const
426445
}
427446

428447
if (auto mti = dyn_cast<MemTransferInst>(inst)) {
448+
#if LLVM_VERSION_MAJOR >= 12
449+
auto at = getUnderlyingObject(
450+
mti->getArgOperand(1), 100);
451+
#else
429452
auto at = GetUnderlyingObject(
430453
mti->getArgOperand(1),
431454
func.getParent()->getDataLayout(), 100);
455+
#endif
432456
if (auto ai = dyn_cast<AllocaInst>(at)) {
433457
bool foundStore = false;
434458
allInstructionsBetween(

enzyme/Enzyme/FunctionUtils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,14 @@ Function *preprocessForClone(Function *F, AAResults &AA, TargetLibraryInfo &TLI,
362362
// DCEPass().run(*NewF, AM);
363363
// DSEPass().run(*NewF, AM);
364364
// MemCpyOptPass().run(*NewF, AM);
365+
#if LLVM_VERSION_MAJOR >= 12
366+
SimplifyCFGOptions scfgo;
367+
#else
365368
SimplifyCFGOptions scfgo(
366369
/*unsigned BonusThreshold=*/1, /*bool ForwardSwitchCond=*/false,
367370
/*bool SwitchToLookup=*/false, /*bool CanonicalLoops=*/true,
368371
/*bool SinkCommon=*/true, /*AssumptionCache *AssumpCache=*/nullptr);
372+
#endif
369373
SimplifyCFGPass(scfgo).run(*NewF, AM);
370374
}
371375
}
@@ -686,10 +690,15 @@ void optimizeIntermediate(GradientUtils *gutils, bool topLevel, Function *F) {
686690

687691
createFunctionToLoopPassAdaptor(LoopDeletionPass()).run(*F, AM);
688692

693+
#if LLVM_VERSION_MAJOR >= 12
694+
SimplifyCFGOptions scfgo = SimplifyCFGOptions();
695+
#else
689696
SimplifyCFGOptions scfgo(
690697
/*unsigned BonusThreshold=*/1, /*bool ForwardSwitchCond=*/false,
691698
/*bool SwitchToLookup=*/false, /*bool CanonicalLoops=*/true,
692699
/*bool SinkCommon=*/true, /*AssumptionCache *AssumpCache=*/nullptr);
700+
701+
#endif
693702
SimplifyCFGPass(scfgo).run(*F, AM);
694703
// LCSSAPass().run(*NewF, AM);
695704
}

enzyme/Enzyme/GradientUtils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,16 +1801,26 @@ Value *GradientUtils::lookupM(Value *val, IRBuilder<> &BuilderM,
18011801

18021802
if (auto origInst = isOriginal(inst))
18031803
if (auto li = dyn_cast<LoadInst>(inst)) {
1804+
#if LLVM_VERSION_MAJOR >= 12
1805+
auto liobj = getUnderlyingObject(
1806+
li->getPointerOperand(), 100);
1807+
#else
18041808
auto liobj = GetUnderlyingObject(
18051809
li->getPointerOperand(), oldFunc->getParent()->getDataLayout(), 100);
1810+
#endif
18061811

18071812
if (scopeMap.find(inst) == scopeMap.end()) {
18081813
for (auto pair : scopeMap) {
18091814
if (auto li2 = dyn_cast<LoadInst>(const_cast<Value *>(pair.first))) {
18101815

1816+
#if LLVM_VERSION_MAJOR >= 12
1817+
auto li2obj =
1818+
getUnderlyingObject(li2->getPointerOperand(), 100);
1819+
#else
18111820
auto li2obj =
18121821
GetUnderlyingObject(li2->getPointerOperand(),
18131822
oldFunc->getParent()->getDataLayout(), 100);
1823+
#endif
18141824

18151825
if (liobj == li2obj && DT.dominates(li2, li)) {
18161826
auto orig2 = isOriginal(li2);

enzyme/Enzyme/SCEV/ScalarEvolutionExpander.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include "llvm/Config/llvm-config.h"
44

5-
#if LLVM_VERSION_MAJOR >= 11
5+
#if LLVM_VERSION_MAJOR >= 12
6+
#include "ScalarEvolutionExpander12.cpp"
7+
#elif LLVM_VERSION_MAJOR >= 11
68
#include "ScalarEvolutionExpander11.cpp"
79
#elif LLVM_VERSION_MAJOR >= 9
810
#include "ScalarEvolutionExpander9.cpp"

0 commit comments

Comments
 (0)