llvm.org GIT mirror llvm / 10382fb
More VNInfo tweaking, plus a little progress on intra-block splitting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73750 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 11 years ago
4 changed file(s) with 92 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
3939 /// Care must be taken in interpreting the def index of the value. The
4040 /// following rules apply:
4141 ///
42 /// If the isDefAccurate() method returns false then the def index does not
43 /// actually point to the defining MachineInstr, or even (necessarily) a
44 /// valid MachineInstr at all. In general such a def index should not be
45 /// used as an index to obtain a MachineInstr. The exception is Values
46 /// defined by PHI instructions, after PHI elimination has occured. In this
47 /// case the def should point to the start of the block in which the PHI
48 /// existed. This fact can be used to insert code dealing with the PHI value
49 /// at the merge point (e.g. to spill or split it).
42 /// If the isDefAccurate() method returns false then def does not contain the
43 /// index of the defining MachineInstr, or even (necessarily) to a
44 /// MachineInstr at all. In general such a def index is not meaningful
45 /// and should not be used. The exception is that, for values originally
46 /// defined by PHI instructions, after PHI elimination def will contain the
47 /// index of the MBB in which the PHI originally existed. This can be used
48 /// to insert code (spills or copies) which deals with the value, which will
49 /// be live in to the block.
5050
5151 class VNInfo {
5252 private:
583583
584584 // Replace the interval with one of a NEW value number. Note that this
585585 // value number isn't actually defined by an instruction, weird huh? :)
586 LiveRange LR(Start, End, interval.getNextValue(Start, 0, false, VNInfoAllocator));
586 LiveRange LR(Start, End,
587 interval.getNextValue(mbb->getNumber(), 0, false, VNInfoAllocator));
587588 LR.valno->setIsPHIDef(true);
588589 DOUT << " replace range with " << LR;
589590 interval.addRange(LR);
784785 }
785786 }
786787
787 VNInfo *vni = interval.getNextValue(start, 0, false, VNInfoAllocator);
788 VNInfo *vni =
789 interval.getNextValue(MBB->getNumber(), 0, false, VNInfoAllocator);
788790 vni->setIsPHIDef(true);
789791 LiveRange LR(start, end, vni);
790792
3838 VirtRegMap *vrm;
3939
4040 /// Construct a spiller base.
41 SpillerBase(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls, VirtRegMap *vrm) :
41 SpillerBase(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls,
42 VirtRegMap *vrm) :
4243 mf(mf), lis(lis), ls(ls), vrm(vrm)
4344 {
4445 mfi = mf->getFrameInfo();
8485 unsigned insertStoreFor(MachineInstr *mi, unsigned ss,
8586 unsigned vreg,
8687 const TargetRegisterClass *trc) {
88
8789 MachineBasicBlock::iterator nextInstItr(mi);
8890 ++nextInstItr;
8991
102104 lis->InsertMachineInstrInMaps(storeInst, storeInstIdx);
103105
104106 return storeInstIdx;
107 }
108
109 void insertStoreOnInterval(LiveInterval *li,
110 MachineInstr *mi, unsigned ss,
111 unsigned vreg,
112 const TargetRegisterClass *trc) {
113
114 unsigned storeInstIdx = insertStoreFor(mi, ss, vreg, trc);
115 unsigned start = lis->getDefIndex(lis->getInstructionIndex(mi)),
116 end = lis->getUseIndex(storeInstIdx);
117
118 VNInfo *vni =
119 li->getNextValue(storeInstIdx, 0, true, lis->getVNInfoAllocator());
120 vni->kills.push_back(storeInstIdx);
121 LiveRange lr(start, end, vni);
122
123 li->addRange(lr);
105124 }
106125
107126 /// Insert a load of the given veg from the given stack slot immediately
129148 return loadInstIdx;
130149 }
131150
151 void insertLoadOnInterval(LiveInterval *li,
152 MachineInstr *mi, unsigned ss,
153 unsigned vreg,
154 const TargetRegisterClass *trc) {
155
156 unsigned loadInstIdx = insertLoadFor(mi, ss, vreg, trc);
157 unsigned start = lis->getDefIndex(loadInstIdx),
158 end = lis->getUseIndex(lis->getInstructionIndex(mi));
159
160 VNInfo *vni =
161 li->getNextValue(loadInstIdx, 0, true, lis->getVNInfoAllocator());
162 vni->kills.push_back(lis->getInstructionIndex(mi));
163 LiveRange lr(start, end, vni);
164
165 li->addRange(lr);
166 }
167
168
169
132170 /// Add spill ranges for every use/def of the live interval, inserting loads
133171 /// immediately before each use, and stores after each def. No folding is
134172 /// attempted.
188226 assert(hasUse || hasDef);
189227
190228 if (hasUse) {
191 unsigned loadInstIdx = insertLoadFor(mi, ss, newVReg, trc);
192 unsigned start = lis->getDefIndex(loadInstIdx),
193 end = lis->getUseIndex(lis->getInstructionIndex(mi));
194
195 VNInfo *vni =
196 newLI->getNextValue(loadInstIdx, 0, true, lis->getVNInfoAllocator());
197 vni->kills.push_back(lis->getInstructionIndex(mi));
198 LiveRange lr(start, end, vni);
199
200 newLI->addRange(lr);
229 insertLoadOnInterval(newLI, mi, ss, newVReg, trc);
201230 }
202231
203232 if (hasDef) {
204 unsigned storeInstIdx = insertStoreFor(mi, ss, newVReg, trc);
205 unsigned start = lis->getDefIndex(lis->getInstructionIndex(mi)),
206 end = lis->getUseIndex(storeInstIdx);
207
208 VNInfo *vni =
209 newLI->getNextValue(storeInstIdx, 0, true, lis->getVNInfoAllocator());
210 vni->kills.push_back(storeInstIdx);
211 LiveRange lr(start, end, vni);
212
213 newLI->addRange(lr);
233 insertStoreOnInterval(newLI, mi, ss, newVReg, trc);
214234 }
215235
216236 added.push_back(newLI);
226246 /// folding.
227247 class TrivialSpiller : public SpillerBase {
228248 public:
229 TrivialSpiller(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls, VirtRegMap *vrm) :
249
250 TrivialSpiller(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls,
251 VirtRegMap *vrm) :
230252 SpillerBase(mf, lis, ls, vrm) {}
231253
232254 std::vector spill(LiveInterval *li) {
233255 return trivialSpillEverywhere(li);
256 }
257
258 std::vector intraBlockSplit(LiveInterval *li, VNInfo *valno) {
259 std::vector spillIntervals;
260 MachineBasicBlock::iterator storeInsertPoint;
261
262 if (valno->isDefAccurate()) {
263 // If we have an accurate def we can just grab an iterator to the instr
264 // after the def.
265 storeInsertPoint =
266 next(MachineBasicBlock::iterator(lis->getInstructionFromIndex(valno->def)));
267 } else {
268 // If the def info isn't accurate we check if this is a PHI def.
269 // If it is then def holds the index of the defining Basic Block, and we
270 // can use that to get an insertion point.
271 if (valno->isPHIDef()) {
272
273 } else {
274 // We have no usable def info. We can't split this value sensibly.
275 // FIXME: Need sensible feedback for "failure to split", an empty
276 // set of spill intervals could be reasonably returned from a
277 // split where both the store and load are folded.
278 return spillIntervals;
279 }
280 }
281
282
283
284 return spillIntervals;
234285 }
235286
236287 };
1212 #include
1313
1414 namespace llvm {
15
1516 class LiveInterval;
1617 class LiveIntervals;
1718 class LiveStacks;
1819 class MachineFunction;
20 class MachineInstr;
1921 class VirtRegMap;
20 class MachineInstr;
22 class VNInfo;
2123
2224 /// Spiller interface.
2325 ///
3133 /// implementation selected.
3234 virtual std::vector spill(LiveInterval *li) = 0;
3335
36 /// Intra-block split.
37 virtual std::vector intraBlockSplit(LiveInterval *li,
38 VNInfo *valno) = 0;
39
3440 };
3541
3642 /// Create and return a spiller object, as specified on the command line.