1 //===--- LivePhysRegs.cpp - Live Physical Register Set --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the LivePhysRegs utility for tracking liveness of
11 // physical registers across machine instructions in forward or backward order.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/LivePhysRegs.h"
16 #include "llvm/CodeGen/MachineInstrBundle.h"
20 /// We assume the high bits of a physical super-register are not preserved
21 /// unless the instruction has an implicit-use operand reading the
24 /// \brief Remove all registers from the set that get clobbered by the register
26 void LivePhysRegs::removeRegsInMask(const MachineOperand &MO) {
27 SparseSet<unsigned>::iterator LRI = LiveRegs.begin();
28 while (LRI != LiveRegs.end()) {
29 if (MO.clobbersPhysReg(*LRI))
30 LRI = LiveRegs.erase(LRI);
36 /// Simulates liveness when stepping backwards over an instruction(bundle):
37 /// Remove Defs, add uses. This is the recommended way of calculating liveness.
38 void LivePhysRegs::stepBackward(const MachineInstr &MI) {
39 // Remove defined registers and regmask kills from the set.
40 for (ConstMIBundleOperands O(&MI); O.isValid(); ++O) {
44 unsigned Reg = O->getReg();
48 } else if (O->isRegMask())
52 // Add uses to the set.
53 for (ConstMIBundleOperands O(&MI); O.isValid(); ++O) {
54 if (!O->isReg() || !O->readsReg() || O->isUndef())
56 unsigned Reg = O->getReg();
63 /// Simulates liveness when stepping forward over an instruction(bundle): Remove
64 /// killed-uses, add defs. This is the not recommended way, because it depends
65 /// on accurate kill flags. If possible use stepBackwards() instead of this
67 void LivePhysRegs::stepForward(const MachineInstr &MI) {
68 SmallVector<unsigned, 4> Defs;
69 // Remove killed registers from the set.
70 for (ConstMIBundleOperands O(&MI); O.isValid(); ++O) {
72 unsigned Reg = O->getReg();
84 } else if (O->isRegMask())
88 // Add defs to the set.
89 for (unsigned i = 0, e = Defs.size(); i != e; ++i)