blob: 962c9dea3e9413562b6b59dbf22e3f0e81c43d70 [file] [log] [blame]
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +00001//===-- llvm/CodeGen/VirtRegMap.h - Virtual Register Map -*- C++ -*--------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner8c4d88d2004-09-30 01:54:45 +000010// This file implements a virtual register map. This maps virtual registers to
11// physical registers and virtual registers to stack slots. It is created and
12// updated by a register allocator and then used by a machine code rewriter that
13// adds spill code and rewrites virtual into physical register references.
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +000014//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_VIRTREGMAP_H
18#define LLVM_CODEGEN_VIRTREGMAP_H
19
Owen Anderson49c8aa02009-03-13 05:55:11 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Dan Gohman6f0d0242008-02-10 18:45:23 +000021#include "llvm/Target/TargetRegisterInfo.h"
Evan Cheng4cce6b42008-04-11 17:53:36 +000022#include "llvm/ADT/BitVector.h"
Chris Lattner94c002a2007-02-01 05:32:05 +000023#include "llvm/ADT/IndexedMap.h"
Evan Chengd3653122008-02-27 03:04:06 +000024#include "llvm/ADT/SmallPtrSet.h"
Dan Gohmand68a0762009-01-05 17:59:02 +000025#include "llvm/ADT/SmallVector.h"
Bill Wendlinge8156192006-12-07 01:30:32 +000026#include "llvm/Support/Streams.h"
Alkis Evlogimenos5f375022004-03-01 20:05:10 +000027#include <map>
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +000028
29namespace llvm {
Chris Lattner8c4d88d2004-09-30 01:54:45 +000030 class MachineInstr;
David Greene7e231462007-08-07 16:34:05 +000031 class MachineFunction;
Chris Lattner29268692006-09-05 02:12:02 +000032 class TargetInstrInfo;
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +000033
Owen Anderson49c8aa02009-03-13 05:55:11 +000034 class VirtRegMap : public MachineFunctionPass {
Chris Lattner8c4d88d2004-09-30 01:54:45 +000035 public:
Evan Cheng2638e1a2007-03-20 08:13:50 +000036 enum {
37 NO_PHYS_REG = 0,
Evan Cheng91935142007-04-04 07:40:01 +000038 NO_STACK_SLOT = (1L << 30)-1,
39 MAX_STACK_SLOT = (1L << 18)-1
Evan Cheng2638e1a2007-03-20 08:13:50 +000040 };
41
Chris Lattner35f27052006-05-01 21:16:03 +000042 enum ModRef { isRef = 1, isMod = 2, isModRef = 3 };
Chris Lattnerbec6a9e2004-10-01 23:15:36 +000043 typedef std::multimap<MachineInstr*,
44 std::pair<unsigned, ModRef> > MI2VirtMapTy;
Alkis Evlogimenos5f375022004-03-01 20:05:10 +000045
Chris Lattner8c4d88d2004-09-30 01:54:45 +000046 private:
Owen Anderson49c8aa02009-03-13 05:55:11 +000047 const TargetInstrInfo *TII;
Chris Lattner29268692006-09-05 02:12:02 +000048
Owen Anderson49c8aa02009-03-13 05:55:11 +000049 MachineFunction *MF;
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +000050 /// Virt2PhysMap - This is a virtual to physical register
51 /// mapping. Each virtual register is required to have an entry in
52 /// it; even spilled virtual registers (the register mapped to a
53 /// spilled register is the temporary used to load it from the
54 /// stack).
Chris Lattner94c002a2007-02-01 05:32:05 +000055 IndexedMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
Evan Cheng81a03822007-11-17 00:40:40 +000056
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +000057 /// Virt2StackSlotMap - This is virtual register to stack slot
58 /// mapping. Each spilled virtual register has an entry in it
59 /// which corresponds to the stack slot this register is spilled
60 /// at.
Chris Lattner94c002a2007-02-01 05:32:05 +000061 IndexedMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
Evan Cheng81a03822007-11-17 00:40:40 +000062
Dan Gohman39e33ac2008-03-12 20:50:04 +000063 /// Virt2ReMatIdMap - This is virtual register to rematerialization id
Evan Cheng81a03822007-11-17 00:40:40 +000064 /// mapping. Each spilled virtual register that should be remat'd has an
65 /// entry in it which corresponds to the remat id.
Evan Cheng549f27d32007-08-13 23:45:17 +000066 IndexedMap<int, VirtReg2IndexFunctor> Virt2ReMatIdMap;
Evan Cheng81a03822007-11-17 00:40:40 +000067
68 /// Virt2SplitMap - This is virtual register to splitted virtual register
69 /// mapping.
70 IndexedMap<unsigned, VirtReg2IndexFunctor> Virt2SplitMap;
71
Evan Chengadf85902007-12-05 09:51:10 +000072 /// Virt2SplitKillMap - This is splitted virtual register to its last use
Evan Chengd120ffd2007-12-05 10:24:35 +000073 /// (kill) index mapping.
74 IndexedMap<unsigned> Virt2SplitKillMap;
Evan Chengadf85902007-12-05 09:51:10 +000075
Evan Cheng81a03822007-11-17 00:40:40 +000076 /// ReMatMap - This is virtual register to re-materialized instruction
77 /// mapping. Each virtual register whose definition is going to be
78 /// re-materialized has an entry in it.
79 IndexedMap<MachineInstr*, VirtReg2IndexFunctor> ReMatMap;
80
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +000081 /// MI2VirtMap - This is MachineInstr to virtual register
82 /// mapping. In the case of memory spill code being folded into
83 /// instructions, we need to know which virtual register was
84 /// read/written by this instruction.
Chris Lattner7f690e62004-09-30 02:15:18 +000085 MI2VirtMapTy MI2VirtMap;
Misha Brukmanedf128a2005-04-21 22:36:52 +000086
Evan Cheng81a03822007-11-17 00:40:40 +000087 /// SpillPt2VirtMap - This records the virtual registers which should
88 /// be spilled right after the MachineInstr due to live interval
89 /// splitting.
Evan Chengb50bb8c2007-12-05 08:16:32 +000090 std::map<MachineInstr*, std::vector<std::pair<unsigned,bool> > >
91 SpillPt2VirtMap;
Evan Cheng2638e1a2007-03-20 08:13:50 +000092
Evan Cheng0cbb1162007-11-29 01:06:25 +000093 /// RestorePt2VirtMap - This records the virtual registers which should
94 /// be restored right before the MachineInstr due to live interval
95 /// splitting.
96 std::map<MachineInstr*, std::vector<unsigned> > RestorePt2VirtMap;
97
Evan Cheng676dd7c2008-03-11 07:19:34 +000098 /// EmergencySpillMap - This records the physical registers that should
99 /// be spilled / restored around the MachineInstr since the register
100 /// allocator has run out of registers.
101 std::map<MachineInstr*, std::vector<unsigned> > EmergencySpillMap;
102
103 /// EmergencySpillSlots - This records emergency spill slots used to
104 /// spill physical registers when the register allocator runs out of
105 /// registers. Ideally only one stack slot is used per function per
106 /// register class.
107 std::map<const TargetRegisterClass*, int> EmergencySpillSlots;
108
Evan Cheng2638e1a2007-03-20 08:13:50 +0000109 /// ReMatId - Instead of assigning a stack slot to a to be rematerialized
Evan Cheng91935142007-04-04 07:40:01 +0000110 /// virtual register, an unique id is being assigned. This keeps track of
Evan Cheng2638e1a2007-03-20 08:13:50 +0000111 /// the highest id used so far. Note, this starts at (1<<18) to avoid
112 /// conflicts with stack slot numbers.
113 int ReMatId;
114
Evan Chengd3653122008-02-27 03:04:06 +0000115 /// LowSpillSlot, HighSpillSlot - Lowest and highest spill slot indexes.
116 int LowSpillSlot, HighSpillSlot;
117
118 /// SpillSlotToUsesMap - Records uses for each register spill slot.
119 SmallVector<SmallPtrSet<MachineInstr*, 4>, 8> SpillSlotToUsesMap;
120
Evan Cheng4cce6b42008-04-11 17:53:36 +0000121 /// ImplicitDefed - One bit for each virtual register. If set it indicates
122 /// the register is implicitly defined.
123 BitVector ImplicitDefed;
124
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000125 VirtRegMap(const VirtRegMap&); // DO NOT IMPLEMENT
126 void operator=(const VirtRegMap&); // DO NOT IMPLEMENT
Alkis Evlogimenos79742872004-02-23 23:47:10 +0000127
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000128 public:
Owen Anderson49c8aa02009-03-13 05:55:11 +0000129 static char ID;
130 VirtRegMap() : MachineFunctionPass(&ID), Virt2PhysMap(NO_PHYS_REG),
131 Virt2StackSlotMap(NO_STACK_SLOT),
132 Virt2ReMatIdMap(NO_STACK_SLOT), Virt2SplitMap(0),
133 Virt2SplitKillMap(0), ReMatMap(NULL),
134 ReMatId(MAX_STACK_SLOT+1),
135 LowSpillSlot(NO_STACK_SLOT), HighSpillSlot(NO_STACK_SLOT) { }
136 virtual bool runOnMachineFunction(MachineFunction &MF);
137
138 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
139 AU.setPreservesAll();
140 MachineFunctionPass::getAnalysisUsage(AU);
141 }
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +0000142
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000143 void grow();
Alkis Evlogimenosdd420e02004-03-01 23:18:15 +0000144
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000145 /// @brief returns true if the specified virtual register is
146 /// mapped to a physical register
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000147 bool hasPhys(unsigned virtReg) const {
148 return getPhys(virtReg) != NO_PHYS_REG;
149 }
Alkis Evlogimenosdd420e02004-03-01 23:18:15 +0000150
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000151 /// @brief returns the physical register mapped to the specified
152 /// virtual register
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000153 unsigned getPhys(unsigned virtReg) const {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000154 assert(TargetRegisterInfo::isVirtualRegister(virtReg));
Chris Lattner7f690e62004-09-30 02:15:18 +0000155 return Virt2PhysMap[virtReg];
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000156 }
Alkis Evlogimenosdd420e02004-03-01 23:18:15 +0000157
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000158 /// @brief creates a mapping for the specified virtual register to
159 /// the specified physical register
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000160 void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000161 assert(TargetRegisterInfo::isVirtualRegister(virtReg) &&
162 TargetRegisterInfo::isPhysicalRegister(physReg));
Chris Lattner7f690e62004-09-30 02:15:18 +0000163 assert(Virt2PhysMap[virtReg] == NO_PHYS_REG &&
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000164 "attempt to assign physical register to already mapped "
165 "virtual register");
Chris Lattner7f690e62004-09-30 02:15:18 +0000166 Virt2PhysMap[virtReg] = physReg;
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000167 }
168
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000169 /// @brief clears the specified virtual register's, physical
170 /// register mapping
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000171 void clearVirt(unsigned virtReg) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000172 assert(TargetRegisterInfo::isVirtualRegister(virtReg));
Chris Lattner7f690e62004-09-30 02:15:18 +0000173 assert(Virt2PhysMap[virtReg] != NO_PHYS_REG &&
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000174 "attempt to clear a not assigned virtual register");
Chris Lattner7f690e62004-09-30 02:15:18 +0000175 Virt2PhysMap[virtReg] = NO_PHYS_REG;
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000176 }
177
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000178 /// @brief clears all virtual to physical register mappings
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000179 void clearAllVirt() {
Chris Lattner7f690e62004-09-30 02:15:18 +0000180 Virt2PhysMap.clear();
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000181 grow();
182 }
183
Evan Cheng81a03822007-11-17 00:40:40 +0000184 /// @brief records virtReg is a split live interval from SReg.
185 void setIsSplitFromReg(unsigned virtReg, unsigned SReg) {
186 Virt2SplitMap[virtReg] = SReg;
187 }
188
189 /// @brief returns the live interval virtReg is split from.
190 unsigned getPreSplitReg(unsigned virtReg) {
191 return Virt2SplitMap[virtReg];
192 }
193
Dan Gohman39e33ac2008-03-12 20:50:04 +0000194 /// @brief returns true if the specified virtual register is not
Evan Cheng549f27d32007-08-13 23:45:17 +0000195 /// mapped to a stack slot or rematerialized.
196 bool isAssignedReg(unsigned virtReg) const {
Evan Cheng81a03822007-11-17 00:40:40 +0000197 if (getStackSlot(virtReg) == NO_STACK_SLOT &&
198 getReMatId(virtReg) == NO_STACK_SLOT)
199 return true;
200 // Split register can be assigned a physical register as well as a
201 // stack slot or remat id.
202 return (Virt2SplitMap[virtReg] && Virt2PhysMap[virtReg] != NO_PHYS_REG);
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000203 }
204
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000205 /// @brief returns the stack slot mapped to the specified virtual
206 /// register
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000207 int getStackSlot(unsigned virtReg) const {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000208 assert(TargetRegisterInfo::isVirtualRegister(virtReg));
Chris Lattner7f690e62004-09-30 02:15:18 +0000209 return Virt2StackSlotMap[virtReg];
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000210 }
211
Evan Cheng549f27d32007-08-13 23:45:17 +0000212 /// @brief returns the rematerialization id mapped to the specified virtual
213 /// register
214 int getReMatId(unsigned virtReg) const {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000215 assert(TargetRegisterInfo::isVirtualRegister(virtReg));
Evan Cheng549f27d32007-08-13 23:45:17 +0000216 return Virt2ReMatIdMap[virtReg];
217 }
218
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000219 /// @brief create a mapping for the specifed virtual register to
220 /// the next available stack slot
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000221 int assignVirt2StackSlot(unsigned virtReg);
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000222 /// @brief create a mapping for the specified virtual register to
223 /// the specified stack slot
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000224 void assignVirt2StackSlot(unsigned virtReg, int frameIndex);
225
Evan Cheng2638e1a2007-03-20 08:13:50 +0000226 /// @brief assign an unique re-materialization id to the specified
227 /// virtual register.
228 int assignVirtReMatId(unsigned virtReg);
Evan Cheng549f27d32007-08-13 23:45:17 +0000229 /// @brief assign an unique re-materialization id to the specified
230 /// virtual register.
231 void assignVirtReMatId(unsigned virtReg, int id);
Evan Cheng2638e1a2007-03-20 08:13:50 +0000232
233 /// @brief returns true if the specified virtual register is being
234 /// re-materialized.
235 bool isReMaterialized(unsigned virtReg) const {
Evan Cheng549f27d32007-08-13 23:45:17 +0000236 return ReMatMap[virtReg] != NULL;
Evan Cheng2638e1a2007-03-20 08:13:50 +0000237 }
238
239 /// @brief returns the original machine instruction being re-issued
240 /// to re-materialize the specified virtual register.
Evan Cheng549f27d32007-08-13 23:45:17 +0000241 MachineInstr *getReMaterializedMI(unsigned virtReg) const {
Evan Cheng2638e1a2007-03-20 08:13:50 +0000242 return ReMatMap[virtReg];
243 }
244
245 /// @brief records the specified virtual register will be
246 /// re-materialized and the original instruction which will be re-issed
Evan Cheng549f27d32007-08-13 23:45:17 +0000247 /// for this purpose. If parameter all is true, then all uses of the
248 /// registers are rematerialized and it's safe to delete the definition.
Evan Cheng2638e1a2007-03-20 08:13:50 +0000249 void setVirtIsReMaterialized(unsigned virtReg, MachineInstr *def) {
250 ReMatMap[virtReg] = def;
251 }
252
Evan Chengadf85902007-12-05 09:51:10 +0000253 /// @brief record the last use (kill) of a split virtual register.
Evan Chengd120ffd2007-12-05 10:24:35 +0000254 void addKillPoint(unsigned virtReg, unsigned index) {
255 Virt2SplitKillMap[virtReg] = index;
Evan Chengadf85902007-12-05 09:51:10 +0000256 }
257
Evan Chengd120ffd2007-12-05 10:24:35 +0000258 unsigned getKillPoint(unsigned virtReg) const {
259 return Virt2SplitKillMap[virtReg];
260 }
261
262 /// @brief remove the last use (kill) of a split virtual register.
Evan Chengadf85902007-12-05 09:51:10 +0000263 void removeKillPoint(unsigned virtReg) {
Evan Chengd120ffd2007-12-05 10:24:35 +0000264 Virt2SplitKillMap[virtReg] = 0;
Evan Chengadf85902007-12-05 09:51:10 +0000265 }
266
Evan Chengcada2452007-11-28 01:28:46 +0000267 /// @brief returns true if the specified MachineInstr is a spill point.
268 bool isSpillPt(MachineInstr *Pt) const {
269 return SpillPt2VirtMap.find(Pt) != SpillPt2VirtMap.end();
270 }
271
Evan Cheng81a03822007-11-17 00:40:40 +0000272 /// @brief returns the virtual registers that should be spilled due to
273 /// splitting right after the specified MachineInstr.
Evan Chengb50bb8c2007-12-05 08:16:32 +0000274 std::vector<std::pair<unsigned,bool> > &getSpillPtSpills(MachineInstr *Pt) {
Evan Cheng81a03822007-11-17 00:40:40 +0000275 return SpillPt2VirtMap[Pt];
276 }
277
278 /// @brief records the specified MachineInstr as a spill point for virtReg.
Evan Chengb50bb8c2007-12-05 08:16:32 +0000279 void addSpillPoint(unsigned virtReg, bool isKill, MachineInstr *Pt) {
Evan Chengcada2452007-11-28 01:28:46 +0000280 if (SpillPt2VirtMap.find(Pt) != SpillPt2VirtMap.end())
Evan Chengb50bb8c2007-12-05 08:16:32 +0000281 SpillPt2VirtMap[Pt].push_back(std::make_pair(virtReg, isKill));
Evan Chengcada2452007-11-28 01:28:46 +0000282 else {
Evan Chengb50bb8c2007-12-05 08:16:32 +0000283 std::vector<std::pair<unsigned,bool> > Virts;
284 Virts.push_back(std::make_pair(virtReg, isKill));
Evan Chengcada2452007-11-28 01:28:46 +0000285 SpillPt2VirtMap.insert(std::make_pair(Pt, Virts));
286 }
Evan Cheng81a03822007-11-17 00:40:40 +0000287 }
288
Evan Chengc1f53c72008-03-11 21:34:46 +0000289 /// @brief - transfer spill point information from one instruction to
290 /// another.
Evan Cheng81a03822007-11-17 00:40:40 +0000291 void transferSpillPts(MachineInstr *Old, MachineInstr *New) {
Evan Chengb50bb8c2007-12-05 08:16:32 +0000292 std::map<MachineInstr*,std::vector<std::pair<unsigned,bool> > >::iterator
293 I = SpillPt2VirtMap.find(Old);
Evan Chengcada2452007-11-28 01:28:46 +0000294 if (I == SpillPt2VirtMap.end())
295 return;
296 while (!I->second.empty()) {
Evan Chengb50bb8c2007-12-05 08:16:32 +0000297 unsigned virtReg = I->second.back().first;
298 bool isKill = I->second.back().second;
Evan Chengcada2452007-11-28 01:28:46 +0000299 I->second.pop_back();
Evan Chengb50bb8c2007-12-05 08:16:32 +0000300 addSpillPoint(virtReg, isKill, New);
Evan Cheng81a03822007-11-17 00:40:40 +0000301 }
Evan Chengcada2452007-11-28 01:28:46 +0000302 SpillPt2VirtMap.erase(I);
Evan Cheng81a03822007-11-17 00:40:40 +0000303 }
304
Evan Cheng0cbb1162007-11-29 01:06:25 +0000305 /// @brief returns true if the specified MachineInstr is a restore point.
306 bool isRestorePt(MachineInstr *Pt) const {
307 return RestorePt2VirtMap.find(Pt) != RestorePt2VirtMap.end();
308 }
309
310 /// @brief returns the virtual registers that should be restoreed due to
311 /// splitting right after the specified MachineInstr.
312 std::vector<unsigned> &getRestorePtRestores(MachineInstr *Pt) {
313 return RestorePt2VirtMap[Pt];
314 }
315
316 /// @brief records the specified MachineInstr as a restore point for virtReg.
317 void addRestorePoint(unsigned virtReg, MachineInstr *Pt) {
318 if (RestorePt2VirtMap.find(Pt) != RestorePt2VirtMap.end())
319 RestorePt2VirtMap[Pt].push_back(virtReg);
320 else {
321 std::vector<unsigned> Virts;
322 Virts.push_back(virtReg);
323 RestorePt2VirtMap.insert(std::make_pair(Pt, Virts));
324 }
325 }
326
Evan Cheng676dd7c2008-03-11 07:19:34 +0000327 /// @brief - transfer restore point information from one instruction to
328 /// another.
Evan Cheng0cbb1162007-11-29 01:06:25 +0000329 void transferRestorePts(MachineInstr *Old, MachineInstr *New) {
330 std::map<MachineInstr*,std::vector<unsigned> >::iterator I =
331 RestorePt2VirtMap.find(Old);
332 if (I == RestorePt2VirtMap.end())
333 return;
334 while (!I->second.empty()) {
335 unsigned virtReg = I->second.back();
336 I->second.pop_back();
337 addRestorePoint(virtReg, New);
338 }
339 RestorePt2VirtMap.erase(I);
340 }
341
Evan Cheng676dd7c2008-03-11 07:19:34 +0000342 /// @brief records that the specified physical register must be spilled
343 /// around the specified machine instr.
344 void addEmergencySpill(unsigned PhysReg, MachineInstr *MI) {
345 if (EmergencySpillMap.find(MI) != EmergencySpillMap.end())
346 EmergencySpillMap[MI].push_back(PhysReg);
347 else {
348 std::vector<unsigned> PhysRegs;
349 PhysRegs.push_back(PhysReg);
350 EmergencySpillMap.insert(std::make_pair(MI, PhysRegs));
351 }
352 }
353
354 /// @brief returns true if one or more physical registers must be spilled
355 /// around the specified instruction.
356 bool hasEmergencySpills(MachineInstr *MI) const {
357 return EmergencySpillMap.find(MI) != EmergencySpillMap.end();
358 }
359
360 /// @brief returns the physical registers to be spilled and restored around
361 /// the instruction.
362 std::vector<unsigned> &getEmergencySpills(MachineInstr *MI) {
363 return EmergencySpillMap[MI];
364 }
365
Evan Chengc1f53c72008-03-11 21:34:46 +0000366 /// @brief - transfer emergency spill information from one instruction to
367 /// another.
368 void transferEmergencySpills(MachineInstr *Old, MachineInstr *New) {
369 std::map<MachineInstr*,std::vector<unsigned> >::iterator I =
370 EmergencySpillMap.find(Old);
371 if (I == EmergencySpillMap.end())
372 return;
373 while (!I->second.empty()) {
374 unsigned virtReg = I->second.back();
375 I->second.pop_back();
376 addEmergencySpill(virtReg, New);
377 }
378 EmergencySpillMap.erase(I);
379 }
380
Evan Cheng676dd7c2008-03-11 07:19:34 +0000381 /// @brief return or get a emergency spill slot for the register class.
382 int getEmergencySpillSlot(const TargetRegisterClass *RC);
383
Evan Chengd3653122008-02-27 03:04:06 +0000384 /// @brief Return lowest spill slot index.
385 int getLowSpillSlot() const {
386 return LowSpillSlot;
387 }
388
389 /// @brief Return highest spill slot index.
390 int getHighSpillSlot() const {
391 return HighSpillSlot;
392 }
393
394 /// @brief Records a spill slot use.
395 void addSpillSlotUse(int FrameIndex, MachineInstr *MI);
396
397 /// @brief Returns true if spill slot has been used.
398 bool isSpillSlotUsed(int FrameIndex) const {
399 assert(FrameIndex >= 0 && "Spill slot index should not be negative!");
400 return !SpillSlotToUsesMap[FrameIndex-LowSpillSlot].empty();
401 }
402
Evan Cheng4cce6b42008-04-11 17:53:36 +0000403 /// @brief Mark the specified register as being implicitly defined.
404 void setIsImplicitlyDefined(unsigned VirtReg) {
405 ImplicitDefed.set(VirtReg-TargetRegisterInfo::FirstVirtualRegister);
406 }
407
408 /// @brief Returns true if the virtual register is implicitly defined.
409 bool isImplicitlyDefined(unsigned VirtReg) const {
410 return ImplicitDefed[VirtReg-TargetRegisterInfo::FirstVirtualRegister];
411 }
412
Chris Lattnerbec6a9e2004-10-01 23:15:36 +0000413 /// @brief Updates information about the specified virtual register's value
Evan Chengaee4af62007-12-02 08:30:39 +0000414 /// folded into newMI machine instruction.
415 void virtFolded(unsigned VirtReg, MachineInstr *OldMI, MachineInstr *NewMI,
416 ModRef MRInfo);
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000417
Evan Cheng7f566252007-10-13 02:50:24 +0000418 /// @brief Updates information about the specified virtual register's value
419 /// folded into the specified machine instruction.
420 void virtFolded(unsigned VirtReg, MachineInstr *MI, ModRef MRInfo);
421
Alkis Evlogimenosc736b3a2004-10-01 00:35:07 +0000422 /// @brief returns the virtual registers' values folded in memory
423 /// operands of this instruction
Chris Lattner7f690e62004-09-30 02:15:18 +0000424 std::pair<MI2VirtMapTy::const_iterator, MI2VirtMapTy::const_iterator>
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000425 getFoldedVirts(MachineInstr* MI) const {
Chris Lattner7f690e62004-09-30 02:15:18 +0000426 return MI2VirtMap.equal_range(MI);
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000427 }
Chris Lattner35f27052006-05-01 21:16:03 +0000428
Evan Chengcada2452007-11-28 01:28:46 +0000429 /// RemoveMachineInstrFromMaps - MI is being erased, remove it from the
430 /// the folded instruction map and spill point map.
Evan Chengd3653122008-02-27 03:04:06 +0000431 void RemoveMachineInstrFromMaps(MachineInstr *MI);
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000432
Bill Wendling8fe00542009-03-31 08:26:26 +0000433 bool OnlyUseOfStackSlot(const MachineInstr *MI) const;
434
Owen Anderson49c8aa02009-03-13 05:55:11 +0000435 void print(std::ostream &OS, const Module* M = 0) const;
Bill Wendling5c7e3262006-12-17 05:15:13 +0000436 void print(std::ostream *OS) const { if (OS) print(*OS); }
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000437 void dump() const;
438 };
439
Bill Wendling5c7e3262006-12-17 05:15:13 +0000440 inline std::ostream *operator<<(std::ostream *OS, const VirtRegMap &VRM) {
441 VRM.print(OS);
442 return OS;
443 }
Chris Lattner8c4d88d2004-09-30 01:54:45 +0000444 inline std::ostream &operator<<(std::ostream &OS, const VirtRegMap &VRM) {
445 VRM.print(OS);
446 return OS;
447 }
Alkis Evlogimenos34d9bc92004-02-23 23:08:11 +0000448} // End llvm namespace
449
450#endif