[flang-commits] [PATCH] D121171: [flang] Add ExternalNameConversionPass to flang-new pipeline

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 16 05:52:02 PDT 2022


rovka updated this revision to Diff 415788.
rovka edited the summary of this revision.
rovka added a comment.

Take 2 :)

This is adding ExternalNameConversion to the default FIR codegen pipeline, right before the FIRtoLLVM pass. This means we're no longer affecting `bbc` in any way, and also `tco` and `flang-new` will both be running it. I think I'm remembering from previous discussions that we do want `tco` and `flang-new` to be consistent about their behaviour, and this is a surefire way to achieve that (they're both calling createMLIRToLLVMPassPipeline, which in turn is calling createDefaultFIRCodeGenPassPipeline).

I think this is a good place to put it because

1. it works on FIR specifically, so we can't run it any later than this, and
2. we probably don't want other FIR passes to worry about what kind of mangling is being used, so it's best to put it last.

There's one lowering test that needs updating, because it's calling `bbc | tco`. I'm not sure why it needs this end-to-end behaviour, but if it really does I'm guessing it's better to let it run the default passes and update the test accordingly than to explicitly disable this pass.

Do we still want to add a flag to optionally disable this pass?
Also, do we want to move the pass from `flang/Optimizer/Transforms/Passes.td` to `flang/Optimizer/Codegen/CGPasses.td`, to clarify that it's a codegen pass?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121171/new/

https://reviews.llvm.org/D121171

Files:
  flang/include/flang/Tools/CLOptions.inc
  flang/test/Lower/common-block.f90


Index: flang/test/Lower/common-block.f90
===================================================================
--- flang/test/Lower/common-block.f90
+++ flang/test/Lower/common-block.f90
@@ -1,40 +1,40 @@
 ! RUN: bbc %s -o - | tco | FileCheck %s
 
-! CHECK: @_QB = common global [8 x i8] zeroinitializer
-! CHECK: @_QBx = global { float, float } { float 1.0{{.*}}, float 2.0{{.*}} }
-! CHECK: @_QBy = common global [12 x i8] zeroinitializer
-! CHECK: @_QBz = global { i32, [4 x i8], float } { i32 42, [4 x i8] undef, float 3.000000e+00 }
-! CHECK: @_QBrien = common global [1 x i8] zeroinitializer
-! CHECK: @_QBwith_empty_equiv = common global [8 x i8] zeroinitializer
+! CHECK: @__BLNK__ = common global [8 x i8] zeroinitializer
+! CHECK: @x_ = global { float, float } { float 1.0{{.*}}, float 2.0{{.*}} }
+! CHECK: @y_ = common global [12 x i8] zeroinitializer
+! CHECK: @z_ = global { i32, [4 x i8], float } { i32 42, [4 x i8] undef, float 3.000000e+00 }
+! CHECK: @rien_ = common global [1 x i8] zeroinitializer
+! CHECK: @with_empty_equiv_ = common global [8 x i8] zeroinitializer
 
-! CHECK-LABEL: _QPs0
+! CHECK-LABEL: s0_
 subroutine s0
     common // a0, b0
   
-    ! CHECK: call void @_QPs(float* bitcast ([8 x i8]* @_QB to float*), float* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @_QB, i32 0, i64 4) to float*))
+    ! CHECK: call void @s_(float* bitcast ([8 x i8]* @__BLNK__ to float*), float* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__BLNK__, i32 0, i64 4) to float*))
     call s(a0, b0)
   end subroutine s0
   
-  ! CHECK-LABEL: _QPs1
+  ! CHECK-LABEL: s1_
   subroutine s1
     common /x/ a1, b1
     data a1 /1.0/, b1 /2.0/
   
-    ! CHECK: call void @_QPs(float* getelementptr inbounds ({ float, float }, { float, float }* @_QBx, i32 0, i32 0), float* bitcast (i8* getelementptr (i8, i8* bitcast ({ float, float }* @_QBx to i8*), i64 4) to float*))
+    ! CHECK: call void @s_(float* getelementptr inbounds ({ float, float }, { float, float }* @x_, i32 0, i32 0), float* bitcast (i8* getelementptr (i8, i8* bitcast ({ float, float }* @x_ to i8*), i64 4) to float*))
     call s(a1, b1)
   end subroutine s1
   
-  ! CHECK-LABEL: _QPs2
+  ! CHECK-LABEL: s2_
   subroutine s2
     common /y/ a2, b2, c2
   
-    ! CHECK: call void @_QPs(float* bitcast ([12 x i8]* @_QBy to float*), float* bitcast (i8* getelementptr inbounds ([12 x i8], [12 x i8]* @_QBy, i32 0, i64 4) to float*))
+    ! CHECK: call void @s_(float* bitcast ([12 x i8]* @y_ to float*), float* bitcast (i8* getelementptr inbounds ([12 x i8], [12 x i8]* @y_, i32 0, i64 4) to float*))
     call s(a2, b2)
   end subroutine s2
   
   ! Test that common initialized through aliases of common members are getting
   ! the correct initializer.
-  ! CHECK-LABEL: _QPs3
+  ! CHECK-LABEL: s3_
   subroutine s3
    integer :: i = 42
    real :: x
@@ -50,22 +50,22 @@
     integer :: i, j
     common /c_in_mod/ i, j
   end module
-  ! CHECK-LABEL: _QPs4
+  ! CHECK-LABEL: s4_
   subroutine s4
     use mod_with_common
-    ! CHECK: load i32, i32* bitcast ([8 x i8]* @_QBc_in_mod to i32*)
+    ! CHECK: load i32, i32* bitcast ([8 x i8]* @c_in_mod_ to i32*)
     print *, i
-    ! CHECK: load i32, i32* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @_QBc_in_mod, i32 0, i64 4) to i32*)
+    ! CHECK: load i32, i32* bitcast (i8* getelementptr inbounds ([8 x i8], [8 x i8]* @c_in_mod_, i32 0, i64 4) to i32*)
     print *, j
   end subroutine s4
   
-  ! CHECK-LABEL: _QPs5
+  ! CHECK-LABEL: s5_
   subroutine s5
     real r(1:0)
     common /rien/ r
   end subroutine s5
   
-  ! CHECK-LABEL: _QPs6
+  ! CHECK-LABEL: s6_
   subroutine s6
     real r1(1:0), r2(1:0), x, y
     common /with_empty_equiv/ x, r1, y
Index: flang/include/flang/Tools/CLOptions.inc
===================================================================
--- flang/include/flang/Tools/CLOptions.inc
+++ flang/include/flang/Tools/CLOptions.inc
@@ -164,6 +164,7 @@
   pm.addNestedPass<mlir::FuncOp>(fir::createAbstractResultOptPass());
   fir::addCodeGenRewritePass(pm);
   fir::addTargetRewritePass(pm);
+  pm.addPass(fir::createExternalNameConversionPass());
   fir::addFIRToLLVMPass(pm);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121171.415788.patch
Type: text/x-patch
Size: 4181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220316/d871e3a9/attachment-0001.bin>


More information about the flang-commits mailing list