mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 02:29:18 +00:00
Use the EdgeBundles analysis in X86FloatingPoint instead of recomputing CFG
bundles in the pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122833 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8dd070edc2
commit
631ee4b89f
@ -37,6 +37,9 @@ public:
|
|||||||
/// bundle number for basic block #N
|
/// bundle number for basic block #N
|
||||||
unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
|
unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
|
||||||
|
|
||||||
|
/// getNumBundles - Return the total number of bundles in the CFG.
|
||||||
|
unsigned getNumBundles() const { return EC.getNumClasses(); }
|
||||||
|
|
||||||
/// getMachineFunction - Return the last machine function computed.
|
/// getMachineFunction - Return the last machine function computed.
|
||||||
const MachineFunction *getMachineFunction() const { return MF; }
|
const MachineFunction *getMachineFunction() const { return MF; }
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ namespace {
|
|||||||
// FixStack[i] == getStackEntry(i) for all i < FixCount.
|
// FixStack[i] == getStackEntry(i) for all i < FixCount.
|
||||||
unsigned char FixStack[8];
|
unsigned char FixStack[8];
|
||||||
|
|
||||||
LiveBundle(unsigned m = 0) : Mask(m), FixCount(0) {}
|
LiveBundle() : Mask(0), FixCount(0) {}
|
||||||
|
|
||||||
// Have the live registers been assigned a stack order yet?
|
// Have the live registers been assigned a stack order yet?
|
||||||
bool isFixed() const { return !Mask || FixCount; }
|
bool isFixed() const { return !Mask || FixCount; }
|
||||||
@ -107,10 +107,8 @@ namespace {
|
|||||||
// with no live FP registers.
|
// with no live FP registers.
|
||||||
SmallVector<LiveBundle, 8> LiveBundles;
|
SmallVector<LiveBundle, 8> LiveBundles;
|
||||||
|
|
||||||
// Map each MBB in the current function to an (ingoing, outgoing) index into
|
// The edge bundle analysis provides indices into the LiveBundles vector.
|
||||||
// LiveBundles. Blocks with no FP registers live in or out map to (0, 0)
|
EdgeBundles *Bundles;
|
||||||
// and are not actually stored in the map.
|
|
||||||
DenseMap<MachineBasicBlock*, std::pair<unsigned, unsigned> > BlockBundle;
|
|
||||||
|
|
||||||
// Return a bitmask of FP registers in block's live-in list.
|
// Return a bitmask of FP registers in block's live-in list.
|
||||||
unsigned calcLiveInMask(MachineBasicBlock *MBB) {
|
unsigned calcLiveInMask(MachineBasicBlock *MBB) {
|
||||||
@ -287,6 +285,7 @@ bool FPS::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
// Early exit.
|
// Early exit.
|
||||||
if (!FPIsUsed) return false;
|
if (!FPIsUsed) return false;
|
||||||
|
|
||||||
|
Bundles = &getAnalysis<EdgeBundles>();
|
||||||
TII = MF.getTarget().getInstrInfo();
|
TII = MF.getTarget().getInstrInfo();
|
||||||
|
|
||||||
// Prepare cross-MBB liveness.
|
// Prepare cross-MBB liveness.
|
||||||
@ -311,7 +310,6 @@ bool FPS::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
if (Processed.insert(BB))
|
if (Processed.insert(BB))
|
||||||
Changed |= processBasicBlock(MF, *BB);
|
Changed |= processBasicBlock(MF, *BB);
|
||||||
|
|
||||||
BlockBundle.clear();
|
|
||||||
LiveBundles.clear();
|
LiveBundles.clear();
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
@ -324,90 +322,16 @@ bool FPS::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
/// registers may be implicitly defined, or not used by all successors.
|
/// registers may be implicitly defined, or not used by all successors.
|
||||||
void FPS::bundleCFG(MachineFunction &MF) {
|
void FPS::bundleCFG(MachineFunction &MF) {
|
||||||
assert(LiveBundles.empty() && "Stale data in LiveBundles");
|
assert(LiveBundles.empty() && "Stale data in LiveBundles");
|
||||||
assert(BlockBundle.empty() && "Stale data in BlockBundle");
|
LiveBundles.resize(Bundles->getNumBundles());
|
||||||
SmallPtrSet<MachineBasicBlock*, 8> PropDown, PropUp;
|
|
||||||
|
|
||||||
// LiveBundle[0] is the empty live-in set.
|
// Gather the actual live-in masks for all MBBs.
|
||||||
LiveBundles.resize(1);
|
|
||||||
|
|
||||||
// First gather the actual live-in masks for all MBBs.
|
|
||||||
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
||||||
MachineBasicBlock *MBB = I;
|
MachineBasicBlock *MBB = I;
|
||||||
const unsigned Mask = calcLiveInMask(MBB);
|
const unsigned Mask = calcLiveInMask(MBB);
|
||||||
if (!Mask)
|
if (!Mask)
|
||||||
continue;
|
continue;
|
||||||
// Ingoing bundle index.
|
// Update MBB ingoing bundle mask.
|
||||||
unsigned &Idx = BlockBundle[MBB].first;
|
LiveBundles[Bundles->getBundle(MBB->getNumber(), false)].Mask |= Mask;
|
||||||
// Already assigned an ingoing bundle?
|
|
||||||
if (Idx)
|
|
||||||
continue;
|
|
||||||
// Allocate a new LiveBundle struct for this block's live-ins.
|
|
||||||
const unsigned BundleIdx = Idx = LiveBundles.size();
|
|
||||||
DEBUG(dbgs() << "Creating LB#" << BundleIdx << ": in:BB#"
|
|
||||||
<< MBB->getNumber());
|
|
||||||
LiveBundles.push_back(Mask);
|
|
||||||
LiveBundle &Bundle = LiveBundles.back();
|
|
||||||
|
|
||||||
// Make sure all predecessors have the same live-out set.
|
|
||||||
PropUp.insert(MBB);
|
|
||||||
|
|
||||||
// Keep pushing liveness up and down the CFG until convergence.
|
|
||||||
// Only critical edges cause iteration here, but when they do, multiple
|
|
||||||
// blocks can be assigned to the same LiveBundle index.
|
|
||||||
do {
|
|
||||||
// Assign BundleIdx as liveout from predecessors in PropUp.
|
|
||||||
for (SmallPtrSet<MachineBasicBlock*, 16>::iterator I = PropUp.begin(),
|
|
||||||
E = PropUp.end(); I != E; ++I) {
|
|
||||||
MachineBasicBlock *MBB = *I;
|
|
||||||
for (MachineBasicBlock::const_pred_iterator LinkI = MBB->pred_begin(),
|
|
||||||
LinkE = MBB->pred_end(); LinkI != LinkE; ++LinkI) {
|
|
||||||
MachineBasicBlock *PredMBB = *LinkI;
|
|
||||||
// PredMBB's liveout bundle should be set to LIIdx.
|
|
||||||
unsigned &Idx = BlockBundle[PredMBB].second;
|
|
||||||
if (Idx) {
|
|
||||||
assert(Idx == BundleIdx && "Inconsistent CFG");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Idx = BundleIdx;
|
|
||||||
DEBUG(dbgs() << " out:BB#" << PredMBB->getNumber());
|
|
||||||
// Propagate to siblings.
|
|
||||||
if (PredMBB->succ_size() > 1)
|
|
||||||
PropDown.insert(PredMBB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PropUp.clear();
|
|
||||||
|
|
||||||
// Assign BundleIdx as livein to successors in PropDown.
|
|
||||||
for (SmallPtrSet<MachineBasicBlock*, 16>::iterator I = PropDown.begin(),
|
|
||||||
E = PropDown.end(); I != E; ++I) {
|
|
||||||
MachineBasicBlock *MBB = *I;
|
|
||||||
for (MachineBasicBlock::const_succ_iterator LinkI = MBB->succ_begin(),
|
|
||||||
LinkE = MBB->succ_end(); LinkI != LinkE; ++LinkI) {
|
|
||||||
MachineBasicBlock *SuccMBB = *LinkI;
|
|
||||||
// LinkMBB's livein bundle should be set to BundleIdx.
|
|
||||||
unsigned &Idx = BlockBundle[SuccMBB].first;
|
|
||||||
if (Idx) {
|
|
||||||
assert(Idx == BundleIdx && "Inconsistent CFG");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Idx = BundleIdx;
|
|
||||||
DEBUG(dbgs() << " in:BB#" << SuccMBB->getNumber());
|
|
||||||
// Propagate to siblings.
|
|
||||||
if (SuccMBB->pred_size() > 1)
|
|
||||||
PropUp.insert(SuccMBB);
|
|
||||||
// Also accumulate the bundle liveness mask from the liveins here.
|
|
||||||
Bundle.Mask |= calcLiveInMask(SuccMBB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PropDown.clear();
|
|
||||||
} while (!PropUp.empty());
|
|
||||||
DEBUG({
|
|
||||||
dbgs() << " live:";
|
|
||||||
for (unsigned i = 0; i < 8; ++i)
|
|
||||||
if (Bundle.Mask & (1<<i))
|
|
||||||
dbgs() << " %FP" << i;
|
|
||||||
dbgs() << '\n';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,13 +419,15 @@ bool FPS::processBasicBlock(MachineFunction &MF, MachineBasicBlock &BB) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// setupBlockStack - Use the BlockBundle map to set up our model of the stack
|
/// setupBlockStack - Use the live bundles to set up our model of the stack
|
||||||
/// to match predecessors' live out stack.
|
/// to match predecessors' live out stack.
|
||||||
void FPS::setupBlockStack() {
|
void FPS::setupBlockStack() {
|
||||||
DEBUG(dbgs() << "\nSetting up live-ins for BB#" << MBB->getNumber()
|
DEBUG(dbgs() << "\nSetting up live-ins for BB#" << MBB->getNumber()
|
||||||
<< " derived from " << MBB->getName() << ".\n");
|
<< " derived from " << MBB->getName() << ".\n");
|
||||||
StackTop = 0;
|
StackTop = 0;
|
||||||
const LiveBundle &Bundle = LiveBundles[BlockBundle.lookup(MBB).first];
|
// Get the live-in bundle for MBB.
|
||||||
|
const LiveBundle &Bundle =
|
||||||
|
LiveBundles[Bundles->getBundle(MBB->getNumber(), false)];
|
||||||
|
|
||||||
if (!Bundle.Mask) {
|
if (!Bundle.Mask) {
|
||||||
DEBUG(dbgs() << "Block has no FP live-ins.\n");
|
DEBUG(dbgs() << "Block has no FP live-ins.\n");
|
||||||
@ -538,7 +464,8 @@ void FPS::finishBlockStack() {
|
|||||||
DEBUG(dbgs() << "Setting up live-outs for BB#" << MBB->getNumber()
|
DEBUG(dbgs() << "Setting up live-outs for BB#" << MBB->getNumber()
|
||||||
<< " derived from " << MBB->getName() << ".\n");
|
<< " derived from " << MBB->getName() << ".\n");
|
||||||
|
|
||||||
unsigned BundleIdx = BlockBundle.lookup(MBB).second;
|
// Get MBB's live-out bundle.
|
||||||
|
unsigned BundleIdx = Bundles->getBundle(MBB->getNumber(), true);
|
||||||
LiveBundle &Bundle = LiveBundles[BundleIdx];
|
LiveBundle &Bundle = LiveBundles[BundleIdx];
|
||||||
|
|
||||||
// We may need to kill and define some registers to match successors.
|
// We may need to kill and define some registers to match successors.
|
||||||
|
Loading…
Reference in New Issue
Block a user