Skip to content

Commit 60d6c94

Browse files
committed
Review feedback
1 parent 9caba54 commit 60d6c94

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

flang/include/flang/Optimizer/Analysis/AliasAnalysis.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,22 @@ struct AliasAnalysis {
5454
// the use-def chain, to arrive at the same origin, even though the starting
5555
// points were known to not alias.
5656
//
57-
// Example:
5857
// clang-format off
59-
// fir.global @_QMtopEa : !fir.box<!fir.ptr<!fir.array<?xf32>>>
58+
// Example:
59+
// ------------------- test.f90 --------------------
60+
// module top
61+
// real, pointer :: a(:)
62+
// end module
63+
//
64+
// subroutine test()
65+
// use top
66+
// a(1) = 1
67+
// -------------------------------------------------
68+
//
69+
// flang-new -fc1 -emit-fir test.f90 -o test.fir
70+
//
71+
// ------------------- test.fir --------------------
72+
// fir.global @_QMtopEa : !fir.box<!fir.ptr<!fir.array<?xf32>>>
6073
//
6174
// func.func @_QPtest() {
6275
// %c1 = arith.constant 1 : index
@@ -69,10 +82,11 @@ struct AliasAnalysis {
6982
// fir.store %cst to %5 : !fir.ref<f32>
7083
// return
7184
// }
85+
// -------------------------------------------------
7286
//
7387
// With high level operations, such as fir.array_coor, it is possible to
74-
// reach into the data wrapped by the box (the descriptor) therefore when
75-
// asking about the memory source of the %5, we are really asking about the
88+
// reach into the data wrapped by the box (the descriptor). Therefore when
89+
// asking about the memory source of %5, we are really asking about the
7690
// source of the data of box %2.
7791
//
7892
// When asking about the source of %0 which is the address of the box, we
@@ -88,7 +102,7 @@ struct AliasAnalysis {
88102
// So in the above example, !fir.ref<f32> and !fir.box<!fir.ptr<!fir.array<?xf32>>> is data,
89103
// while !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> is not data.
90104

91-
// This generally applies to function arguments. In the example below, %arg0
105+
// This also applies to function arguments. In the example below, %arg0
92106
// is data, %arg1 is not data but a load of %arg1 is.
93107
//
94108
// func.func @_QFPtest2(%arg0: !fir.ref<f32>, %arg1: !fir.ref<!fir.box<!fir.ptr<f32>>> ) {

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
173173
return AliasResult::MayAlias;
174174
}
175175

176-
// Box for POINTER component inside an object of a derived type
177-
// may alias box of a POINTER object, as well as boxes for POINTER
178-
// components inside two objects of derived types may alias.
176+
// POINTER components may alias with POINTER objects,
177+
// as well as other POINTER components
179178
if ((src1->isRecordWithPointerComponent() && src2->isTargetOrPointer()) ||
180179
(src2->isRecordWithPointerComponent() && src1->isTargetOrPointer()) ||
181180
(src1->isRecordWithPointerComponent() &&
@@ -290,7 +289,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v) {
290289
.Case<fir::LoadOp>([&](auto op) {
291290
// If the load is from a leaf source, return the leaf. Do not track
292291
// through indirections otherwise.
293-
// TODO: At support to fir.alloca and fir.allocmem
292+
// TODO: Add support to fir.alloca and fir.allocmem
294293
auto def = getOriginalDef(op.getMemref());
295294
if (isDummyArgument(def) ||
296295
def.template getDefiningOp<fir::AddrOfOp>()) {

flang/test/Analysis/AliasAnalysis/alias-analysis-2.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func.func @_QFPtest2(%arg0: !fir.ref<f32> {fir.bindc_name = "v1", fir.target}, %
143143
// alias with the wrapped scalar _QFEvar2. We meant box_addr of _QMpointersEp
144144
// CHECK-DAG: p#0 <-> box.addr#0: NoAlias
145145

146-
// Now handling more gracefully the difference between !fir.ref<!fir.box<>> and !fir.box<>
146+
// Handling gracefully the difference between !fir.ref<!fir.box<>> and !fir.box<>
147147
// CHECK-DAG: box.addr#0 <-> func.region0#0: NoAlias
148148

149149
// var2, although it is a target, cannot alias with p

flang/test/Analysis/AliasAnalysis/alias-analysis-3.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// FIXME: a's box cannot alias with raw reference to f32 (x), so MayAlias below must be NoAlias:
2424
// CHECK: a#0 <-> func.region0#1: MayAlias
2525

26-
// pointer_dummy's box cannot alias with raw reference to f32 (x), so MayAlias below must be NoAlias:
26+
// pointer_dummy's box cannot alias with raw reference to f32 (x)
2727
// CHECK: func.region0#0 <-> func.region0#1: NoAlias
2828

2929
fir.global @_QMmEa : !fir.type<_QMmTt{pointer_component:!fir.box<!fir.ptr<f32>>}> {

flang/test/Analysis/AliasAnalysis/alias-analysis-9.fir

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717
// end module
1818

1919
// CHECK-LABEL: Testing : "_QMmPfoo"
20-
// TODO: x and y do not alias
20+
// TODO: x and y are non pointer, non target argument and therefore do not alias.
2121
// CHECK-DAG: x#0 <-> y#0: MayAlias
22+
23+
// TODO: y is not a pointer object and therefore does not alias with the x%next component.
2224
// CHECK-DAG: y#0 <-> xnext1#0: MayAlias
2325
// CHECK-DAG: y#0 <-> xnext2#0: MayAlias
2426

25-
// These however do alias
27+
// Pointer components may alias with pointer objects,
28+
// as well as other pointer components
2629
// CHECK-DAG: x#0 <-> xnext1#0: MayAlias
2730
// CHECK-DAG: x#0 <-> xnext2#0: MayAlias
31+
32+
// TODO: xnext1#0 <-> xnext2#0 are the same and therefore MustAlias but
33+
// we are currently not comparing operands involved in offset computations
2834
// CHECK-DAG: xnext1#0 <-> xnext2#0: MayAlias
2935

3036
func.func @_QMmPfoo(%arg0: !fir.ref<!fir.type<_QMmTt{next:!fir.box<!fir.ptr<!fir.type<_QMmTt>>>,i:i32}>> {fir.bindc_name = "x"}, %arg1: !fir.ref<!fir.type<_QMmTt{next:!fir.box<!fir.ptr<!fir.type<_QMmTt>>>,i:i32}>> {fir.bindc_name = "y"}) {

0 commit comments

Comments
 (0)