From: Chris Lattner Date: Mon, 12 May 2003 14:23:04 +0000 (+0000) Subject: Beef up interface, move getVarInfo out-of-line. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc4a15f6faa6c32b2b84205fcdac9042728cf365;p=llvm Beef up interface, move getVarInfo out-of-line. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6114 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/LiveVariables.h b/include/llvm/CodeGen/LiveVariables.h index 7b03c31654e..51d3e82e771 100644 --- a/include/llvm/CodeGen/LiveVariables.h +++ b/include/llvm/CodeGen/LiveVariables.h @@ -28,6 +28,7 @@ class MRegisterInfo; class LiveVariables : public MachineFunctionPass { +public: struct VarInfo { /// DefBlock - The basic block which defines this value... MachineBasicBlock *DefBlock; @@ -46,8 +47,20 @@ class LiveVariables : public MachineFunctionPass { std::vector > Kills; VarInfo() : DefBlock(0), DefInst(0) {} + + /// removeKill - Delete a kill corresponding to the specified machine instr + void removeKill(MachineInstr *MI) { + for (unsigned i = 0; ; ++i) { + assert(i < Kills.size() && "Machine instr is not a kill!"); + if (Kills[i].second == MI) { + Kills.erase(Kills.begin()+i); + return; + } + } + } }; +private: /// VirtRegInfo - This list is a mapping from virtual register number to /// variable information. FirstVirtualRegister is subtracted from the virtual /// register number before indexing into this list. @@ -88,6 +101,17 @@ public: virtual bool runOnMachineFunction(MachineFunction &MF); + /// getMachineBasicBlockIndex - Turn a MachineBasicBlock into an index number + /// suitable for use with VarInfo's. + /// + const std::pair + &getMachineBasicBlockInfo(MachineBasicBlock *MBB) const; + const std::pair + &getBasicBlockInfo(const BasicBlock *BB) const { + return BBMap.find(BB)->second; + } + + /// killed_iterator - Iterate over registers killed by a machine instruction /// typedef std::multimap::iterator killed_iterator; @@ -123,26 +147,34 @@ public: /// specified register is killed after being used by the specified /// instruction. /// - void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI) { + void addVirtualRegisterKilled(unsigned IncomingReg, MachineBasicBlock *MBB, + MachineInstr *MI) { RegistersKilled.insert(std::make_pair(MI, IncomingReg)); + getVarInfo(IncomingReg).Kills.push_back(std::make_pair(MBB, MI)); } /// removeVirtualRegistersKilled - Remove all of the specified killed /// registers from the live variable information. void removeVirtualRegistersKilled(killed_iterator B, killed_iterator E) { + for (killed_iterator I = B; I != E; ++I) // Remove VarInfo entries... + getVarInfo(I->second).removeKill(I->first); RegistersKilled.erase(B, E); } /// addVirtualRegisterDead - Add information about the fact that the specified /// register is dead after being used by the specified instruction. /// - void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI) { + void addVirtualRegisterDead(unsigned IncomingReg, MachineBasicBlock *MBB, + MachineInstr *MI) { RegistersDead.insert(std::make_pair(MI, IncomingReg)); + getVarInfo(IncomingReg).Kills.push_back(std::make_pair(MBB, MI)); } /// removeVirtualRegistersKilled - Remove all of the specified killed /// registers from the live variable information. void removeVirtualRegistersDead(killed_iterator B, killed_iterator E) { + for (killed_iterator I = B; I != E; ++I) // Remove VarInfo entries... + getVarInfo(I->second).removeKill(I->first); RegistersDead.erase(B, E); } @@ -154,17 +186,12 @@ public: VirtRegInfo.clear(); RegistersKilled.clear(); RegistersDead.clear(); + BBMap.clear(); } -private: - VarInfo &getVarInfo(unsigned RegIdx) { - if (RegIdx >= VirtRegInfo.size()) { - if (RegIdx >= 2*VirtRegInfo.size()) - VirtRegInfo.resize(RegIdx*2); - else - VirtRegInfo.resize(2*VirtRegInfo.size()); - } - return VirtRegInfo[RegIdx]; - } + + /// getVarInfo - Return the VarInfo structure for the specified VIRTUAL + /// register. + VarInfo &getVarInfo(unsigned RegIdx); void MarkVirtRegAliveInBlock(VarInfo &VRInfo, const BasicBlock *BB); void HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,