Stop LiveVariables from using BasicBlocks as part of the mapping, instead

use MachineBasicBlocks.  To do this, we traverse the Machine CFG instead of
the LLVM CFG, which is also *MUCH* more efficient by having fewer levels of
indirections and mappings.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13301 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-05-01 21:24:24 +00:00
parent 96362e9cac
commit f25fb4bc64

View File

@ -31,28 +31,22 @@
#include "llvm/Target/MRegisterInfo.h" #include "llvm/Target/MRegisterInfo.h"
#include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h" #include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"
using namespace llvm; using namespace llvm;
static RegisterAnalysis<LiveVariables> X("livevars", "Live Variable Analysis"); static RegisterAnalysis<LiveVariables> X("livevars", "Live Variable Analysis");
const std::pair<MachineBasicBlock*, unsigned> &
LiveVariables::getMachineBasicBlockInfo(MachineBasicBlock *MBB) const{
return BBMap.find(MBB->getBasicBlock())->second;
}
/// getIndexMachineBasicBlock() - Given a block index, return the /// getIndexMachineBasicBlock() - Given a block index, return the
/// MachineBasicBlock corresponding to it. /// MachineBasicBlock corresponding to it.
MachineBasicBlock *LiveVariables::getIndexMachineBasicBlock(unsigned Idx) { MachineBasicBlock *LiveVariables::getIndexMachineBasicBlock(unsigned Idx) {
if (BBIdxMap.empty()) { if (BBIdxMap.empty()) {
BBIdxMap.resize(BBMap.size()); BBIdxMap.resize(BBMap.size());
for (std::map<const BasicBlock*, std::pair<MachineBasicBlock*, unsigned> > for (std::map<MachineBasicBlock*, unsigned>::iterator I = BBMap.begin(),
::iterator I = BBMap.begin(), E = BBMap.end(); I != E; ++I) { E = BBMap.end(); I != E; ++I) {
assert(BBIdxMap.size() > I->second.second &&"Indices are not sequential"); assert(BBIdxMap.size() > I->second && "Indices are not sequential");
assert(BBIdxMap[I->second.second] == 0 && "Multiple idx collision!"); assert(BBIdxMap[I->second] == 0 && "Multiple idx collision!");
BBIdxMap[I->second.second] = I->second.first; BBIdxMap[I->second] = I->first;
} }
} }
assert(Idx < BBIdxMap.size() && "BB Index out of range!"); assert(Idx < BBIdxMap.size() && "BB Index out of range!");
@ -75,10 +69,8 @@ LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) {
void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo, void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
const BasicBlock *BB) { MachineBasicBlock *MBB) {
const std::pair<MachineBasicBlock*,unsigned> &Info = BBMap.find(BB)->second; unsigned BBNum = getMachineBasicBlockIndex(MBB);
MachineBasicBlock *MBB = Info.first;
unsigned BBNum = Info.second;
// Check to see if this basic block is one of the killing blocks. If so, // Check to see if this basic block is one of the killing blocks. If so,
// remove it... // remove it...
@ -99,7 +91,8 @@ void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
// Mark the variable known alive in this bb // Mark the variable known alive in this bb
VRInfo.AliveBlocks[BBNum] = true; VRInfo.AliveBlocks[BBNum] = true;
for (pred_const_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
E = MBB->pred_end(); PI != E; ++PI)
MarkVirtRegAliveInBlock(VRInfo, *PI); MarkVirtRegAliveInBlock(VRInfo, *PI);
} }
@ -125,8 +118,8 @@ void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
// Update all dominating blocks to mark them known live. // Update all dominating blocks to mark them known live.
const BasicBlock *BB = MBB->getBasicBlock(); const BasicBlock *BB = MBB->getBasicBlock();
for (pred_const_iterator PI = pred_begin(BB), E = pred_end(BB); for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
PI != E; ++PI) E = MBB->pred_end(); PI != E; ++PI)
MarkVirtRegAliveInBlock(VRInfo, *PI); MarkVirtRegAliveInBlock(VRInfo, *PI);
} }
@ -182,7 +175,7 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
// Build BBMap... // Build BBMap...
unsigned BBNum = 0; unsigned BBNum = 0;
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
BBMap[I->getBasicBlock()] = std::make_pair(I, BBNum++); BBMap[I] = BBNum++;
// PhysRegInfo - Keep track of which instruction was the last use of a // PhysRegInfo - Keep track of which instruction was the last use of a
// physical register. This is a purely local property, because all physical // physical register. This is a purely local property, because all physical
@ -202,13 +195,11 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
// register before its uses due to dominance properties of SSA (except for PHI // register before its uses due to dominance properties of SSA (except for PHI
// nodes, which are treated as a special case). // nodes, which are treated as a special case).
// //
const BasicBlock *Entry = MF.getFunction()->begin(); MachineBasicBlock *Entry = MF.begin();
for (df_iterator<const BasicBlock*> DFI = df_begin(Entry), E = df_end(Entry); for (df_iterator<MachineBasicBlock*> DFI = df_begin(Entry), E = df_end(Entry);
DFI != E; ++DFI) { DFI != E; ++DFI) {
const BasicBlock *BB = *DFI; MachineBasicBlock *MBB = *DFI;
std::pair<MachineBasicBlock*, unsigned> &BBRec = BBMap.find(BB)->second; unsigned BBNum = getMachineBasicBlockIndex(MBB);
MachineBasicBlock *MBB = BBRec.first;
unsigned BBNum = BBRec.second;
// Loop over all of the instructions, processing them. // Loop over all of the instructions, processing them.
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
@ -270,9 +261,9 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
// bottom of this basic block. We check all of our successor blocks to see // bottom of this basic block. We check all of our successor blocks to see
// if they have PHI nodes, and if so, we simulate an assignment at the end // if they have PHI nodes, and if so, we simulate an assignment at the end
// of the current block. // of the current block.
for (succ_const_iterator SI = succ_begin(BB), E = succ_end(BB); for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
SI != E; ++SI) { E = MBB->succ_end(); SI != E; ++SI) {
MachineBasicBlock *Succ = BBMap.find(*SI)->second.first; MachineBasicBlock *Succ = *SI;
// PHI nodes are guaranteed to be at the top of the block... // PHI nodes are guaranteed to be at the top of the block...
for (MachineBasicBlock::iterator MI = Succ->begin(), ME = Succ->end(); for (MachineBasicBlock::iterator MI = Succ->begin(), ME = Succ->end();
@ -286,7 +277,7 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
VarInfo &VRInfo = getVarInfo(MO.getReg()); VarInfo &VRInfo = getVarInfo(MO.getReg());
// Only mark it alive only in the block we are representing... // Only mark it alive only in the block we are representing...
MarkVirtRegAliveInBlock(VRInfo, BB); MarkVirtRegAliveInBlock(VRInfo, MBB);
break; // Found the PHI entry for this block... break; // Found the PHI entry for this block...
} }
} }