llvm.org GIT mirror llvm / bc4a15f
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 Chris Lattner 17 years ago
1 changed file(s) with 40 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2727 class MRegisterInfo;
2828
2929 class LiveVariables : public MachineFunctionPass {
30 public:
3031 struct VarInfo {
3132 /// DefBlock - The basic block which defines this value...
3233 MachineBasicBlock *DefBlock;
4546 std::vector > Kills;
4647
4748 VarInfo() : DefBlock(0), DefInst(0) {}
49
50 /// removeKill - Delete a kill corresponding to the specified machine instr
51 void removeKill(MachineInstr *MI) {
52 for (unsigned i = 0; ; ++i) {
53 assert(i < Kills.size() && "Machine instr is not a kill!");
54 if (Kills[i].second == MI) {
55 Kills.erase(Kills.begin()+i);
56 return;
57 }
58 }
59 }
4860 };
4961
62 private:
5063 /// VirtRegInfo - This list is a mapping from virtual register number to
5164 /// variable information. FirstVirtualRegister is subtracted from the virtual
5265 /// register number before indexing into this list.
8699 public:
87100
88101 virtual bool runOnMachineFunction(MachineFunction &MF);
102
103 /// getMachineBasicBlockIndex - Turn a MachineBasicBlock into an index number
104 /// suitable for use with VarInfo's.
105 ///
106 const std::pair
107 &getMachineBasicBlockInfo(MachineBasicBlock *MBB) const;
108 const std::pair
109 &getBasicBlockInfo(const BasicBlock *BB) const {
110 return BBMap.find(BB)->second;
111 }
112
89113
90114 /// killed_iterator - Iterate over registers killed by a machine instruction
91115 ///
122146 /// specified register is killed after being used by the specified
123147 /// instruction.
124148 ///
125 void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI) {
149 void addVirtualRegisterKilled(unsigned IncomingReg, MachineBasicBlock *MBB,
150 MachineInstr *MI) {
126151 RegistersKilled.insert(std::make_pair(MI, IncomingReg));
152 getVarInfo(IncomingReg).Kills.push_back(std::make_pair(MBB, MI));
127153 }
128154
129155 /// removeVirtualRegistersKilled - Remove all of the specified killed
130156 /// registers from the live variable information.
131157 void removeVirtualRegistersKilled(killed_iterator B, killed_iterator E) {
158 for (killed_iterator I = B; I != E; ++I) // Remove VarInfo entries...
159 getVarInfo(I->second).removeKill(I->first);
132160 RegistersKilled.erase(B, E);
133161 }
134162
135163 /// addVirtualRegisterDead - Add information about the fact that the specified
136164 /// register is dead after being used by the specified instruction.
137165 ///
138 void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI) {
166 void addVirtualRegisterDead(unsigned IncomingReg, MachineBasicBlock *MBB,
167 MachineInstr *MI) {
139168 RegistersDead.insert(std::make_pair(MI, IncomingReg));
169 getVarInfo(IncomingReg).Kills.push_back(std::make_pair(MBB, MI));
140170 }
141171
142172 /// removeVirtualRegistersKilled - Remove all of the specified killed
143173 /// registers from the live variable information.
144174 void removeVirtualRegistersDead(killed_iterator B, killed_iterator E) {
175 for (killed_iterator I = B; I != E; ++I) // Remove VarInfo entries...
176 getVarInfo(I->second).removeKill(I->first);
145177 RegistersDead.erase(B, E);
146178 }
147179
153185 VirtRegInfo.clear();
154186 RegistersKilled.clear();
155187 RegistersDead.clear();
156 }
157 private:
158 VarInfo &getVarInfo(unsigned RegIdx) {
159 if (RegIdx >= VirtRegInfo.size()) {
160 if (RegIdx >= 2*VirtRegInfo.size())
161 VirtRegInfo.resize(RegIdx*2);
162 else
163 VirtRegInfo.resize(2*VirtRegInfo.size());
164 }
165 return VirtRegInfo[RegIdx];
166 }
188 BBMap.clear();
189 }
190
191 /// getVarInfo - Return the VarInfo structure for the specified VIRTUAL
192 /// register.
193 VarInfo &getVarInfo(unsigned RegIdx);
167194
168195 void MarkVirtRegAliveInBlock(VarInfo &VRInfo, const BasicBlock *BB);
169196 void HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,