Skip to content

Commit 57ab62a

Browse files
authored
[flang] Add FIR AliasAnalysis alias() wrapper to allow external getSource() method (#115073)
Adding a wrapper around alias(mlir::Value lhs, mlir::Value rhs) to allow user to provide Source objects.
1 parent 4d12a14 commit 57ab62a

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ struct AliasAnalysis {
6060
// module top
6161
// real, pointer :: a(:)
6262
// end module
63-
//
63+
//
6464
// subroutine test()
6565
// use top
6666
// a(1) = 1
6767
// end subroutine
6868
// -------------------------------------------------
69-
//
69+
//
7070
// flang -fc1 -emit-fir test.f90 -o test.fir
7171
//
7272
// ------------------- test.fir --------------------
73-
// fir.global @_QMtopEa : !fir.box<!fir.ptr<!fir.array<?xf32>>>
74-
//
73+
// fir.global @_QMtopEa : !fir.box<!fir.ptr<!fir.array<?xf32>>>
74+
//
7575
// func.func @_QPtest() {
7676
// %c1 = arith.constant 1 : index
7777
// %cst = arith.constant 1.000000e+00 : f32
@@ -100,12 +100,12 @@ struct AliasAnalysis {
100100
// Additionally, because it is relied on in HLFIR lowering, we allow querying
101101
// on a box SSA value, which is interpreted as querying on its data.
102102
//
103-
// So in the above example, !fir.ref<f32> and !fir.box<!fir.ptr<!fir.array<?xf32>>> is data,
103+
// So in the above example, !fir.ref<f32> and !fir.box<!fir.ptr<!fir.array<?xf32>>> is data,
104104
// while !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> is not data.
105105

106106
// This also applies to function arguments. In the example below, %arg0
107107
// is data, %arg1 is not data but a load of %arg1 is.
108-
//
108+
//
109109
// func.func @_QFPtest2(%arg0: !fir.ref<f32>, %arg1: !fir.ref<!fir.box<!fir.ptr<f32>>> ) {
110110
// %0 = fir.load %arg1 : !fir.ref<!fir.box<!fir.ptr<f32>>>
111111
// ... }
@@ -183,6 +183,10 @@ struct AliasAnalysis {
183183
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
184184
const AliasAnalysis::Source &op);
185185

186+
/// Given the values and their sources, return their aliasing behavior.
187+
mlir::AliasResult alias(Source lhsSrc, Source rhsSrc, mlir::Value lhs,
188+
mlir::Value rhs);
189+
186190
/// Given two values, return their aliasing behavior.
187191
mlir::AliasResult alias(mlir::Value lhs, mlir::Value rhs);
188192

@@ -193,7 +197,8 @@ struct AliasAnalysis {
193197
/// If getInstantiationPoint is true, the search for the source
194198
/// will stop at [hl]fir.declare if it represents a dummy
195199
/// argument declaration (i.e. it has the dummy_scope operand).
196-
Source getSource(mlir::Value, bool getInstantiationPoint = false);
200+
fir::AliasAnalysis::Source getSource(mlir::Value,
201+
bool getInstantiationPoint = false);
197202

198203
private:
199204
/// Return true, if `ty` is a reference type to an object of derived type

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,19 @@ bool AliasAnalysis::Source::mayBeActualArgWithPtr(
130130
}
131131

132132
AliasResult AliasAnalysis::alias(mlir::Value lhs, mlir::Value rhs) {
133+
// A wrapper around alias(Source lhsSrc, Source rhsSrc, mlir::Value lhs,
134+
// mlir::Value rhs) This allows a user to provide Source that may be obtained
135+
// through other dialects
136+
auto lhsSrc = getSource(lhs);
137+
auto rhsSrc = getSource(rhs);
138+
return alias(lhsSrc, rhsSrc, lhs, rhs);
139+
}
140+
141+
AliasResult AliasAnalysis::alias(Source lhsSrc, Source rhsSrc, mlir::Value lhs,
142+
mlir::Value rhs) {
133143
// TODO: alias() has to be aware of the function scopes.
134144
// After MLIR inlining, the current implementation may
135145
// not recognize non-aliasing entities.
136-
auto lhsSrc = getSource(lhs);
137-
auto rhsSrc = getSource(rhs);
138146
bool approximateSource = lhsSrc.approximateSource || rhsSrc.approximateSource;
139147
LLVM_DEBUG(llvm::dbgs() << "\nAliasAnalysis::alias\n";
140148
llvm::dbgs() << " lhs: " << lhs << "\n";

0 commit comments

Comments
 (0)