LCOV - code coverage report
Current view: top level - lib/CodeGen - LiveRegUnits.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 74 81 91.4 %
Date: 2017-09-14 15:23:50 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- LiveRegUnits.cpp - Register Unit Set -------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : /// \file This file imlements the LiveRegUnits set.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/CodeGen/LiveRegUnits.h"
      15             : 
      16             : #include "llvm/CodeGen/MachineBasicBlock.h"
      17             : #include "llvm/CodeGen/MachineFrameInfo.h"
      18             : #include "llvm/CodeGen/MachineFunction.h"
      19             : #include "llvm/CodeGen/MachineInstrBundle.h"
      20             : #include "llvm/CodeGen/MachineOperand.h"
      21             : #include "llvm/CodeGen/MachineRegisterInfo.h"
      22             : #include "llvm/MC/MCRegisterInfo.h"
      23             : #include "llvm/Target/TargetRegisterInfo.h"
      24             : 
      25             : using namespace llvm;
      26             : 
      27        1504 : void LiveRegUnits::removeRegsNotPreserved(const uint32_t *RegMask) {
      28      165451 :   for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
      29      493205 :     for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid(); ++RootReg) {
      30      495933 :       if (MachineOperand::clobbersPhysReg(RegMask, *RootReg))
      31      122835 :         Units.reset(U);
      32             :     }
      33             :   }
      34        1504 : }
      35             : 
      36           8 : void LiveRegUnits::addRegsInMask(const uint32_t *RegMask) {
      37         598 :   for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
      38        1770 :     for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid(); ++RootReg) {
      39        1770 :       if (MachineOperand::clobbersPhysReg(RegMask, *RootReg))
      40         414 :         Units.set(U);
      41             :     }
      42             :   }
      43           8 : }
      44             : 
      45       39827 : void LiveRegUnits::stepBackward(const MachineInstr &MI) {
      46             :   // Remove defined registers and regmask kills from the set.
      47      191453 :   for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
      48      303252 :     if (O->isReg()) {
      49      196826 :       if (!O->isDef())
      50       63842 :         continue;
      51       34571 :       unsigned Reg = O->getReg();
      52       34571 :       if (!TargetRegisterInfo::isPhysicalRegister(Reg))
      53           0 :         continue;
      54       34571 :       removeReg(Reg);
      55       53213 :     } else if (O->isRegMask())
      56        1504 :       removeRegsNotPreserved(O->getRegMask());
      57             :   }
      58             : 
      59             :   // Add uses to the set.
      60      191453 :   for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
      61      489506 :     if (!O->isReg() || !O->readsReg())
      62       87841 :       continue;
      63       63785 :     unsigned Reg = O->getReg();
      64       85067 :     if (!TargetRegisterInfo::isPhysicalRegister(Reg))
      65       21282 :       continue;
      66       42503 :     addReg(Reg);
      67             :   }
      68       39827 : }
      69             : 
      70        4612 : void LiveRegUnits::accumulate(const MachineInstr &MI) {
      71             :   // Add defs, uses and regmask clobbers to the set.
      72       23157 :   for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
      73       37090 :     if (O->isReg()) {
      74       12866 :       unsigned Reg = O->getReg();
      75       12866 :       if (!TargetRegisterInfo::isPhysicalRegister(Reg))
      76        7774 :         continue;
      77       14421 :       if (!O->isDef() && !O->readsReg())
      78           0 :         continue;
      79        5092 :       addReg(Reg);
      80        5679 :     } else if (O->isRegMask())
      81           8 :       addRegsInMask(O->getRegMask());
      82             :   }
      83        4612 : }
      84             : 
      85             : /// Add live-in registers of basic block \p MBB to \p LiveUnits.
      86        1987 : static void addBlockLiveIns(LiveRegUnits &LiveUnits,
      87             :                             const MachineBasicBlock &MBB) {
      88       13795 :   for (const auto &LI : MBB.liveins())
      89        9821 :     LiveUnits.addRegMasked(LI.PhysReg, LI.LaneMask);
      90        1987 : }
      91             : 
      92             : /// Adds all callee saved registers to \p LiveUnits.
      93        1791 : static void addCalleeSavedRegs(LiveRegUnits &LiveUnits,
      94             :                                const MachineFunction &MF) {
      95        1791 :   const MachineRegisterInfo &MRI = MF.getRegInfo();
      96       44537 :   for (const MCPhysReg *CSR = MRI.getCalleeSavedRegs(); CSR && *CSR; ++CSR)
      97       42746 :     LiveUnits.addReg(*CSR);
      98        1791 : }
      99             : 
     100        1379 : void LiveRegUnits::addPristines(const MachineFunction &MF) {
     101        1379 :   const MachineFrameInfo &MFI = MF.getFrameInfo();
     102        1379 :   if (!MFI.isCalleeSavedInfoValid())
     103        1379 :     return;
     104             :   /// This function will usually be called on an empty object, handle this
     105             :   /// as a special case.
     106        1305 :   if (empty()) {
     107             :     /// Add all callee saved regs, then remove the ones that are saved and
     108             :     /// restored.
     109        1305 :     addCalleeSavedRegs(*this, MF);
     110             :     /// Remove the ones that are not saved/restored; they are pristine.
     111       13274 :     for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo())
     112        8054 :       removeReg(Info.getReg());
     113             :     return;
     114             :   }
     115             :   /// If a callee-saved register that is not pristine is already present
     116             :   /// in the set, we should make sure that it stays in it. Precompute the
     117             :   /// set of pristine registers in a separate object.
     118             :   /// Add all callee saved regs, then remove the ones that are saved+restored.
     119           0 :   LiveRegUnits Pristine(*TRI);
     120           0 :   addCalleeSavedRegs(Pristine, MF);
     121             :   /// Remove the ones that are not saved/restored; they are pristine.
     122           0 :   for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo())
     123           0 :     Pristine.removeReg(Info.getReg());
     124           0 :   addUnits(Pristine.getBitVector());
     125             : }
     126             : 
     127        1529 : void LiveRegUnits::addLiveOuts(const MachineBasicBlock &MBB) {
     128        1529 :   const MachineFunction &MF = *MBB.getParent();
     129        1529 :   if (!MBB.succ_empty()) {
     130         908 :     addPristines(MF);
     131             :     // To get the live-outs we simply merge the live-ins of all successors.
     132        3332 :     for (const MachineBasicBlock *Succ : MBB.successors())
     133        1516 :       addBlockLiveIns(*this, *Succ);
     134         621 :   } else if (MBB.isReturnBlock()) {
     135             :     // For the return block: Add all callee saved registers.
     136         594 :     const MachineFrameInfo &MFI = MF.getFrameInfo();
     137         594 :     if (MFI.isCalleeSavedInfoValid())
     138         486 :       addCalleeSavedRegs(*this, MF);
     139             :   }
     140        1529 : }
     141             : 
     142         471 : void LiveRegUnits::addLiveIns(const MachineBasicBlock &MBB) {
     143         471 :   const MachineFunction &MF = *MBB.getParent();
     144         471 :   addPristines(MF);
     145         471 :   addBlockLiveIns(*this, MBB);
     146         471 : }

Generated by: LCOV version 1.13