Address intermittent ICE triggered from the OpenMPIRBuilder::finalize method due to an invalid builder insertion point

This commit is contained in:
Sergio Afonso 2025-08-05 15:34:28 +01:00
parent 688b61435b
commit 4da11cfd7d

View File

@ -5872,6 +5872,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
static LogicalResult
convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
llvm::OpenMPIRBuilder *ompBuilder,
LLVM::ModuleTranslation &moduleTranslation) {
// Amend omp.declare_target by deleting the IR of the outlined functions
// created for target regions. They cannot be filtered out from MLIR earlier
@ -5894,6 +5895,11 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
moduleTranslation.lookupFunction(funcOp.getName());
llvmFunc->dropAllReferences();
llvmFunc->eraseFromParent();
// Invalidate the builder's current insertion point, as it now points to
// a deleted block.
ompBuilder->Builder.ClearInsertionPoint();
ompBuilder->Builder.SetCurrentDebugLocation(llvm::DebugLoc());
}
}
return success();
@ -6338,9 +6344,12 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
.Case("omp.declare_target",
[&](Attribute attr) {
if (auto declareTargetAttr =
dyn_cast<omp::DeclareTargetAttr>(attr))
dyn_cast<omp::DeclareTargetAttr>(attr)) {
llvm::OpenMPIRBuilder *ompBuilder =
moduleTranslation.getOpenMPBuilder();
return convertDeclareTargetAttr(op, declareTargetAttr,
moduleTranslation);
ompBuilder, moduleTranslation);
}
return failure();
})
.Case("omp.requires",