[llvm-commits] [llvm] r73750 - in /llvm/trunk: include/llvm/CodeGen/LiveInterval.h lib/CodeGen/LiveIntervalAnalysis.cpp lib/CodeGen/Spiller.cpp lib/CodeGen/Spiller.h
Lang Hames
lhames at gmail.com
Thu Jun 18 19:17:53 PDT 2009
Author: lhames
Date: Thu Jun 18 21:17:53 2009
New Revision: 73750
URL: http://llvm.org/viewvc/llvm-project?rev=73750&view=rev
Log:
More VNInfo tweaking, plus a little progress on intra-block splitting.
Modified:
llvm/trunk/include/llvm/CodeGen/LiveInterval.h
llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
llvm/trunk/lib/CodeGen/Spiller.cpp
llvm/trunk/lib/CodeGen/Spiller.h
Modified: llvm/trunk/include/llvm/CodeGen/LiveInterval.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LiveInterval.h?rev=73750&r1=73749&r2=73750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LiveInterval.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LiveInterval.h Thu Jun 18 21:17:53 2009
@@ -40,14 +40,14 @@
/// Care must be taken in interpreting the def index of the value. The
/// following rules apply:
///
- /// If the isDefAccurate() method returns false then the def index does not
- /// actually point to the defining MachineInstr, or even (necessarily) a
- /// valid MachineInstr at all. In general such a def index should not be
- /// used as an index to obtain a MachineInstr. The exception is Values
- /// defined by PHI instructions, after PHI elimination has occured. In this
- /// case the def should point to the start of the block in which the PHI
- /// existed. This fact can be used to insert code dealing with the PHI value
- /// at the merge point (e.g. to spill or split it).
+ /// If the isDefAccurate() method returns false then def does not contain the
+ /// index of the defining MachineInstr, or even (necessarily) to a
+ /// MachineInstr at all. In general such a def index is not meaningful
+ /// and should not be used. The exception is that, for values originally
+ /// defined by PHI instructions, after PHI elimination def will contain the
+ /// index of the MBB in which the PHI originally existed. This can be used
+ /// to insert code (spills or copies) which deals with the value, which will
+ /// be live in to the block.
class VNInfo {
private:
Modified: llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp?rev=73750&r1=73749&r2=73750&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp Thu Jun 18 21:17:53 2009
@@ -584,7 +584,8 @@
// Replace the interval with one of a NEW value number. Note that this
// value number isn't actually defined by an instruction, weird huh? :)
- LiveRange LR(Start, End, interval.getNextValue(Start, 0, false, VNInfoAllocator));
+ LiveRange LR(Start, End,
+ interval.getNextValue(mbb->getNumber(), 0, false, VNInfoAllocator));
LR.valno->setIsPHIDef(true);
DOUT << " replace range with " << LR;
interval.addRange(LR);
@@ -785,7 +786,8 @@
}
}
- VNInfo *vni = interval.getNextValue(start, 0, false, VNInfoAllocator);
+ VNInfo *vni =
+ interval.getNextValue(MBB->getNumber(), 0, false, VNInfoAllocator);
vni->setIsPHIDef(true);
LiveRange LR(start, end, vni);
Modified: llvm/trunk/lib/CodeGen/Spiller.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Spiller.cpp?rev=73750&r1=73749&r2=73750&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Spiller.cpp (original)
+++ llvm/trunk/lib/CodeGen/Spiller.cpp Thu Jun 18 21:17:53 2009
@@ -39,7 +39,8 @@
VirtRegMap *vrm;
/// Construct a spiller base.
- SpillerBase(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls, VirtRegMap *vrm) :
+ SpillerBase(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls,
+ VirtRegMap *vrm) :
mf(mf), lis(lis), ls(ls), vrm(vrm)
{
mfi = mf->getFrameInfo();
@@ -85,6 +86,7 @@
unsigned insertStoreFor(MachineInstr *mi, unsigned ss,
unsigned vreg,
const TargetRegisterClass *trc) {
+
MachineBasicBlock::iterator nextInstItr(mi);
++nextInstItr;
@@ -105,6 +107,23 @@
return storeInstIdx;
}
+ void insertStoreOnInterval(LiveInterval *li,
+ MachineInstr *mi, unsigned ss,
+ unsigned vreg,
+ const TargetRegisterClass *trc) {
+
+ unsigned storeInstIdx = insertStoreFor(mi, ss, vreg, trc);
+ unsigned start = lis->getDefIndex(lis->getInstructionIndex(mi)),
+ end = lis->getUseIndex(storeInstIdx);
+
+ VNInfo *vni =
+ li->getNextValue(storeInstIdx, 0, true, lis->getVNInfoAllocator());
+ vni->kills.push_back(storeInstIdx);
+ LiveRange lr(start, end, vni);
+
+ li->addRange(lr);
+ }
+
/// Insert a load of the given veg from the given stack slot immediately
/// before the given instruction. Returns the base index of the inserted
/// instruction. The caller is responsible for adding an appropriate
@@ -130,6 +149,25 @@
return loadInstIdx;
}
+ void insertLoadOnInterval(LiveInterval *li,
+ MachineInstr *mi, unsigned ss,
+ unsigned vreg,
+ const TargetRegisterClass *trc) {
+
+ unsigned loadInstIdx = insertLoadFor(mi, ss, vreg, trc);
+ unsigned start = lis->getDefIndex(loadInstIdx),
+ end = lis->getUseIndex(lis->getInstructionIndex(mi));
+
+ VNInfo *vni =
+ li->getNextValue(loadInstIdx, 0, true, lis->getVNInfoAllocator());
+ vni->kills.push_back(lis->getInstructionIndex(mi));
+ LiveRange lr(start, end, vni);
+
+ li->addRange(lr);
+ }
+
+
+
/// Add spill ranges for every use/def of the live interval, inserting loads
/// immediately before each use, and stores after each def. No folding is
/// attempted.
@@ -189,29 +227,11 @@
assert(hasUse || hasDef);
if (hasUse) {
- unsigned loadInstIdx = insertLoadFor(mi, ss, newVReg, trc);
- unsigned start = lis->getDefIndex(loadInstIdx),
- end = lis->getUseIndex(lis->getInstructionIndex(mi));
-
- VNInfo *vni =
- newLI->getNextValue(loadInstIdx, 0, true, lis->getVNInfoAllocator());
- vni->kills.push_back(lis->getInstructionIndex(mi));
- LiveRange lr(start, end, vni);
-
- newLI->addRange(lr);
+ insertLoadOnInterval(newLI, mi, ss, newVReg, trc);
}
if (hasDef) {
- unsigned storeInstIdx = insertStoreFor(mi, ss, newVReg, trc);
- unsigned start = lis->getDefIndex(lis->getInstructionIndex(mi)),
- end = lis->getUseIndex(storeInstIdx);
-
- VNInfo *vni =
- newLI->getNextValue(storeInstIdx, 0, true, lis->getVNInfoAllocator());
- vni->kills.push_back(storeInstIdx);
- LiveRange lr(start, end, vni);
-
- newLI->addRange(lr);
+ insertStoreOnInterval(newLI, mi, ss, newVReg, trc);
}
added.push_back(newLI);
@@ -227,13 +247,44 @@
/// folding.
class TrivialSpiller : public SpillerBase {
public:
- TrivialSpiller(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls, VirtRegMap *vrm) :
+
+ TrivialSpiller(MachineFunction *mf, LiveIntervals *lis, LiveStacks *ls,
+ VirtRegMap *vrm) :
SpillerBase(mf, lis, ls, vrm) {}
std::vector<LiveInterval*> spill(LiveInterval *li) {
return trivialSpillEverywhere(li);
}
+ std::vector<LiveInterval*> intraBlockSplit(LiveInterval *li, VNInfo *valno) {
+ std::vector<LiveInterval*> spillIntervals;
+ MachineBasicBlock::iterator storeInsertPoint;
+
+ if (valno->isDefAccurate()) {
+ // If we have an accurate def we can just grab an iterator to the instr
+ // after the def.
+ storeInsertPoint =
+ next(MachineBasicBlock::iterator(lis->getInstructionFromIndex(valno->def)));
+ } else {
+ // If the def info isn't accurate we check if this is a PHI def.
+ // If it is then def holds the index of the defining Basic Block, and we
+ // can use that to get an insertion point.
+ if (valno->isPHIDef()) {
+
+ } else {
+ // We have no usable def info. We can't split this value sensibly.
+ // FIXME: Need sensible feedback for "failure to split", an empty
+ // set of spill intervals could be reasonably returned from a
+ // split where both the store and load are folded.
+ return spillIntervals;
+ }
+ }
+
+
+
+ return spillIntervals;
+ }
+
};
}
Modified: llvm/trunk/lib/CodeGen/Spiller.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Spiller.h?rev=73750&r1=73749&r2=73750&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Spiller.h (original)
+++ llvm/trunk/lib/CodeGen/Spiller.h Thu Jun 18 21:17:53 2009
@@ -13,12 +13,14 @@
#include <vector>
namespace llvm {
+
class LiveInterval;
class LiveIntervals;
class LiveStacks;
class MachineFunction;
- class VirtRegMap;
class MachineInstr;
+ class VirtRegMap;
+ class VNInfo;
/// Spiller interface.
///
@@ -32,6 +34,10 @@
/// implementation selected.
virtual std::vector<LiveInterval*> spill(LiveInterval *li) = 0;
+ /// Intra-block split.
+ virtual std::vector<LiveInterval*> intraBlockSplit(LiveInterval *li,
+ VNInfo *valno) = 0;
+
};
/// Create and return a spiller object, as specified on the command line.
More information about the llvm-commits
mailing list