1 //===-- LiveInterval.cpp - Live Interval Representation -------------------===//
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 LiveRegUnits utility for tracking liveness of
11 // physical register units across machine instructions in forward or backward
14 //===----------------------------------------------------------------------===//
16 #include "llvm/CodeGen/LiveRegUnits.h"
17 #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
22 /// super-register or a register unit for the upper bits is available.
23 void LiveRegUnits::removeRegsInMask(const MachineOperand &Op,
24 const MCRegisterInfo &MCRI) {
25 const uint32_t *Mask = Op.getRegMask();
27 for (unsigned R = 0; R < MCRI.getNumRegs(); ++R) {
28 if ((*Mask & (1u << Bit)) == 0)
38 void LiveRegUnits::stepBackward(const MachineInstr &MI,
39 const MCRegisterInfo &MCRI) {
40 // Remove defined registers and regmask kills from the set.
41 for (ConstMIBundleOperands O(&MI); O.isValid(); ++O) {
45 unsigned Reg = O->getReg();
49 } else if (O->isRegMask()) {
50 removeRegsInMask(*O, MCRI);
53 // Add uses to the set.
54 for (ConstMIBundleOperands O(&MI); O.isValid(); ++O) {
55 if (!O->isReg() || !O->readsReg() || O->isUndef())
57 unsigned Reg = O->getReg();
64 /// Uses with kill flag get removed from the set, defs added. If possible
65 /// use StepBackward() instead of this function because some kill flags may
67 void LiveRegUnits::stepForward(const MachineInstr &MI,
68 const MCRegisterInfo &MCRI) {
69 SmallVector<unsigned, 4> Defs;
70 // Remove killed registers from the set.
71 for (ConstMIBundleOperands O(&MI); O.isValid(); ++O) {
73 unsigned Reg = O->getReg();
85 } else if (O->isRegMask()) {
86 removeRegsInMask(*O, MCRI);
89 // Add defs to the set.
90 for (unsigned i = 0, e = Defs.size(); i != e; ++i) {
91 addReg(Defs[i], MCRI);
95 /// Adds all registers in the live-in list of block @p BB.
96 void LiveRegUnits::addLiveIns(const MachineBasicBlock &BB,
97 const MCRegisterInfo &MCRI) {
98 for (MachineBasicBlock::livein_iterator L = BB.livein_begin(),
99 LE = BB.livein_end(); L != LE; ++L) {