LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - MachineInstrBundle.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 31 33 93.9 %
Date: 2017-09-14 15:23:50 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- CodeGen/MachineInstBundle.h - MI bundle utilities -------*- C++ -*-===//
       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             : // This file provide utility functions to manipulate machine instruction
      11             : // bundles.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_CODEGEN_MACHINEINSTRBUNDLE_H
      16             : #define LLVM_CODEGEN_MACHINEINSTRBUNDLE_H
      17             : 
      18             : #include "llvm/CodeGen/MachineBasicBlock.h"
      19             : 
      20             : namespace llvm {
      21             : 
      22             : /// finalizeBundle - Finalize a machine instruction bundle which includes
      23             : /// a sequence of instructions starting from FirstMI to LastMI (exclusive).
      24             : /// This routine adds a BUNDLE instruction to represent the bundle, it adds
      25             : /// IsInternalRead markers to MachineOperands which are defined inside the
      26             : /// bundle, and it copies externally visible defs and uses to the BUNDLE
      27             : /// instruction.
      28             : void finalizeBundle(MachineBasicBlock &MBB,
      29             :                     MachineBasicBlock::instr_iterator FirstMI,
      30             :                     MachineBasicBlock::instr_iterator LastMI);
      31             : 
      32             : /// finalizeBundle - Same functionality as the previous finalizeBundle except
      33             : /// the last instruction in the bundle is not provided as an input. This is
      34             : /// used in cases where bundles are pre-determined by marking instructions
      35             : /// with 'InsideBundle' marker. It returns the MBB instruction iterator that
      36             : /// points to the end of the bundle.
      37             : MachineBasicBlock::instr_iterator finalizeBundle(MachineBasicBlock &MBB,
      38             :                     MachineBasicBlock::instr_iterator FirstMI);
      39             : 
      40             : /// finalizeBundles - Finalize instruction bundles in the specified
      41             : /// MachineFunction. Return true if any bundles are finalized.
      42             : bool finalizeBundles(MachineFunction &MF);
      43             : 
      44             : /// Returns an iterator to the first instruction in the bundle containing \p I.
      45             : inline MachineBasicBlock::instr_iterator getBundleStart(
      46             :     MachineBasicBlock::instr_iterator I) {
      47    33204658 :   while (I->isBundledWithPred())
      48             :     --I;
      49             :   return I;
      50             : }
      51             : 
      52             : /// Returns an iterator to the first instruction in the bundle containing \p I.
      53             : inline MachineBasicBlock::const_instr_iterator getBundleStart(
      54             :     MachineBasicBlock::const_instr_iterator I) {
      55    94184776 :   while (I->isBundledWithPred())
      56             :     --I;
      57             :   return I;
      58             : }
      59             : 
      60             : /// Returns an iterator pointing beyond the bundle containing \p I.
      61             : inline MachineBasicBlock::instr_iterator getBundleEnd(
      62             :     MachineBasicBlock::instr_iterator I) {
      63          98 :   while (I->isBundledWithSucc())
      64             :     ++I;
      65          49 :   return ++I;
      66             : }
      67             : 
      68             : /// Returns an iterator pointing beyond the bundle containing \p I.
      69             : inline MachineBasicBlock::const_instr_iterator getBundleEnd(
      70             :     MachineBasicBlock::const_instr_iterator I) {
      71           0 :   while (I->isBundledWithSucc())
      72             :     ++I;
      73           0 :   return ++I;
      74             : }
      75             : 
      76             : //===----------------------------------------------------------------------===//
      77             : // MachineOperand iterator
      78             : //
      79             : 
      80             : /// MachineOperandIteratorBase - Iterator that can visit all operands on a
      81             : /// MachineInstr, or all operands on a bundle of MachineInstrs.  This class is
      82             : /// not intended to be used directly, use one of the sub-classes instead.
      83             : ///
      84             : /// Intended use:
      85             : ///
      86             : ///   for (MIBundleOperands MIO(MI); MIO.isValid(); ++MIO) {
      87             : ///     if (!MIO->isReg())
      88             : ///       continue;
      89             : ///     ...
      90             : ///   }
      91             : ///
      92             : class MachineOperandIteratorBase {
      93             :   MachineBasicBlock::instr_iterator InstrI, InstrE;
      94             :   MachineInstr::mop_iterator OpI, OpE;
      95             : 
      96             :   // If the operands on InstrI are exhausted, advance InstrI to the next
      97             :   // bundled instruction with operands.
      98    88877462 :   void advance() {
      99    88884450 :     while (OpI == OpE) {
     100             :       // Don't advance off the basic block, or into a new bundle.
     101    80234806 :       if (++InstrI == InstrE || !InstrI->isInsideBundle())
     102             :         break;
     103        6988 :       OpI = InstrI->operands_begin();
     104       10482 :       OpE = InstrI->operands_end();
     105             :     }
     106    88877462 :   }
     107             : 
     108             : protected:
     109             :   /// MachineOperandIteratorBase - Create an iterator that visits all operands
     110             :   /// on MI, or all operands on every instruction in the bundle containing MI.
     111             :   ///
     112             :   /// @param MI The instruction to examine.
     113             :   /// @param WholeBundle When true, visit all operands on the entire bundle.
     114             :   ///
     115    48998631 :   explicit MachineOperandIteratorBase(MachineInstr &MI, bool WholeBundle) {
     116    16332877 :     if (WholeBundle) {
     117    48992001 :       InstrI = getBundleStart(MI.getIterator());
     118    32661334 :       InstrE = MI.getParent()->instr_end();
     119             :     } else {
     120        4420 :       InstrI = InstrE = MI.getIterator();
     121        2210 :       ++InstrE;
     122             :     }
     123    32665754 :     OpI = InstrI->operands_begin();
     124    48998631 :     OpE = InstrI->operands_end();
     125    16332877 :     if (WholeBundle)
     126    16330667 :       advance();
     127    16332877 :   }
     128             : 
     129             :   MachineOperand &deref() const { return *OpI; }
     130             : 
     131             : public:
     132             :   /// isValid - Returns true until all the operands have been visited.
     133             :   bool isValid() const { return OpI != OpE; }
     134             : 
     135             :   /// Preincrement.  Move to the next operand.
     136             :   void operator++() {
     137             :     assert(isValid() && "Cannot advance MIOperands beyond the last operand");
     138    72546795 :     ++OpI;
     139    72546795 :     advance();
     140             :   }
     141             : 
     142             :   /// getOperandNo - Returns the number of the current operand relative to its
     143             :   /// instruction.
     144             :   ///
     145             :   unsigned getOperandNo() const {
     146      319334 :     return OpI - InstrI->operands_begin();
     147             :   }
     148             : 
     149             :   /// VirtRegInfo - Information about a virtual register used by a set of operands.
     150             :   ///
     151             :   struct VirtRegInfo {
     152             :     /// Reads - One of the operands read the virtual register.  This does not
     153             :     /// include <undef> or <internal> use operands, see MO::readsReg().
     154             :     bool Reads;
     155             : 
     156             :     /// Writes - One of the operands writes the virtual register.
     157             :     bool Writes;
     158             : 
     159             :     /// Tied - Uses and defs must use the same register. This can be because of
     160             :     /// a two-address constraint, or there may be a partial redefinition of a
     161             :     /// sub-register.
     162             :     bool Tied;
     163             :   };
     164             : 
     165             :   /// Information about how a physical register Reg is used by a set of
     166             :   /// operands.
     167             :   struct PhysRegInfo {
     168             :     /// There is a regmask operand indicating Reg is clobbered.
     169             :     /// \see MachineOperand::CreateRegMask().
     170             :     bool Clobbered;
     171             : 
     172             :     /// Reg or one of its aliases is defined. The definition may only cover
     173             :     /// parts of the register.
     174             :     bool Defined;
     175             :     /// Reg or a super-register is defined. The definition covers the full
     176             :     /// register.
     177             :     bool FullyDefined;
     178             : 
     179             :     /// Reg or one of its aliases is read. The register may only be read
     180             :     /// partially.
     181             :     bool Read;
     182             :     /// Reg or a super-register is read. The full register is read.
     183             :     bool FullyRead;
     184             : 
     185             :     /// Either:
     186             :     /// - Reg is FullyDefined and all defs of reg or an overlapping
     187             :     ///   register are dead, or
     188             :     /// - Reg is completely dead because "defined" by a clobber.
     189             :     bool DeadDef;
     190             : 
     191             :     /// Reg is Defined and all defs of reg or an overlapping register are
     192             :     /// dead.
     193             :     bool PartialDeadDef;
     194             : 
     195             :     /// There is a use operand of reg or a super-register with kill flag set.
     196             :     bool Killed;
     197             :   };
     198             : 
     199             :   /// analyzeVirtReg - Analyze how the current instruction or bundle uses a
     200             :   /// virtual register.  This function should not be called after operator++(),
     201             :   /// it expects a fresh iterator.
     202             :   ///
     203             :   /// @param Reg The virtual register to analyze.
     204             :   /// @param Ops When set, this vector will receive an (MI, OpNum) entry for
     205             :   ///            each operand referring to Reg.
     206             :   /// @returns A filled-in RegInfo struct.
     207             :   VirtRegInfo analyzeVirtReg(unsigned Reg,
     208             :            SmallVectorImpl<std::pair<MachineInstr*, unsigned> > *Ops = nullptr);
     209             : 
     210             :   /// analyzePhysReg - Analyze how the current instruction or bundle uses a
     211             :   /// physical register.  This function should not be called after operator++(),
     212             :   /// it expects a fresh iterator.
     213             :   ///
     214             :   /// @param Reg The physical register to analyze.
     215             :   /// @returns A filled-in PhysRegInfo struct.
     216             :   PhysRegInfo analyzePhysReg(unsigned Reg, const TargetRegisterInfo *TRI);
     217             : };
     218             : 
     219             : /// MIOperands - Iterate over operands of a single instruction.
     220             : ///
     221             : class MIOperands : public MachineOperandIteratorBase {
     222             : public:
     223          16 :   MIOperands(MachineInstr &MI) : MachineOperandIteratorBase(MI, false) {}
     224             :   MachineOperand &operator* () const { return deref(); }
     225             :   MachineOperand *operator->() const { return &deref(); }
     226             : };
     227             : 
     228             : /// ConstMIOperands - Iterate over operands of a single const instruction.
     229             : ///
     230             : class ConstMIOperands : public MachineOperandIteratorBase {
     231             : public:
     232             :   ConstMIOperands(const MachineInstr &MI)
     233        2194 :       : MachineOperandIteratorBase(const_cast<MachineInstr &>(MI), false) {}
     234             :   const MachineOperand &operator* () const { return deref(); }
     235             :   const MachineOperand *operator->() const { return &deref(); }
     236             : };
     237             : 
     238             : /// MIBundleOperands - Iterate over all operands in a bundle of machine
     239             : /// instructions.
     240             : ///
     241             : class MIBundleOperands : public MachineOperandIteratorBase {
     242             : public:
     243      201649 :   MIBundleOperands(MachineInstr &MI) : MachineOperandIteratorBase(MI, true) {}
     244             :   MachineOperand &operator* () const { return deref(); }
     245      688548 :   MachineOperand *operator->() const { return &deref(); }
     246             : };
     247             : 
     248             : /// ConstMIBundleOperands - Iterate over all operands in a const bundle of
     249             : /// machine instructions.
     250             : ///
     251             : class ConstMIBundleOperands : public MachineOperandIteratorBase {
     252             : public:
     253             :   ConstMIBundleOperands(const MachineInstr &MI)
     254    16129018 :       : MachineOperandIteratorBase(const_cast<MachineInstr &>(MI), true) {}
     255    30725208 :   const MachineOperand &operator* () const { return deref(); }
     256    90593506 :   const MachineOperand *operator->() const { return &deref(); }
     257             : };
     258             : 
     259             : } // End llvm namespace
     260             : 
     261             : #endif

Generated by: LCOV version 1.13