Skip to content

Commit fd1c2e8

Browse files
committed
[TSAR, Memory] Fix filling of sets Def, MayDef and Use with memory locations of kind 'Hint'.
1 parent f7bf20c commit fd1c2e8

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed

include/tsar/Analysis/Memory/DefinedMemory.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class DefUseSet {
9595

9696
/// Set of data flow nodes with which memory locations from the
9797
/// ExplicitAccesses set are associated.
98-
typedef llvm::DenseMap<const llvm::Value *, llvm::DenseSet<const DFNode *>>
99-
ExplicitNodeMap;
98+
typedef llvm::SmallDenseMap<const llvm::Value *,
99+
llvm::SmallDenseSet<const DFNode *>> ExplicitNodeMap;
100100

101101
/// Returns set of the must defined locations.
102102
const LocationSet & getDefs() const { return mDefs; }
@@ -392,18 +392,26 @@ class DefUseSet {
392392
.second;
393393
}
394394

395-
/// TODO: description
396-
void addExplicitAccessNode(const llvm::Value *Ptr, const DFNode *N) {
397-
assert(Ptr && "Location pointer must not be null!");
398-
mCollapsableExplicitAccesses.try_emplace(Ptr).first->second.insert(N);
395+
/// Inserts a data flow node associated with a collapsable explicit access
396+
/// ExplLoc. ColLoc is a collapsed memory location created from the ExplLoc.
397+
void addNodeOfCollapsableExplicitAccess(
398+
const MemoryLocationRange &ExplLoc,
399+
const MemoryLocationRange &ColLoc,
400+
const DFNode *N) {
401+
assert(ExplLoc.Ptr && "Location pointer must not be null!");
402+
assert(ColLoc.Kind == MemoryLocationRange::LocKind::Collapsed &&
403+
"Location must be of a `collapsed` kind!");
404+
mCollapsableExplicitAccesses.try_emplace(ExplLoc.Ptr).first->second.insert(N);
399405
}
400406

401-
/// TODO: description
407+
/// Returns a map of collapsable explicit accesses with associated data flow
408+
/// nodes.
402409
const ExplicitNodeMap & getCollapsableExplicitAccesses() const {
403410
return mCollapsableExplicitAccesses;
404411
}
405412

406-
/// TODO: description
413+
/// Specifies that there are a collapsable explicit access to all collapsable
414+
/// explicit accesses from a specified map.
407415
void addCollapsableExplicitAccesses(const ExplicitNodeMap &ENM) {
408416
for (auto Itr = ENM.begin(); Itr != ENM.end(); ++Itr) {
409417
auto &NodeList = Itr->second;
@@ -412,10 +420,11 @@ class DefUseSet {
412420
}
413421
}
414422

415-
/// TODO: description
416-
const llvm::DenseSet<const DFNode *> *
417-
getCollapExpAccessNodes(const llvm::Value *Ptr) const {
418-
auto Itr = mCollapsableExplicitAccesses.find(Ptr);
423+
/// Returns a pointer to a set of data flow nodes associated with the memory
424+
/// location Loc if it is collabsable. Returns `nullptr` otherwise.
425+
const llvm::SmallDenseSet<const DFNode *> *
426+
getNodesOfCollapsableExplicitAccess(const MemoryLocationRange &Loc) const {
427+
auto Itr = mCollapsableExplicitAccesses.find(Loc.Ptr);
419428
return Itr == mCollapsableExplicitAccesses.end() ? nullptr : &Itr->second;
420429
}
421430

lib/Analysis/Memory/DefinedMemory.cpp

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,6 @@ std::pair<MemoryLocationRange, bool> aggregate(
386386
break;
387387
}
388388
unsigned int TripCount = 0;
389-
/*if (C->getLoop()->getLoopLatch() == C->getLoop()->getExitingBlock()) {
390-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Node kind: Latch and Exiting.\n");
391-
TripCount = SE->getSmallConstantTripCount(C->getLoop());
392-
} else {
393-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Node kind: Latch or Exiting.\n");
394-
auto BTC = SE->getBackedgeTakenCount(C->getLoop());
395-
if (isa<SCEVConstant>(BTC))
396-
TripCount = cast<SCEVConstant>(BTC)->getAPInt().getZExtValue();
397-
}*/
398389
if (C->getLoop()->getLoopLatch() == C->getLoop()->getExitingBlock()) {
399390
LLVM_DEBUG(dbgs() << "[AGGREGATE] Node kind: Latch and Exiting.\n");
400391
TripCount = SE->getSmallConstantTripCount(C->getLoop());
@@ -525,7 +516,8 @@ std::pair<MemoryLocationRange, bool> aggregate(
525516
getSExtValue() >= DimInfo.DimSize && DimensionN != 0 && N != nullptr) {
526517
auto End = cast<SCEVConstant>(DimInfo.End)->getAPInt().
527518
getSExtValue();
528-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds. End = " << End << ", DimSize = " << DimInfo.DimSize << "\n");
519+
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds. End = " <<
520+
End << ", DimSize = " << DimInfo.DimSize << "\n");
529521
break;
530522
}
531523
ResLoc.DimList.push_back(DimInfo);
@@ -878,7 +870,7 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
878870
DU->addExplicitAccess(ALoc);
879871
auto ColLoc = aggregate(nullptr, nullptr, ALoc, DFF).first;
880872
if (ColLoc.Kind == MemoryLocationRange::LocKind::Collapsed) {
881-
DU->addExplicitAccessNode(ALoc.Ptr, N);
873+
DU->addNodeOfCollapsableExplicitAccess(ALoc, ColLoc, N);
882874
}
883875
}
884876
}
@@ -1101,22 +1093,6 @@ void ReachDFFwk::collapse(DFRegion *R) {
11011093
LLVM_DEBUG(printLocInfo("[COLLAPSE] Collapse Use location: ", Loc));
11021094
distribute(aggregate(R, N, Loc, this), Loc, OwnUses, OtherUses);
11031095
}
1104-
/*LLVM_DEBUG(
1105-
dbgs() << "[COLLAPSE] OwnUses:\n";
1106-
for (auto &Loc : OwnUses)
1107-
printLocationSource(dbgs(), Loc, &getDomTree(), true); dbgs() << "\n";
1108-
dbgs() << "[COLLAPSE] OtherUses:\n";
1109-
for (auto &Pair : OtherUses) {
1110-
printLocationSource(dbgs(), Pair.first, &getDomTree(), true); dbgs() << "\n";
1111-
printLocationSource(dbgs(), Pair.second, &getDomTree(), true); dbgs() << "\n";
1112-
}
1113-
);
1114-
OwnUses.clarify(OtherUses);
1115-
LLVM_DEBUG(
1116-
dbgs() << "[COLLAPSE] OwnUses after clarify:\n";
1117-
for (auto &Loc : OwnUses)
1118-
printLocationSource(dbgs(), Loc, &getDomTree(), true); dbgs() << "\n";
1119-
);*/
11201096
for (auto &Loc : OwnUses) {
11211097
SmallVector<MemoryLocationRange, 4> UseDiff;
11221098
if (MustReachIn.subtractFrom(Loc, UseDiff)) {
@@ -1239,10 +1215,13 @@ void ReachDFFwk::collapse(DFRegion *R) {
12391215
EM = EM->getTopLevelParent();
12401216
}
12411217
LLVM_DEBUG(printLocInfo("[COLLAPSE] Collapse Explicit Access: ", Loc));
1242-
auto *DFNS = DefUse->getCollapExpAccessNodes(Loc.Ptr);
1243-
if (!DFNS)
1244-
continue;
1245-
for (auto *N : *DFNS) {
1218+
auto *DFNS = DefUse->getNodesOfCollapsableExplicitAccess(Loc);
1219+
llvm::SmallVector<const DFNode *, 4> Nodes;
1220+
if (DFNS)
1221+
Nodes.append(DFNS->begin(), DFNS->end());
1222+
if (Nodes.empty())
1223+
Nodes.push_back(nullptr);
1224+
for (auto *N : Nodes) {
12461225
MemoryLocationRange ExpLoc = aggregate(R, N, Loc, this).first;
12471226
MemoryLocationRange NewLoc(Loc);
12481227
NewLoc.Kind |= MemoryLocationRange::LocKind::Hint;

0 commit comments

Comments
 (0)