Skip to content

Commit 568337a

Browse files
author
Mikhail Gudim
committed
fix the memory problem
1 parent 799e1c2 commit 568337a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

llvm/include/llvm/CodeGen/ReachingDefAnalysis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ReachingDefAnalysis : public MachineFunctionPass {
142142

143143
MBBReachingDefsInfo MBBReachingDefs;
144144
using MBBFrameObjsReachingDefsInfo =
145-
std::vector<std::vector<SmallVector<int>>>;
145+
DenseMap<unsigned, DenseMap<int, SmallVector<int>>>;
146146
// MBBFrameObjsReachingDefs[i][j] is a list of instruction indices (relative
147147
// to begining of MBB) that define frame index (j +
148148
// MF->getFrameInfo().getObjectIndexBegin()) in MBB i. This is used in
@@ -188,7 +188,7 @@ class ReachingDefAnalysis : public MachineFunctionPass {
188188

189189
/// Provides the instruction id of the closest reaching def instruction of
190190
/// Reg that reaches MI, relative to the begining of MI's basic block.
191-
// Note that Reg may represent a stack slot.
191+
/// Note that Reg may represent a stack slot.
192192
int getReachingDef(MachineInstr *MI, Register Reg) const;
193193

194194
/// Return whether A and B use the same def of Reg.
@@ -317,7 +317,7 @@ class ReachingDefAnalysis : public MachineFunctionPass {
317317

318318
/// Provides the instruction of the closest reaching def instruction of
319319
/// Reg that reaches MI, relative to the begining of MI's basic block.
320-
// Note that Reg may represent a stack slot.
320+
/// Note that Reg may represent a stack slot.
321321
MachineInstr *getReachingLocalMIDef(MachineInstr *MI, Register Reg) const;
322322
};
323323

llvm/lib/CodeGen/ReachingDefAnalysis.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ static bool isFIDef(const MachineInstr &MI, int FrameIndex,
5959
int DefFrameIndex = 0;
6060
int SrcFrameIndex = 0;
6161
if (TII->isStoreToStackSlot(MI, DefFrameIndex) ||
62-
TII->isStackSlotCopy(MI, DefFrameIndex, SrcFrameIndex)) {
62+
TII->isStackSlotCopy(MI, DefFrameIndex, SrcFrameIndex))
6363
return DefFrameIndex == FrameIndex;
64-
}
6564
return false;
6665
}
6766

@@ -71,8 +70,6 @@ void ReachingDefAnalysis::enterBasicBlock(MachineBasicBlock *MBB) {
7170
"Unexpected basic block number.");
7271
MBBReachingDefs.startBasicBlock(MBBNumber, NumRegUnits);
7372

74-
MBBFrameObjsReachingDefs[MBBNumber].resize(NumStackObjects, {-1});
75-
7673
// Reset instruction counter in each basic block.
7774
CurInstr = 0;
7875

@@ -150,8 +147,16 @@ void ReachingDefAnalysis::processDefs(MachineInstr *MI) {
150147
assert(FrameIndex >= 0 && "Can't handle negative frame indicies yet!");
151148
if (!isFIDef(*MI, FrameIndex, TII))
152149
continue;
153-
MBBFrameObjsReachingDefs[MBBNumber][FrameIndex - ObjectIndexBegin]
154-
.push_back(CurInstr);
150+
if (MBBFrameObjsReachingDefs.contains(MBBNumber)) {
151+
auto Frame2InstrIdx = MBBFrameObjsReachingDefs[MBBNumber];
152+
if (Frame2InstrIdx.count(FrameIndex - ObjectIndexBegin) > 0)
153+
Frame2InstrIdx[FrameIndex - ObjectIndexBegin].push_back(CurInstr);
154+
else
155+
Frame2InstrIdx[FrameIndex - ObjectIndexBegin] = {CurInstr};
156+
} else {
157+
MBBFrameObjsReachingDefs[MBBNumber] = {
158+
{FrameIndex - ObjectIndexBegin, {CurInstr}}};
159+
}
155160
}
156161
if (!isValidRegDef(MO))
157162
continue;
@@ -307,7 +312,6 @@ void ReachingDefAnalysis::init() {
307312
NumStackObjects = MF->getFrameInfo().getNumObjects();
308313
ObjectIndexBegin = MF->getFrameInfo().getObjectIndexBegin();
309314
MBBReachingDefs.init(MF->getNumBlockIDs());
310-
MBBFrameObjsReachingDefs.resize(MF->getNumBlockIDs());
311315
// Initialize the MBBOutRegsInfos
312316
MBBOutRegsInfos.resize(MF->getNumBlockIDs());
313317
LoopTraversal Traversal;
@@ -344,8 +348,8 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, Register Reg) const {
344348

345349
if (Register::isStackSlot(Reg)) {
346350
int FrameIndex = Register::stackSlot2Index(Reg);
347-
for (int Def :
348-
MBBFrameObjsReachingDefs[MBBNumber][FrameIndex - ObjectIndexBegin]) {
351+
for (int Def : MBBFrameObjsReachingDefs.lookup(MBBNumber).lookup(
352+
FrameIndex - ObjectIndexBegin)) {
349353
if (Def >= InstId)
350354
break;
351355
DefRes = Def;

0 commit comments

Comments
 (0)