Skip to content

Commit a36b54b

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

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
@@ -385,15 +385,6 @@ std::pair<MemoryLocationRange, bool> aggregate(
385385
break;
386386
}
387387
unsigned int TripCount = 0;
388-
/*if (C->getLoop()->getLoopLatch() == C->getLoop()->getExitingBlock()) {
389-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Node kind: Latch and Exiting.\n");
390-
TripCount = SE->getSmallConstantTripCount(C->getLoop());
391-
} else {
392-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Node kind: Latch or Exiting.\n");
393-
auto BTC = SE->getBackedgeTakenCount(C->getLoop());
394-
if (isa<SCEVConstant>(BTC))
395-
TripCount = cast<SCEVConstant>(BTC)->getAPInt().getZExtValue();
396-
}*/
397388
if (C->getLoop()->getLoopLatch() == C->getLoop()->getExitingBlock()) {
398389
LLVM_DEBUG(dbgs() << "[AGGREGATE] Node kind: Latch and Exiting.\n");
399390
TripCount = SE->getSmallConstantTripCount(C->getLoop());
@@ -524,7 +515,8 @@ std::pair<MemoryLocationRange, bool> aggregate(
524515
getSExtValue() >= DimInfo.DimSize && DimensionN != 0 && N != nullptr) {
525516
auto End = cast<SCEVConstant>(DimInfo.End)->getAPInt().
526517
getSExtValue();
527-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds. End = " << End << ", DimSize = " << DimInfo.DimSize << "\n");
518+
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds. End = " <<
519+
End << ", DimSize = " << DimInfo.DimSize << "\n");
528520
break;
529521
}
530522
ResLoc.DimList.push_back(DimInfo);
@@ -891,7 +883,7 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
891883
DU->addExplicitAccess(ALoc);
892884
auto ColLoc = aggregate(nullptr, nullptr, ALoc, DFF).first;
893885
if (ColLoc.Kind == MemoryLocationRange::LocKind::Collapsed) {
894-
DU->addExplicitAccessNode(ALoc.Ptr, N);
886+
DU->addNodeOfCollapsableExplicitAccess(ALoc, ColLoc, N);
895887
}
896888
}
897889
}
@@ -1114,22 +1106,6 @@ void ReachDFFwk::collapse(DFRegion *R) {
11141106
LLVM_DEBUG(printLocInfo("[COLLAPSE] Collapse Use location: ", Loc));
11151107
distribute(aggregate(R, N, Loc, this), Loc, OwnUses, OtherUses);
11161108
}
1117-
/*LLVM_DEBUG(
1118-
dbgs() << "[COLLAPSE] OwnUses:\n";
1119-
for (auto &Loc : OwnUses)
1120-
printLocationSource(dbgs(), Loc, &getDomTree(), true); dbgs() << "\n";
1121-
dbgs() << "[COLLAPSE] OtherUses:\n";
1122-
for (auto &Pair : OtherUses) {
1123-
printLocationSource(dbgs(), Pair.first, &getDomTree(), true); dbgs() << "\n";
1124-
printLocationSource(dbgs(), Pair.second, &getDomTree(), true); dbgs() << "\n";
1125-
}
1126-
);
1127-
OwnUses.clarify(OtherUses);
1128-
LLVM_DEBUG(
1129-
dbgs() << "[COLLAPSE] OwnUses after clarify:\n";
1130-
for (auto &Loc : OwnUses)
1131-
printLocationSource(dbgs(), Loc, &getDomTree(), true); dbgs() << "\n";
1132-
);*/
11331109
for (auto &Loc : OwnUses) {
11341110
SmallVector<MemoryLocationRange, 4> UseDiff;
11351111
if (MustReachIn.subtractFrom(Loc, UseDiff)) {
@@ -1252,10 +1228,13 @@ void ReachDFFwk::collapse(DFRegion *R) {
12521228
EM = EM->getTopLevelParent();
12531229
}
12541230
LLVM_DEBUG(printLocInfo("[COLLAPSE] Collapse Explicit Access: ", Loc));
1255-
auto *DFNS = DefUse->getCollapExpAccessNodes(Loc.Ptr);
1256-
if (!DFNS)
1257-
continue;
1258-
for (auto *N : *DFNS) {
1231+
auto *DFNS = DefUse->getNodesOfCollapsableExplicitAccess(Loc);
1232+
llvm::SmallVector<const DFNode *, 4> Nodes;
1233+
if (DFNS)
1234+
Nodes.append(DFNS->begin(), DFNS->end());
1235+
if (Nodes.empty())
1236+
Nodes.push_back(nullptr);
1237+
for (auto *N : Nodes) {
12591238
MemoryLocationRange ExpLoc = aggregate(R, N, Loc, this).first;
12601239
MemoryLocationRange NewLoc(Loc);
12611240
NewLoc.Kind |= MemoryLocationRange::LocKind::Hint;

0 commit comments

Comments
 (0)