[flang-commits] [flang] acd7544 - [Flang] Lower the FailImage Statement

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Wed Apr 27 05:25:19 PDT 2022


Author: Kiran Chandramohan
Date: 2022-04-27T12:20:25Z
New Revision: acd75440c67acc31d9a5b0afdd64b5700be8960e

URL: https://github.com/llvm/llvm-project/commit/acd75440c67acc31d9a5b0afdd64b5700be8960e
DIFF: https://github.com/llvm/llvm-project/commit/acd75440c67acc31d9a5b0afdd64b5700be8960e.diff

LOG: [Flang] Lower the FailImage Statement

Lowering of FailImage statement generates a runtime call and the
unreachable operation. The unreachable operation cannot terminate
a structured operation like the IF operation, hence  mark as
unstructured.

Note: This patch is part of upstreaming code from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D124520

Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>

Added: 
    flang/test/Lower/fail_image.f90

Modified: 
    flang/lib/Lower/Bridge.cpp
    flang/lib/Lower/PFTBuilder.cpp
    flang/test/Lower/pre-fir-tree04.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 675f9c93d56d..df89b8c73565 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2013,7 +2013,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
 
   // call FAIL IMAGE in runtime
   void genFIR(const Fortran::parser::FailImageStmt &stmt) {
-    TODO(toLocation(), "FailImageStmt lowering");
+    genFailImageStatement(*this);
   }
 
   // call STOP, ERROR STOP in runtime

diff  --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index 4d80ff52afc1..478ca19f7211 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -744,6 +744,11 @@ class PFTBuilder {
             assert(construct && "missing EXIT construct");
             markBranchTarget(eval, *construct->constructExit);
           },
+          [&](const parser::FailImageStmt &) {
+            eval.isUnstructured = true;
+            if (eval.lexicalSuccessor->lexicalSuccessor)
+              markSuccessorAsNewBlock(eval);
+          },
           [&](const parser::GotoStmt &s) { markBranchTarget(eval, s.v); },
           [&](const parser::IfStmt &) {
             eval.lexicalSuccessor->isNewBlock = true;

diff  --git a/flang/test/Lower/fail_image.f90 b/flang/test/Lower/fail_image.f90
new file mode 100644
index 000000000000..9da162faca24
--- /dev/null
+++ b/flang/test/Lower/fail_image.f90
@@ -0,0 +1,20 @@
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
+
+! CHECK-LABEL: func @_QPfail_image_test
+subroutine fail_image_test(fail)
+  logical :: fail
+! CHECK:  cond_br {{.*}}, ^[[BB1:.*]], ^[[BB2:.*]]
+! CHECK: ^[[BB1]]:
+  if (fail) then
+! CHECK:  {{.*}} = fir.call @_FortranAFailImageStatement() : () -> none
+! CHECK-NEXT:  fir.unreachable
+   FAIL IMAGE
+  end if
+! CHECK: ^[[BB2]]:
+! CHECK-NEXT:  br ^[[BB3:.*]]
+! CHECK-NEXT: ^[[BB3]]
+! CEHCK-NEXT:  return
+  return
+end subroutine
+! CHECK-LABEL: func private @_FortranAFailImageStatement() -> none attributes {fir.runtime}

diff  --git a/flang/test/Lower/pre-fir-tree04.f90 b/flang/test/Lower/pre-fir-tree04.f90
index a04bf14c3a5f..8188bfd54b40 100644
--- a/flang/test/Lower/pre-fir-tree04.f90
+++ b/flang/test/Lower/pre-fir-tree04.f90
@@ -61,10 +61,10 @@ Subroutine test_coarray
   end if
   ! CHECK: <<End IfConstruct>>
 
-  ! CHECK: <<IfConstruct>>
+  ! CHECK: <<IfConstruct!>>
   if (y<0.) then
     ! CHECK: FailImageStmt
    fail image
   end if
-  ! CHECK: <<End IfConstruct>>
+  ! CHECK: <<End IfConstruct!>>
 end


        


More information about the flang-commits mailing list