@@ -59,16 +59,6 @@ void RegScavenger::init(MachineBasicBlock &MBB) {
59
59
MRI = &MF.getRegInfo ();
60
60
LiveUnits.init (*TRI);
61
61
62
- assert ((NumRegUnits == 0 || NumRegUnits == TRI->getNumRegUnits ()) &&
63
- " Target changed?" );
64
-
65
- // Self-initialize.
66
- if (!this ->MBB ) {
67
- NumRegUnits = TRI->getNumRegUnits ();
68
- KillRegUnits.resize (NumRegUnits);
69
- DefRegUnits.resize (NumRegUnits);
70
- TmpRegUnits.resize (NumRegUnits);
71
- }
72
62
this ->MBB = &MBB;
73
63
74
64
for (ScavengedInfo &SI : Scavenged) {
@@ -95,135 +85,6 @@ void RegScavenger::enterBasicBlockEnd(MachineBasicBlock &MBB) {
95
85
}
96
86
}
97
87
98
- void RegScavenger::addRegUnits (BitVector &BV, MCRegister Reg) {
99
- for (MCRegUnit Unit : TRI->regunits (Reg))
100
- BV.set (Unit);
101
- }
102
-
103
- void RegScavenger::removeRegUnits (BitVector &BV, MCRegister Reg) {
104
- for (MCRegUnit Unit : TRI->regunits (Reg))
105
- BV.reset (Unit);
106
- }
107
-
108
- void RegScavenger::determineKillsAndDefs () {
109
- assert (Tracking && " Must be tracking to determine kills and defs" );
110
-
111
- MachineInstr &MI = *MBBI;
112
- assert (!MI.isDebugInstr () && " Debug values have no kills or defs" );
113
-
114
- // Find out which registers are early clobbered, killed, defined, and marked
115
- // def-dead in this instruction.
116
- KillRegUnits.reset ();
117
- DefRegUnits.reset ();
118
- for (const MachineOperand &MO : MI.operands ()) {
119
- if (MO.isRegMask ()) {
120
- TmpRegUnits.reset ();
121
- for (unsigned RU = 0 , RUEnd = TRI->getNumRegUnits (); RU != RUEnd; ++RU) {
122
- for (MCRegUnitRootIterator RURI (RU, TRI); RURI.isValid (); ++RURI) {
123
- if (MO.clobbersPhysReg (*RURI)) {
124
- TmpRegUnits.set (RU);
125
- break ;
126
- }
127
- }
128
- }
129
-
130
- // Apply the mask.
131
- KillRegUnits |= TmpRegUnits;
132
- }
133
- if (!MO.isReg ())
134
- continue ;
135
- if (!MO.getReg ().isPhysical () || isReserved (MO.getReg ()))
136
- continue ;
137
- MCRegister Reg = MO.getReg ().asMCReg ();
138
-
139
- if (MO.isUse ()) {
140
- // Ignore undef uses.
141
- if (MO.isUndef ())
142
- continue ;
143
- if (MO.isKill ())
144
- addRegUnits (KillRegUnits, Reg);
145
- } else {
146
- assert (MO.isDef ());
147
- if (MO.isDead ())
148
- addRegUnits (KillRegUnits, Reg);
149
- else
150
- addRegUnits (DefRegUnits, Reg);
151
- }
152
- }
153
- }
154
-
155
- void RegScavenger::forward () {
156
- // Move ptr forward.
157
- if (!Tracking) {
158
- MBBI = MBB->begin ();
159
- Tracking = true ;
160
- } else {
161
- assert (MBBI != MBB->end () && " Already past the end of the basic block!" );
162
- MBBI = std::next (MBBI);
163
- }
164
- assert (MBBI != MBB->end () && " Already at the end of the basic block!" );
165
-
166
- MachineInstr &MI = *MBBI;
167
-
168
- for (ScavengedInfo &I : Scavenged) {
169
- if (I.Restore != &MI)
170
- continue ;
171
-
172
- I.Reg = 0 ;
173
- I.Restore = nullptr ;
174
- }
175
-
176
- if (MI.isDebugOrPseudoInstr ())
177
- return ;
178
-
179
- determineKillsAndDefs ();
180
-
181
- // Verify uses and defs.
182
- #ifndef NDEBUG
183
- for (const MachineOperand &MO : MI.operands ()) {
184
- if (!MO.isReg ())
185
- continue ;
186
- Register Reg = MO.getReg ();
187
- if (!Reg.isPhysical () || isReserved (Reg))
188
- continue ;
189
- if (MO.isUse ()) {
190
- if (MO.isUndef ())
191
- continue ;
192
- if (!isRegUsed (Reg)) {
193
- // Check if it's partial live: e.g.
194
- // D0 = insert_subreg undef D0, S0
195
- // ... D0
196
- // The problem is the insert_subreg could be eliminated. The use of
197
- // D0 is using a partially undef value. This is not *incorrect* since
198
- // S1 is can be freely clobbered.
199
- // Ideally we would like a way to model this, but leaving the
200
- // insert_subreg around causes both correctness and performance issues.
201
- if (none_of (TRI->subregs (Reg),
202
- [&](MCPhysReg SR) { return isRegUsed (SR); }) &&
203
- none_of (TRI->superregs (Reg),
204
- [&](MCPhysReg SR) { return isRegUsed (SR); })) {
205
- MBB->getParent ()->verify (nullptr , " In Register Scavenger" );
206
- llvm_unreachable (" Using an undefined register!" );
207
- }
208
- }
209
- } else {
210
- assert (MO.isDef ());
211
- #if 0
212
- // FIXME: Enable this once we've figured out how to correctly transfer
213
- // implicit kills during codegen passes like the coalescer.
214
- assert((KillRegs.test(Reg) || isUnused(Reg) ||
215
- isLiveInButUnusedBefore(Reg, MI, MBB, TRI, MRI)) &&
216
- "Re-defining a live register!");
217
- #endif
218
- }
219
- }
220
- #endif // NDEBUG
221
-
222
- // Commit the changes.
223
- setUnused (KillRegUnits);
224
- setUsed (DefRegUnits);
225
- }
226
-
227
88
void RegScavenger::backward () {
228
89
assert (Tracking && " Must be tracking to determine kills and defs" );
229
90
0 commit comments