47
47
#include < llvm/IR/Function.h>
48
48
#include < llvm/IR/Instructions.h>
49
49
#include < llvm/IR/InstIterator.h>
50
+ #include < llvm/IR/Operator.h>
50
51
#include < llvm/Support/Debug.h>
51
52
#include < functional>
52
53
@@ -276,8 +277,7 @@ std::pair<MemoryLocationRange, bool> aggregate(
276
277
auto ArrayPtr = LocInfo.first ;
277
278
if (!ArrayPtr || !ArrayPtr->isDelinearized () || !LocInfo.second ->isValid ()) {
278
279
LLVM_DEBUG (dbgs () << " [AGGREGATE] Failed to delinearize location.\n " );
279
- ResLoc.Kind = LocKind::Default;
280
- return std::make_pair (ResLoc, true );
280
+ return std::make_pair (Loc, true );
281
281
}
282
282
LLVM_DEBUG (dbgs () << " [AGGREGATE] Array info: " << *ArrayPtr->getBase () <<
283
283
" , IsAddress: " << ArrayPtr->isAddressOfVariable () << " .\n " );
@@ -292,7 +292,6 @@ std::pair<MemoryLocationRange, bool> aggregate(
292
292
auto ArraySizeInfo = arraySize (ArrayType);
293
293
if (ArraySizeInfo == std::make_tuple (0 , 1 , ArrayType) &&
294
294
ArrayPtr->getNumberOfDims () != 1 ) {
295
- LLVM_DEBUG (dbgs () << " [AGGREGATE] Failed to get array size.\n " );
296
295
ResLoc.Kind = LocKind::NonCollapsable;
297
296
return std::make_pair (ResLoc, true );
298
297
}
@@ -550,7 +549,11 @@ std::pair<MemoryLocationRange, bool> aggregate(
550
549
ResLoc.DimList .push_back (DimInfo);
551
550
ResLoc.Kind = LocKind::Collapsed;
552
551
} else {
553
- break ;
552
+ DimInfo.Start = DimInfo.End = SCEV;
553
+ DimInfo.Step = SE->getOne (Int64Ty);
554
+ ResLoc.DimList .push_back (DimInfo);
555
+ ResLoc.Kind = LocKind::Collapsed;
556
+ ++ConstMatchCount;
554
557
}
555
558
++DimensionN;
556
559
}
@@ -615,7 +618,7 @@ class AddKnownAccessFunctor :
615
618
auto AR = aliasRelation (this ->mAA , this ->mDL , mLoc , ALoc);
616
619
if (AR.template is_any <trait::CoverAlias, trait::CoincideAlias>()) {
617
620
MemoryLocationRange Loc (ALoc);
618
- if (mEM ->getParent () = = &EM)
621
+ if (mEM ->isDescendantOf (EM) && mEM ! = &EM)
619
622
Loc.Kind |= MemoryLocationRange::LocKind::Auxiliary;
620
623
addMust (Loc);
621
624
} else if (AR.template is <trait::ContainedAlias>()) {
@@ -644,14 +647,14 @@ class AddKnownAccessFunctor :
644
647
} else {
645
648
Range = MemoryLocationRange{ALoc.Ptr , 0 , mLoc .Size , ALoc.AATags };
646
649
}
647
- if (mEM ->getParent () = = &EM)
650
+ if (mEM ->isDescendantOf (EM) && mEM ! = &EM)
648
651
Range.Kind |= MemoryLocationRange::LocKind::Auxiliary;
649
652
if (this ->mDU .hasDef (Range))
650
653
continue ;
651
654
addMust (Range);
652
655
} else if (!AR.template is <trait::NoAlias>()) {
653
656
MemoryLocationRange Loc (ALoc);
654
- if (mEM ->getParent () = = &EM)
657
+ if (mEM ->isDescendantOf (EM) && mEM ! = &EM)
655
658
Loc.Kind |= MemoryLocationRange::LocKind::Auxiliary;
656
659
addMay (Loc);
657
660
}
@@ -802,8 +805,19 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
802
805
if (isMemoryMarkerIntrinsic (II->getIntrinsicID ()) ||
803
806
isDbgInfoIntrinsic (II->getIntrinsicID ()))
804
807
continue ;
805
- if (I.getType () && I.getType ()->isPointerTy ())
806
- DU->addAddressAccess (&I);
808
+ if (I.getType () && I.getType ()->isPointerTy ()) {
809
+ if (isa<GEPOperator>(I)) {
810
+ auto IsOnlyGEPUsers{true };
811
+ for_each_user_insts (I,
812
+ [&IsOnlyGEPUsers](auto *U) {
813
+ IsOnlyGEPUsers &= isa<GEPOperator>(U);
814
+ });
815
+ if (!IsOnlyGEPUsers)
816
+ DU->addAddressAccess (&I);
817
+ } else {
818
+ DU->addAddressAccess (&I);
819
+ }
820
+ }
807
821
auto isAddressAccess = [&F](const Value *V) {
808
822
if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(V)) {
809
823
if (!NullPointerIsDefined (F, CPN->getType ()->getAddressSpace ()))
@@ -818,6 +832,13 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
818
832
} else if (auto *GV{dyn_cast<GlobalValue>(V)};
819
833
GV && GV->hasGlobalUnnamedAddr ()) {
820
834
return false ;
835
+ } else if (isa<GEPOperator>(V)) {
836
+ auto IsOnlyGEPUsers{true };
837
+ for_each_user_insts (const_cast <Value &>(*V),
838
+ [&IsOnlyGEPUsers](auto *U) {
839
+ IsOnlyGEPUsers &= isa<GEPOperator>(U);
840
+ });
841
+ return !IsOnlyGEPUsers;
821
842
}
822
843
return true ;
823
844
};
@@ -1136,11 +1157,15 @@ void ReachDFFwk::collapse(DFRegion *R) {
1136
1157
const LocationSet &LS) -> bool {
1137
1158
bool AreAllCollapsedOrAuxiliary = true ;
1138
1159
bool HasCollapsed = false ;
1160
+ bool HasOtherGV = false ;
1139
1161
auto *GV{dyn_cast<GlobalValue>(getUnderlyingObject (Loc.Ptr , 0 ))};
1140
1162
for (auto &OtherLoc : LS) {
1163
+ if (&Loc == &OtherLoc)
1164
+ continue ;
1141
1165
auto *OtherGV{dyn_cast<GlobalValue>(
1142
1166
getUnderlyingObject (OtherLoc.Ptr , 0 ))};
1143
1167
if (GV == OtherGV) {
1168
+ HasOtherGV = true ;
1144
1169
if ((OtherLoc.Kind & MemoryLocationRange::LocKind::Collapsed) &&
1145
1170
!(OtherLoc.Kind & MemoryLocationRange::LocKind::Auxiliary))
1146
1171
HasCollapsed = true ;
@@ -1151,7 +1176,7 @@ void ReachDFFwk::collapse(DFRegion *R) {
1151
1176
}
1152
1177
}
1153
1178
}
1154
- if (AreAllCollapsedOrAuxiliary && HasCollapsed)
1179
+ if (AreAllCollapsedOrAuxiliary && HasCollapsed || !HasOtherGV )
1155
1180
return true ;
1156
1181
return false ;
1157
1182
};
@@ -1229,7 +1254,9 @@ void ReachDFFwk::collapse(DFRegion *R) {
1229
1254
}
1230
1255
}
1231
1256
}
1232
- if (AreAllCollapsed && SameUnderlyingObjCount > 1 )
1257
+ if (AreAllCollapsed && SameUnderlyingObjCount > 1 ||
1258
+ Loc.Kind == MemoryLocationRange::LocKind::Auxiliary &&
1259
+ SameUnderlyingObjCount == 1 && AreAllCollapsed)
1233
1260
SkipExcessUse = true ;
1234
1261
} else if (Loc.Kind & MemoryLocationRange::LocKind::Auxiliary) {
1235
1262
SkipExcessUse = MaySkipAuxiliaryLocation (Loc, NewUses);
0 commit comments