Skip to content

Commit ccb60c5

Browse files
committed
[TSAR, Memory] Fix 'index out of bounds' for an initialization of a basic block.
1 parent 5999001 commit ccb60c5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

include/tsar/Analysis/Memory/DefinedMemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class DefUseSet {
393393
}
394394

395395
/// TODO: description
396-
void addExplicitAccessAndDFNode(const llvm::Value *Ptr, const DFNode *N) {
396+
void addExplicitAccessNode(const llvm::Value *Ptr, const DFNode *N) {
397397
assert(Ptr && "Location pointer must not be null!");
398398
mCollapsableExplicitAccesses.try_emplace(Ptr).first->second.insert(N);
399399
}

lib/Analysis/Memory/DefinedMemory.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ std::pair<MemoryLocationRange, bool> aggregate(
412412
break;
413413
}
414414
} else {
415+
// TODO: more adequate value
415416
TripCount = 100500;
416417
}
417418
}
@@ -520,8 +521,10 @@ std::pair<MemoryLocationRange, bool> aggregate(
520521
"Dimension bounds and step must be specified!");
521522
if (isa<SCEVConstant>(DimInfo.End) &&
522523
cast<SCEVConstant>(DimInfo.End)->getAPInt().
523-
getSExtValue() >= DimInfo.DimSize && DimensionN != 0) {
524-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds.");
524+
getSExtValue() >= DimInfo.DimSize && DimensionN != 0 && N != nullptr) {
525+
auto End = cast<SCEVConstant>(DimInfo.End)->getAPInt().
526+
getSExtValue();
527+
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds. End = " << End << ", DimSize = " << DimInfo.DimSize << "\n");
525528
break;
526529
}
527530
ResLoc.DimList.push_back(DimInfo);
@@ -888,7 +891,7 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
888891
DU->addExplicitAccess(ALoc);
889892
auto ColLoc = aggregate(nullptr, nullptr, ALoc, DFF).first;
890893
if (ColLoc.Kind == MemoryLocationRange::LocKind::Collapsed) {
891-
DU->addExplicitAccessAndDFNode(ALoc.Ptr, N);
894+
DU->addExplicitAccessNode(ALoc.Ptr, N);
892895
}
893896
}
894897
}
@@ -1111,7 +1114,22 @@ void ReachDFFwk::collapse(DFRegion *R) {
11111114
LLVM_DEBUG(printLocInfo("[COLLAPSE] Collapse Use location: ", Loc));
11121115
distribute(aggregate(R, N, Loc, this), Loc, OwnUses, OtherUses);
11131116
}
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+
);
11141127
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+
);*/
11151133
for (auto &Loc : OwnUses) {
11161134
SmallVector<MemoryLocationRange, 4> UseDiff;
11171135
if (MustReachIn.subtractFrom(Loc, UseDiff)) {

lib/Analysis/Memory/MemoryLocationRange.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ using namespace tsar;
3636
using namespace llvm;
3737

3838
#undef DEBUG_TYPE
39-
#define DEBUG_TYPE "def-mem"
39+
//#define DEBUG_TYPE "def-mem"
40+
#define DEBUG_TYPE "live-mem"
4041

4142
namespace {
4243
typedef int64_t ColumnT;

0 commit comments

Comments
 (0)