[flang-commits] [flang] 32e0824 - [flang][CodeGen] Transform `fir.unreachable` to `llvm.unreachable`
Andrzej Warzynski via flang-commits
flang-commits at lists.llvm.org
Tue Nov 2 11:23:24 PDT 2021
Author: Andrzej Warzynski
Date: 2021-11-02T18:22:51Z
New Revision: 32e08248aa113bf3a5008d580753876fe3bcf021
URL: https://github.com/llvm/llvm-project/commit/32e08248aa113bf3a5008d580753876fe3bcf021
DIFF: https://github.com/llvm/llvm-project/commit/32e08248aa113bf3a5008d580753876fe3bcf021.diff
LOG: [flang][CodeGen] Transform `fir.unreachable` to `llvm.unreachable`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.unreachable` to `llvm.unreachable`.
This is part of the upstreaming effort from the `fir-dev` branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Differential Revision: https://reviews.llvm.org/D113023
Added:
Modified:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/convert-to-llvm.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index ce4860c8c0c6..15ac2d7cb45f 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -167,6 +167,18 @@ struct UndefOpConversion : public FIROpConversion<fir::UndefOp> {
}
};
+// convert to LLVM IR dialect `unreachable`
+struct UnreachableOpConversion : public FIROpConversion<fir::UnreachableOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::UnreachableOp unreach, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ rewriter.replaceOpWithNewOp<mlir::LLVM::UnreachableOp>(unreach);
+ return success();
+ }
+};
+
struct ZeroOpConversion : public FIROpConversion<fir::ZeroOp> {
using FIROpConversion::FIROpConversion;
@@ -190,6 +202,7 @@ struct ZeroOpConversion : public FIROpConversion<fir::ZeroOp> {
return success();
}
};
+
} // namespace
namespace {
@@ -207,8 +220,10 @@ class FIRToLLVMLowering : public fir::FIRToLLVMLoweringBase<FIRToLLVMLowering> {
auto *context = getModule().getContext();
fir::LLVMTypeConverter typeConverter{getModule()};
mlir::OwningRewritePatternList pattern(context);
- pattern.insert<AddrOfOpConversion, HasValueOpConversion, GlobalOpConversion,
- UndefOpConversion, ZeroOpConversion>(typeConverter);
+ pattern
+ .insert<AddrOfOpConversion, HasValueOpConversion, GlobalOpConversion,
+ UndefOpConversion, UnreachableOpConversion, ZeroOpConversion>(
+ typeConverter);
mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern);
mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter,
pattern);
diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir
index a20037beeb8c..3ef31ac28818 100644
--- a/flang/test/Fir/convert-to-llvm.fir
+++ b/flang/test/Fir/convert-to-llvm.fir
@@ -133,3 +133,15 @@ func @zero_test_float() {
// CHECK: %{{.*}} = llvm.mlir.constant(0.000000e+00 : f80) : f80
// CHECK: %{{.*}} = llvm.mlir.constant(0.000000e+00 : f128) : f128
// CHECK-NOT: fir.zero_bits
+
+// -----
+
+// Verify that fir.unreachable is transformed to llvm.unreachable
+
+// CHECK: llvm.func @test_unreachable() {
+// CHECK-NEXT: llvm.unreachable
+// CHECK-NEXT: }
+
+func @test_unreachable() {
+ fir.unreachable
+}
More information about the flang-commits
mailing list