Skip to content

Commit 8cc940f

Browse files
committed
[ReachingDefAnalysis] Extend the analysis to stack objects.
We track definitions of stack objects, the implementation is identical to tracking of registers. Also, added printing of all found reaching definitions for testing purposes.
1 parent 5192cb7 commit 8cc940f

File tree

3 files changed

+333
-81
lines changed

3 files changed

+333
-81
lines changed

llvm/include/llvm/CodeGen/ReachingDefAnalysis.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ class ReachingDefAnalysis : public MachineFunctionPass {
114114
private:
115115
MachineFunction *MF = nullptr;
116116
const TargetRegisterInfo *TRI = nullptr;
117+
const TargetInstrInfo *TII = nullptr;
117118
LoopTraversal::TraversalOrder TraversedMBBOrder;
118119
unsigned NumRegUnits = 0;
120+
unsigned NumStackObjects = 0;
121+
int ObjectIndexBegin = 0;
119122
/// Instruction that defined each register, relative to the beginning of the
120123
/// current basic block. When a LiveRegsDefInfo is used to represent a
121124
/// live-out register, this value is relative to the end of the basic block,
@@ -138,6 +141,13 @@ class ReachingDefAnalysis : public MachineFunctionPass {
138141
DenseMap<MachineInstr *, int> InstIds;
139142

140143
MBBReachingDefsInfo MBBReachingDefs;
144+
using MBBFrameObjsReachingDefsInfo =
145+
std::vector<std::vector<std::vector<int>>>;
146+
// MBBFrameObjsReachingDefs[i][j] is a list of instruction indicies (relative
147+
// to begining of MBB) that define frame index (j +
148+
// MF->getFrameInfo().getObjectIndexBegin()) in MBB i. This is used in
149+
// answering reaching defenition queries.
150+
MBBFrameObjsReachingDefsInfo MBBFrameObjsReachingDefs;
141151

142152
/// Default values are 'nothing happened a long time ago'.
143153
const int ReachingDefDefaultVal = -(1 << 21);
@@ -158,6 +168,7 @@ class ReachingDefAnalysis : public MachineFunctionPass {
158168
MachineFunctionPass::getAnalysisUsage(AU);
159169
}
160170

171+
void printAllReachingDefs(MachineFunction &MF);
161172
bool runOnMachineFunction(MachineFunction &MF) override;
162173

163174
MachineFunctionProperties getRequiredProperties() const override {
@@ -176,12 +187,13 @@ class ReachingDefAnalysis : public MachineFunctionPass {
176187
void traverse();
177188

178189
/// Provides the instruction id of the closest reaching def instruction of
179-
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
180-
int getReachingDef(MachineInstr *MI, MCRegister PhysReg) const;
190+
/// Reg that reaches MI, relative to the begining of MI's basic block.
191+
// Note that Reg may represent a stack slot.
192+
int getReachingDef(MachineInstr *MI, MCRegister Reg) const;
181193

182-
/// Return whether A and B use the same def of PhysReg.
194+
/// Return whether A and B use the same def of Reg.
183195
bool hasSameReachingDef(MachineInstr *A, MachineInstr *B,
184-
MCRegister PhysReg) const;
196+
MCRegister Reg) const;
185197

186198
/// Return whether the reaching def for MI also is live out of its parent
187199
/// block.
@@ -309,9 +321,9 @@ class ReachingDefAnalysis : public MachineFunctionPass {
309321
MachineInstr *getInstFromId(MachineBasicBlock *MBB, int InstId) const;
310322

311323
/// Provides the instruction of the closest reaching def instruction of
312-
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
313-
MachineInstr *getReachingLocalMIDef(MachineInstr *MI,
314-
MCRegister PhysReg) const;
324+
/// Reg that reaches MI, relative to the begining of MI's basic block.
325+
// Note that Reg may represent a stack slot.
326+
MachineInstr *getReachingLocalMIDef(MachineInstr *MI, MCRegister Reg) const;
315327
};
316328

317329
} // namespace llvm

0 commit comments

Comments
 (0)