@@ -108,12 +108,11 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
108
108
auto lhsSrc = getSource (lhs);
109
109
auto rhsSrc = getSource (rhs);
110
110
bool approximateSource = lhsSrc.approximateSource || rhsSrc.approximateSource ;
111
- LLVM_DEBUG (llvm::dbgs () << " AliasAnalysis::alias\n " ;
111
+ LLVM_DEBUG (llvm::dbgs () << " \n " ; llvm::dbgs () << " AliasAnalysis::alias\n " ;
112
112
llvm::dbgs () << " lhs: " << lhs << " \n " ;
113
113
llvm::dbgs () << " lhsSrc: " << lhsSrc << " \n " ;
114
114
llvm::dbgs () << " rhs: " << rhs << " \n " ;
115
- llvm::dbgs () << " rhsSrc: " << rhsSrc << " \n " ;
116
- llvm::dbgs () << " \n " ;);
115
+ llvm::dbgs () << " rhsSrc: " << rhsSrc << " \n " ;);
117
116
118
117
// Indirect case currently not handled. Conservatively assume
119
118
// it aliases with everything
@@ -122,43 +121,22 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
122
121
return AliasResult::MayAlias;
123
122
}
124
123
125
- // If we have reached the same source but comparing box reference against
126
- // data we are not comparing apples-to-apples. The 2 cannot alias.
127
- if ((lhsSrc.origin .u == rhsSrc.origin .u ) &&
128
- lhsSrc.isData () != rhsSrc.isData ()) {
129
- return AliasResult::NoAlias;
130
- }
131
-
132
124
if (lhsSrc.kind == rhsSrc.kind ) {
133
125
if (lhsSrc.origin == rhsSrc.origin ) {
126
+ LLVM_DEBUG (llvm::dbgs ()
127
+ << " aliasing because same source kind and origin\n " );
134
128
if (approximateSource)
135
129
return AliasResult::MayAlias;
136
130
return AliasResult::MustAlias;
137
131
}
138
132
139
133
// Two host associated accesses may overlap due to an equivalence.
140
- if (lhsSrc.kind == SourceKind::HostAssoc)
141
- return AliasResult::MayAlias;
142
-
143
- // TARGET/POINTER arguments may alias.
144
- if (lhsSrc.isTargetOrPointer () && rhsSrc.isTargetOrPointer () &&
145
- lhsSrc.isData () == rhsSrc.isData ())
134
+ if (lhsSrc.kind == SourceKind::HostAssoc) {
135
+ LLVM_DEBUG (llvm::dbgs () << " aliasing because of host association\n " );
146
136
return AliasResult::MayAlias;
147
-
148
- // Box for POINTER component inside an object of a derived type
149
- // may alias box of a POINTER object, as well as boxes for POINTER
150
- // components inside two objects of derived types may alias.
151
- if ((lhsSrc.isRecordWithPointerComponent () && rhsSrc.isTargetOrPointer ()) ||
152
- (rhsSrc.isRecordWithPointerComponent () && lhsSrc.isTargetOrPointer ()) ||
153
- (lhsSrc.isRecordWithPointerComponent () &&
154
- rhsSrc.isRecordWithPointerComponent ()))
155
- return AliasResult::MayAlias;
156
-
157
- return AliasResult::NoAlias;
137
+ }
158
138
}
159
139
160
- assert (lhsSrc.kind != rhsSrc.kind && " memory source kinds must be different" );
161
-
162
140
Source *src1, *src2;
163
141
if (lhsSrc.kind < rhsSrc.kind ) {
164
142
src1 = &lhsSrc;
@@ -190,17 +168,21 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
190
168
191
169
// Dummy TARGET/POINTER argument may alias with a global TARGET/POINTER.
192
170
if (src1->isTargetOrPointer () && src2->isTargetOrPointer () &&
193
- src1->isData () == src2->isData ())
171
+ src1->isData () == src2->isData ()) {
172
+ LLVM_DEBUG (llvm::dbgs () << " aliasing because of target or pointer\n " );
194
173
return AliasResult::MayAlias;
174
+ }
195
175
196
176
// Box for POINTER component inside an object of a derived type
197
177
// may alias box of a POINTER object, as well as boxes for POINTER
198
178
// components inside two objects of derived types may alias.
199
179
if ((src1->isRecordWithPointerComponent () && src2->isTargetOrPointer ()) ||
200
180
(src2->isRecordWithPointerComponent () && src1->isTargetOrPointer ()) ||
201
181
(src1->isRecordWithPointerComponent () &&
202
- src2->isRecordWithPointerComponent ()))
182
+ src2->isRecordWithPointerComponent ())) {
183
+ LLVM_DEBUG (llvm::dbgs () << " aliasing because of pointer components\n " );
203
184
return AliasResult::MayAlias;
185
+ }
204
186
205
187
return AliasResult::NoAlias;
206
188
}
@@ -306,17 +288,15 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v) {
306
288
breakFromLoop = true ;
307
289
})
308
290
.Case <fir::LoadOp>([&](auto op) {
309
- if (followBoxData && mlir::isa<fir::BaseBoxType>(op.getType ())) {
310
- // For now, support the load of an argument or fir.address_of
311
- // TODO: generalize to all operations (in particular fir.alloca and
312
- // fir.allocmem)
313
- auto def = getOriginalDef (op.getMemref ());
314
- if (isDummyArgument (def) ||
315
- def.template getDefiningOp <fir::AddrOfOp>()) {
316
- v = def;
317
- defOp = v.getDefiningOp ();
318
- return ;
319
- }
291
+ // If the load is from a leaf source, return the leaf. Do not track
292
+ // through indirections otherwise.
293
+ // TODO: At support to fir.alloca and fir.allocmem
294
+ auto def = getOriginalDef (op.getMemref ());
295
+ if (isDummyArgument (def) ||
296
+ def.template getDefiningOp <fir::AddrOfOp>()) {
297
+ v = def;
298
+ defOp = v.getDefiningOp ();
299
+ return ;
320
300
}
321
301
// No further tracking for addresses loaded from memory for now.
322
302
type = SourceKind::Indirect;
0 commit comments