Skip to content

Commit f7bf20c

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

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
@@ -413,6 +413,7 @@ std::pair<MemoryLocationRange, bool> aggregate(
413413
break;
414414
}
415415
} else {
416+
// TODO: more adequate value
416417
TripCount = 100500;
417418
}
418419
}
@@ -521,8 +522,10 @@ std::pair<MemoryLocationRange, bool> aggregate(
521522
"Dimension bounds and step must be specified!");
522523
if (isa<SCEVConstant>(DimInfo.End) &&
523524
cast<SCEVConstant>(DimInfo.End)->getAPInt().
524-
getSExtValue() >= DimInfo.DimSize && DimensionN != 0) {
525-
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds.");
525+
getSExtValue() >= DimInfo.DimSize && DimensionN != 0 && N != nullptr) {
526+
auto End = cast<SCEVConstant>(DimInfo.End)->getAPInt().
527+
getSExtValue();
528+
LLVM_DEBUG(dbgs() << "[AGGREGATE] Array index out of bounds. End = " << End << ", DimSize = " << DimInfo.DimSize << "\n");
526529
break;
527530
}
528531
ResLoc.DimList.push_back(DimInfo);
@@ -875,7 +878,7 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
875878
DU->addExplicitAccess(ALoc);
876879
auto ColLoc = aggregate(nullptr, nullptr, ALoc, DFF).first;
877880
if (ColLoc.Kind == MemoryLocationRange::LocKind::Collapsed) {
878-
DU->addExplicitAccessAndDFNode(ALoc.Ptr, N);
881+
DU->addExplicitAccessNode(ALoc.Ptr, N);
879882
}
880883
}
881884
}
@@ -1098,7 +1101,22 @@ void ReachDFFwk::collapse(DFRegion *R) {
10981101
LLVM_DEBUG(printLocInfo("[COLLAPSE] Collapse Use location: ", Loc));
10991102
distribute(aggregate(R, N, Loc, this), Loc, OwnUses, OtherUses);
11001103
}
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+
);
11011114
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+
);*/
11021120
for (auto &Loc : OwnUses) {
11031121
SmallVector<MemoryLocationRange, 4> UseDiff;
11041122
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)