LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - MachineInstrBuilder.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 121 126 96.0 %
Date: 2018-02-21 17:27:13 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- CodeGen/MachineInstrBuilder.h - Simplify creation of MIs --*- 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 exposes a function named BuildMI, which is useful for dramatically
      11             : // simplifying how MachineInstr's are created.  It allows use of code like this:
      12             : //
      13             : //   M = BuildMI(MBB, MI, DL, TII.get(X86::ADD8rr), Dst)
      14             : //           .addReg(argVal1)
      15             : //           .addReg(argVal2);
      16             : //
      17             : //===----------------------------------------------------------------------===//
      18             : 
      19             : #ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
      20             : #define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
      21             : 
      22             : #include "llvm/ADT/ArrayRef.h"
      23             : #include "llvm/CodeGen/GlobalISel/Utils.h"
      24             : #include "llvm/CodeGen/MachineBasicBlock.h"
      25             : #include "llvm/CodeGen/MachineFunction.h"
      26             : #include "llvm/CodeGen/MachineInstr.h"
      27             : #include "llvm/CodeGen/MachineInstrBundle.h"
      28             : #include "llvm/CodeGen/MachineOperand.h"
      29             : #include "llvm/CodeGen/TargetRegisterInfo.h"
      30             : #include "llvm/IR/InstrTypes.h"
      31             : #include "llvm/IR/Intrinsics.h"
      32             : #include "llvm/Support/ErrorHandling.h"
      33             : #include <cassert>
      34             : #include <cstdint>
      35             : #include <utility>
      36             : 
      37             : namespace llvm {
      38             : 
      39             : class MCInstrDesc;
      40             : class MDNode;
      41             : 
      42             : namespace RegState {
      43             : 
      44             :   enum {
      45             :     Define         = 0x2,
      46             :     Implicit       = 0x4,
      47             :     Kill           = 0x8,
      48             :     Dead           = 0x10,
      49             :     Undef          = 0x20,
      50             :     EarlyClobber   = 0x40,
      51             :     Debug          = 0x80,
      52             :     InternalRead   = 0x100,
      53             :     Renamable      = 0x200,
      54             :     DefineNoRead   = Define | Undef,
      55             :     ImplicitDefine = Implicit | Define,
      56             :     ImplicitKill   = Implicit | Kill
      57             :   };
      58             : 
      59             : } // end namespace RegState
      60             : 
      61             : class MachineInstrBuilder {
      62             :   MachineFunction *MF = nullptr;
      63             :   MachineInstr *MI = nullptr;
      64             : 
      65             : public:
      66             :   MachineInstrBuilder() = default;
      67             : 
      68             :   /// Create a MachineInstrBuilder for manipulating an existing instruction.
      69             :   /// F must be the machine function that was used to allocate I.
      70     3155192 :   MachineInstrBuilder(MachineFunction &F, MachineInstr *I) : MF(&F), MI(I) {}
      71             :   MachineInstrBuilder(MachineFunction &F, MachineBasicBlock::iterator I)
      72      715819 :       : MF(&F), MI(&*I) {}
      73             : 
      74             :   /// Allow automatic conversion to the machine instruction we are working on.
      75             :   operator MachineInstr*() const { return MI; }
      76             :   MachineInstr *operator->() const { return MI; }
      77             :   operator MachineBasicBlock::iterator() const { return MI; }
      78             : 
      79             :   /// If conversion operators fail, use this method to get the MachineInstr
      80             :   /// explicitly.
      81             :   MachineInstr *getInstr() const { return MI; }
      82             : 
      83             :   /// Add a new virtual register operand.
      84    14240241 :   const MachineInstrBuilder &addReg(unsigned RegNo, unsigned flags = 0,
      85             :                                     unsigned SubReg = 0) const {
      86             :     assert((flags & 0x1) == 0 &&
      87             :            "Passing in 'true' to addReg is forbidden! Use enums instead.");
      88    28480482 :     MI->addOperand(*MF, MachineOperand::CreateReg(RegNo,
      89    14240241 :                                                flags & RegState::Define,
      90    14240241 :                                                flags & RegState::Implicit,
      91             :                                                flags & RegState::Kill,
      92             :                                                flags & RegState::Dead,
      93    14240241 :                                                flags & RegState::Undef,
      94    14240241 :                                                flags & RegState::EarlyClobber,
      95             :                                                SubReg,
      96    14240241 :                                                flags & RegState::Debug,
      97    14240241 :                                                flags & RegState::InternalRead,
      98    99681687 :                                                flags & RegState::Renamable));
      99    14240240 :     return *this;
     100             :   }
     101             : 
     102             :   /// Add a virtual register definition operand.
     103             :   const MachineInstrBuilder &addDef(unsigned RegNo, unsigned Flags = 0,
     104             :                                     unsigned SubReg = 0) const {
     105       14453 :     return addReg(RegNo, Flags | RegState::Define, SubReg);
     106             :   }
     107             : 
     108             :   /// Add a virtual register use operand. It is an error for Flags to contain
     109             :   /// `RegState::Define` when calling this function.
     110             :   const MachineInstrBuilder &addUse(unsigned RegNo, unsigned Flags = 0,
     111             :                                     unsigned SubReg = 0) const {
     112             :     assert(!(Flags & RegState::Define) &&
     113             :            "Misleading addUse defines register, use addReg instead.");
     114       11458 :     return addReg(RegNo, Flags, SubReg);
     115             :   }
     116             : 
     117             :   /// Add a new immediate operand.
     118             :   const MachineInstrBuilder &addImm(int64_t Val) const {
     119    11604775 :     MI->addOperand(*MF, MachineOperand::CreateImm(Val));
     120             :     return *this;
     121             :   }
     122             : 
     123             :   const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
     124        1833 :     MI->addOperand(*MF, MachineOperand::CreateCImm(Val));
     125             :     return *this;
     126             :   }
     127             : 
     128             :   const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
     129         365 :     MI->addOperand(*MF, MachineOperand::CreateFPImm(Val));
     130             :     return *this;
     131             :   }
     132             : 
     133             :   const MachineInstrBuilder &addMBB(MachineBasicBlock *MBB,
     134             :                                     unsigned char TargetFlags = 0) const {
     135      988997 :     MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
     136             :     return *this;
     137             :   }
     138             : 
     139             :   const MachineInstrBuilder &addFrameIndex(int Idx) const {
     140     1042298 :     MI->addOperand(*MF, MachineOperand::CreateFI(Idx));
     141             :     return *this;
     142             :   }
     143             : 
     144             :   const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx,
     145             :                                                   int Offset = 0,
     146             :                                           unsigned char TargetFlags = 0) const {
     147       51852 :     MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
     148             :     return *this;
     149             :   }
     150             : 
     151             :   const MachineInstrBuilder &addTargetIndex(unsigned Idx, int64_t Offset = 0,
     152             :                                           unsigned char TargetFlags = 0) const {
     153           0 :     MI->addOperand(*MF, MachineOperand::CreateTargetIndex(Idx, Offset,
     154             :                                                           TargetFlags));
     155             :     return *this;
     156             :   }
     157             : 
     158             :   const MachineInstrBuilder &addJumpTableIndex(unsigned Idx,
     159             :                                           unsigned char TargetFlags = 0) const {
     160         869 :     MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
     161             :     return *this;
     162             :   }
     163             : 
     164             :   const MachineInstrBuilder &addGlobalAddress(const GlobalValue *GV,
     165             :                                               int64_t Offset = 0,
     166             :                                           unsigned char TargetFlags = 0) const {
     167     1804604 :     MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
     168             :     return *this;
     169             :   }
     170             : 
     171             :   const MachineInstrBuilder &addExternalSymbol(const char *FnName,
     172             :                                           unsigned char TargetFlags = 0) const {
     173       48642 :     MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
     174             :     return *this;
     175             :   }
     176             : 
     177             :   const MachineInstrBuilder &addBlockAddress(const BlockAddress *BA,
     178             :                                              int64_t Offset = 0,
     179             :                                           unsigned char TargetFlags = 0) const {
     180         260 :     MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
     181             :     return *this;
     182             :   }
     183             : 
     184             :   const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
     185      547996 :     MI->addOperand(*MF, MachineOperand::CreateRegMask(Mask));
     186             :     return *this;
     187             :   }
     188             : 
     189             :   const MachineInstrBuilder &addMemOperand(MachineMemOperand *MMO) const {
     190      170129 :     MI->addMemOperand(*MF, MMO);
     191             :     return *this;
     192             :   }
     193             : 
     194             :   const MachineInstrBuilder &setMemRefs(MachineInstr::mmo_iterator b,
     195             :                                         MachineInstr::mmo_iterator e) const {
     196     2968989 :     MI->setMemRefs(b, e);
     197             :     return *this;
     198             :   }
     199             : 
     200             :   const MachineInstrBuilder &setMemRefs(std::pair<MachineInstr::mmo_iterator,
     201             :                                         unsigned> MemOperandsRef) const {
     202        2967 :     MI->setMemRefs(MemOperandsRef);
     203             :     return *this;
     204             :   }
     205             : 
     206             :   const MachineInstrBuilder &add(const MachineOperand &MO) const {
     207      791016 :     MI->addOperand(*MF, MO);
     208             :     return *this;
     209             :   }
     210             : 
     211             :   const MachineInstrBuilder &add(ArrayRef<MachineOperand> MOs) const {
     212      275420 :     for (const MachineOperand &MO : MOs) {
     213      110168 :       MI->addOperand(*MF, MO);
     214             :     }
     215             :     return *this;
     216             :   }
     217             : 
     218             :   const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
     219      247017 :     MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
     220             :     assert((MI->isDebugValue() ? static_cast<bool>(MI->getDebugVariable())
     221             :                                : true) &&
     222             :            "first MDNode argument of a DBG_VALUE not a variable");
     223             :     return *this;
     224             :   }
     225             : 
     226             :   const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
     227      670462 :     MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
     228             :     return *this;
     229             :   }
     230             : 
     231             :   const MachineInstrBuilder &addIntrinsicID(Intrinsic::ID ID) const {
     232          18 :     MI->addOperand(*MF, MachineOperand::CreateIntrinsicID(ID));
     233             :     return *this;
     234             :   }
     235             : 
     236             :   const MachineInstrBuilder &addPredicate(CmpInst::Predicate Pred) const {
     237         248 :     MI->addOperand(*MF, MachineOperand::CreatePredicate(Pred));
     238             :     return *this;
     239             :   }
     240             : 
     241             :   const MachineInstrBuilder &addSym(MCSymbol *Sym,
     242             :                                     unsigned char TargetFlags = 0) const {
     243      219494 :     MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));
     244             :     return *this;
     245             :   }
     246             : 
     247             :   const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
     248       12925 :     MI->setFlags(Flags);
     249             :     return *this;
     250             :   }
     251             : 
     252             :   const MachineInstrBuilder &setMIFlag(MachineInstr::MIFlag Flag) const {
     253      228759 :     MI->setFlag(Flag);
     254             :     return *this;
     255             :   }
     256             : 
     257             :   // Add a displacement from an existing MachineOperand with an added offset.
     258          41 :   const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
     259             :                                      unsigned char TargetFlags = 0) const {
     260             :     // If caller specifies new TargetFlags then use it, otherwise the
     261             :     // default behavior is to copy the target flags from the existing
     262             :     // MachineOperand. This means if the caller wants to clear the
     263             :     // target flags it needs to do so explicitly.
     264          41 :     if (0 == TargetFlags)
     265          41 :       TargetFlags = Disp.getTargetFlags();
     266             : 
     267          41 :     switch (Disp.getType()) {
     268           0 :       default:
     269           0 :         llvm_unreachable("Unhandled operand type in addDisp()");
     270          18 :       case MachineOperand::MO_Immediate:
     271          36 :         return addImm(Disp.getImm() + off);
     272           6 :       case MachineOperand::MO_ConstantPoolIndex:
     273          18 :         return addConstantPoolIndex(Disp.getIndex(), Disp.getOffset() + off,
     274          12 :                                     TargetFlags);
     275          17 :       case MachineOperand::MO_GlobalAddress:
     276          17 :         return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
     277          34 :                                 TargetFlags);
     278             :     }
     279             :   }
     280             : 
     281             :   /// Copy all the implicit operands from OtherMI onto this one.
     282             :   const MachineInstrBuilder &
     283             :   copyImplicitOps(const MachineInstr &OtherMI) const {
     284        4417 :     MI->copyImplicitOps(*MF, OtherMI);
     285             :     return *this;
     286             :   }
     287             : 
     288             :   bool constrainAllUses(const TargetInstrInfo &TII,
     289             :                         const TargetRegisterInfo &TRI,
     290             :                         const RegisterBankInfo &RBI) const {
     291           4 :     return constrainSelectedInstRegOperands(*MI, TII, TRI, RBI);
     292             :   }
     293             : };
     294             : 
     295             : /// Builder interface. Specify how to create the initial instruction itself.
     296             : inline MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
     297             :                                    const MCInstrDesc &MCID) {
     298     3082365 :   return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL));
     299             : }
     300             : 
     301             : /// This version of the builder sets up the first operand as a
     302             : /// destination virtual register.
     303      121581 : inline MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
     304             :                                    const MCInstrDesc &MCID, unsigned DestReg) {
     305      243162 :   return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL))
     306      243162 :            .addReg(DestReg, RegState::Define);
     307             : }
     308             : 
     309             : /// This version of the builder inserts the newly-built instruction before
     310             : /// the given position in the given MachineBasicBlock, and sets up the first
     311             : /// operand as a destination virtual register.
     312     2907090 : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
     313             :                                    MachineBasicBlock::iterator I,
     314             :                                    const DebugLoc &DL, const MCInstrDesc &MCID,
     315             :                                    unsigned DestReg) {
     316     2907090 :   MachineFunction &MF = *BB.getParent();
     317     2907090 :   MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
     318             :   BB.insert(I, MI);
     319     2907090 :   return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
     320             : }
     321             : 
     322             : /// This version of the builder inserts the newly-built instruction before
     323             : /// the given position in the given MachineBasicBlock, and sets up the first
     324             : /// operand as a destination virtual register.
     325             : ///
     326             : /// If \c I is inside a bundle, then the newly inserted \a MachineInstr is
     327             : /// added to the same bundle.
     328        8457 : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
     329             :                                    MachineBasicBlock::instr_iterator I,
     330             :                                    const DebugLoc &DL, const MCInstrDesc &MCID,
     331             :                                    unsigned DestReg) {
     332        8457 :   MachineFunction &MF = *BB.getParent();
     333        8457 :   MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
     334        8457 :   BB.insert(I, MI);
     335        8457 :   return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
     336             : }
     337             : 
     338      311961 : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr &I,
     339             :                                    const DebugLoc &DL, const MCInstrDesc &MCID,
     340             :                                    unsigned DestReg) {
     341             :   // Calling the overload for instr_iterator is always correct.  However, the
     342             :   // definition is not available in headers, so inline the check.
     343      311961 :   if (I.isInsideBundle())
     344           0 :     return BuildMI(BB, MachineBasicBlock::instr_iterator(I), DL, MCID, DestReg);
     345      311961 :   return BuildMI(BB, MachineBasicBlock::iterator(I), DL, MCID, DestReg);
     346             : }
     347             : 
     348             : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr *I,
     349             :                                    const DebugLoc &DL, const MCInstrDesc &MCID,
     350             :                                    unsigned DestReg) {
     351      295755 :   return BuildMI(BB, *I, DL, MCID, DestReg);
     352             : }
     353             : 
     354             : /// This version of the builder inserts the newly-built instruction before the
     355             : /// given position in the given MachineBasicBlock, and does NOT take a
     356             : /// destination register.
     357     1903366 : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
     358             :                                    MachineBasicBlock::iterator I,
     359             :                                    const DebugLoc &DL,
     360             :                                    const MCInstrDesc &MCID) {
     361     1903366 :   MachineFunction &MF = *BB.getParent();
     362     1903366 :   MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
     363             :   BB.insert(I, MI);
     364     1903366 :   return MachineInstrBuilder(MF, MI);
     365             : }
     366             : 
     367       36594 : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
     368             :                                    MachineBasicBlock::instr_iterator I,
     369             :                                    const DebugLoc &DL,
     370             :                                    const MCInstrDesc &MCID) {
     371       36594 :   MachineFunction &MF = *BB.getParent();
     372       36594 :   MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
     373       36594 :   BB.insert(I, MI);
     374       36594 :   return MachineInstrBuilder(MF, MI);
     375             : }
     376             : 
     377      239881 : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr &I,
     378             :                                    const DebugLoc &DL,
     379             :                                    const MCInstrDesc &MCID) {
     380             :   // Calling the overload for instr_iterator is always correct.  However, the
     381             :   // definition is not available in headers, so inline the check.
     382      239881 :   if (I.isInsideBundle())
     383         523 :     return BuildMI(BB, MachineBasicBlock::instr_iterator(I), DL, MCID);
     384      239358 :   return BuildMI(BB, MachineBasicBlock::iterator(I), DL, MCID);
     385             : }
     386             : 
     387             : inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr *I,
     388             :                                    const DebugLoc &DL,
     389             :                                    const MCInstrDesc &MCID) {
     390      106015 :   return BuildMI(BB, *I, DL, MCID);
     391             : }
     392             : 
     393             : /// This version of the builder inserts the newly-built instruction at the end
     394             : /// of the given MachineBasicBlock, and does NOT take a destination register.
     395             : inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const DebugLoc &DL,
     396             :                                    const MCInstrDesc &MCID) {
     397      432159 :   return BuildMI(*BB, BB->end(), DL, MCID);
     398             : }
     399             : 
     400             : /// This version of the builder inserts the newly-built instruction at the
     401             : /// end of the given MachineBasicBlock, and sets up the first operand as a
     402             : /// destination virtual register.
     403             : inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const DebugLoc &DL,
     404             :                                    const MCInstrDesc &MCID, unsigned DestReg) {
     405       50422 :   return BuildMI(*BB, BB->end(), DL, MCID, DestReg);
     406             : }
     407             : 
     408             : /// This version of the builder builds a DBG_VALUE intrinsic
     409             : /// for either a value in a register or a register-indirect
     410             : /// address.  The convention is that a DBG_VALUE is indirect iff the
     411             : /// second operand is an immediate.
     412             : MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
     413             :                             const MCInstrDesc &MCID, bool IsIndirect,
     414             :                             unsigned Reg, const MDNode *Variable,
     415             :                             const MDNode *Expr);
     416             : 
     417             : /// This version of the builder builds a DBG_VALUE intrinsic
     418             : /// for either a value in a register or a register-indirect
     419             : /// address and inserts it at position I.
     420             : MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
     421             :                             MachineBasicBlock::iterator I, const DebugLoc &DL,
     422             :                             const MCInstrDesc &MCID, bool IsIndirect,
     423             :                             unsigned Reg, const MDNode *Variable,
     424             :                             const MDNode *Expr);
     425             : 
     426             : /// Clone a DBG_VALUE whose value has been spilled to FrameIndex.
     427             : MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
     428             :                                     MachineBasicBlock::iterator I,
     429             :                                     const MachineInstr &Orig, int FrameIndex);
     430             : 
     431             : /// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
     432             : /// modifying an instruction in place while iterating over a basic block.
     433             : void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex);
     434             : 
     435             : inline unsigned getDefRegState(bool B) {
     436     2030047 :   return B ? RegState::Define : 0;
     437             : }
     438             : inline unsigned getImplRegState(bool B) {
     439       54781 :   return B ? RegState::Implicit : 0;
     440             : }
     441             : inline unsigned getKillRegState(bool B) {
     442     2573528 :   return B ? RegState::Kill : 0;
     443             : }
     444             : inline unsigned getDeadRegState(bool B) {
     445        5015 :   return B ? RegState::Dead : 0;
     446             : }
     447             : inline unsigned getUndefRegState(bool B) {
     448      100116 :   return B ? RegState::Undef : 0;
     449             : }
     450             : inline unsigned getInternalReadRegState(bool B) {
     451        1211 :   return B ? RegState::InternalRead : 0;
     452             : }
     453             : inline unsigned getDebugRegState(bool B) {
     454     2015488 :   return B ? RegState::Debug : 0;
     455             : }
     456             : inline unsigned getRenamableRegState(bool B) {
     457             :   return B ? RegState::Renamable : 0;
     458             : }
     459             : 
     460             : /// Get all register state flags from machine operand \p RegOp.
     461        1108 : inline unsigned getRegState(const MachineOperand &RegOp) {
     462             :   assert(RegOp.isReg() && "Not a register operand");
     463        1108 :   return getDefRegState(RegOp.isDef())                    |
     464        1108 :          getImplRegState(RegOp.isImplicit())              |
     465        1108 :          getKillRegState(RegOp.isKill())                  |
     466        1108 :          getDeadRegState(RegOp.isDead())                  |
     467        1108 :          getUndefRegState(RegOp.isUndef())                |
     468        1108 :          getInternalReadRegState(RegOp.isInternalRead())  |
     469             :          getDebugRegState(RegOp.isDebug())                |
     470             :          getRenamableRegState(
     471        2453 :              TargetRegisterInfo::isPhysicalRegister(RegOp.getReg()) &&
     472        1345 :              RegOp.isRenamable());
     473             : }
     474             : 
     475             : /// Helper class for constructing bundles of MachineInstrs.
     476             : ///
     477             : /// MIBundleBuilder can create a bundle from scratch by inserting new
     478             : /// MachineInstrs one at a time, or it can create a bundle from a sequence of
     479             : /// existing MachineInstrs in a basic block.
     480             : class MIBundleBuilder {
     481             :   MachineBasicBlock &MBB;
     482             :   MachineBasicBlock::instr_iterator Begin;
     483             :   MachineBasicBlock::instr_iterator End;
     484             : 
     485             : public:
     486             :   /// Create an MIBundleBuilder that inserts instructions into a new bundle in
     487             :   /// BB above the bundle or instruction at Pos.
     488             :   MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator Pos)
     489         501 :       : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
     490             : 
     491             :   /// Create a bundle from the sequence of instructions between B and E.
     492       34450 :   MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator B,
     493             :                   MachineBasicBlock::iterator E)
     494      103350 :       : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
     495             :     assert(B != E && "No instructions to bundle");
     496             :     ++B;
     497      126404 :     while (B != E) {
     498             :       MachineInstr &MI = *B;
     499             :       ++B;
     500       45977 :       MI.bundleWithPred();
     501             :     }
     502       34450 :   }
     503             : 
     504             :   /// Create an MIBundleBuilder representing an existing instruction or bundle
     505             :   /// that has MI as its head.
     506             :   explicit MIBundleBuilder(MachineInstr *MI)
     507          65 :       : MBB(*MI->getParent()), Begin(MI),
     508         195 :         End(getBundleEnd(MI->getIterator())) {}
     509             : 
     510             :   /// Return a reference to the basic block containing this bundle.
     511             :   MachineBasicBlock &getMBB() const { return MBB; }
     512             : 
     513             :   /// Return true if no instructions have been inserted in this bundle yet.
     514             :   /// Empty bundles aren't representable in a MachineBasicBlock.
     515             :   bool empty() const { return Begin == End; }
     516             : 
     517             :   /// Return an iterator to the first bundled instruction.
     518             :   MachineBasicBlock::instr_iterator begin() const { return Begin; }
     519             : 
     520             :   /// Return an iterator beyond the last bundled instruction.
     521             :   MachineBasicBlock::instr_iterator end() const { return End; }
     522             : 
     523             :   /// Insert MI into this bundle before I which must point to an instruction in
     524             :   /// the bundle, or end().
     525       21036 :   MIBundleBuilder &insert(MachineBasicBlock::instr_iterator I,
     526             :                           MachineInstr *MI) {
     527       21036 :     MBB.insert(I, MI);
     528       21036 :     if (I == Begin) {
     529       19971 :       if (!empty())
     530       19470 :         MI->bundleWithSucc();
     531       19971 :       Begin = MI->getIterator();
     532       19971 :       return *this;
     533             :     }
     534        1065 :     if (I == End) {
     535        1065 :       MI->bundleWithPred();
     536        1065 :       return *this;
     537             :     }
     538             :     // MI was inserted in the middle of the bundle, so its neighbors' flags are
     539             :     // already fine. Update MI's bundle flags manually.
     540             :     MI->setFlag(MachineInstr::BundledPred);
     541             :     MI->setFlag(MachineInstr::BundledSucc);
     542           0 :     return *this;
     543             :   }
     544             : 
     545             :   /// Insert MI into MBB by prepending it to the instructions in the bundle.
     546             :   /// MI will become the first instruction in the bundle.
     547             :   MIBundleBuilder &prepend(MachineInstr *MI) {
     548       19470 :     return insert(begin(), MI);
     549             :   }
     550             : 
     551             :   /// Insert MI into MBB by appending it to the instructions in the bundle.
     552             :   /// MI will become the last instruction in the bundle.
     553             :   MIBundleBuilder &append(MachineInstr *MI) {
     554        1566 :     return insert(end(), MI);
     555             :   }
     556             : };
     557             : 
     558             : } // end namespace llvm
     559             : 
     560             : #endif // LLVM_CODEGEN_MACHINEINSTRBUILDER_H

Generated by: LCOV version 1.13