Skip to content

Commit 322766c

Browse files
authored
LLVM integrate (#2802)
* LLVM integrate * fix * Modify commit matrix in enzyme-rust.yml Updated the commit matrix to an empty array as a placeholder until Rust updates LLVM. * fix
1 parent 03fe699 commit 322766c

9 files changed

Lines changed: 52 additions & 17 deletions

File tree

.github/workflows/enzyme-mlir.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- uses: actions/checkout@v4
4646
with:
4747
repository: 'llvm/llvm-project'
48-
ref: '293623ce99d4d6819378311c1506c5ab08d1d860'
48+
ref: 'a7c97252ed18839e87796dffd3926086ab62e8fd'
4949
path: 'llvm-project'
5050

5151
- name: Set BASE_DIR

enzyme/Enzyme/CacheUtility.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,17 @@ void RemoveRedundantIVs(
264264
if (auto addrec = dyn_cast<SCEVAddRecExpr>(S)) {
265265
if (addrec->getLoop()->getHeader() == Header) {
266266
if (auto add_or_mul = dyn_cast<BinaryOperator>(NewIV)) {
267+
#if LLVM_VERSION_MAJOR >= 23
268+
if (any(addrec->getNoWrapFlags(llvm::SCEV::FlagNUW)))
269+
add_or_mul->setHasNoUnsignedWrap(true);
270+
if (any(addrec->getNoWrapFlags(llvm::SCEV::FlagNSW)))
271+
add_or_mul->setHasNoSignedWrap(true);
272+
#else
267273
if (addrec->getNoWrapFlags(llvm::SCEV::FlagNUW))
268274
add_or_mul->setHasNoUnsignedWrap(true);
269275
if (addrec->getNoWrapFlags(llvm::SCEV::FlagNSW))
270276
add_or_mul->setHasNoSignedWrap(true);
277+
#endif
271278
}
272279
}
273280
}

enzyme/Enzyme/Enzyme.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3122,7 +3122,11 @@ AnalysisKey EnzymeNewPM::Key;
31223122
#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
31233123

31243124
static InlineParams getInlineParamsFromOptLevel(OptimizationLevel Level) {
3125+
#if LLVM_VERSION_MAJOR >= 23
3126+
return getInlineParams(Level.getSpeedupLevel());
3127+
#else
31253128
return getInlineParams(Level.getSpeedupLevel(), Level.getSizeLevel());
3129+
#endif
31263130
}
31273131

31283132
#include "llvm/Transforms/Scalar/LowerConstantIntrinsics.h"
@@ -3157,7 +3161,12 @@ void augmentPassBuilder(llvm::PassBuilder &PB) {
31573161
bool LTOPreLink = false;
31583162
// First rotate loops that may have been un-rotated by prior passes.
31593163
// Disable header duplication at -Oz.
3164+
#if LLVM_VERSION_MAJOR >= 23
3165+
LPM.addPass(LoopRotatePass(/*EnableLoopHeaderDuplication=*/true, LTOPreLink,
3166+
/*CheckExitCount=*/true));
3167+
#else
31603168
LPM.addPass(LoopRotatePass(Level != OptimizationLevel::Oz, LTOPreLink));
3169+
#endif
31613170
// Some loops may have become dead by now. Try to delete them.
31623171
// FIXME: see discussion in https://reviews.llvm.org/D112851,
31633172
// this may need to be revisited once we run GVN before
@@ -3267,7 +3276,9 @@ void augmentPassBuilder(llvm::PassBuilder &PB) {
32673276
// This opens opportunities for globalopt (and inlining) by
32683277
// substituting function pointers passed as arguments to direct uses
32693278
// of functions.
3270-
#if LLVM_VERSION_MAJOR >= 16
3279+
#if LLVM_VERSION_MAJOR >= 23
3280+
MPM.addPass(IPSCCPPass(IPSCCPOptions(/*AllowFuncSpec=*/true)));
3281+
#elif LLVM_VERSION_MAJOR >= 16
32713282
MPM.addPass(IPSCCPPass(IPSCCPOptions(/*AllowFuncSpec=*/
32723283
Level != OptimizationLevel::Os &&
32733284
Level != OptimizationLevel::Oz)));

enzyme/Enzyme/MLIR/Implementations/ArithAutoDiffOpInterfaceImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ArithConstantOpBatchInterface
5353
}
5454
auto cop = mlir::Operation::create(
5555
src->getLoc(), src->getName(), resultTypes, {}, std::move(attrs),
56-
OpaqueProperties(nullptr), mlir::BlockRange(), 0);
56+
mlir::PropertyRef(), mlir::BlockRange(), 0);
5757
builder.insert(cop);
5858
mapper.map(src->getResult(0), cop->getResult(0));
5959
return success();

enzyme/Enzyme/MLIR/Implementations/CoreDialectsAutoDiffImplementations.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ void mlir::enzyme::detail::branchingForwardHandler(Operation *inst,
119119
}
120120

121121
gutils->getNewFromOriginal(inst->getBlock())
122-
->push_back(
123-
newInst->create(newInst->getLoc(), newInst->getName(), TypeRange(),
124-
newVals, attrs, OpaqueProperties(nullptr),
125-
newInst->getSuccessors(), newInst->getNumRegions()));
122+
->push_back(newInst->create(newInst->getLoc(), newInst->getName(),
123+
TypeRange(), newVals, attrs,
124+
mlir::PropertyRef(), newInst->getSuccessors(),
125+
newInst->getNumRegions()));
126126
gutils->erase(newInst);
127127
return;
128128
}

enzyme/Enzyme/MLIR/Interfaces/CloneFunction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ Operation *clone(Operation *src, IRMapping &mapper,
9696
if (!newOp) {
9797
SmallVector<Type> resultTypes(src->getResultTypes().begin(),
9898
src->getResultTypes().end());
99-
newOp = Operation::create(
100-
src->getLoc(), src->getName(), resultTypes, operands, src->getAttrs(),
101-
OpaqueProperties(nullptr), successors, src->getNumRegions());
99+
newOp = Operation::create(src->getLoc(), src->getName(), resultTypes,
100+
operands, src->getAttrs(), mlir::PropertyRef(),
101+
successors, src->getNumRegions());
102102

103103
// Clone the regions.
104104
if (options.shouldCloneRegions()) {

enzyme/Enzyme/MLIR/Interfaces/EnzymeLogic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ void createTerminator(MGradientUtils *gutils, mlir::Block *oBB,
6464
}
6565
}
6666

67-
nBB->push_back(
68-
newInst->create(newInst->getLoc(), newInst->getName(), TypeRange(),
69-
retargs, newInst->getAttrs(), OpaqueProperties(nullptr),
70-
newInst->getSuccessors(), newInst->getNumRegions()));
67+
nBB->push_back(newInst->create(newInst->getLoc(), newInst->getName(),
68+
TypeRange(), retargs, newInst->getAttrs(),
69+
mlir::PropertyRef(), newInst->getSuccessors(),
70+
newInst->getNumRegions()));
7171
gutils->erase(newInst);
7272
return;
7373
}

enzyme/Enzyme/MLIR/Passes/EnzymeBatchPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void batchCloneBlock(
143143

144144
Operation *newOp = Operation::create(
145145
src.getLoc(), src.getName(), resultTypes, operands, src.getAttrs(),
146-
OpaqueProperties(nullptr), successors, src.getNumRegions());
146+
mlir::PropertyRef(), successors, src.getNumRegions());
147147

148148
// Clone the regions.
149149
for (auto &&[oldReg, newReg] :

enzyme/Enzyme/MustExitScalarEvolution.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,15 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR, Type *Ty,
625625
//
626626

627627
const SCEV *BECount = SE->getBackedgeTakenCount(L);
628+
#if LLVM_VERSION_MAJOR >= 23
629+
if (PreAR && any(PreAR->getNoWrapFlags(WrapType)) &&
630+
!isa<SCEVCouldNotCompute>(BECount) && SE->isKnownPositive(BECount))
631+
return PreStart;
632+
#else
628633
if (PreAR && PreAR->getNoWrapFlags(WrapType) &&
629634
!isa<SCEVCouldNotCompute>(BECount) && SE->isKnownPositive(BECount))
630635
return PreStart;
636+
#endif
631637

632638
// 2. Direct overflow check on the step operation's expression.
633639
unsigned BitWidth = SE->getTypeSizeInBits(AR->getType());
@@ -636,7 +642,12 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR, Type *Ty,
636642
SE->getAddExpr((SE->*GetExtendExpr)(PreStart, WideTy, Depth),
637643
(SE->*GetExtendExpr)(Step, WideTy, Depth));
638644
if ((SE->*GetExtendExpr)(Start, WideTy, Depth) == OperandExtendedStart) {
639-
if (PreAR && AR->getNoWrapFlags(WrapType)) {
645+
#if LLVM_VERSION_MAJOR >= 23
646+
if (PreAR && any(AR->getNoWrapFlags(WrapType)))
647+
#else
648+
if (PreAR && AR->getNoWrapFlags(WrapType))
649+
#endif
650+
{
640651
// If we know `AR` == {`PreStart`+`Step`,+,`Step`} is `WrapType` (FlagNSW
641652
// or FlagNUW) and that `PreStart` + `Step` is `WrapType` too, then
642653
// `PreAR` == {`PreStart`,+,`Step`} is also `WrapType`. Cache this fact.
@@ -684,7 +695,7 @@ static SCEV::NoWrapFlags StrengthenNoWrapFlags(ScalarEvolution *SE,
684695
(void)CanAnalyze;
685696
assert(CanAnalyze && "don't call from other places!");
686697

687-
int SignOrUnsignMask = SCEV::FlagNUW | SCEV::FlagNSW;
698+
auto SignOrUnsignMask = SCEV::FlagNUW | SCEV::FlagNSW;
688699
SCEV::NoWrapFlags SignOrUnsignWrap =
689700
ScalarEvolution::maskFlags(Flags, SignOrUnsignMask);
690701

@@ -843,7 +854,13 @@ ScalarEvolution::ExitLimit MustExitScalarEvolution::howManyLessThans(
843854
// implicit/exceptional) which causes the loop to execute before the
844855
// exiting instruction we're analyzing would trigger UB.
845856
auto WrapType = IsSigned ? SCEV::FlagNSW : SCEV::FlagNUW;
857+
858+
#if LLVM_VERSION_MAJOR >= 23
859+
bool NoWrap = ControlsExit && any(IV->getNoWrapFlags(WrapType));
860+
#else
846861
bool NoWrap = ControlsExit && IV->getNoWrapFlags(WrapType);
862+
#endif
863+
847864
ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
848865

849866
const SCEV *Stride = IV->getStepRecurrence(*this);

0 commit comments

Comments
 (0)