Skip to content

Commit 54eb89f

Browse files
authored
[flang][NFC] AliasAnalysis: Prepare for PR llvm#94242 (llvm#105899)
This PR extracts several small NFC changes from PR llvm#94242 to make it more readable.
1 parent f80c248 commit 54eb89f

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,11 @@ struct AliasAnalysis {
153153
/// Return true, if Target or Pointer attribute is set.
154154
bool isTargetOrPointer() const;
155155

156-
/// Return true, if the memory source's `valueType` is a reference type
157-
/// to an object of derived type that contains a component with POINTER
158-
/// attribute.
159-
bool isRecordWithPointerComponent() const;
160-
161156
bool isDummyArgument() const;
162157
bool isData() const;
163158
bool isBoxData() const;
164159

165160
mlir::Type getType() const;
166-
167-
/// Return true, if `ty` is a reference type to a boxed
168-
/// POINTER object or a raw fir::PointerType.
169-
static bool isPointerReference(mlir::Type ty);
170161
};
171162

172163
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
@@ -183,6 +174,15 @@ struct AliasAnalysis {
183174
/// will stop at [hl]fir.declare if it represents a dummy
184175
/// argument declaration (i.e. it has the dummy_scope operand).
185176
Source getSource(mlir::Value, bool getInstantiationPoint = false);
177+
178+
private:
179+
/// Return true, if `ty` is a reference type to an object of derived type
180+
/// that contains a component with POINTER attribute.
181+
static bool isRecordWithPointerComponent(mlir::Type ty);
182+
183+
/// Return true, if `ty` is a reference type to a boxed
184+
/// POINTER object or a raw fir::PointerType.
185+
static bool isPointerReference(mlir::Type ty);
186186
};
187187

188188
inline bool operator==(const AliasAnalysis::Source::SourceOrigin &lhs,

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ void AliasAnalysis::Source::print(llvm::raw_ostream &os) const {
6060
attributes.Dump(os, EnumToString);
6161
}
6262

63-
bool AliasAnalysis::Source::isPointerReference(mlir::Type ty) {
63+
bool AliasAnalysis::isRecordWithPointerComponent(mlir::Type ty) {
64+
auto eleTy = fir::dyn_cast_ptrEleTy(ty);
65+
if (!eleTy)
66+
return false;
67+
// TO DO: Look for pointer components
68+
return mlir::isa<fir::RecordType>(eleTy);
69+
}
70+
71+
bool AliasAnalysis::isPointerReference(mlir::Type ty) {
6472
auto eleTy = fir::dyn_cast_ptrEleTy(ty);
6573
if (!eleTy)
6674
return false;
@@ -86,15 +94,7 @@ bool AliasAnalysis::Source::isBoxData() const {
8694
origin.isData;
8795
}
8896

89-
bool AliasAnalysis::Source::isRecordWithPointerComponent() const {
90-
auto eleTy = fir::dyn_cast_ptrEleTy(valueType);
91-
if (!eleTy)
92-
return false;
93-
// TO DO: Look for pointer components
94-
return mlir::isa<fir::RecordType>(eleTy);
95-
}
96-
97-
AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
97+
AliasResult AliasAnalysis::alias(mlir::Value lhs, mlir::Value rhs) {
9898
// TODO: alias() has to be aware of the function scopes.
9999
// After MLIR inlining, the current implementation may
100100
// not recognize non-aliasing entities.
@@ -111,6 +111,7 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
111111
// it aliases with everything
112112
if (lhsSrc.kind >= SourceKind::Indirect ||
113113
rhsSrc.kind >= SourceKind::Indirect) {
114+
LLVM_DEBUG(llvm::dbgs() << " aliasing because of indirect access\n");
114115
return AliasResult::MayAlias;
115116
}
116117

@@ -169,10 +170,12 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
169170
// Box for POINTER component inside an object of a derived type
170171
// may alias box of a POINTER object, as well as boxes for POINTER
171172
// components inside two objects of derived types may alias.
172-
if ((src1->isRecordWithPointerComponent() && src2->isTargetOrPointer()) ||
173-
(src2->isRecordWithPointerComponent() && src1->isTargetOrPointer()) ||
174-
(src1->isRecordWithPointerComponent() &&
175-
src2->isRecordWithPointerComponent())) {
173+
if ((isRecordWithPointerComponent(src1->valueType) &&
174+
src2->isTargetOrPointer()) ||
175+
(isRecordWithPointerComponent(src2->valueType) &&
176+
src1->isTargetOrPointer()) ||
177+
(isRecordWithPointerComponent(src1->valueType) &&
178+
isRecordWithPointerComponent(src2->valueType))) {
176179
LLVM_DEBUG(llvm::dbgs() << " aliasing because of pointer components\n");
177180
return AliasResult::MayAlias;
178181
}
@@ -310,7 +313,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
310313

311314
// TODO: Take followBoxData into account when setting the pointer
312315
// attribute
313-
if (Source::isPointerReference(ty))
316+
if (isPointerReference(ty))
314317
attributes.set(Attribute::Pointer);
315318
global = llvm::cast<fir::AddrOfOp>(op).getSymbol();
316319
breakFromLoop = true;
@@ -387,7 +390,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
387390
if (fir::valueHasFirAttribute(v, fir::getTargetAttrName()))
388391
attributes.set(Attribute::Target);
389392

390-
if (Source::isPointerReference(ty))
393+
if (isPointerReference(ty))
391394
attributes.set(Attribute::Pointer);
392395
}
393396

0 commit comments

Comments
 (0)