|
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | 9 | #include "llvm/CodeGen/MachineInstrBundle.h" |
| 10 | +#include "llvm/ADT/SetVector.h" |
10 | 11 | #include "llvm/ADT/SmallSet.h" |
11 | 12 | #include "llvm/ADT/SmallVector.h" |
12 | 13 | #include "llvm/CodeGen/MachineFunctionPass.h" |
@@ -134,103 +135,82 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, |
134 | 135 | BuildMI(MF, getDebugLoc(FirstMI, LastMI), TII->get(TargetOpcode::BUNDLE)); |
135 | 136 | Bundle.prepend(MIB); |
136 | 137 |
|
137 | | - SmallVector<Register, 32> LocalDefs; |
138 | | - SmallSet<Register, 32> LocalDefSet; |
| 138 | + SmallSetVector<Register, 32> LocalDefs; |
139 | 139 | SmallSet<Register, 8> DeadDefSet; |
140 | 140 | SmallSet<Register, 16> KilledDefSet; |
141 | | - SmallVector<Register, 8> ExternUses; |
142 | | - SmallSet<Register, 8> ExternUseSet; |
| 141 | + SmallSetVector<Register, 8> ExternUses; |
143 | 142 | SmallSet<Register, 8> KilledUseSet; |
144 | 143 | SmallSet<Register, 8> UndefUseSet; |
145 | | - SmallVector<MachineOperand*, 4> Defs; |
146 | 144 | for (auto MII = FirstMI; MII != LastMI; ++MII) { |
147 | 145 | // Debug instructions have no effects to track. |
148 | 146 | if (MII->isDebugInstr()) |
149 | 147 | continue; |
150 | 148 |
|
151 | | - for (MachineOperand &MO : MII->operands()) { |
152 | | - if (!MO.isReg()) |
153 | | - continue; |
154 | | - if (MO.isDef()) { |
155 | | - Defs.push_back(&MO); |
156 | | - continue; |
157 | | - } |
158 | | - |
| 149 | + for (MachineOperand &MO : MII->all_uses()) { |
159 | 150 | Register Reg = MO.getReg(); |
160 | 151 | if (!Reg) |
161 | 152 | continue; |
162 | 153 |
|
163 | | - if (LocalDefSet.count(Reg)) { |
| 154 | + if (LocalDefs.contains(Reg)) { |
164 | 155 | MO.setIsInternalRead(); |
165 | | - if (MO.isKill()) |
| 156 | + if (MO.isKill()) { |
166 | 157 | // Internal def is now killed. |
167 | 158 | KilledDefSet.insert(Reg); |
| 159 | + } |
168 | 160 | } else { |
169 | | - if (ExternUseSet.insert(Reg).second) { |
170 | | - ExternUses.push_back(Reg); |
| 161 | + if (ExternUses.insert(Reg)) { |
171 | 162 | if (MO.isUndef()) |
172 | 163 | UndefUseSet.insert(Reg); |
173 | 164 | } |
174 | | - if (MO.isKill()) |
| 165 | + if (MO.isKill()) { |
175 | 166 | // External def is now killed. |
176 | 167 | KilledUseSet.insert(Reg); |
| 168 | + } |
177 | 169 | } |
178 | 170 | } |
179 | 171 |
|
180 | | - for (MachineOperand *MO : Defs) { |
181 | | - Register Reg = MO->getReg(); |
| 172 | + for (MachineOperand &MO : MII->all_defs()) { |
| 173 | + Register Reg = MO.getReg(); |
182 | 174 | if (!Reg) |
183 | 175 | continue; |
184 | 176 |
|
185 | | - if (LocalDefSet.insert(Reg).second) { |
186 | | - LocalDefs.push_back(Reg); |
187 | | - if (MO->isDead()) { |
| 177 | + if (LocalDefs.insert(Reg)) { |
| 178 | + if (MO.isDead()) |
188 | 179 | DeadDefSet.insert(Reg); |
189 | | - } |
190 | 180 | } else { |
191 | 181 | // Re-defined inside the bundle, it's no longer killed. |
192 | 182 | KilledDefSet.erase(Reg); |
193 | | - if (!MO->isDead()) |
| 183 | + if (!MO.isDead()) { |
194 | 184 | // Previously defined but dead. |
195 | 185 | DeadDefSet.erase(Reg); |
196 | | - } |
197 | | - |
198 | | - if (!MO->isDead() && Reg.isPhysical()) { |
199 | | - for (MCPhysReg SubReg : TRI->subregs(Reg)) { |
200 | | - if (LocalDefSet.insert(SubReg).second) |
201 | | - LocalDefs.push_back(SubReg); |
202 | 186 | } |
203 | 187 | } |
| 188 | + |
| 189 | + if (!MO.isDead() && Reg.isPhysical()) |
| 190 | + LocalDefs.insert_range(TRI->subregs(Reg)); |
204 | 191 | } |
205 | 192 |
|
206 | | - Defs.clear(); |
| 193 | + // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions |
| 194 | + // got the property, then also set it on the bundle. |
| 195 | + if (MII->getFlag(MachineInstr::FrameSetup)) |
| 196 | + MIB.setMIFlag(MachineInstr::FrameSetup); |
| 197 | + if (MII->getFlag(MachineInstr::FrameDestroy)) |
| 198 | + MIB.setMIFlag(MachineInstr::FrameDestroy); |
207 | 199 | } |
208 | 200 |
|
209 | | - SmallSet<Register, 32> Added; |
210 | 201 | for (Register Reg : LocalDefs) { |
211 | | - if (Added.insert(Reg).second) { |
212 | | - // If it's not live beyond end of the bundle, mark it dead. |
213 | | - bool isDead = DeadDefSet.count(Reg) || KilledDefSet.count(Reg); |
214 | | - MIB.addReg(Reg, getDefRegState(true) | getDeadRegState(isDead) | |
215 | | - getImplRegState(true)); |
216 | | - } |
| 202 | + // If it's not live beyond end of the bundle, mark it dead. |
| 203 | + bool isDead = DeadDefSet.contains(Reg) || KilledDefSet.contains(Reg); |
| 204 | + MIB.addReg(Reg, getDefRegState(true) | getDeadRegState(isDead) | |
| 205 | + getImplRegState(true)); |
217 | 206 | } |
218 | 207 |
|
219 | 208 | for (Register Reg : ExternUses) { |
220 | | - bool isKill = KilledUseSet.count(Reg); |
221 | | - bool isUndef = UndefUseSet.count(Reg); |
| 209 | + bool isKill = KilledUseSet.contains(Reg); |
| 210 | + bool isUndef = UndefUseSet.contains(Reg); |
222 | 211 | MIB.addReg(Reg, getKillRegState(isKill) | getUndefRegState(isUndef) | |
223 | 212 | getImplRegState(true)); |
224 | 213 | } |
225 | | - |
226 | | - // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions got |
227 | | - // the property, then also set it on the bundle. |
228 | | - for (auto MII = FirstMI; MII != LastMI; ++MII) { |
229 | | - if (MII->getFlag(MachineInstr::FrameSetup)) |
230 | | - MIB.setMIFlag(MachineInstr::FrameSetup); |
231 | | - if (MII->getFlag(MachineInstr::FrameDestroy)) |
232 | | - MIB.setMIFlag(MachineInstr::FrameDestroy); |
233 | | - } |
234 | 214 | } |
235 | 215 |
|
236 | 216 | /// finalizeBundle - Same functionality as the previous finalizeBundle except |
|
0 commit comments