llvm.org GIT mirror llvm / 0d4bdde
Rewrite LiveVariable liveness computation. The new implementation is much simplified. It eliminated the nasty recursive routines and removed the partial def / use bookkeeping. There is also potential for performance improvement by replacing the conservative handling of partial physical register definitions. The code is currently disabled until live interval analysis is taught of the name scheme. This patch also fixed a couple of nasty corner cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49784 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 12 years ago
3 changed file(s) with 310 addition(s) and 253 deletion(s). Raw diff Collapse all Expand all
133133
134134 const TargetRegisterInfo *TRI;
135135
136 // PhysRegInfo - Keep track of which instruction was the last def/use of a
136 // PhysRegInfo - Keep track of which instruction was the last def of a
137137 // physical register. This is a purely local property, because all physical
138138 // register references are presumed dead across basic blocks.
139 MachineInstr **PhysRegInfo;
140
141 // PhysRegUsed - Keep track of whether the physical register has been used
142 // after its last definition. This is local property.
143 bool *PhysRegUsed;
144
145 // PhysRegPartUse - Keep track of which instruction was the last partial use
146 // of a physical register (e.g. on X86 a def of EAX followed by a use of AX).
147 // This is a purely local property.
148 MachineInstr **PhysRegPartUse;
149
150 // PhysRegPartDef - Keep track of a list of instructions which "partially"
151 // defined the physical register (e.g. on X86 AX partially defines EAX).
152 // These are turned into use/mod/write if there is a use of the register
153 // later in the same block. This is local property.
154 SmallVector *PhysRegPartDef;
139 MachineInstr **PhysRegDef;
140
141 // PhysRegInfo - Keep track of which instruction was the last use of a
142 // physical register. This is a purely local property, because all physical
143 // register references are presumed dead across basic blocks.
144 MachineInstr **PhysRegUse;
155145
156146 SmallVector *PHIVarInfo;
157147
159149 // current basic block.
160150 DenseMap DistanceMap;
161151
162 void addRegisterKills(unsigned Reg, MachineInstr *MI,
163 SmallSet &SubKills);
164
165152 /// HandlePhysRegKill - Add kills of Reg and its sub-registers to the
166153 /// uses. Pay special attention to the sub-register uses which may come below
167154 /// the last use of the whole register.
168 bool HandlePhysRegKill(unsigned Reg, const MachineInstr *MI,
169 SmallSet &SubKills);
170 bool HandlePhysRegKill(unsigned Reg, MachineInstr *MI);
155 bool HandlePhysRegKill(unsigned Reg);
156
171157 void HandlePhysRegUse(unsigned Reg, MachineInstr *MI);
172158 void HandlePhysRegDef(unsigned Reg, MachineInstr *MI);
173159
160 /// FindLastPartialDef - Return the last partial def of the specified register.
161 /// Also returns the sub-register that's defined.
162 MachineInstr *FindLastPartialDef(unsigned Reg, unsigned &PartDefReg);
163
174164 /// hasRegisterUseBelow - Return true if the specified register is used after
175165 /// the current instruction and before it's next definition.
176 bool hasRegisterUseBelow(unsigned Reg,
177 MachineBasicBlock::iterator I,
166 bool hasRegisterUseBelow(unsigned Reg, MachineBasicBlock::iterator I,
178167 MachineBasicBlock *MBB);
179168
180169 /// analyzePHINodes - Gather information about the PHI nodes in here. In
153153 MarkVirtRegAliveInBlock(VRInfo, MRI->getVRegDef(reg)->getParent(), *PI);
154154 }
155155
156 /// FindLastPartialDef - Return the last partial def of the specified register.
157 /// Also returns the sub-register that's defined.
158 MachineInstr *LiveVariables::FindLastPartialDef(unsigned Reg,
159 unsigned &PartDefReg) {
160 unsigned LastDefReg = 0;
161 unsigned LastDefDist = 0;
162 MachineInstr *LastDef = NULL;
163 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
164 unsigned SubReg = *SubRegs; ++SubRegs) {
165 MachineInstr *Def = PhysRegDef[SubReg];
166 if (!Def)
167 continue;
168 unsigned Dist = DistanceMap[Def];
169 if (Dist > LastDefDist) {
170 LastDefReg = SubReg;
171 LastDef = Def;
172 LastDefDist = Dist;
173 }
174 }
175 PartDefReg = LastDefReg;
176 return LastDef;
177 }
178
156179 /// HandlePhysRegUse - Turn previous partial def's into read/mod/writes. Add
157180 /// implicit defs to a machine instruction if there was an earlier def of its
158181 /// super-register.
159182 void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) {
160 // Turn previous partial def's into read/mod/write.
161 for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) {
162 MachineInstr *Def = PhysRegPartDef[Reg][i];
163
164 // First one is just a def. This means the use is reading some undef bits.
165 if (i != 0)
166 Def->addOperand(MachineOperand::CreateReg(Reg,
167 false /*IsDef*/,
168 true /*IsImp*/,
169 true /*IsKill*/));
170
171 Def->addOperand(MachineOperand::CreateReg(Reg,
172 true /*IsDef*/,
173 true /*IsImp*/));
174 }
175
176 PhysRegPartDef[Reg].clear();
183 // If there was a previous use or a "full" def all is well.
184 if (!PhysRegDef[Reg] && !PhysRegUse[Reg]) {
185 // Otherwise, the last sub-register def implicitly defines this register.
186 // e.g.
187 // AH =
188 // AL = ... ,
189 // = AH
190 // ...
191 // = EAX
192 // All of the sub-registers must have been defined before the use of Reg!
193 unsigned PartDefReg = 0;
194 MachineInstr *LastPartialDef = FindLastPartialDef(Reg, PartDefReg);
195 // If LastPartialDef is NULL, it must be using a livein register.
196 if (LastPartialDef) {
197 LastPartialDef->addOperand(MachineOperand::CreateReg(Reg, true/*IsDef*/,
198 true/*IsImp*/));
199 PhysRegDef[Reg] = LastPartialDef;
200 std::set Processed;
201 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
202 unsigned SubReg = *SubRegs; ++SubRegs) {
203 if (Processed.count(SubReg))
204 continue;
205 if (SubReg == PartDefReg || TRI->isSubRegister(PartDefReg, SubReg))
206 continue;
207 // This part of Reg was defined before the last partial def. It's killed
208 // here.
209 LastPartialDef->addOperand(MachineOperand::CreateReg(SubReg,
210 false/*IsDef*/,
211 true/*IsImp*/));
212 PhysRegDef[SubReg] = LastPartialDef;
213 for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS)
214 Processed.insert(*SS);
215 }
216 }
217 }
177218
178219 // There was an earlier def of a super-register. Add implicit def to that MI.
179220 //
180221 // A: EAX = ...
181222 // B: ... = AX
182223 //
183 // Add implicit def to A.
184 if (PhysRegInfo[Reg] && PhysRegInfo[Reg] != PhysRegPartUse[Reg] &&
185 !PhysRegUsed[Reg]) {
186 MachineInstr *Def = PhysRegInfo[Reg];
187
188 if (!Def->modifiesRegister(Reg))
224 // Add implicit def to A if there isn't a use of AX (or EAX) before B.
225 if (!PhysRegUse[Reg]) {
226 MachineInstr *Def = PhysRegDef[Reg];
227 if (Def && !Def->modifiesRegister(Reg))
189228 Def->addOperand(MachineOperand::CreateReg(Reg,
190229 true /*IsDef*/,
191230 true /*IsImp*/));
192231 }
193
194 // There is a now a proper use, forget about the last partial use.
195 PhysRegPartUse[Reg] = NULL;
196 PhysRegInfo[Reg] = MI;
197 PhysRegUsed[Reg] = true;
198
199 // Now reset the use information for the sub-registers.
232
233 // Remember this use.
234 PhysRegUse[Reg] = MI;
200235 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
201 unsigned SubReg = *SubRegs; ++SubRegs) {
202 PhysRegPartUse[SubReg] = NULL;
203 PhysRegInfo[SubReg] = MI;
204 PhysRegUsed[SubReg] = true;
205 }
206
207 for (const unsigned *SuperRegs = TRI->getSuperRegisters(Reg);
208 unsigned SuperReg = *SuperRegs; ++SuperRegs) {
209 // Remember the partial use of this super-register if it was previously
210 // defined.
211 bool HasPrevDef = PhysRegInfo[SuperReg] != NULL;
212
213 if (!HasPrevDef)
214 // No need to go up more levels. A def of a register also sets its sub-
215 // registers. So if PhysRegInfo[SuperReg] is NULL, it means SuperReg's
216 // super-registers are not previously defined.
217 for (const unsigned *SSRegs = TRI->getSuperRegisters(SuperReg);
218 unsigned SSReg = *SSRegs; ++SSRegs)
219 if (PhysRegInfo[SSReg] != NULL) {
220 HasPrevDef = true;
221 break;
222 }
223
224 if (HasPrevDef) {
225 PhysRegInfo[SuperReg] = MI;
226 PhysRegPartUse[SuperReg] = MI;
227 }
228 }
229 }
230
231 /// addRegisterKills - For all of a register's sub-registers that are killed in
232 /// at this machine instruction, mark them as "killed". (If the machine operand
233 /// isn't found, add it first.)
234 void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI,
235 SmallSet &SubKills) {
236 if (SubKills.count(Reg) == 0) {
237 MI->addRegisterKilled(Reg, TRI, true);
238 return;
239 }
240
241 for (const unsigned *SubRegs = TRI->getImmediateSubRegisters(Reg);
242236 unsigned SubReg = *SubRegs; ++SubRegs)
243 addRegisterKills(SubReg, MI, SubKills);
244 }
245
246 /// HandlePhysRegKill - The recursive version of HandlePhysRegKill. Returns true
247 /// if:
248 ///
249 /// - The register has no sub-registers and the machine instruction is the
250 /// last def/use of the register, or
251 /// - The register has sub-registers and none of them are killed elsewhere.
252 ///
253 /// SubKills is filled with the set of sub-registers that are killed elsewhere.
254 bool LiveVariables::HandlePhysRegKill(unsigned Reg, const MachineInstr *RefMI,
255 SmallSet &SubKills) {
256 const unsigned *SubRegs = TRI->getImmediateSubRegisters(Reg);
257
258 for (; unsigned SubReg = *SubRegs; ++SubRegs) {
259 const MachineInstr *LastRef = PhysRegInfo[SubReg];
260
261 if (LastRef != RefMI ||
262 !HandlePhysRegKill(SubReg, RefMI, SubKills))
263 SubKills.insert(SubReg);
264 }
265
266 if (*SubRegs == 0) {
267 // No sub-registers, just check if reg is killed by RefMI.
268 if (PhysRegInfo[Reg] == RefMI && PhysRegInfo[Reg]->readsRegister(Reg)) {
269 return true;
270 }
271 } else if (SubKills.empty()) {
272 // None of the sub-registers are killed elsewhere.
273 return true;
274 }
275
276 return false;
277 }
278
279 /// HandlePhysRegKill - Returns true if the whole register is killed in the
280 /// machine instruction. If only some of its sub-registers are killed in this
281 /// machine instruction, then mark those as killed and return false.
282 bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) {
283 SmallSet SubKills;
284
285 if (HandlePhysRegKill(Reg, RefMI, SubKills)) {
286 // This machine instruction kills this register.
287 RefMI->addRegisterKilled(Reg, TRI, true);
288 return true;
289 }
290
291 // Some sub-registers are killed by another machine instruction.
292 for (const unsigned *SubRegs = TRI->getImmediateSubRegisters(Reg);
293 unsigned SubReg = *SubRegs; ++SubRegs)
294 addRegisterKills(SubReg, RefMI, SubKills);
295
296 return false;
237 PhysRegUse[SubReg] = MI;
297238 }
298239
299240 /// hasRegisterUseBelow - Return true if the specified register is used after
347288 DistanceMap.insert(std::make_pair(I, CurDist));
348289 }
349290
350 unsigned EarliestUse = CurDist;
351 for (unsigned i = 0, e = Uses.size(); i != e; ++i) {
291 unsigned EarliestUse = DistanceMap[Uses[0]];
292 for (unsigned i = 1, e = Uses.size(); i != e; ++i) {
352293 unsigned Dist = DistanceMap[Uses[i]];
353294 if (Dist < EarliestUse)
354295 EarliestUse = Dist;
362303 return true;
363304 }
364305
365 void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
366 // Does this kill a previous version of this register?
367 if (MachineInstr *LastRef = PhysRegInfo[Reg]) {
368 if (PhysRegUsed[Reg]) {
369 if (!HandlePhysRegKill(Reg, LastRef)) {
370 if (PhysRegPartUse[Reg])
371 PhysRegPartUse[Reg]->addRegisterKilled(Reg, TRI, true);
372 }
373 } else if (PhysRegPartUse[Reg]) {
374 // Add implicit use / kill to last partial use.
375 PhysRegPartUse[Reg]->addRegisterKilled(Reg, TRI, true);
376 } else if (LastRef != MI) {
377 // Defined, but not used. However, watch out for cases where a super-reg
378 // is also defined on the same MI.
379 LastRef->addRegisterDead(Reg, TRI);
380 }
381 }
382
306 bool LiveVariables::HandlePhysRegKill(unsigned Reg) {
307 if (!PhysRegUse[Reg] && !PhysRegDef[Reg])
308 return false;
309
310 MachineInstr *LastRefOrPartRef = PhysRegUse[Reg]
311 ? PhysRegUse[Reg] : PhysRegDef[Reg];
312 unsigned LastRefOrPartRefDist = DistanceMap[LastRefOrPartRef];
313 // The whole register is used.
314 // AL =
315 // AH =
316 //
317 // = AX
318 // = AL, AX
319 // AX =
320 //
321 // Or whole register is defined, but not used at all.
322 // AX =
323 // ...
324 // AX =
325 //
326 // Or whole register is defined, but only partly used.
327 // AX = AL
328 // = AL
329 // AX =
330 std::set PartUses;
383331 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
384332 unsigned SubReg = *SubRegs; ++SubRegs) {
385 if (MachineInstr *LastRef = PhysRegInfo[SubReg]) {
386 if (PhysRegUsed[SubReg]) {
387 if (!HandlePhysRegKill(SubReg, LastRef)) {
388 if (PhysRegPartUse[SubReg])
389 PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, TRI, true);
390 }
391 } else if (PhysRegPartUse[SubReg]) {
392 // Add implicit use / kill to last use of a sub-register.
393 PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, TRI, true);
394 } else if (LastRef != MI) {
395 // This must be a def of the subreg on the same MI.
396 LastRef->addRegisterDead(SubReg, TRI);
397 }
398 }
333 if (MachineInstr *Use = PhysRegUse[SubReg]) {
334 PartUses.insert(SubReg);
335 for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS)
336 PartUses.insert(*SS);
337 unsigned Dist = DistanceMap[Use];
338 if (Dist > LastRefOrPartRefDist) {
339 LastRefOrPartRefDist = Dist;
340 LastRefOrPartRef = Use;
341 }
342 }
343 }
344 if (LastRefOrPartRef == PhysRegDef[Reg])
345 // Not used at all.
346 LastRefOrPartRef->addRegisterDead(Reg, TRI, true);
347
348 /* Partial uses. Mark register def dead and add implicit def of
349 sub-registers which are used.
350 FIXME: LiveIntervalAnalysis can't handle this yet!
351 EAX = op AL
352 That is, EAX def is dead but AL def extends pass it.
353 Enable this after live interval analysis is fixed to improve codegen!
354 else if (!PhysRegUse[Reg]) {
355 PhysRegDef[Reg]->addRegisterDead(Reg, TRI, true);
356 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
357 unsigned SubReg = *SubRegs; ++SubRegs) {
358 if (PartUses.count(SubReg)) {
359 PhysRegDef[Reg]->addOperand(MachineOperand::CreateReg(SubReg,
360 true, true));
361 LastRefOrPartRef->addRegisterKilled(SubReg, TRI, true);
362 for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS)
363 PartUses.erase(*SS);
364 }
365 }
366 } */
367 else
368 LastRefOrPartRef->addRegisterKilled(Reg, TRI, true);
369 return true;
370 }
371
372 void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
373 // What parts of the register are previously defined?
374 std::set Live;
375 if (PhysRegDef[Reg] || PhysRegUse[Reg]) {
376 Live.insert(Reg);
377 for (const unsigned *SS = TRI->getSubRegisters(Reg); *SS; ++SS)
378 Live.insert(*SS);
379 } else {
380 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
381 unsigned SubReg = *SubRegs; ++SubRegs) {
382 // If a register isn't itself defined, but all parts that make up of it
383 // are defined, then consider it also defined.
384 // e.g.
385 // AL =
386 // AH =
387 // = AX
388 if (PhysRegDef[SubReg] || PhysRegUse[SubReg]) {
389 Live.insert(SubReg);
390 for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS)
391 Live.insert(*SS);
392 }
393 }
394 }
395
396 // Start from the largest piece, find the last time any part of the register
397 // is referenced.
398 if (!HandlePhysRegKill(Reg)) {
399 // Only some of the sub-registers are used.
400 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
401 unsigned SubReg = *SubRegs; ++SubRegs) {
402 if (!Live.count(SubReg))
403 // Skip if this sub-register isn't defined.
404 continue;
405 if (HandlePhysRegKill(SubReg)) {
406 Live.erase(SubReg);
407 for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS)
408 Live.erase(*SS);
409 }
410 }
411 assert(Live.empty() && "Not all defined registers are killed / dead?");
399412 }
400413
401414 if (MI) {
415 // Does this extend the live range of a super-register?
416 std::set Processed;
402417 for (const unsigned *SuperRegs = TRI->getSuperRegisters(Reg);
403418 unsigned SuperReg = *SuperRegs; ++SuperRegs) {
404 if (PhysRegInfo[SuperReg] && PhysRegInfo[SuperReg] != MI) {
419 if (Processed.count(SuperReg))
420 continue;
421 MachineInstr *LastRef = PhysRegUse[SuperReg]
422 ? PhysRegUse[SuperReg] : PhysRegDef[SuperReg];
423 if (LastRef && LastRef != MI) {
405424 // The larger register is previously defined. Now a smaller part is
406425 // being re-defined. Treat it as read/mod/write if there are uses
407426 // below.
409428 // AX = EAX, EAX
410429 // ...
411430 /// = EAX
412 if (MI && hasRegisterUseBelow(SuperReg, MI, MI->getParent())) {
431 if (hasRegisterUseBelow(SuperReg, MI, MI->getParent())) {
413432 MI->addOperand(MachineOperand::CreateReg(SuperReg, false/*IsDef*/,
414 true/*IsImp*/,true/*IsKill*/));
433 true/*IsImp*/,true/*IsKill*/));
415434 MI->addOperand(MachineOperand::CreateReg(SuperReg, true/*IsDef*/,
416435 true/*IsImp*/));
417 PhysRegInfo[SuperReg] = MI;
436 PhysRegDef[SuperReg] = MI;
437 PhysRegUse[SuperReg] = NULL;
438 Processed.insert(SuperReg);
439 for (const unsigned *SS = TRI->getSubRegisters(SuperReg); *SS; ++SS) {
440 PhysRegDef[*SS] = MI;
441 PhysRegUse[*SS] = NULL;
442 Processed.insert(*SS);
443 }
418444 } else {
419 PhysRegInfo[SuperReg]->addRegisterKilled(SuperReg, TRI, true);
420 PhysRegInfo[SuperReg] = NULL;
445 // Otherwise, the super register is killed.
446 if (HandlePhysRegKill(SuperReg)) {
447 PhysRegDef[SuperReg] = NULL;
448 PhysRegUse[SuperReg] = NULL;
449 for (const unsigned *SS = TRI->getSubRegisters(SuperReg); *SS; ++SS) {
450 PhysRegDef[*SS] = NULL;
451 PhysRegUse[*SS] = NULL;
452 Processed.insert(*SS);
453 }
454 }
421455 }
422 PhysRegUsed[SuperReg] = false;
423 PhysRegPartUse[SuperReg] = NULL;
424 } else {
425 // Remember this partial def.
426 PhysRegPartDef[SuperReg].push_back(MI);
427 }
428 }
429
430 PhysRegInfo[Reg] = MI;
431 PhysRegUsed[Reg] = false;
432 PhysRegPartDef[Reg].clear();
433 PhysRegPartUse[Reg] = NULL;
434
456 }
457 }
458
459 // Remember this def.
460 PhysRegDef[Reg] = MI;
461 PhysRegUse[Reg] = NULL;
435462 for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
436463 unsigned SubReg = *SubRegs; ++SubRegs) {
437 PhysRegInfo[SubReg] = MI;
438 PhysRegUsed[SubReg] = false;
439 PhysRegPartDef[SubReg].clear();
440 PhysRegPartUse[SubReg] = NULL;
464 PhysRegDef[SubReg] = MI;
465 PhysRegUse[SubReg] = NULL;
441466 }
442467 }
443468 }
450475 ReservedRegisters = TRI->getReservedRegs(mf);
451476
452477 unsigned NumRegs = TRI->getNumRegs();
453 PhysRegInfo = new MachineInstr*[NumRegs];
454 PhysRegUsed = new bool[NumRegs];
455 PhysRegPartUse = new MachineInstr*[NumRegs];
456 PhysRegPartDef = new SmallVector[NumRegs];
478 PhysRegDef = new MachineInstr*[NumRegs];
479 PhysRegUse = new MachineInstr*[NumRegs];
457480 PHIVarInfo = new SmallVector[MF->getNumBlockIDs()];
458 std::fill(PhysRegInfo, PhysRegInfo + NumRegs, (MachineInstr*)0);
459 std::fill(PhysRegUsed, PhysRegUsed + NumRegs, false);
460 std::fill(PhysRegPartUse, PhysRegPartUse + NumRegs, (MachineInstr*)0);
481 std::fill(PhysRegDef, PhysRegDef + NumRegs, (MachineInstr*)0);
482 std::fill(PhysRegUse, PhysRegUse + NumRegs, (MachineInstr*)0);
461483
462484 /// Get some space for a respectable number of registers.
463485 VirtRegInfo.resize(64);
500522 if (MI->getOpcode() == TargetInstrInfo::PHI)
501523 NumOperandsToProcess = 1;
502524
503 // Process all uses.
525 SmallVector UseRegs;
526 SmallVector DefRegs;
504527 for (unsigned i = 0; i != NumOperandsToProcess; ++i) {
505528 const MachineOperand &MO = MI->getOperand(i);
506
507 if (MO.isRegister() && MO.isUse() && MO.getReg()) {
529 if (MO.isRegister() && MO.getReg()) {
508530 unsigned MOReg = MO.getReg();
509
510 if (TargetRegisterInfo::isVirtualRegister(MOReg))
511 HandleVirtRegUse(MOReg, MBB, MI);
512 else if (TargetRegisterInfo::isPhysicalRegister(MOReg) &&
513 !ReservedRegisters[MOReg])
514 HandlePhysRegUse(MOReg, MI);
531 if (!MOReg)
532 continue;
533 if (MO.isUse())
534 UseRegs.push_back(MOReg);
535 if (MO.isDef())
536 DefRegs.push_back(MOReg);
515537 }
516538 }
517539
540 // Process all uses.
541 for (unsigned i = 0, e = UseRegs.size(); i != e; ++i) {
542 unsigned MOReg = UseRegs[i];
543 if (TargetRegisterInfo::isVirtualRegister(MOReg))
544 HandleVirtRegUse(MOReg, MBB, MI);
545 else if (TargetRegisterInfo::isPhysicalRegister(MOReg) &&
546 !ReservedRegisters[MOReg])
547 HandlePhysRegUse(MOReg, MI);
548 }
549
518550 // Process all defs.
519 for (unsigned i = 0; i != NumOperandsToProcess; ++i) {
520 const MachineOperand &MO = MI->getOperand(i);
521
522 if (MO.isRegister() && MO.isDef() && MO.getReg()) {
523 unsigned MOReg = MO.getReg();
524
525 if (TargetRegisterInfo::isVirtualRegister(MOReg)) {
526 VarInfo &VRInfo = getVarInfo(MOReg);
527
528 if (VRInfo.AliveBlocks.none())
529 // If vr is not alive in any block, then defaults to dead.
530 VRInfo.Kills.push_back(MI);
531 } else if (TargetRegisterInfo::isPhysicalRegister(MOReg) &&
532 !ReservedRegisters[MOReg]) {
533 HandlePhysRegDef(MOReg, MI);
534 }
551 for (unsigned i = 0, e = DefRegs.size(); i != e; ++i) {
552 unsigned MOReg = DefRegs[i];
553 if (TargetRegisterInfo::isVirtualRegister(MOReg)) {
554 VarInfo &VRInfo = getVarInfo(MOReg);
555
556 if (VRInfo.AliveBlocks.none())
557 // If vr is not alive in any block, then defaults to dead.
558 VRInfo.Kills.push_back(MI);
559 } else if (TargetRegisterInfo::isPhysicalRegister(MOReg) &&
560 !ReservedRegisters[MOReg]) {
561 HandlePhysRegDef(MOReg, MI);
535562 }
536563 }
537564 }
568595 }
569596 }
570597
571 // Loop over PhysRegInfo, killing any registers that are available at the
572 // end of the basic block. This also resets the PhysRegInfo map.
598 // Loop over PhysRegDef / PhysRegUse, killing any registers that are
599 // available at the end of the basic block.
573600 for (unsigned i = 0; i != NumRegs; ++i)
574 if (PhysRegInfo[i])
601 if (PhysRegDef[i] || PhysRegUse[i])
575602 HandlePhysRegDef(i, 0);
576603
577 // Clear some states between BB's. These are purely local information.
578 for (unsigned i = 0; i != NumRegs; ++i)
579 PhysRegPartDef[i].clear();
580
581 std::fill(PhysRegInfo, PhysRegInfo + NumRegs, (MachineInstr*)0);
582 std::fill(PhysRegUsed, PhysRegUsed + NumRegs, false);
583 std::fill(PhysRegPartUse, PhysRegPartUse + NumRegs, (MachineInstr*)0);
604 std::fill(PhysRegDef, PhysRegDef + NumRegs, (MachineInstr*)0);
605 std::fill(PhysRegUse, PhysRegUse + NumRegs, (MachineInstr*)0);
584606 }
585607
586608 // Convert and transfer the dead / killed information we have gathered into
607629 assert(Visited.count(&*i) != 0 && "unreachable basic block found");
608630 #endif
609631
610 delete[] PhysRegInfo;
611 delete[] PhysRegUsed;
612 delete[] PhysRegPartUse;
613 delete[] PhysRegPartDef;
632 delete[] PhysRegDef;
633 delete[] PhysRegUse;
614634 delete[] PHIVarInfo;
615635
616636 return false;
0 ; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin
1
2 %struct.CGPoint = type { double, double }
3 %struct.NSArray = type { %struct.NSObject }
4 %struct.NSAssertionHandler = type { %struct.NSObject, i8* }
5 %struct.NSDockTile = type { %struct.NSObject, %struct.NSObject*, i8*, %struct.NSView*, %struct.NSView*, %struct.NSView*, %struct.NSArray*, %struct._SPFlags, %struct.CGPoint, [5 x %struct.NSObject*] }
6 %struct.NSDocument = type { %struct.NSObject, %struct.NSWindow*, %struct.NSObject*, %struct.NSURL*, %struct.NSArray*, %struct.NSPrintInfo*, i64, %struct.NSView*, %struct.NSObject*, %struct.NSObject*, %struct.NSUndoManager*, %struct._BCFlags2, %struct.NSArray* }
7 %struct.AA = type { %struct.NSObject, %struct.NSDocument*, %struct.NSURL*, %struct.NSArray*, %struct.NSArray* }
8 %struct.NSError = type { %struct.NSObject, i8*, i64, %struct.NSArray*, %struct.NSArray* }
9 %struct.NSImage = type { %struct.NSObject, %struct.NSArray*, %struct.CGPoint, %struct._BCFlags2, %struct.NSObject*, %struct._NSImageAuxiliary* }
10 %struct.NSMutableArray = type { %struct.NSArray }
11 %struct.NSObject = type { %struct.NSObject* }
12 %struct.NSPrintInfo = type { %struct.NSObject, %struct.NSMutableArray*, %struct.NSObject* }
13 %struct.NSRect = type { %struct.CGPoint, %struct.CGPoint }
14 %struct.NSRegion = type opaque
15 %struct.NSResponder = type { %struct.NSObject, %struct.NSObject* }
16 %struct.NSToolbar = type { %struct.NSObject, %struct.NSArray*, %struct.NSMutableArray*, %struct.NSMutableArray*, %struct.NSArray*, %struct.NSObject*, %struct.NSArray*, i8*, %struct.NSObject*, %struct.NSWindow*, %struct.NSObject*, %struct.NSObject*, i64, %struct._BCFlags2, i64, %struct.NSObject* }
17 %struct.NSURL = type { %struct.NSObject, %struct.NSArray*, %struct.NSURL*, i8*, i8* }
18 %struct.NSUndoManager = type { %struct.NSObject, %struct.NSObject*, %struct.NSObject*, %struct.NSArray*, i64, %struct._SPFlags, %struct.NSObject*, i8*, i8*, i8* }
19 %struct.NSView = type { %struct.NSResponder, %struct.NSRect, %struct.NSRect, %struct.NSObject*, %struct.NSObject*, %struct.NSWindow*, %struct.NSObject*, %struct.NSObject*, %struct.NSObject*, %struct.NSObject*, %struct._NSViewAuxiliary*, %struct._BCFlags, %struct._SPFlags }
20 %struct.NSWindow = type { %struct.NSResponder, %struct.NSRect, %struct.NSObject*, %struct.NSObject*, %struct.NSResponder*, %struct.NSView*, %struct.NSView*, %struct.NSObject*, %struct.NSObject*, i32, i64, i32, %struct.NSArray*, %struct.NSObject*, i8, i8, i8, i8, i8*, i8*, %struct.NSImage*, i32, %struct.NSMutableArray*, %struct.NSURL*, %struct.CGPoint*, %struct.NSArray*, %struct.NSArray*, %struct.__wFlags, %struct.NSObject*, %struct.NSView*, %struct.NSWindowAuxiliary* }
21 %struct.NSWindowAuxiliary = type { %struct.NSObject, %struct.NSArray*, %struct.NSDockTile*, %struct._NSWindowAnimator*, %struct.NSRect, i32, %struct.NSAssertionHandler*, %struct.NSUndoManager*, %struct.NSWindowController*, %struct.NSAssertionHandler*, %struct.NSObject*, i32, %struct.__CFRunLoopObserver*, %struct.__CFRunLoopObserver*, %struct.NSArray*, %struct.NSArray*, %struct.NSView*, %struct.NSRegion*, %struct.NSWindow*, %struct.NSWindow*, %struct.NSArray*, %struct.NSMutableArray*, %struct.NSArray*, %struct.NSWindow*, %struct.CGPoint, %struct.NSObject*, i8*, i8*, i32, %struct.NSObject*, %struct.NSArray*, double, %struct.CGPoint, %struct.NSArray*, %struct.NSMutableArray*, %struct.NSMutableArray*, %struct.NSWindow*, %struct.NSView*, %struct.NSArray*, %struct.__auxWFlags, i32, i8*, double, %struct.NSObject*, %struct.NSObject*, %struct.__CFArray*, %struct.NSRegion*, %struct.NSArray*, %struct.NSRect, %struct.NSToolbar*, %struct.NSRect, %struct.NSMutableArray* }
22 %struct.NSWindowController = type { %struct.NSResponder, %struct.NSWindow*, %struct.NSArray*, %struct.NSDocument*, %struct.NSArray*, %struct.NSObject*, %struct._SPFlags, %struct.NSArray*, %struct.NSObject* }
23 %struct._BCFlags = type <{ i8, i8, i8, i8 }>
24 %struct._BCFlags2 = type <{ i8, [3 x i8] }>
25 %struct._NSImageAuxiliary = type opaque
26 %struct._NSViewAuxiliary = type opaque
27 %struct._NSWindowAnimator = type opaque
28 %struct._SPFlags = type <{ i32 }>
29 %struct.__CFArray = type opaque
30 %struct.__CFRunLoopObserver = type opaque
31 %struct.__auxWFlags = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i16 }
32 %struct.__wFlags = type <{ i8, i8, i8, i8, i8, i8, i8, i8 }>
33 %struct._message_ref_t = type { %struct.NSObject* (%struct.NSObject*, %struct._message_ref_t*, ...)*, %struct.objc_selector* }
34 %struct.objc_selector = type opaque
35 @"\01L_OBJC_MESSAGE_REF_228" = internal global %struct._message_ref_t zeroinitializer ; <%struct._message_ref_t*> [#uses=1]
36 @llvm.used1 = appending global [1 x i8*] [ i8* bitcast (void (%struct.AA*, %struct._message_ref_t*, %struct.NSError*, i64, %struct.NSObject*, %struct.objc_selector*, i8*)* @"-[AA BB:optionIndex:delegate:CC:contextInfo:]" to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
37
38 define void @"-[AA BB:optionIndex:delegate:CC:contextInfo:]"(%struct.AA* %self, %struct._message_ref_t* %_cmd, %struct.NSError* %inError, i64 %inOptionIndex, %struct.NSObject* %inDelegate, %struct.objc_selector* %inDidRecoverSelector, i8* %inContextInfo) {
39 entry:
40 %tmp105 = load %struct.NSArray** null, align 8 ; <%struct.NSArray*> [#uses=1]
41 %tmp107 = load %struct.NSObject** null, align 8 ; <%struct.NSObject*> [#uses=1]
42 call void null( %struct.NSObject* %tmp107, %struct._message_ref_t* @"\01L_OBJC_MESSAGE_REF_228", %struct.NSArray* %tmp105, i8 signext 0 )
43 %tmp111 = call %struct.NSObject* (%struct.NSObject*, %struct.objc_selector*, ...)* @objc_msgSend( %struct.NSObject* null, %struct.objc_selector* null, i32 0, i8* null ) ; <%struct.NSObject*> [#uses=0]
44 ret void
45 }
46
47 declare %struct.NSObject* @objc_msgSend(%struct.NSObject*, %struct.objc_selector*, ...)