@@ -51,6 +51,30 @@ STATISTIC(NumMergedNode, "Number of alias nodes merged in");
5151STATISTIC (NumEstimateMemory, " Number of estimate memory created" );
5252STATISTIC (NumUnknownMemory, " Number of unknown memory created" );
5353
54+ static inline void clarifyUnknownSize (const DataLayout &DL,
55+ MemoryLocation &Loc, const DominatorTree *DT = nullptr ) {
56+ if (Loc.Size .hasValue ())
57+ return ;
58+ if (auto GV = dyn_cast<GlobalValue>(Loc.Ptr )) {
59+ auto Ty = GV->getValueType ();
60+ if (Ty->isSized ())
61+ Loc.Size = LocationSize::precise (DL.getTypeStoreSize (Ty));
62+ } else if (auto AI = dyn_cast<AllocaInst>(Loc.Ptr )) {
63+ auto Ty = AI->getAllocatedType ();
64+ auto Size = AI->getArraySize ();
65+ if (Ty->isSized () && isa<ConstantInt>(Size))
66+ Loc.Size = LocationSize::precise (
67+ cast<ConstantInt>(Size)->getValue ().getZExtValue () *
68+ DL.getTypeStoreSize (Ty));
69+ }
70+ LLVM_DEBUG (if (Loc.Size .hasValue ()) {
71+ dbgs ()
72+ << " [ALIAS TREE]: decrease the location size to the allocated size: " ;
73+ printLocationSource (dbgs (), Loc, DT);
74+ dbgs () << " \n " ;
75+ });
76+ }
77+
5478namespace tsar {
5579Value * stripPointer (const DataLayout &DL, Value *Ptr) {
5680 assert (Ptr && " Pointer to memory location must not be null!" );
@@ -179,18 +203,7 @@ bool stripMemoryLevel(const DataLayout &DL, MemoryLocation &Loc) {
179203 return true ;
180204 }
181205 Loc.Size = LocationSize::unknown ();
182- if (auto GV = dyn_cast<GlobalValue>(Loc.Ptr )) {
183- auto Ty = GV->getValueType ();
184- if (Ty->isSized ())
185- Loc.Size = LocationSize::precise (DL.getTypeStoreSize (Ty));
186- } else if (auto AI = dyn_cast<AllocaInst>(Loc.Ptr )) {
187- auto Ty = AI->getAllocatedType ();
188- auto Size = AI->getArraySize ();
189- if (Ty->isSized () && isa<ConstantInt>(Size))
190- Loc.Size = LocationSize::precise (
191- cast<ConstantInt>(Size)->getValue ().getZExtValue () *
192- DL.getTypeStoreSize (Ty));
193- }
206+ clarifyUnknownSize (DL, Loc);
194207 return true ;
195208 }
196209 return false ;
@@ -491,6 +504,7 @@ void AliasTree::add(const MemoryLocation &Loc) {
491504 mSearchCache .clear ();
492505 using CT = bcl::ChainTraits<EstimateMemory, Hierarchy>;
493506 MemoryLocation Base (Loc);
507+ clarifyUnknownSize (*mDL , Base, mDT );
494508 EstimateMemory *PrevChainEnd = nullptr ;
495509 do {
496510 LLVM_DEBUG (evaluateMemoryLevelLog (Base, getDomTree ()));
@@ -831,6 +845,7 @@ const AliasUnknownNode * AliasTree::findUnknown(
831845const EstimateMemory * AliasTree::find (const llvm::MemoryLocation &Loc) const {
832846 assert (Loc.Ptr && " Pointer to memory location must not be null!" );
833847 MemoryLocation Base (Loc);
848+ clarifyUnknownSize (*mDL , Base, mDT );
834849 stripToBase (*mDL , Base);
835850 auto SearchInfo = mSearchCache .try_emplace (Base, nullptr );
836851 if (!SearchInfo.second )
@@ -1014,8 +1029,8 @@ bool EstimateMemoryPass::runOnFunction(Function &F) {
10141029 AccessedUnknown.insert (&I);
10151030 mAliasTree ->addUnknown (&I);
10161031 };
1017- for_each_memory (F, TLI, [&addLocation](
1018- Instruction &, MemoryLocation &&Loc, unsigned , AccessInfo, AccessInfo) {
1032+ for_each_memory (F, TLI, [&DL, & addLocation](
1033+ Instruction &I , MemoryLocation &&Loc, unsigned , AccessInfo, AccessInfo) {
10191034 addLocation (std::move (Loc));
10201035 },
10211036 [&addUnknown](Instruction &I, AccessInfo, AccessInfo) {
0 commit comments