aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Target/LLVMIR/ModuleImport.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2025-03-25 13:15:51 -0700
committerGitHub <noreply@github.com>2025-03-25 13:15:51 -0700
commite7e242e7ad6901e5f4c85d6e5ee4455d6be29b50 (patch)
treee548134ee5acf272464c4d43aa2eb742007bc782 /mlir/lib/Target/LLVMIR/ModuleImport.cpp
parent9aecbdf8ed787a8edd1b7f97a1c7fbf6e9d12515 (diff)
downloadllvm-e7e242e7ad6901e5f4c85d6e5ee4455d6be29b50.zip
llvm-e7e242e7ad6901e5f4c85d6e5ee4455d6be29b50.tar.gz
llvm-e7e242e7ad6901e5f4c85d6e5ee4455d6be29b50.tar.bz2
[MLIR][LLVM] Fix debug value/declare import in face of landing pads (#132871)
Debug value/declare operations imported before landing pad operations at the bb start break invoke op verification: ``` error: first operation in unwind destination should be a llvm.landingpad operation ``` This this issue by making the placement slightly more smart.
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleImport.cpp')
-rw-r--r--mlir/lib/Target/LLVMIR/ModuleImport.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 7657661..00b16c8 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -2512,7 +2512,19 @@ ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
Block *dominatedBlock = (*dominatedBlocks.begin())->getBlock();
builder.setInsertionPoint(dominatedBlock->getTerminator());
} else {
- builder.setInsertionPointAfterValue(*argOperand);
+ Value insertPt = *argOperand;
+ if (auto blockArg = dyn_cast<BlockArgument>(*argOperand)) {
+ // The value might be coming from a phi node and is now a block argument,
+ // which means the insertion point is set to the start of the block. If
+ // this block is a target destination of an invoke, the insertion point
+ // must happen after the landing pad operation.
+ Block *insertionBlock = argOperand->getParentBlock();
+ if (!insertionBlock->empty() &&
+ isa<LandingpadOp>(insertionBlock->front()))
+ insertPt = cast<LandingpadOp>(insertionBlock->front()).getRes();
+ }
+
+ builder.setInsertionPointAfterValue(insertPt);
}
auto locationExprAttr =
debugImporter->translateExpression(dbgIntr->getExpression());