[flang] Adding fir::getSymbolAttrName attribute to the function corresponding to...
authorRenaud-K <rkauffmann@nvidia.com>
Fri, 17 Feb 2023 20:44:33 +0000 (12:44 -0800)
committerRenaud-K <rkauffmann@nvidia.com>
Sat, 18 Feb 2023 02:20:03 +0000 (18:20 -0800)
This is because the source name cannot be deconstructed from _QQmain

Differential revision: https://reviews.llvm.org/D144295

17 files changed:
flang/include/flang/Lower/PFTBuilder.h
flang/lib/Lower/CallInterface.cpp
flang/test/Lower/OpenMP/atomic-read.f90
flang/test/Lower/OpenMP/atomic-update.f90
flang/test/Lower/OpenMP/atomic-write.f90
flang/test/Lower/OpenMP/default-clause.f90
flang/test/Lower/OpenMP/omp-wsloop-chunks.f90
flang/test/Lower/OpenMP/sections.f90
flang/test/Lower/array-character.f90
flang/test/Lower/array-expression-slice-1.f90
flang/test/Lower/basic-program.f90
flang/test/Lower/big-integer-parameter.f90
flang/test/Lower/derived-type-finalization.f90
flang/test/Lower/nested-where.f90
flang/test/Lower/polymorphic.f90
flang/test/Lower/program-units-fir-mangling.f90
flang/test/Lower/return-statement.f90

index 65ff0b2..ef513c2 100644 (file)
@@ -638,6 +638,15 @@ struct FunctionLikeUnit : public ProgramUnit {
     return *symbol;
   }
 
