Skip to content

Commit 7299f21

Browse files
committed
Applying formatting
1 parent 6dc41a6 commit 7299f21

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) {
5151
v, fir::GlobalOp::getTargetAttrName(globalOpName));
5252
}
5353

54-
mlir::Value getOriginalDef(mlir::Value v) {
54+
static mlir::Value getOriginalDef(mlir::Value v) {
5555
mlir::Operation *defOp;
5656
bool breakFromLoop = false;
5757
while (!breakFromLoop && (defOp = v.getDefiningOp())) {
@@ -578,16 +578,6 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
578578
breakFromLoop = true;
579579
})
580580
.Case<fir::LoadOp>([&](auto op) {
581-
// If the load is from a leaf source, return the leaf. Do not track
582-
// through indirections otherwise.
583-
// TODO: Add support to fir.alloca and fir.allocmem
584-
auto def = getOriginalDef(op.getMemref());
585-
if (isDummyArgument(def) ||
586-
def.template getDefiningOp<fir::AddrOfOp>()) {
587-
v = def;
588-
defOp = v.getDefiningOp();
589-
return;
590-
}
591581
// If load is inside target and it points to mapped item,
592582
// continue tracking.
593583
Operation *loadMemrefOp = op.getMemref().getDefiningOp();
@@ -600,6 +590,41 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
600590
defOp = v.getDefiningOp();
601591
return;
602592
}
593+
594+
// If we are loading a box reference, but following the data,
595+
// we gather the attributes of the box to populate the source
596+
// and stop tracking.
597+
if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty);
598+
boxTy && followingData) {
599+
600+
if (mlir::isa<fir::PointerType>(boxTy.getEleTy())) {
601+
attributes.set(Attribute::Pointer);
602+
}
603+
604+
auto def = getOriginalDef(op.getMemref());
605+
if (auto addrOfOp = def.template getDefiningOp<fir::AddrOfOp>()) {
606+
global = addrOfOp.getSymbol();
607+
608+
if (hasGlobalOpTargetAttr(def, addrOfOp))
609+
attributes.set(Attribute::Target);
610+
611+
type = SourceKind::Global;
612+
}
613+
614+
// TODO: Add support to fir.alloca and fir.allocmem
615+
// if (auto allocOp = def.template getDefiningOp<fir::AllocaOp>()) {
616+
// ...
617+
// }
618+
619+
if (isDummyArgument(def)) {
620+
defOp = nullptr;
621+
v = def;
622+
}
623+
624+
breakFromLoop = true;
625+
return;
626+
}
627+
603628
// No further tracking for addresses loaded from memory for now.
604629
type = SourceKind::Indirect;
605630
breakFromLoop = true;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@
4949

5050
// TODO: Can the address in a pointer alias the address of a pointer, even when the
5151
// pointer has no box. Should this be NoAlias?
52-
// T3: CHECK-DAG: p1.addr#0 <-> p1.tgt#0: MayAlias
52+
// T3:
53+
// CHECK-DAG: p1.addr#0 <-> p1.tgt#0: MayAlias
5354

5455
// The addresses stored in two different pointers can alias, even if one has no
5556
// box. In this program, they happen to be the same address.
56-
// T4: CHECK-DAG: p1.tgt#0 <-> boxp1.addr#0: MayAlias
57+
// T4:
58+
// CHECK-DAG: p1.tgt#0 <-> boxp1.addr#0: MayAlias
5759

5860
func.func @_QFPtest(%arg0: !fir.ref<f32> {fir.bindc_name = "v1", fir.target}, %arg1: !fir.ref<f32> {fir.bindc_name = "v2", fir.target}, %arg2: !fir.ref<!fir.box<!fir.ptr<f32>>> ) attributes {test.ptr = "func"} {
5961

0 commit comments

Comments
 (0)