Skip to content

Commit b7d347b

Browse files
author
Razvan Lupusoru
committed
[FIR] Avoid generating llvm.undef for dummy scoping info
Dummy scoping operations are generated to keep track of scopes for purpose of Fortran level analyses like Alias Analysis. For codegen, the scoping info is converted to a fir.undef during pre-codegen rewrite. Then during declare lowering, this info is no longer used - but it is still translated to llvm.undef. I cleaned up so it is simply erased. The generated LLVM should now no longer have a stray undef which looks off when trying to make sense of the IR.
1 parent df9d3c2 commit b7d347b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,6 +3575,14 @@ struct UndefOpConversion : public fir::FIROpConversion<fir::UndefOp> {
35753575
llvm::LogicalResult
35763576
matchAndRewrite(fir::UndefOp undef, OpAdaptor,
35773577
mlir::ConversionPatternRewriter &rewriter) const override {
3578+
if (mlir::isa<fir::DummyScopeType>(undef.getType())) {
3579+
// Dummy scoping is used for Fortran analyses like AA. Once it gets to
3580+
// pre-codegen rewrite it is erased and a fir.undef is created to
3581+
// feed to the fir declare operation. Thus, during codegen, we can
3582+
// simply erase is as it is no longer used.
3583+
rewriter.eraseOp(undef);
3584+
return mlir::success();
3585+
}
35783586
rewriter.replaceOpWithNewOp<mlir::LLVM::UndefOp>(
35793587
undef, convertType(undef.getType()));
35803588
return mlir::success();

0 commit comments

Comments
 (0)