[flang-commits] [flang] 703b105 - [Flang] enable fir.is_present and fir.absent with function types

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Fri Jun 24 01:55:46 PDT 2022


Author: Kiran Chandramohan
Date: 2022-06-24T08:46:14Z
New Revision: 703b1054e93b7fb1ce88a797f3f63feab6b5a4f7

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

LOG: [Flang] enable fir.is_present and fir.absent with function types

Fortran dummy procedures and procedure pointer can be OPTIONAL, and
there is no technical reason to prevent fir.is_present and
fir.absent from accepting function types, so allow it and add test.

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

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier at nvidia.com>

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIRTypes.td
    flang/test/Fir/optional.fir

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 165a3a614a5dd..5a9cc62bcbf00 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -580,7 +580,7 @@ def AnyBoxLike : TypeConstraint<Or<[fir_BoxType.predicate,
     fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
 
 def AnyRefOrBoxLike : TypeConstraint<Or<[AnyReferenceLike.predicate,
-    AnyBoxLike.predicate]>,
+    AnyBoxLike.predicate, FunctionType.predicate]>,
     "any reference or box like">;
 def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
     fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>,

diff  --git a/flang/test/Fir/optional.fir b/flang/test/Fir/optional.fir
index 644a7ef8d2198..3b350d6fa9419 100644
--- a/flang/test/Fir/optional.fir
+++ b/flang/test/Fir/optional.fir
@@ -51,3 +51,37 @@ func.func @bar3() -> i1 {
   %1 = fir.call @foo3(%0) : (!fir.boxchar<1>) -> i1
   return %1 : i1
 }
+
+// CHECK-LABEL: @foo4(
+// CHECK-SAME: ptr %[[arg:.*]])
+func.func @foo4(%arg0: !fir.boxproc<(i32)->(i64)>) -> i1 {
+  // CHECK: %[[ptr:.*]] = ptrtoint ptr %[[arg]] to i64
+  // CHECK: icmp ne i64 %[[ptr]], 0
+  %0 = fir.is_present %arg0 : (!fir.boxproc<(i32)->(i64)>) -> i1
+  return %0 : i1
+}
+
+// CHECK-LABEL: @bar4
+func.func @bar4() -> i1 {
+  %0 = fir.absent !fir.boxproc<(i32)->(i64)>
+  // CHECK: call i1 @foo4(ptr null)
+  %1 = fir.call @foo4(%0) : (!fir.boxproc<(i32)->(i64)>) -> i1
+  return %1 : i1
+}
+
+// CHECK-LABEL: @foo5(
+// CHECK-SAME: ptr %[[arg:.*]])
+func.func @foo5(%arg0: (i32)->(i64)) -> i1 {
+  // CHECK: %[[ptr:.*]] = ptrtoint ptr %[[arg]] to i64
+  // CHECK: icmp ne i64 %[[ptr]], 0
+  %0 = fir.is_present %arg0 : ((i32)->(i64)) -> i1
+  return %0 : i1
+}
+
+// CHECK-LABEL: @bar5
+func.func @bar5() -> i1 {
+  %0 = fir.absent (i32)->(i64)
+  // CHECK: call i1 @foo5(ptr null)
+  %1 = fir.call @foo5(%0) : ((i32)->(i64)) -> i1
+  return %1 : i1
+}


        


More information about the flang-commits mailing list