LCOV - code coverage report
Current view: top level - lib/CodeGen - LiveRegUnits.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 73 78 93.6 %
Date: 2018-06-17 00:07:59 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/CodeGen/TargetRegisterInfo.h"
      23             : #include "llvm/MC/MCRegisterInfo.h"
      24             : 
      25             : using namespace llvm;
      26             : 
      27        1541 : void LiveRegUnits::removeRegsNotPreserved(const uint32_t *RegMask) {
      28      176285 :   for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
      29      525901 :     for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid(); ++RootReg) {
      30      176413 :       if (MachineOperand::clobbersPhysReg(RegMask, *RootReg))
      31             :         Units.reset(U);
      32             :     }
      33             :   }
      34        1541 : }
      35             : 
      36        1044 : void LiveRegUnits::addRegsInMask(const uint32_t *RegMask) {
      37      120004 :   for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
      38      356908 :     for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid(); ++RootReg) {
      39      118988 :       if (MachineOperand::clobbersPhysReg(RegMask, *RootReg))
      40             :         Units.set(U);
      41             :     }
      42             :   }
      43        1044 : }
      44             : 
      45       41105 : void LiveRegUnits::stepBackward(const MachineInstr &MI) {
      46             :   // Remove defined registers and regmask kills from the set.
      47      197475 :   for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
      48      156370 :     if (O->isReg()) {
      49      101899 :       if (!O->isDef())
      50       66321 :         continue;
      51       35578 :       unsigned Reg = O->getReg();
      52       35578 :       if (!TargetRegisterInfo::isPhysicalRegister(Reg))
      53           0 :         continue;
      54       35578 :       removeReg(Reg);
      55       54471 :     } else if (O->isRegMask())
      56        1541 :       removeRegsNotPreserved(O->getRegMask());
      57             :   }
      58             : 
      59             :   // Add uses to the set.
      60      197475 :   for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
      61      246647 :     if (!O->isReg() || !O->readsReg())
      62       90277 :       continue;
      63       66093 :     unsigned Reg = O->getReg();
      64       87160 :     if (!TargetRegisterInfo::isPhysicalRegister(Reg))
      65       21067 :       continue;
      66       45026 :     addReg(Reg);
      67             :   }
      68       41105 : }
      69             : 
      70        4943 : void LiveRegUnits::accumulate(const MachineInstr &MI) {
      71             :   // Add defs, uses and regmask clobbers to the set.
      72       24871 :   for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
      73       19928 :     if (O->isReg()) {
      74       13822 :       unsigned Reg = O->getReg();
      75       13822 :       if (!TargetRegisterInfo::isPhysicalRegister(Reg))
      76        7578 :         continue;
      77        6274 :       if (!O->isDef() && !O->readsReg())
      78          30 :         continue;
      79        6214 :       addReg(Reg);
      80        6106 :     } else if (O->isRegMask())
      81          16 :       addRegsInMask(O->getRegMask());
      82             :   }
      83        4943 : }
      84             : 
      85             : /// Add live-in registers of basic block \p MBB to \p LiveUnits.
      86       13287 : static void addBlockLiveIns(LiveRegUnits &LiveUnits,
      87             :                             const MachineBasicBlock &MBB) {
      88       60989 :   for (const auto &LI : MBB.liveins())
      89       47702 :     LiveUnits.addRegMasked(LI.PhysReg, LI.LaneMask);
      90       13287 : }
      91             : 
      92             : /// Adds all callee saved registers to \p LiveUnits.
      93        2119 : static void addCalleeSavedRegs(LiveRegUnits &LiveUnits,
      94             :                                const MachineFunction &MF) {
      95        2119 :   const MachineRegisterInfo &MRI = MF.getRegInfo();
      96       57290 :   for (const MCPhysReg *CSR = MRI.getCalleeSavedRegs(); CSR && *CSR; ++CSR)
      97       55171 :     LiveUnits.addReg(*CSR);
      98        2119 : }
      99             : 
     100       12594 : void LiveRegUnits::addPristines(const MachineFunction &MF) {
     101       12594 :   const MachineFrameInfo &MFI = MF.getFrameInfo();
     102       12594 :   if (!MFI.isCalleeSavedInfoValid())
     103       12594 :     return;
     104             :   /// This function will usually be called on an empty object, handle this
     105             :   /// as a special case.
     106        1504 :   if (empty()) {
     107             :     /// Add all callee saved regs, then remove the ones that are saved and
     108             :     /// restored.
     109        1504 :     addCalleeSavedRegs(*this, MF);
     110             :     /// Remove the ones that are not saved/restored; they are pristine.
     111        1504 :     for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo())
     112        8616 :       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             :   addUnits(Pristine.getBitVector());
     125             : }
     126             : 
     127        1845 : void LiveRegUnits::addLiveOuts(const MachineBasicBlock &MBB) {
     128        1845 :   const MachineFunction &MF = *MBB.getParent();
     129        1845 :   if (!MBB.succ_empty()) {
     130        1090 :     addPristines(MF);
     131             :     // To get the live-outs we simply merge the live-ins of all successors.
     132        2873 :     for (const MachineBasicBlock *Succ : MBB.successors())
     133        1783 :       addBlockLiveIns(*this, *Succ);
     134         755 :   } else if (MBB.isReturnBlock()) {
     135             :     // For the return block: Add all callee saved registers.
     136         727 :     const MachineFrameInfo &MFI = MF.getFrameInfo();
     137         727 :     if (MFI.isCalleeSavedInfoValid())
     138         615 :       addCalleeSavedRegs(*this, MF);
     139             :   }
     140        1845 : }
     141             : 
     142       11504 : void LiveRegUnits::addLiveIns(const MachineBasicBlock &MBB) {
     143       11504 :   const MachineFunction &MF = *MBB.getParent();
     144       11504 :   addPristines(MF);
     145       11504 :   addBlockLiveIns(*this, MBB);
     146       11504 : }

Generated by: LCOV version 1.13