+  /// Return a pointer to the main program symbol for named programs
+  /// Return the null pointer for anonymous programs
+  const semantics::Symbol *getMainProgramSymbol() const {
+    if (!isMainProgram()) {
+      llvm::report_fatal_error("call only on main program.");
+    }
+    return entryPointList[activeEntry].first;
+  }
+
   /// Return a pointer to the current entry point Evaluation.
   /// This is null for a primary entry point.
   Evaluation *getEntryEval() const {
index b87ce7b..85d438c 100644 (file)
@@ -428,7 +428,7 @@ std::string Fortran::lower::CalleeInterface::getMangledName() const {
 const Fortran::semantics::Symbol *
 Fortran::lower::CalleeInterface::getProcedureSymbol() const {
   if (funit.isMainProgram())
-    return nullptr;
+    return funit.getMainProgramSymbol();
   return &funit.getSubprogramSymbol();
 }
 
@@ -529,8 +529,15 @@ void Fortran::lower::CallInterface<T>::declare() {
       mlir::Location loc = side().getCalleeLocation();
       mlir::FunctionType ty = genFunctionType();
       func = fir::FirOpBuilder::createFunction(loc, module, name, ty);
-      if (const Fortran::semantics::Symbol *sym = side().getProcedureSymbol())
-        addSymbolAttribute(func, *sym, converter.getMLIRContext());
+      if (const Fortran::semantics::Symbol *sym = side().getProcedureSymbol()) {
+        if (side().isMainProgram()) {
+          func->setAttr(fir::getSymbolAttrName(),
+                        mlir::StringAttr::get(&converter.getMLIRContext(),
+                                              sym->name().ToString()));
+        } else {
+          addSymbolAttribute(func, *sym, converter.getMLIRContext());
+        }
+      }
       for (const auto &placeHolder : llvm::enumerate(inputs))
         if (!placeHolder.value().attributes.empty())
           func.setArgAttrs(placeHolder.index(), placeHolder.value().attributes);
index 0282f16..ea0ff45 100644 (file)
@@ -2,7 +2,7 @@
 
 ! This test checks the lowering of atomic read
 
-!CHECK: func @_QQmain() {
+!CHECK: func @_QQmain() attributes {fir.bindc_name = "ompatomic"} {
 !CHECK: %[[VAR_A:.*]] = fir.alloca !fir.char<1> {bindc_name = "a", uniq_name = "_QFEa"}
 !CHECK: %[[VAR_B:.*]] = fir.alloca !fir.char<1> {bindc_name = "b", uniq_name = "_QFEb"}
 !CHECK: %[[VAR_C:.*]] = fir.alloca !fir.logical<4> {bindc_name = "c", uniq_name = "_QFEc"}
index 3ca7d95..5dd90c0 100644 (file)
@@ -10,7 +10,7 @@ program OmpAtomicUpdate
     a=>c
     b=>d
 
-!CHECK: func.func @_QQmain() {
+!CHECK: func.func @_QQmain() attributes {fir.bindc_name = "ompatomicupdate"} {
 !CHECK: %[[A:.*]] = fir.alloca !fir.box<!fir.ptr<i32>> {bindc_name = "a", uniq_name = "_QFEa"}
 !CHECK: %[[A_ADDR:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFEa.addr"}
 !CHECK: %{{.*}} = fir.zero_bits !fir.ptr<i32>
index ed82090..d8e5e90 100644 (file)
@@ -2,7 +2,7 @@
 
 ! This test checks the lowering of atomic write
 
-!CHECK: func @_QQmain() {
+!CHECK: func @_QQmain() attributes {fir.bindc_name = "ompatomicwrite"} {
 !CHECK: %[[VAR_X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
 !CHECK: %[[VAR_Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
 !CHECK: %[[VAR_Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"}
index 7ad357c..4f4da79 100644 (file)
@@ -5,7 +5,7 @@
 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
 
 
-!CHECK: func @_QQmain() {
+!CHECK: func @_QQmain() attributes {fir.bindc_name = "default_clause_lowering"} {
 !CHECK: %[[W:.*]] = fir.alloca i32 {bindc_name = "w", uniq_name = "_QFEw"}
 !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
 !CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
index 6e58607..99b0cf0 100644 (file)
@@ -7,7 +7,7 @@ program wsloop
         integer :: i
         integer :: chunk
 
-! CHECK-LABEL: func.func @_QQmain() {
+! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "wsloop"} {
 ! CHECK:         %[[VAL_0:.*]] = fir.alloca i32 {bindc_name = "chunk", uniq_name = "_QFEchunk"}
 
 !$OMP DO SCHEDULE(static, 4)
index bb17af3..358f317 100644 (file)
@@ -2,7 +2,7 @@
 
 ! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
 
-!CHECK: func @_QQmain() {
+!CHECK: func @_QQmain() attributes {fir.bindc_name = "sample"} {
 !CHECK:   %[[COUNT:.*]] = fir.address_of(@_QFEcount) : !fir.ref<i32>
 !CHECK:   %[[ETA:.*]] = fir.alloca f32 {bindc_name = "eta", uniq_name = "_QFEeta"}
 !CHECK:   %[[CONST_1:.*]] = arith.constant 1 : i32
index 91fcaa9..d4fd340 100644 (file)
@@ -53,7 +53,7 @@ subroutine issue(c1, c2)
   ! CHECK:       }
 end subroutine
 
-! CHECK-LABEL: func @_QQmain() {
+! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "p"} {
 program p
   ! CHECK-DAG: %[[VAL_0:.*]] = arith.constant 4 : index
   ! CHECK-DAG: %[[VAL_1:.*]] = arith.constant 3 : index
index cfea862..ba1b923 100644 (file)
@@ -1,6 +1,6 @@
 ! RUN: bbc -o - --outline-intrinsics %s | FileCheck %s
 
-! CHECK-LABEL: func @_QQmain() {
+! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "p"} {
 ! CHECK-DAG:         %[[VAL_0:.*]] = arith.constant 10 : index
 ! CHECK-DAG:         %[[VAL_4:.*]] = arith.constant 2 : index
 ! CHECK-DAG:         %[[VAL_5:.*]] = arith.constant 1 : index
index da693cc..5a0e4bd 100644 (file)
@@ -8,6 +8,6 @@ end program
 ! CHECK:   1 EndProgramStmt: end program
 ! CHECK: End Program basic
 
-! FIR-LABEL: func @_QQmain() {
+! FIR-LABEL: func @_QQmain() attributes {fir.bindc_name = "basic"} {
 ! FIR:         return
 ! FIR:       }
index b9e27e8..a413b12 100644 (file)
@@ -13,7 +13,7 @@ program i128
   print*,y
 end
 
-! CHECK-LABEL: func.func @_QQmain() {
+! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "i128"} {
 ! CHECK-COUNT-2:  %{{.*}} = fir.call @_FortranAioOutputInteger128(%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i8>, i128) -> i1
 
 
index d2280be..8de16bc 100644 (file)
@@ -212,7 +212,7 @@ program p
   print *, 'end of program'
 end program
 
-! CHECK-LABEL: func.func @_QQmain() {
+! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "p"} {
 ! CHECK: %[[T:.*]] = fir.alloca !fir.type<_QMderived_type_finalizationTt1{a:i32}> {bindc_name = "t", uniq_name = "_QFEt"}
 ! CHECK: cf.cond_br %{{.*}}, ^bb1, ^bb2
 ! CHECK: ^bb1:
index 47f436a..d976522 100644 (file)
@@ -1,6 +1,6 @@
 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
 
-! CHECK-LABEL: func @_QQmain() {
+! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "nested_where"} {
 program nested_where
 
   ! CHECK:  %[[VAL_0:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
index 9525ba9..6935261 100644 (file)
@@ -945,7 +945,7 @@ program test
   l = i < o%inner
 end program
 
-! CHECK-LABEL: func.func @_QQmain() {
+! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "test"} {
 ! CHECK: %[[ADDR_O:.*]] = fir.address_of(@_QFEo) : !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>>
 ! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ADDR_O]] : (!fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>>) -> !fir.ref<!fir.box<none>>
 ! CHECK: %{{.*}} = fir.call @_FortranAAllocatableAllocate(%[[BOX_NONE]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
index cb9e00f..348849f 100644 (file)
@@ -126,7 +126,7 @@ subroutine should_not_collide()
 ! CHECK: }
 end subroutine
 
-! CHECK-LABEL: func @_QQmain() {
+! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "test"} {
 program test
 ! CHECK: }
 contains
index 99ede9d..6631075 100644 (file)
@@ -4,7 +4,7 @@ program basic
   return
 end program
 
-! CHECK-LABEL: func @_QQmain() {
+! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "basic"} {
 ! CHECK:         return
 ! CHECK:       }