Skip to content

Commit c1557e5

Browse files
authored
drop no-longer-supported lifetime annotations (#1280)
LLVM IR dropped support for lifetime intrinsics on everything but allocas and poisons while we still seem to be producing these. Remove them immediately before lowering. This gives us the possibility to rewrite them into something else if we figure out what.
1 parent b1d7223 commit c1557e5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/enzyme_ad/jax/Passes/ConvertPolygeistToLLVM.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,6 +3513,24 @@ populateCStyleFuncLoweringPatterns(RewritePatternSet &patterns,
35133513
patterns.add<CallOpLowering, FuncOpLowering, ReturnOpLowering>(typeConverter);
35143514
}
35153515

3516+
static void removeUnsupportedLifeTimes(mlir::Operation *root) {
3517+
llvm::SmallVector<mlir::Operation *> toErase;
3518+
root->walk([&](mlir::Operation *op) {
3519+
if (auto lifetimeStart = llvm::dyn_cast<mlir::LLVM::LifetimeStartOp>(op)) {
3520+
if (!llvm::isa_and_nonnull<mlir::LLVM::AllocaOp, mlir::LLVM::PoisonOp>(
3521+
lifetimeStart.getPtr().getDefiningOp()))
3522+
toErase.push_back(op);
3523+
} else if (auto lifetimeEnd =
3524+
llvm::dyn_cast<mlir::LLVM::LifetimeEndOp>(op)) {
3525+
if (!llvm::isa_and_nonnull<mlir::LLVM::AllocaOp, mlir::LLVM::PoisonOp>(
3526+
lifetimeEnd.getPtr().getDefiningOp()))
3527+
toErase.push_back(op);
3528+
}
3529+
});
3530+
for (mlir::Operation *op : toErase)
3531+
op->erase();
3532+
}
3533+
35163534
//===-----------------------------------------------------------------------===/
35173535

35183536
namespace {
@@ -3727,6 +3745,8 @@ struct ConvertPolygeistToLLVMPass
37273745
}
37283746
});
37293747
}
3748+
3749+
removeUnsupportedLifeTimes(m);
37303750
}
37313751

37323752
void runOnOperation() override {

src/enzyme_ad/jax/raise.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ extern "C" std::string runLLVMToMLIRRoundTrip(std::string input,
156156
llvm::LLVMContext llvmContext;
157157
llvmContext.setDiscardValueNames(false);
158158
auto outModule = translateModuleToLLVMIR(*mod, llvmContext);
159+
if (!outModule) {
160+
llvm::errs() << "failed to translate MLIR to LLVM IR\n";
161+
return "";
162+
}
159163

160164
if (auto F = outModule->getFunction("mgpuModuleLoad")) {
161165
for (auto U : llvm::make_early_inc_range(F->users())) {

0 commit comments

Comments
 (0)