LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - TargetInstrInfo.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 107 210 51.0 %
Date: 2018-05-20 00:06:23 Functions: 44 98 44.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/CodeGen/TargetInstrInfo.h - Instruction Info --------*- 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 describes the target machine instruction set to the code generator.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_TARGET_TARGETINSTRINFO_H
      15             : #define LLVM_TARGET_TARGETINSTRINFO_H
      16             : 
      17             : #include "llvm/ADT/ArrayRef.h"
      18             : #include "llvm/ADT/DenseMap.h"
      19             : #include "llvm/ADT/DenseMapInfo.h"
      20             : #include "llvm/ADT/None.h"
      21             : #include "llvm/CodeGen/LiveRegUnits.h"
      22             : #include "llvm/CodeGen/MachineBasicBlock.h"
      23             : #include "llvm/CodeGen/MachineCombinerPattern.h"
      24             : #include "llvm/CodeGen/MachineFunction.h"
      25             : #include "llvm/CodeGen/MachineInstr.h"
      26             : #include "llvm/CodeGen/MachineLoopInfo.h"
      27             : #include "llvm/CodeGen/MachineOperand.h"
      28             : #include "llvm/CodeGen/PseudoSourceValue.h"
      29             : #include "llvm/MC/MCInstrInfo.h"
      30             : #include "llvm/Support/BranchProbability.h"
      31             : #include "llvm/Support/ErrorHandling.h"
      32             : #include <cassert>
      33             : #include <cstddef>
      34             : #include <cstdint>
      35             : #include <utility>
      36             : #include <vector>
      37             : 
      38             : namespace llvm {
      39             : 
      40             : class DFAPacketizer;
      41             : class InstrItineraryData;
      42             : class LiveIntervals;
      43             : class LiveVariables;
      44             : class MachineMemOperand;
      45             : class MachineRegisterInfo;
      46             : class MCAsmInfo;
      47             : class MCInst;
      48             : struct MCSchedModel;
      49             : class Module;
      50             : class ScheduleDAG;
      51             : class ScheduleHazardRecognizer;
      52             : class SDNode;
      53             : class SelectionDAG;
      54             : class RegScavenger;
      55             : class TargetRegisterClass;
      56             : class TargetRegisterInfo;
      57             : class TargetSchedModel;
      58             : class TargetSubtargetInfo;
      59             : 
      60             : template <class T> class SmallVectorImpl;
      61             : 
      62             : //---------------------------------------------------------------------------
      63             : ///
      64             : /// TargetInstrInfo - Interface to description of machine instruction set
      65             : ///
      66             : class TargetInstrInfo : public MCInstrInfo {
      67             : public:
      68             :   TargetInstrInfo(unsigned CFSetupOpcode = ~0u, unsigned CFDestroyOpcode = ~0u,
      69             :                   unsigned CatchRetOpcode = ~0u, unsigned ReturnOpcode = ~0u)
      70       34776 :       : CallFrameSetupOpcode(CFSetupOpcode),
      71             :         CallFrameDestroyOpcode(CFDestroyOpcode), CatchRetOpcode(CatchRetOpcode),
      72       34776 :         ReturnOpcode(ReturnOpcode) {}
      73             :   TargetInstrInfo(const TargetInstrInfo &) = delete;
      74             :   TargetInstrInfo &operator=(const TargetInstrInfo &) = delete;
      75             :   virtual ~TargetInstrInfo();
      76             : 
      77             :   static bool isGenericOpcode(unsigned Opc) {
      78             :     return Opc <= TargetOpcode::GENERIC_OP_END;
      79             :   }
      80             : 
      81             :   /// Given a machine instruction descriptor, returns the register
      82             :   /// class constraint for OpNum, or NULL.
      83             :   const TargetRegisterClass *getRegClass(const MCInstrDesc &TID, unsigned OpNum,
      84             :                                          const TargetRegisterInfo *TRI,
      85             :                                          const MachineFunction &MF) const;
      86             : 
      87             :   /// Return true if the instruction is trivially rematerializable, meaning it
      88             :   /// has no side effects and requires no operands that aren't always available.
      89             :   /// This means the only allowed uses are constants and unallocatable physical
      90             :   /// registers so that the instructions result is independent of the place
      91             :   /// in the function.
      92      833347 :   bool isTriviallyReMaterializable(const MachineInstr &MI,
      93             :                                    AliasAnalysis *AA = nullptr) const {
      94     2499768 :     return MI.getOpcode() == TargetOpcode::IMPLICIT_DEF ||
      95     1311903 :            (MI.getDesc().isRematerializable() &&
      96      769016 :             (isReallyTriviallyReMaterializable(MI, AA) ||
      97     1123534 :              isReallyTriviallyReMaterializableGeneric(MI, AA)));
      98             :   }
      99             : 
     100             : protected:
     101             :   /// For instructions with opcodes for which the M_REMATERIALIZABLE flag is
     102             :   /// set, this hook lets the target specify whether the instruction is actually
     103             :   /// trivially rematerializable, taking into consideration its operands. This
     104             :   /// predicate must return false if the instruction has any side effects other
     105             :   /// than producing a value, or if it requres any address registers that are
     106             :   /// not always available.
     107             :   /// Requirements must be check as stated in isTriviallyReMaterializable() .
     108       36601 :   virtual bool isReallyTriviallyReMaterializable(const MachineInstr &MI,
     109             :                                                  AliasAnalysis *AA) const {
     110       36601 :     return false;
     111             :   }
     112             : 
     113             :   /// This method commutes the operands of the given machine instruction MI.
     114             :   /// The operands to be commuted are specified by their indices OpIdx1 and
     115             :   /// OpIdx2.
     116             :   ///
     117             :   /// If a target has any instructions that are commutable but require
     118             :   /// converting to different instructions or making non-trivial changes
     119             :   /// to commute them, this method can be overloaded to do that.
     120             :   /// The default implementation simply swaps the commutable operands.
     121             :   ///
     122             :   /// If NewMI is false, MI is modified in place and returned; otherwise, a
     123             :   /// new machine instruction is created and returned.
     124             :   ///
     125             :   /// Do not call this method for a non-commutable instruction.
     126             :   /// Even though the instruction is commutable, the method may still
     127             :   /// fail to commute the operands, null pointer is returned in such cases.
     128             :   virtual MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,
     129             :                                                unsigned OpIdx1,
     130             :                                                unsigned OpIdx2) const;
     131             : 
     132             :   /// Assigns the (CommutableOpIdx1, CommutableOpIdx2) pair of commutable
     133             :   /// operand indices to (ResultIdx1, ResultIdx2).
     134             :   /// One or both input values of the pair: (ResultIdx1, ResultIdx2) may be
     135             :   /// predefined to some indices or be undefined (designated by the special
     136             :   /// value 'CommuteAnyOperandIndex').
     137             :   /// The predefined result indices cannot be re-defined.
     138             :   /// The function returns true iff after the result pair redefinition
     139             :   /// the fixed result pair is equal to or equivalent to the source pair of
     140             :   /// indices: (CommutableOpIdx1, CommutableOpIdx2). It is assumed here that
     141             :   /// the pairs (x,y) and (y,x) are equivalent.
     142             :   static bool fixCommutedOpIndices(unsigned &ResultIdx1, unsigned &ResultIdx2,
     143             :                                    unsigned CommutableOpIdx1,
     144             :                                    unsigned CommutableOpIdx2);
     145             : 
     146             : private:
     147             :   /// For instructions with opcodes for which the M_REMATERIALIZABLE flag is
     148             :   /// set and the target hook isReallyTriviallyReMaterializable returns false,
     149             :   /// this function does target-independent tests to determine if the
     150             :   /// instruction is really trivially rematerializable.
     151             :   bool isReallyTriviallyReMaterializableGeneric(const MachineInstr &MI,
     152             :                                                 AliasAnalysis *AA) const;
     153             : 
     154             : public:
     155             :   /// These methods return the opcode of the frame setup/destroy instructions
     156             :   /// if they exist (-1 otherwise).  Some targets use pseudo instructions in
     157             :   /// order to abstract away the difference between operating with a frame
     158             :   /// pointer and operating without, through the use of these two instructions.
     159             :   ///
     160             :   unsigned getCallFrameSetupOpcode() const { return CallFrameSetupOpcode; }
     161             :   unsigned getCallFrameDestroyOpcode() const { return CallFrameDestroyOpcode; }
     162             : 
     163             :   /// Returns true if the argument is a frame pseudo instruction.
     164             :   bool isFrameInstr(const MachineInstr &I) const {
     165    21955315 :     return I.getOpcode() == getCallFrameSetupOpcode() ||
     166     7142289 :            I.getOpcode() == getCallFrameDestroyOpcode();
     167             :   }
     168             : 
     169             :   /// Returns true if the argument is a frame setup pseudo instruction.
     170             :   bool isFrameSetup(const MachineInstr &I) const {
     171      835979 :     return I.getOpcode() == getCallFrameSetupOpcode();
     172             :   }
     173             : 
     174             :   /// Returns size of the frame associated with the given frame instruction.
     175             :   /// For frame setup instruction this is frame that is set up space set up
     176             :   /// after the instruction. For frame destroy instruction this is the frame
     177             :   /// freed by the caller.
     178             :   /// Note, in some cases a call frame (or a part of it) may be prepared prior
     179             :   /// to the frame setup instruction. It occurs in the calls that involve
     180             :   /// inalloca arguments. This function reports only the size of the frame part
     181             :   /// that is set up between the frame setup and destroy pseudo instructions.
     182             :   int64_t getFrameSize(const MachineInstr &I) const {
     183             :     assert(isFrameInstr(I) && "Not a frame instruction");
     184             :     assert(I.getOperand(0).getImm() >= 0);
     185      908818 :     return I.getOperand(0).getImm();
     186             :   }
     187             : 
     188             :   /// Returns the total frame size, which is made up of the space set up inside
     189             :   /// the pair of frame start-stop instructions and the space that is set up
     190             :   /// prior to the pair.
     191             :   int64_t getFrameTotalSize(const MachineInstr &I) const {
     192      228966 :     if (isFrameSetup(I)) {
     193             :       assert(I.getOperand(1).getImm() >= 0 &&
     194             :              "Frame size must not be negative");
     195      114483 :       return getFrameSize(I) + I.getOperand(1).getImm();
     196             :     }
     197             :     return getFrameSize(I);
     198             :   }
     199             : 
     200             :   unsigned getCatchReturnOpcode() const { return CatchRetOpcode; }
     201             :   unsigned getReturnOpcode() const { return ReturnOpcode; }
     202             : 
     203             :   /// Returns the actual stack pointer adjustment made by an instruction
     204             :   /// as part of a call sequence. By default, only call frame setup/destroy
     205             :   /// instructions adjust the stack, but targets may want to override this
     206             :   /// to enable more fine-grained adjustment, or adjust by a different value.
     207             :   virtual int getSPAdjust(const MachineInstr &MI) const;
     208             : 
     209             :   /// Return true if the instruction is a "coalescable" extension instruction.
     210             :   /// That is, it's like a copy where it's legal for the source to overlap the
     211             :   /// destination. e.g. X86::MOVSX64rr32. If this returns true, then it's
     212             :   /// expected the pre-extension value is available as a subreg of the result
     213             :   /// register. This also returns the sub-register index in SubIdx.
     214      933700 :   virtual bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
     215             :                                      unsigned &DstReg, unsigned &SubIdx) const {
     216      933700 :     return false;
     217             :   }
     218             : 
     219             :   /// If the specified machine instruction is a direct
     220             :   /// load from a stack slot, return the virtual or physical register number of
     221             :   /// the destination along with the FrameIndex of the loaded stack slot.  If
     222             :   /// not, return 0.  This predicate must return 0 if the instruction has
     223             :   /// any side effects other than loading from the stack slot.
     224        1710 :   virtual unsigned isLoadFromStackSlot(const MachineInstr &MI,
     225             :                                        int &FrameIndex) const {
     226        1710 :     return 0;
     227             :   }
     228             : 
     229             :   /// Optional extension of isLoadFromStackSlot that returns the number of
     230             :   /// bytes loaded from the stack. This must be implemented if a backend
     231             :   /// supports partial stack slot spills/loads to further disambiguate
     232             :   /// what the load does.
     233       13704 :   virtual unsigned isLoadFromStackSlot(const MachineInstr &MI,
     234             :                                        int &FrameIndex,
     235             :                                        unsigned &MemBytes) const {
     236       13704 :     MemBytes = 0;
     237       13704 :     return isLoadFromStackSlot(MI, FrameIndex);
     238             :   }
     239             : 
     240             :   /// Check for post-frame ptr elimination stack locations as well.
     241             :   /// This uses a heuristic so it isn't reliable for correctness.
     242      769289 :   virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
     243             :                                              int &FrameIndex) const {
     244      769289 :     return 0;
     245             :   }
     246             : 
     247             :   /// If the specified machine instruction has a load from a stack slot,
     248             :   /// return true along with the FrameIndex of the loaded stack slot and the
     249             :   /// machine mem operand containing the reference.
     250             :   /// If not, return false.  Unlike isLoadFromStackSlot, this returns true for
     251             :   /// any instructions that loads from the stack.  This is just a hint, as some
     252             :   /// cases may be missed.
     253             :   virtual bool hasLoadFromStackSlot(const MachineInstr &MI,
     254             :                                     const MachineMemOperand *&MMO,
     255             :                                     int &FrameIndex) const;
     256             : 
     257             :   /// If the specified machine instruction is a direct
     258             :   /// store to a stack slot, return the virtual or physical register number of
     259             :   /// the source reg along with the FrameIndex of the loaded stack slot.  If
     260             :   /// not, return 0.  This predicate must return 0 if the instruction has
     261             :   /// any side effects other than storing to the stack slot.
     262        1036 :   virtual unsigned isStoreToStackSlot(const MachineInstr &MI,
     263             :                                       int &FrameIndex) const {
     264        1036 :     return 0;
     265             :   }
     266             : 
     267             :   /// Optional extension of isStoreToStackSlot that returns the number of
     268             :   /// bytes stored to the stack. This must be implemented if a backend
     269             :   /// supports partial stack slot spills/loads to further disambiguate
     270             :   /// what the store does.
     271        1214 :   virtual unsigned isStoreToStackSlot(const MachineInstr &MI,
     272             :                                       int &FrameIndex,
     273             :                                       unsigned &MemBytes) const {
     274        1214 :     MemBytes = 0;
     275        1214 :     return isStoreToStackSlot(MI, FrameIndex);
     276             :   }
     277             : 
     278             :   /// Check for post-frame ptr elimination stack locations as well.
     279             :   /// This uses a heuristic, so it isn't reliable for correctness.
     280      749855 :   virtual unsigned isStoreToStackSlotPostFE(const MachineInstr &MI,
     281             :                                             int &FrameIndex) const {
     282      749855 :     return 0;
     283             :   }
     284             : 
     285             :   /// If the specified machine instruction has a store to a stack slot,
     286             :   /// return true along with the FrameIndex of the loaded stack slot and the
     287             :   /// machine mem operand containing the reference.
     288             :   /// If not, return false.  Unlike isStoreToStackSlot,
     289             :   /// this returns true for any instructions that stores to the
     290             :   /// stack.  This is just a hint, as some cases may be missed.
     291             :   virtual bool hasStoreToStackSlot(const MachineInstr &MI,
     292             :                                    const MachineMemOperand *&MMO,
     293             :                                    int &FrameIndex) const;
     294             : 
     295             :   /// Return true if the specified machine instruction
     296             :   /// is a copy of one stack slot to another and has no other effect.
     297             :   /// Provide the identity of the two frame indices.
     298      806773 :   virtual bool isStackSlotCopy(const MachineInstr &MI, int &DestFrameIndex,
     299             :                                int &SrcFrameIndex) const {
     300      806773 :     return false;
     301             :   }
     302             : 
     303             :   /// Compute the size in bytes and offset within a stack slot of a spilled
     304             :   /// register or subregister.
     305             :   ///
     306             :   /// \param [out] Size in bytes of the spilled value.
     307             :   /// \param [out] Offset in bytes within the stack slot.
     308             :   /// \returns true if both Size and Offset are successfully computed.
     309             :   ///
     310             :   /// Not all subregisters have computable spill slots. For example,
     311             :   /// subregisters registers may not be byte-sized, and a pair of discontiguous
     312             :   /// subregisters has no single offset.
     313             :   ///
     314             :   /// Targets with nontrivial bigendian implementations may need to override
     315             :   /// this, particularly to support spilled vector registers.
     316             :   virtual bool getStackSlotRange(const TargetRegisterClass *RC, unsigned SubIdx,
     317             :                                  unsigned &Size, unsigned &Offset,
     318             :                                  const MachineFunction &MF) const;
     319             : 
     320             :   /// Returns the size in bytes of the specified MachineInstr, or ~0U
     321             :   /// when this function is not implemented by a target.
     322           0 :   virtual unsigned getInstSizeInBytes(const MachineInstr &MI) const {
     323           0 :     return ~0U;
     324             :   }
     325             : 
     326             :   /// Return true if the instruction is as cheap as a move instruction.
     327             :   ///
     328             :   /// Targets for different archs need to override this, and different
     329             :   /// micro-architectures can also be finely tuned inside.
     330      615392 :   virtual bool isAsCheapAsAMove(const MachineInstr &MI) const {
     331      615392 :     return MI.isAsCheapAsAMove();
     332             :   }
     333             : 
     334             :   /// Return true if the instruction should be sunk by MachineSink.
     335             :   ///
     336             :   /// MachineSink determines on its own whether the instruction is safe to sink;
     337             :   /// this gives the target a hook to override the default behavior with regards
     338             :   /// to which instructions should be sunk.
     339     2798799 :   virtual bool shouldSink(const MachineInstr &MI) const { return true; }
     340             : 
     341             :   /// Re-issue the specified 'original' instruction at the
     342             :   /// specific location targeting a new destination register.
     343             :   /// The register in Orig->getOperand(0).getReg() will be substituted by
     344             :   /// DestReg:SubIdx. Any existing subreg index is preserved or composed with
     345             :   /// SubIdx.
     346             :   virtual void reMaterialize(MachineBasicBlock &MBB,
     347             :                              MachineBasicBlock::iterator MI, unsigned DestReg,
     348             :                              unsigned SubIdx, const MachineInstr &Orig,
     349             :                              const TargetRegisterInfo &TRI) const;
     350             : 
     351             :   /// Clones instruction or the whole instruction bundle \p Orig and
     352             :   /// insert into \p MBB before \p InsertBefore. The target may update operands
     353             :   /// that are required to be unique.
     354             :   ///
     355             :   /// \p Orig must not return true for MachineInstr::isNotDuplicable().
     356             :   virtual MachineInstr &duplicate(MachineBasicBlock &MBB,
     357             :                                   MachineBasicBlock::iterator InsertBefore,
     358             :                                   const MachineInstr &Orig) const;
     359             : 
     360             :   /// This method must be implemented by targets that
     361             :   /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
     362             :   /// may be able to convert a two-address instruction into one or more true
     363             :   /// three-address instructions on demand.  This allows the X86 target (for
     364             :   /// example) to convert ADD and SHL instructions into LEA instructions if they
     365             :   /// would require register copies due to two-addressness.
     366             :   ///
     367             :   /// This method returns a null pointer if the transformation cannot be
     368             :   /// performed, otherwise it returns the last new instruction.
     369             :   ///
     370           0 :   virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
     371             :                                               MachineInstr &MI,
     372             :                                               LiveVariables *LV) const {
     373           0 :     return nullptr;
     374             :   }
     375             : 
     376             :   // This constant can be used as an input value of operand index passed to
     377             :   // the method findCommutedOpIndices() to tell the method that the
     378             :   // corresponding operand index is not pre-defined and that the method
     379             :   // can pick any commutable operand.
     380             :   static const unsigned CommuteAnyOperandIndex = ~0U;
     381             : 
     382             :   /// This method commutes the operands of the given machine instruction MI.
     383             :   ///
     384             :   /// The operands to be commuted are specified by their indices OpIdx1 and
     385             :   /// OpIdx2. OpIdx1 and OpIdx2 arguments may be set to a special value
     386             :   /// 'CommuteAnyOperandIndex', which means that the method is free to choose
     387             :   /// any arbitrarily chosen commutable operand. If both arguments are set to
     388             :   /// 'CommuteAnyOperandIndex' then the method looks for 2 different commutable
     389             :   /// operands; then commutes them if such operands could be found.
     390             :   ///
     391             :   /// If NewMI is false, MI is modified in place and returned; otherwise, a
     392             :   /// new machine instruction is created and returned.
     393             :   ///
     394             :   /// Do not call this method for a non-commutable instruction or
     395             :   /// for non-commuable operands.
     396             :   /// Even though the instruction is commutable, the method may still
     397             :   /// fail to commute the operands, null pointer is returned in such cases.
     398             :   MachineInstr *
     399             :   commuteInstruction(MachineInstr &MI, bool NewMI = false,
     400             :                      unsigned OpIdx1 = CommuteAnyOperandIndex,
     401             :                      unsigned OpIdx2 = CommuteAnyOperandIndex) const;
     402             : 
     403             :   /// Returns true iff the routine could find two commutable operands in the
     404             :   /// given machine instruction.
     405             :   /// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments.
     406             :   /// If any of the INPUT values is set to the special value
     407             :   /// 'CommuteAnyOperandIndex' then the method arbitrarily picks a commutable
     408             :   /// operand, then returns its index in the corresponding argument.
     409             :   /// If both of INPUT values are set to 'CommuteAnyOperandIndex' then method
     410             :   /// looks for 2 commutable operands.
     411             :   /// If INPUT values refer to some operands of MI, then the method simply
     412             :   /// returns true if the corresponding operands are commutable and returns
     413             :   /// false otherwise.
     414             :   ///
     415             :   /// For example, calling this method this way:
     416             :   ///     unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
     417             :   ///     findCommutedOpIndices(MI, Op1, Op2);
     418             :   /// can be interpreted as a query asking to find an operand that would be
     419             :   /// commutable with the operand#1.
     420             :   virtual bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
     421             :                                      unsigned &SrcOpIdx2) const;
     422             : 
     423             :   /// A pair composed of a register and a sub-register index.
     424             :   /// Used to give some type checking when modeling Reg:SubReg.
     425             :   struct RegSubRegPair {
     426             :     unsigned Reg;
     427             :     unsigned SubReg;
     428             : 
     429             :     RegSubRegPair(unsigned Reg = 0, unsigned SubReg = 0)
     430     2377635 :         : Reg(Reg), SubReg(SubReg) {}
     431             :   };
     432             : 
     433             :   /// A pair composed of a pair of a register and a sub-register index,
     434             :   /// and another sub-register index.
     435             :   /// Used to give some type checking when modeling Reg:SubReg1, SubReg2.
     436             :   struct RegSubRegPairAndIdx : RegSubRegPair {
     437             :     unsigned SubIdx;
     438             : 
     439             :     RegSubRegPairAndIdx(unsigned Reg = 0, unsigned SubReg = 0,
     440             :                         unsigned SubIdx = 0)
     441     1195998 :         : RegSubRegPair(Reg, SubReg), SubIdx(SubIdx) {}
     442             :   };
     443             : 
     444             :   /// Build the equivalent inputs of a REG_SEQUENCE for the given \p MI
     445             :   /// and \p DefIdx.
     446             :   /// \p [out] InputRegs of the equivalent REG_SEQUENCE. Each element of
     447             :   /// the list is modeled as <Reg:SubReg, SubIdx>. Operands with the undef
     448             :   /// flag are not added to this list.
     449             :   /// E.g., REG_SEQUENCE %1:sub1, sub0, %2, sub1 would produce
     450             :   /// two elements:
     451             :   /// - %1:sub1, sub0
     452             :   /// - %2<:0>, sub1
     453             :   ///
     454             :   /// \returns true if it is possible to build such an input sequence
     455             :   /// with the pair \p MI, \p DefIdx. False otherwise.
     456             :   ///
     457             :   /// \pre MI.isRegSequence() or MI.isRegSequenceLike().
     458             :   ///
     459             :   /// \note The generic implementation does not provide any support for
     460             :   /// MI.isRegSequenceLike(). In other words, one has to override
     461             :   /// getRegSequenceLikeInputs for target specific instructions.
     462             :   bool
     463             :   getRegSequenceInputs(const MachineInstr &MI, unsigned DefIdx,
     464             :                        SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const;
     465             : 
     466             :   /// Build the equivalent inputs of a EXTRACT_SUBREG for the given \p MI
     467             :   /// and \p DefIdx.
     468             :   /// \p [out] InputReg of the equivalent EXTRACT_SUBREG.
     469             :   /// E.g., EXTRACT_SUBREG %1:sub1, sub0, sub1 would produce:
     470             :   /// - %1:sub1, sub0
     471             :   ///
     472             :   /// \returns true if it is possible to build such an input sequence
     473             :   /// with the pair \p MI, \p DefIdx and the operand has no undef flag set.
     474             :   /// False otherwise.
     475             :   ///
     476             :   /// \pre MI.isExtractSubreg() or MI.isExtractSubregLike().
     477             :   ///
     478             :   /// \note The generic implementation does not provide any support for
     479             :   /// MI.isExtractSubregLike(). In other words, one has to override
     480             :   /// getExtractSubregLikeInputs for target specific instructions.
     481             :   bool getExtractSubregInputs(const MachineInstr &MI, unsigned DefIdx,
     482             :                               RegSubRegPairAndIdx &InputReg) const;
     483             : 
     484             :   /// Build the equivalent inputs of a INSERT_SUBREG for the given \p MI
     485             :   /// and \p DefIdx.
     486             :   /// \p [out] BaseReg and \p [out] InsertedReg contain
     487             :   /// the equivalent inputs of INSERT_SUBREG.
     488             :   /// E.g., INSERT_SUBREG %0:sub0, %1:sub1, sub3 would produce:
     489             :   /// - BaseReg: %0:sub0
     490             :   /// - InsertedReg: %1:sub1, sub3
     491             :   ///
     492             :   /// \returns true if it is possible to build such an input sequence
     493             :   /// with the pair \p MI, \p DefIdx and the operand has no undef flag set.
     494             :   /// False otherwise.
     495             :   ///
     496             :   /// \pre MI.isInsertSubreg() or MI.isInsertSubregLike().
     497             :   ///
     498             :   /// \note The generic implementation does not provide any support for
     499             :   /// MI.isInsertSubregLike(). In other words, one has to override
     500             :   /// getInsertSubregLikeInputs for target specific instructions.
     501             :   bool getInsertSubregInputs(const MachineInstr &MI, unsigned DefIdx,
     502             :                              RegSubRegPair &BaseReg,
     503             :                              RegSubRegPairAndIdx &InsertedReg) const;
     504             : 
     505             :   /// Return true if two machine instructions would produce identical values.
     506             :   /// By default, this is only true when the two instructions
     507             :   /// are deemed identical except for defs. If this function is called when the
     508             :   /// IR is still in SSA form, the caller can pass the MachineRegisterInfo for
     509             :   /// aggressive checks.
     510             :   virtual bool produceSameValue(const MachineInstr &MI0,
     511             :                                 const MachineInstr &MI1,
     512             :                                 const MachineRegisterInfo *MRI = nullptr) const;
     513             : 
     514             :   /// \returns true if a branch from an instruction with opcode \p BranchOpc
     515             :   ///  bytes is capable of jumping to a position \p BrOffset bytes away.
     516           0 :   virtual bool isBranchOffsetInRange(unsigned BranchOpc,
     517             :                                      int64_t BrOffset) const {
     518           0 :     llvm_unreachable("target did not implement");
     519             :   }
     520             : 
     521             :   /// \returns The block that branch instruction \p MI jumps to.
     522           0 :   virtual MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const {
     523           0 :     llvm_unreachable("target did not implement");
     524             :   }
     525             : 
     526             :   /// Insert an unconditional indirect branch at the end of \p MBB to \p
     527             :   /// NewDestBB.  \p BrOffset indicates the offset of \p NewDestBB relative to
     528             :   /// the offset of the position to insert the new branch.
     529             :   ///
     530             :   /// \returns The number of bytes added to the block.
     531           0 :   virtual unsigned insertIndirectBranch(MachineBasicBlock &MBB,
     532             :                                         MachineBasicBlock &NewDestBB,
     533             :                                         const DebugLoc &DL,
     534             :                                         int64_t BrOffset = 0,
     535             :                                         RegScavenger *RS = nullptr) const {
     536           0 :     llvm_unreachable("target did not implement");
     537             :   }
     538             : 
     539             :   /// Analyze the branching code at the end of MBB, returning
     540             :   /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
     541             :   /// implemented for a target).  Upon success, this returns false and returns
     542             :   /// with the following information in various cases:
     543             :   ///
     544             :   /// 1. If this block ends with no branches (it just falls through to its succ)
     545             :   ///    just return false, leaving TBB/FBB null.
     546             :   /// 2. If this block ends with only an unconditional branch, it sets TBB to be
     547             :   ///    the destination block.
     548             :   /// 3. If this block ends with a conditional branch and it falls through to a
     549             :   ///    successor block, it sets TBB to be the branch destination block and a
     550             :   ///    list of operands that evaluate the condition. These operands can be
     551             :   ///    passed to other TargetInstrInfo methods to create new branches.
     552             :   /// 4. If this block ends with a conditional branch followed by an
     553             :   ///    unconditional branch, it returns the 'true' destination in TBB, the
     554             :   ///    'false' destination in FBB, and a list of operands that evaluate the
     555             :   ///    condition.  These operands can be passed to other TargetInstrInfo
     556             :   ///    methods to create new branches.
     557             :   ///
     558             :   /// Note that removeBranch and insertBranch must be implemented to support
     559             :   /// cases where this method returns success.
     560             :   ///
     561             :   /// If AllowModify is true, then this routine is allowed to modify the basic
     562             :   /// block (e.g. delete instructions after the unconditional branch).
     563             :   ///
     564             :   /// The CFG information in MBB.Predecessors and MBB.Successors must be valid
     565             :   /// before calling this function.
     566           0 :   virtual bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
     567             :                              MachineBasicBlock *&FBB,
     568             :                              SmallVectorImpl<MachineOperand> &Cond,
     569             :                              bool AllowModify = false) const {
     570           0 :     return true;
     571             :   }
     572             : 
     573             :   /// Represents a predicate at the MachineFunction level.  The control flow a
     574             :   /// MachineBranchPredicate represents is:
     575             :   ///
     576             :   ///  Reg = LHS `Predicate` RHS         == ConditionDef
     577             :   ///  if Reg then goto TrueDest else goto FalseDest
     578             :   ///
     579             :   struct MachineBranchPredicate {
     580             :     enum ComparePredicate {
     581             :       PRED_EQ,     // True if two values are equal
     582             :       PRED_NE,     // True if two values are not equal
     583             :       PRED_INVALID // Sentinel value
     584             :     };
     585             : 
     586             :     ComparePredicate Predicate = PRED_INVALID;
     587             :     MachineOperand LHS = MachineOperand::CreateImm(0);
     588             :     MachineOperand RHS = MachineOperand::CreateImm(0);
     589             :     MachineBasicBlock *TrueDest = nullptr;
     590             :     MachineBasicBlock *FalseDest = nullptr;
     591             :     MachineInstr *ConditionDef = nullptr;
     592             : 
     593             :     /// SingleUseCondition is true if ConditionDef is dead except for the
     594             :     /// branch(es) at the end of the basic block.
     595             :     ///
     596             :     bool SingleUseCondition = false;
     597             : 
     598         120 :     explicit MachineBranchPredicate() = default;
     599             :   };
     600             : 
     601             :   /// Analyze the branching code at the end of MBB and parse it into the
     602             :   /// MachineBranchPredicate structure if possible.  Returns false on success
     603             :   /// and true on failure.
     604             :   ///
     605             :   /// If AllowModify is true, then this routine is allowed to modify the basic
     606             :   /// block (e.g. delete instructions after the unconditional branch).
     607             :   ///
     608           0 :   virtual bool analyzeBranchPredicate(MachineBasicBlock &MBB,
     609             :                                       MachineBranchPredicate &MBP,
     610             :                                       bool AllowModify = false) const {
     611           0 :     return true;
     612             :   }
     613             : 
     614             :   /// Remove the branching code at the end of the specific MBB.
     615             :   /// This is only invoked in cases where AnalyzeBranch returns success. It
     616             :   /// returns the number of instructions that were removed.
     617             :   /// If \p BytesRemoved is non-null, report the change in code size from the
     618             :   /// removed instructions.
     619           0 :   virtual unsigned removeBranch(MachineBasicBlock &MBB,
     620             :                                 int *BytesRemoved = nullptr) const {
     621           0 :     llvm_unreachable("Target didn't implement TargetInstrInfo::removeBranch!");
     622             :   }
     623             : 
     624             :   /// Insert branch code into the end of the specified MachineBasicBlock. The
     625             :   /// operands to this method are the same as those returned by AnalyzeBranch.
     626             :   /// This is only invoked in cases where AnalyzeBranch returns success. It
     627             :   /// returns the number of instructions inserted. If \p BytesAdded is non-null,
     628             :   /// report the change in code size from the added instructions.
     629             :   ///
     630             :   /// It is also invoked by tail merging to add unconditional branches in
     631             :   /// cases where AnalyzeBranch doesn't apply because there was no original
     632             :   /// branch to analyze.  At least this much must be implemented, else tail
     633             :   /// merging needs to be disabled.
     634             :   ///
     635             :   /// The CFG information in MBB.Predecessors and MBB.Successors must be valid
     636             :   /// before calling this function.
     637           0 :   virtual unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
     638             :                                 MachineBasicBlock *FBB,
     639             :                                 ArrayRef<MachineOperand> Cond,
     640             :                                 const DebugLoc &DL,
     641             :                                 int *BytesAdded = nullptr) const {
     642           0 :     llvm_unreachable("Target didn't implement TargetInstrInfo::insertBranch!");
     643             :   }
     644             : 
     645             :   unsigned insertUnconditionalBranch(MachineBasicBlock &MBB,
     646             :                                      MachineBasicBlock *DestBB,
     647             :                                      const DebugLoc &DL,
     648             :                                      int *BytesAdded = nullptr) const {
     649           3 :     return insertBranch(MBB, DestBB, nullptr, ArrayRef<MachineOperand>(), DL,
     650           3 :                         BytesAdded);
     651             :   }
     652             : 
     653             :   /// Analyze the loop code, return true if it cannot be understoo. Upon
     654             :   /// success, this function returns false and returns information about the
     655             :   /// induction variable and compare instruction used at the end.
     656           0 :   virtual bool analyzeLoop(MachineLoop &L, MachineInstr *&IndVarInst,
     657             :                            MachineInstr *&CmpInst) const {
     658           0 :     return true;
     659             :   }
     660             : 
     661             :   /// Generate code to reduce the loop iteration by one and check if the loop
     662             :   /// is finished.  Return the value/register of the new loop count.  We need
     663             :   /// this function when peeling off one or more iterations of a loop. This
     664             :   /// function assumes the nth iteration is peeled first.
     665           0 :   virtual unsigned reduceLoopCount(MachineBasicBlock &MBB, MachineInstr *IndVar,
     666             :                                    MachineInstr &Cmp,
     667             :                                    SmallVectorImpl<MachineOperand> &Cond,
     668             :                                    SmallVectorImpl<MachineInstr *> &PrevInsts,
     669             :                                    unsigned Iter, unsigned MaxIter) const {
     670           0 :     llvm_unreachable("Target didn't implement ReduceLoopCount");
     671             :   }
     672             : 
     673             :   /// Delete the instruction OldInst and everything after it, replacing it with
     674             :   /// an unconditional branch to NewDest. This is used by the tail merging pass.
     675             :   virtual void ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail,
     676             :                                        MachineBasicBlock *NewDest) const;
     677             : 
     678             :   /// Return true if it's legal to split the given basic
     679             :   /// block at the specified instruction (i.e. instruction would be the start
     680             :   /// of a new basic block).
     681        3545 :   virtual bool isLegalToSplitMBBAt(MachineBasicBlock &MBB,
     682             :                                    MachineBasicBlock::iterator MBBI) const {
     683        3545 :     return true;
     684             :   }
     685             : 
     686             :   /// Return true if it's profitable to predicate
     687             :   /// instructions with accumulated instruction latency of "NumCycles"
     688             :   /// of the specified basic block, where the probability of the instructions
     689             :   /// being executed is given by Probability, and Confidence is a measure
     690             :   /// of our confidence that it will be properly predicted.
     691           0 :   virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
     692             :                                    unsigned ExtraPredCycles,
     693             :                                    BranchProbability Probability) const {
     694           0 :     return false;
     695             :   }
     696             : 
     697             :   /// Second variant of isProfitableToIfCvt. This one
     698             :   /// checks for the case where two basic blocks from true and false path
     699             :   /// of a if-then-else (diamond) are predicated on mutally exclusive
     700             :   /// predicates, where the probability of the true path being taken is given
     701             :   /// by Probability, and Confidence is a measure of our confidence that it
     702             :   /// will be properly predicted.
     703           0 :   virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumTCycles,
     704             :                                    unsigned ExtraTCycles,
     705             :                                    MachineBasicBlock &FMBB, unsigned NumFCycles,
     706             :                                    unsigned ExtraFCycles,
     707             :                                    BranchProbability Probability) const {
     708           0 :     return false;
     709             :   }
     710             : 
     711             :   /// Return true if it's profitable for if-converter to duplicate instructions
     712             :   /// of specified accumulated instruction latencies in the specified MBB to
     713             :   /// enable if-conversion.
     714             :   /// The probability of the instructions being executed is given by
     715             :   /// Probability, and Confidence is a measure of our confidence that it
     716             :   /// will be properly predicted.
     717           0 :   virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
     718             :                                          unsigned NumCycles,
     719             :                                          BranchProbability Probability) const {
     720           0 :     return false;
     721             :   }
     722             : 
     723             :   /// Return true if it's profitable to unpredicate
     724             :   /// one side of a 'diamond', i.e. two sides of if-else predicated on mutually
     725             :   /// exclusive predicates.
     726             :   /// e.g.
     727             :   ///   subeq  r0, r1, #1
     728             :   ///   addne  r0, r1, #1
     729             :   /// =>
     730             :   ///   sub    r0, r1, #1
     731             :   ///   addne  r0, r1, #1
     732             :   ///
     733             :   /// This may be profitable is conditional instructions are always executed.
     734          18 :   virtual bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
     735             :                                          MachineBasicBlock &FMBB) const {
     736          18 :     return false;
     737             :   }
     738             : 
     739             :   /// Return true if it is possible to insert a select
     740             :   /// instruction that chooses between TrueReg and FalseReg based on the
     741             :   /// condition code in Cond.
     742             :   ///
     743             :   /// When successful, also return the latency in cycles from TrueReg,
     744             :   /// FalseReg, and Cond to the destination register. In most cases, a select
     745             :   /// instruction will be 1 cycle, so CondCycles = TrueCycles = FalseCycles = 1
     746             :   ///
     747             :   /// Some x86 implementations have 2-cycle cmov instructions.
     748             :   ///
     749             :   /// @param MBB         Block where select instruction would be inserted.
     750             :   /// @param Cond        Condition returned by AnalyzeBranch.
     751             :   /// @param TrueReg     Virtual register to select when Cond is true.
     752             :   /// @param FalseReg    Virtual register to select when Cond is false.
     753             :   /// @param CondCycles  Latency from Cond+Branch to select output.
     754             :   /// @param TrueCycles  Latency from TrueReg to select output.
     755             :   /// @param FalseCycles Latency from FalseReg to select output.
     756           0 :   virtual bool canInsertSelect(const MachineBasicBlock &MBB,
     757             :                                ArrayRef<MachineOperand> Cond, unsigned TrueReg,
     758             :                                unsigned FalseReg, int &CondCycles,
     759             :                                int &TrueCycles, int &FalseCycles) const {
     760           0 :     return false;
     761             :   }
     762             : 
     763             :   /// Insert a select instruction into MBB before I that will copy TrueReg to
     764             :   /// DstReg when Cond is true, and FalseReg to DstReg when Cond is false.
     765             :   ///
     766             :   /// This function can only be called after canInsertSelect() returned true.
     767             :   /// The condition in Cond comes from AnalyzeBranch, and it can be assumed
     768             :   /// that the same flags or registers required by Cond are available at the
     769             :   /// insertion point.
     770             :   ///
     771             :   /// @param MBB      Block where select instruction should be inserted.
     772             :   /// @param I        Insertion point.
     773             :   /// @param DL       Source location for debugging.
     774             :   /// @param DstReg   Virtual register to be defined by select instruction.
     775             :   /// @param Cond     Condition as computed by AnalyzeBranch.
     776             :   /// @param TrueReg  Virtual register to copy when Cond is true.
     777             :   /// @param FalseReg Virtual register to copy when Cons is false.
     778           0 :   virtual void insertSelect(MachineBasicBlock &MBB,
     779             :                             MachineBasicBlock::iterator I, const DebugLoc &DL,
     780             :                             unsigned DstReg, ArrayRef<MachineOperand> Cond,
     781             :                             unsigned TrueReg, unsigned FalseReg) const {
     782           0 :     llvm_unreachable("Target didn't implement TargetInstrInfo::insertSelect!");
     783             :   }
     784             : 
     785             :   /// Analyze the given select instruction, returning true if
     786             :   /// it cannot be understood. It is assumed that MI->isSelect() is true.
     787             :   ///
     788             :   /// When successful, return the controlling condition and the operands that
     789             :   /// determine the true and false result values.
     790             :   ///
     791             :   ///   Result = SELECT Cond, TrueOp, FalseOp
     792             :   ///
     793             :   /// Some targets can optimize select instructions, for example by predicating
     794             :   /// the instruction defining one of the operands. Such targets should set
     795             :   /// Optimizable.
     796             :   ///
     797             :   /// @param         MI Select instruction to analyze.
     798             :   /// @param Cond    Condition controlling the select.
     799             :   /// @param TrueOp  Operand number of the value selected when Cond is true.
     800             :   /// @param FalseOp Operand number of the value selected when Cond is false.
     801             :   /// @param Optimizable Returned as true if MI is optimizable.
     802             :   /// @returns False on success.
     803         338 :   virtual bool analyzeSelect(const MachineInstr &MI,
     804             :                              SmallVectorImpl<MachineOperand> &Cond,
     805             :                              unsigned &TrueOp, unsigned &FalseOp,
     806             :                              bool &Optimizable) const {
     807             :     assert(MI.getDesc().isSelect() && "MI must be a select instruction");
     808         338 :     return true;
     809             :   }
     810             : 
     811             :   /// Given a select instruction that was understood by
     812             :   /// analyzeSelect and returned Optimizable = true, attempt to optimize MI by
     813             :   /// merging it with one of its operands. Returns NULL on failure.
     814             :   ///
     815             :   /// When successful, returns the new select instruction. The client is
     816             :   /// responsible for deleting MI.
     817             :   ///
     818             :   /// If both sides of the select can be optimized, PreferFalse is used to pick
     819             :   /// a side.
     820             :   ///
     821             :   /// @param MI          Optimizable select instruction.
     822             :   /// @param NewMIs     Set that record all MIs in the basic block up to \p
     823             :   /// MI. Has to be updated with any newly created MI or deleted ones.
     824             :   /// @param PreferFalse Try to optimize FalseOp instead of TrueOp.
     825             :   /// @returns Optimized instruction or NULL.
     826           0 :   virtual MachineInstr *optimizeSelect(MachineInstr &MI,
     827             :                                        SmallPtrSetImpl<MachineInstr *> &NewMIs,
     828             :                                        bool PreferFalse = false) const {
     829             :     // This function must be implemented if Optimizable is ever set.
     830           0 :     llvm_unreachable("Target must implement TargetInstrInfo::optimizeSelect!");
     831             :   }
     832             : 
     833             :   /// Emit instructions to copy a pair of physical registers.
     834             :   ///
     835             :   /// This function should support copies within any legal register class as
     836             :   /// well as any cross-class copies created during instruction selection.
     837             :   ///
     838             :   /// The source and destination registers may overlap, which may require a
     839             :   /// careful implementation when multiple copy instructions are required for
     840             :   /// large registers. See for example the ARM target.
     841           0 :   virtual void copyPhysReg(MachineBasicBlock &MBB,
     842             :                            MachineBasicBlock::iterator MI, const DebugLoc &DL,
     843             :                            unsigned DestReg, unsigned SrcReg,
     844             :                            bool KillSrc) const {
     845           0 :     llvm_unreachable("Target didn't implement TargetInstrInfo::copyPhysReg!");
     846             :   }
     847             : 
     848             :   /// Store the specified register of the given register class to the specified
     849             :   /// stack frame index. The store instruction is to be added to the given
     850             :   /// machine basic block before the specified machine instruction. If isKill
     851             :   /// is true, the register operand is the last use and must be marked kill.
     852           0 :   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
     853             :                                    MachineBasicBlock::iterator MI,
     854             :                                    unsigned SrcReg, bool isKill, int FrameIndex,
     855             :                                    const TargetRegisterClass *RC,
     856             :                                    const TargetRegisterInfo *TRI) const {
     857           0 :     llvm_unreachable("Target didn't implement "
     858             :                      "TargetInstrInfo::storeRegToStackSlot!");
     859             :   }
     860             : 
     861             :   /// Load the specified register of the given register class from the specified
     862             :   /// stack frame index. The load instruction is to be added to the given
     863             :   /// machine basic block before the specified machine instruction.
     864           0 :   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
     865             :                                     MachineBasicBlock::iterator MI,
     866             :                                     unsigned DestReg, int FrameIndex,
     867             :                                     const TargetRegisterClass *RC,
     868             :                                     const TargetRegisterInfo *TRI) const {
     869           0 :     llvm_unreachable("Target didn't implement "
     870             :                      "TargetInstrInfo::loadRegFromStackSlot!");
     871             :   }
     872             : 
     873             :   /// This function is called for all pseudo instructions
     874             :   /// that remain after register allocation. Many pseudo instructions are
     875             :   /// created to help register allocation. This is the place to convert them
     876             :   /// into real instructions. The target can edit MI in place, or it can insert
     877             :   /// new instructions and erase MI. The function should return true if
     878             :   /// anything was changed.
     879         928 :   virtual bool expandPostRAPseudo(MachineInstr &MI) const { return false; }
     880             : 
     881             :   /// Check whether the target can fold a load that feeds a subreg operand
     882             :   /// (or a subreg operand that feeds a store).
     883             :   /// For example, X86 may want to return true if it can fold
     884             :   /// movl (%esp), %eax
     885             :   /// subb, %al, ...
     886             :   /// Into:
     887             :   /// subb (%esp), ...
     888             :   ///
     889             :   /// Ideally, we'd like the target implementation of foldMemoryOperand() to
     890             :   /// reject subregs - but since this behavior used to be enforced in the
     891             :   /// target-independent code, moving this responsibility to the targets
     892             :   /// has the potential of causing nasty silent breakage in out-of-tree targets.
     893        6941 :   virtual bool isSubregFoldable() const { return false; }
     894             : 
     895             :   /// Attempt to fold a load or store of the specified stack
     896             :   /// slot into the specified machine instruction for the specified operand(s).
     897             :   /// If this is possible, a new instruction is returned with the specified
     898             :   /// operand folded, otherwise NULL is returned.
     899             :   /// The new instruction is inserted before MI, and the client is responsible
     900             :   /// for removing the old instruction.
     901             :   MachineInstr *foldMemoryOperand(MachineInstr &MI, ArrayRef<unsigned> Ops,
     902             :                                   int FrameIndex,
     903             :                                   LiveIntervals *LIS = nullptr) const;
     904             : 
     905             :   /// Same as the previous version except it allows folding of any load and
     906             :   /// store from / to any address, not just from a specific stack slot.
     907             :   MachineInstr *foldMemoryOperand(MachineInstr &MI, ArrayRef<unsigned> Ops,
     908             :                                   MachineInstr &LoadMI,
     909             :                                   LiveIntervals *LIS = nullptr) const;
     910             : 
     911             :   /// Return true when there is potentially a faster code sequence
     912             :   /// for an instruction chain ending in \p Root. All potential patterns are
     913             :   /// returned in the \p Pattern vector. Pattern should be sorted in priority
     914             :   /// order since the pattern evaluator stops checking as soon as it finds a
     915             :   /// faster sequence.
     916             :   /// \param Root - Instruction that could be combined with one of its operands
     917             :   /// \param Patterns - Vector of possible combination patterns
     918             :   virtual bool getMachineCombinerPatterns(
     919             :       MachineInstr &Root,
     920             :       SmallVectorImpl<MachineCombinerPattern> &Patterns) const;
     921             : 
     922             :   /// Return true when a code sequence can improve throughput. It
     923             :   /// should be called only for instructions in loops.
     924             :   /// \param Pattern - combiner pattern
     925             :   virtual bool isThroughputPattern(MachineCombinerPattern Pattern) const;
     926             : 
     927             :   /// Return true if the input \P Inst is part of a chain of dependent ops
     928             :   /// that are suitable for reassociation, otherwise return false.
     929             :   /// If the instruction's operands must be commuted to have a previous
     930             :   /// instruction of the same type define the first source operand, \P Commuted
     931             :   /// will be set to true.
     932             :   bool isReassociationCandidate(const MachineInstr &Inst, bool &Commuted) const;
     933             : 
     934             :   /// Return true when \P Inst is both associative and commutative.
     935           0 :   virtual bool isAssociativeAndCommutative(const MachineInstr &Inst) const {
     936           0 :     return false;
     937             :   }
     938             : 
     939             :   /// Return true when \P Inst has reassociable operands in the same \P MBB.
     940             :   virtual bool hasReassociableOperands(const MachineInstr &Inst,
     941             :                                        const MachineBasicBlock *MBB) const;
     942             : 
     943             :   /// Return true when \P Inst has reassociable sibling.
     944             :   bool hasReassociableSibling(const MachineInstr &Inst, bool &Commuted) const;
     945             : 
     946             :   /// When getMachineCombinerPatterns() finds patterns, this function generates
     947             :   /// the instructions that could replace the original code sequence. The client
     948             :   /// has to decide whether the actual replacement is beneficial or not.
     949             :   /// \param Root - Instruction that could be combined with one of its operands
     950             :   /// \param Pattern - Combination pattern for Root
     951             :   /// \param InsInstrs - Vector of new instructions that implement P
     952             :   /// \param DelInstrs - Old instructions, including Root, that could be
     953             :   /// replaced by InsInstr
     954             :   /// \param InstrIdxForVirtReg - map of virtual register to instruction in
     955             :   /// InsInstr that defines it
     956             :   virtual void genAlternativeCodeSequence(
     957             :       MachineInstr &Root, MachineCombinerPattern Pattern,
     958             :       SmallVectorImpl<MachineInstr *> &InsInstrs,
     959             :       SmallVectorImpl<MachineInstr *> &DelInstrs,
     960             :       DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;
     961             : 
     962             :   /// Attempt to reassociate \P Root and \P Prev according to \P Pattern to
     963             :   /// reduce critical path length.
     964             :   void reassociateOps(MachineInstr &Root, MachineInstr &Prev,
     965             :                       MachineCombinerPattern Pattern,
     966             :                       SmallVectorImpl<MachineInstr *> &InsInstrs,
     967             :                       SmallVectorImpl<MachineInstr *> &DelInstrs,
     968             :                       DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;
     969             : 
     970             :   /// This is an architecture-specific helper function of reassociateOps.
     971             :   /// Set special operand attributes for new instructions after reassociation.
     972         269 :   virtual void setSpecialOperandAttr(MachineInstr &OldMI1, MachineInstr &OldMI2,
     973             :                                      MachineInstr &NewMI1,
     974         269 :                                      MachineInstr &NewMI2) const {}
     975             : 
     976             :   /// Return true when a target supports MachineCombiner.
     977           0 :   virtual bool useMachineCombiner() const { return false; }
     978             : 
     979             :   /// Return true if the given SDNode can be copied during scheduling
     980             :   /// even if it has glue.
     981         104 :   virtual bool canCopyGluedNodeDuringSchedule(SDNode *N) const { return false; }
     982             : 
     983             : protected:
     984             :   /// Target-dependent implementation for foldMemoryOperand.
     985             :   /// Target-independent code in foldMemoryOperand will
     986             :   /// take care of adding a MachineMemOperand to the newly created instruction.
     987             :   /// The instruction and any auxiliary instructions necessary will be inserted
     988             :   /// at InsertPt.
     989             :   virtual MachineInstr *
     990        5739 :   foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
     991             :                         ArrayRef<unsigned> Ops,
     992             :                         MachineBasicBlock::iterator InsertPt, int FrameIndex,
     993             :                         LiveIntervals *LIS = nullptr) const {
     994        5739 :     return nullptr;
     995             :   }
     996             : 
     997             :   /// Target-dependent implementation for foldMemoryOperand.
     998             :   /// Target-independent code in foldMemoryOperand will
     999             :   /// take care of adding a MachineMemOperand to the newly created instruction.
    1000             :   /// The instruction and any auxiliary instructions necessary will be inserted
    1001             :   /// at InsertPt.
    1002          27 :   virtual MachineInstr *foldMemoryOperandImpl(
    1003             :       MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops,
    1004             :       MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI,
    1005             :       LiveIntervals *LIS = nullptr) const {
    1006          27 :     return nullptr;
    1007             :   }
    1008             : 
    1009             :   /// Target-dependent implementation of getRegSequenceInputs.
    1010             :   ///
    1011             :   /// \returns true if it is possible to build the equivalent
    1012             :   /// REG_SEQUENCE inputs with the pair \p MI, \p DefIdx. False otherwise.
    1013             :   ///
    1014             :   /// \pre MI.isRegSequenceLike().
    1015             :   ///
    1016             :   /// \see TargetInstrInfo::getRegSequenceInputs.
    1017           0 :   virtual bool getRegSequenceLikeInputs(
    1018             :       const MachineInstr &MI, unsigned DefIdx,
    1019             :       SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const {
    1020           0 :     return false;
    1021             :   }
    1022             : 
    1023             :   /// Target-dependent implementation of getExtractSubregInputs.
    1024             :   ///
    1025             :   /// \returns true if it is possible to build the equivalent
    1026             :   /// EXTRACT_SUBREG inputs with the pair \p MI, \p DefIdx. False otherwise.
    1027             :   ///
    1028             :   /// \pre MI.isExtractSubregLike().
    1029             :   ///
    1030             :   /// \see TargetInstrInfo::getExtractSubregInputs.
    1031           0 :   virtual bool getExtractSubregLikeInputs(const MachineInstr &MI,
    1032             :                                           unsigned DefIdx,
    1033             :                                           RegSubRegPairAndIdx &InputReg) const {
    1034           0 :     return false;
    1035             :   }
    1036             : 
    1037             :   /// Target-dependent implementation of getInsertSubregInputs.
    1038             :   ///
    1039             :   /// \returns true if it is possible to build the equivalent
    1040             :   /// INSERT_SUBREG inputs with the pair \p MI, \p DefIdx. False otherwise.
    1041             :   ///
    1042             :   /// \pre MI.isInsertSubregLike().
    1043             :   ///
    1044             :   /// \see TargetInstrInfo::getInsertSubregInputs.
    1045             :   virtual bool
    1046           0 :   getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx,
    1047             :                             RegSubRegPair &BaseReg,
    1048             :                             RegSubRegPairAndIdx &InsertedReg) const {
    1049           0 :     return false;
    1050             :   }
    1051             : 
    1052             : public:
    1053             :   /// getAddressSpaceForPseudoSourceKind - Given the kind of memory
    1054             :   /// (e.g. stack) the target returns the corresponding address space.
    1055             :   virtual unsigned
    1056      916057 :   getAddressSpaceForPseudoSourceKind(PseudoSourceValue::PSVKind Kind) const {
    1057      916057 :     return 0;
    1058             :   }
    1059             : 
    1060             :   /// unfoldMemoryOperand - Separate a single instruction which folded a load or
    1061             :   /// a store or a load and a store into two or more instruction. If this is
    1062             :   /// possible, returns true as well as the new instructions by reference.
    1063             :   virtual bool
    1064           0 :   unfoldMemoryOperand(MachineFunction &MF, MachineInstr &MI, unsigned Reg,
    1065             :                       bool UnfoldLoad, bool UnfoldStore,
    1066             :                       SmallVectorImpl<MachineInstr *> &NewMIs) const {
    1067           0 :     return false;
    1068             :   }
    1069             : 
    1070           0 :   virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
    1071             :                                    SmallVectorImpl<SDNode *> &NewNodes) const {
    1072           0 :     return false;
    1073             :   }
    1074             : 
    1075             :   /// Returns the opcode of the would be new
    1076             :   /// instruction after load / store are unfolded from an instruction of the
    1077             :   /// specified opcode. It returns zero if the specified unfolding is not
    1078             :   /// possible. If LoadRegIndex is non-null, it is filled in with the operand
    1079             :   /// index of the operand which will hold the register holding the loaded
    1080             :   /// value.
    1081             :   virtual unsigned
    1082         594 :   getOpcodeAfterMemoryUnfold(unsigned Opc, bool UnfoldLoad, bool UnfoldStore,
    1083             :                              unsigned *LoadRegIndex = nullptr) const {
    1084         594 :     return 0;
    1085             :   }
    1086             : 
    1087             :   /// This is used by the pre-regalloc scheduler to determine if two loads are
    1088             :   /// loading from the same base address. It should only return true if the base
    1089             :   /// pointers are the same and the only differences between the two addresses
    1090             :   /// are the offset. It also returns the offsets by reference.
    1091      275604 :   virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
    1092             :                                        int64_t &Offset1,
    1093             :                                        int64_t &Offset2) const {
    1094      275604 :     return false;
    1095             :   }
    1096             : 
    1097             :   /// This is a used by the pre-regalloc scheduler to determine (in conjunction
    1098             :   /// with areLoadsFromSameBasePtr) if two loads should be scheduled together.
    1099             :   /// On some targets if two loads are loading from
    1100             :   /// addresses in the same cache line, it's better if they are scheduled
    1101             :   /// together. This function takes two integers that represent the load offsets
    1102             :   /// from the common base address. It returns true if it decides it's desirable
    1103             :   /// to schedule the two loads together. "NumLoads" is the number of loads that
    1104             :   /// have already been scheduled after Load1.
    1105           0 :   virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
    1106             :                                        int64_t Offset1, int64_t Offset2,
    1107             :                                        unsigned NumLoads) const {
    1108           0 :     return false;
    1109             :   }
    1110             : 
    1111             :   /// Get the base register and byte offset of an instruction that reads/writes
    1112             :   /// memory.
    1113           0 :   virtual bool getMemOpBaseRegImmOfs(MachineInstr &MemOp, unsigned &BaseReg,
    1114             :                                      int64_t &Offset,
    1115             :                                      const TargetRegisterInfo *TRI) const {
    1116           0 :     return false;
    1117             :   }
    1118             : 
    1119             :   /// Return true if the instruction contains a base register and offset. If
    1120             :   /// true, the function also sets the operand position in the instruction
    1121             :   /// for the base register and offset.
    1122           0 :   virtual bool getBaseAndOffsetPosition(const MachineInstr &MI,
    1123             :                                         unsigned &BasePos,
    1124             :                                         unsigned &OffsetPos) const {
    1125           0 :     return false;
    1126             :   }
    1127             : 
    1128             :   /// If the instruction is an increment of a constant value, return the amount.
    1129           0 :   virtual bool getIncrementValue(const MachineInstr &MI, int &Value) const {
    1130           0 :     return false;
    1131             :   }
    1132             : 
    1133             :   /// Returns true if the two given memory operations should be scheduled
    1134             :   /// adjacent. Note that you have to add:
    1135             :   ///   DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
    1136             :   /// or
    1137             :   ///   DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
    1138             :   /// to TargetPassConfig::createMachineScheduler() to have an effect.
    1139           0 :   virtual bool shouldClusterMemOps(MachineInstr &FirstLdSt, unsigned BaseReg1,
    1140             :                                    MachineInstr &SecondLdSt, unsigned BaseReg2,
    1141             :                                    unsigned NumLoads) const {
    1142           0 :     llvm_unreachable("target did not implement shouldClusterMemOps()");
    1143             :   }
    1144             : 
    1145             :   /// Reverses the branch condition of the specified condition list,
    1146             :   /// returning false on success and true if it cannot be reversed.
    1147             :   virtual bool
    1148          19 :   reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
    1149          19 :     return true;
    1150             :   }
    1151             : 
    1152             :   /// Insert a noop into the instruction stream at the specified point.
    1153             :   virtual void insertNoop(MachineBasicBlock &MBB,
    1154             :                           MachineBasicBlock::iterator MI) const;
    1155             : 
    1156             :   /// Return the noop instruction to use for a noop.
    1157             :   virtual void getNoop(MCInst &NopInst) const;
    1158             : 
    1159             :   /// Return true for post-incremented instructions.
    1160           0 :   virtual bool isPostIncrement(const MachineInstr &MI) const { return false; }
    1161             : 
    1162             :   /// Returns true if the instruction is already predicated.
    1163     3807020 :   virtual bool isPredicated(const MachineInstr &MI) const { return false; }
    1164             : 
    1165             :   /// Returns true if the instruction is a
    1166             :   /// terminator instruction that has not been predicated.
    1167             :   virtual bool isUnpredicatedTerminator(const MachineInstr &MI) const;
    1168             : 
    1169             :   /// Returns true if MI is an unconditional tail call.
    1170         784 :   virtual bool isUnconditionalTailCall(const MachineInstr &MI) const {
    1171         784 :     return false;
    1172             :   }
    1173             : 
    1174             :   /// Returns true if the tail call can be made conditional on BranchCond.
    1175           0 :   virtual bool canMakeTailCallConditional(SmallVectorImpl<MachineOperand> &Cond,
    1176             :                                           const MachineInstr &TailCall) const {
    1177           0 :     return false;
    1178             :   }
    1179             : 
    1180             :   /// Replace the conditional branch in MBB with a conditional tail call.
    1181           0 :   virtual void replaceBranchWithTailCall(MachineBasicBlock &MBB,
    1182             :                                          SmallVectorImpl<MachineOperand> &Cond,
    1183             :                                          const MachineInstr &TailCall) const {
    1184           0 :     llvm_unreachable("Target didn't implement replaceBranchWithTailCall!");
    1185             :   }
    1186             : 
    1187             :   /// Convert the instruction into a predicated instruction.
    1188             :   /// It returns true if the operation was successful.
    1189             :   virtual bool PredicateInstruction(MachineInstr &MI,
    1190             :                                     ArrayRef<MachineOperand> Pred) const;
    1191             : 
    1192             :   /// Returns true if the first specified predicate
    1193             :   /// subsumes the second, e.g. GE subsumes GT.
    1194           0 :   virtual bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
    1195             :                                  ArrayRef<MachineOperand> Pred2) const {
    1196           0 :     return false;
    1197             :   }
    1198             : 
    1199             :   /// If the specified instruction defines any predicate
    1200             :   /// or condition code register(s) used for predication, returns true as well
    1201             :   /// as the definition predicate(s) by reference.
    1202       11110 :   virtual bool DefinesPredicate(MachineInstr &MI,
    1203             :                                 std::vector<MachineOperand> &Pred) const {
    1204       11110 :     return false;
    1205             :   }
    1206             : 
    1207             :   /// Return true if the specified instruction can be predicated.
    1208             :   /// By default, this returns true for every instruction with a
    1209             :   /// PredicateOperand.
    1210           0 :   virtual bool isPredicable(const MachineInstr &MI) const {
    1211         905 :     return MI.getDesc().isPredicable();
    1212             :   }
    1213             : 
    1214             :   /// Return true if it's safe to move a machine
    1215             :   /// instruction that defines the specified register class.
    1216       65312 :   virtual bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
    1217       65312 :     return true;
    1218             :   }
    1219             : 
    1220             :   /// Test if the given instruction should be considered a scheduling boundary.
    1221             :   /// This primarily includes labels and terminators.
    1222             :   virtual bool isSchedulingBoundary(const MachineInstr &MI,
    1223             :                                     const MachineBasicBlock *MBB,
    1224             :                                     const MachineFunction &MF) const;
    1225             : 
    1226             :   /// Measure the specified inline asm to determine an approximation of its
    1227             :   /// length.
    1228             :   virtual unsigned getInlineAsmLength(const char *Str,
    1229             :                                       const MCAsmInfo &MAI) const;
    1230             : 
    1231             :   /// Allocate and return a hazard recognizer to use for this target when
    1232             :   /// scheduling the machine instructions before register allocation.
    1233             :   virtual ScheduleHazardRecognizer *
    1234             :   CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
    1235             :                                const ScheduleDAG *DAG) const;
    1236             : 
    1237             :   /// Allocate and return a hazard recognizer to use for this target when
    1238             :   /// scheduling the machine instructions before register allocation.
    1239             :   virtual ScheduleHazardRecognizer *
    1240             :   CreateTargetMIHazardRecognizer(const InstrItineraryData *,
    1241             :                                  const ScheduleDAG *DAG) const;
    1242             : 
    1243             :   /// Allocate and return a hazard recognizer to use for this target when
    1244             :   /// scheduling the machine instructions after register allocation.
    1245             :   virtual ScheduleHazardRecognizer *
    1246             :   CreateTargetPostRAHazardRecognizer(const InstrItineraryData *,
    1247             :                                      const ScheduleDAG *DAG) const;
    1248             : 
    1249             :   /// Allocate and return a hazard recognizer to use for by non-scheduling
    1250             :   /// passes.
    1251             :   virtual ScheduleHazardRecognizer *
    1252           0 :   CreateTargetPostRAHazardRecognizer(const MachineFunction &MF) const {
    1253           0 :     return nullptr;
    1254             :   }
    1255             : 
    1256             :   /// Provide a global flag for disabling the PreRA hazard recognizer that
    1257             :   /// targets may choose to honor.
    1258             :   bool usePreRAHazardRecognizer() const;
    1259             : 
    1260             :   /// For a comparison instruction, return the source registers
    1261             :   /// in SrcReg and SrcReg2 if having two register operands, and the value it
    1262             :   /// compares against in CmpValue. Return true if the comparison instruction
    1263             :   /// can be analyzed.
    1264        4468 :   virtual bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
    1265             :                               unsigned &SrcReg2, int &Mask, int &Value) const {
    1266        4468 :     return false;
    1267             :   }
    1268             : 
    1269             :   /// See if the comparison instruction can be converted
    1270             :   /// into something more efficient. E.g., on ARM most instructions can set the
    1271             :   /// flags register, obviating the need for a separate CMP.
    1272         908 :   virtual bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
    1273             :                                     unsigned SrcReg2, int Mask, int Value,
    1274             :                                     const MachineRegisterInfo *MRI) const {
    1275         908 :     return false;
    1276             :   }
    1277       44978 :   virtual bool optimizeCondBranch(MachineInstr &MI) const { return false; }
    1278             : 
    1279             :   /// Try to remove the load by folding it to a register operand at the use.
    1280             :   /// We fold the load instructions if and only if the
    1281             :   /// def and use are in the same BB. We only look at one load and see
    1282             :   /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
    1283             :   /// defined by the load we are trying to fold. DefMI returns the machine
    1284             :   /// instruction that defines FoldAsLoadDefReg, and the function returns
    1285             :   /// the machine instruction generated due to folding.
    1286       13427 :   virtual MachineInstr *optimizeLoadInstr(MachineInstr &MI,
    1287             :                                           const MachineRegisterInfo *MRI,
    1288             :                                           unsigned &FoldAsLoadDefReg,
    1289             :                                           MachineInstr *&DefMI) const {
    1290       13427 :     return nullptr;
    1291             :   }
    1292             : 
    1293             :   /// 'Reg' is known to be defined by a move immediate instruction,
    1294             :   /// try to fold the immediate into the use instruction.
    1295             :   /// If MRI->hasOneNonDBGUse(Reg) is true, and this function returns true,
    1296             :   /// then the caller may assume that DefMI has been erased from its parent
    1297             :   /// block. The caller may assume that it will not be erased by this
    1298             :   /// function otherwise.
    1299        5566 :   virtual bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
    1300             :                              unsigned Reg, MachineRegisterInfo *MRI) const {
    1301        5566 :     return false;
    1302             :   }
    1303             : 
    1304             :   /// Return the number of u-operations the given machine
    1305             :   /// instruction will be decoded to on the target cpu. The itinerary's
    1306             :   /// IssueWidth is the number of microops that can be dispatched each
    1307             :   /// cycle. An instruction with zero microops takes no dispatch resources.
    1308             :   virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData,
    1309             :                                   const MachineInstr &MI) const;
    1310             : 
    1311             :   /// Return true for pseudo instructions that don't consume any
    1312             :   /// machine resources in their current form. These are common cases that the
    1313             :   /// scheduler should consider free, rather than conservatively handling them
    1314             :   /// as instructions with no itinerary.
    1315             :   bool isZeroCost(unsigned Opcode) const {
    1316             :     return Opcode <= TargetOpcode::COPY;
    1317             :   }
    1318             : 
    1319             :   virtual int getOperandLatency(const InstrItineraryData *ItinData,
    1320             :                                 SDNode *DefNode, unsigned DefIdx,
    1321             :                                 SDNode *UseNode, unsigned UseIdx) const;
    1322             : 
    1323             :   /// Compute and return the use operand latency of a given pair of def and use.
    1324             :   /// In most cases, the static scheduling itinerary was enough to determine the
    1325             :   /// operand latency. But it may not be possible for instructions with variable
    1326             :   /// number of defs / uses.
    1327             :   ///
    1328             :   /// This is a raw interface to the itinerary that may be directly overridden
    1329             :   /// by a target. Use computeOperandLatency to get the best estimate of
    1330             :   /// latency.
    1331             :   virtual int getOperandLatency(const InstrItineraryData *ItinData,
    1332             :                                 const MachineInstr &DefMI, unsigned DefIdx,
    1333             :                                 const MachineInstr &UseMI,
    1334             :                                 unsigned UseIdx) const;
    1335             : 
    1336             :   /// Compute the instruction latency of a given instruction.
    1337             :   /// If the instruction has higher cost when predicated, it's returned via
    1338             :   /// PredCost.
    1339             :   virtual unsigned getInstrLatency(const InstrItineraryData *ItinData,
    1340             :                                    const MachineInstr &MI,
    1341             :                                    unsigned *PredCost = nullptr) const;
    1342             : 
    1343             :   virtual unsigned getPredicationCost(const MachineInstr &MI) const;
    1344             : 
    1345             :   virtual int getInstrLatency(const InstrItineraryData *ItinData,
    1346             :                               SDNode *Node) const;
    1347             : 
    1348             :   /// Return the default expected latency for a def based on its opcode.
    1349             :   unsigned defaultDefLatency(const MCSchedModel &SchedModel,
    1350             :                              const MachineInstr &DefMI) const;
    1351             : 
    1352             :   int computeDefOperandLatency(const InstrItineraryData *ItinData,
    1353             :                                const MachineInstr &DefMI) const;
    1354             : 
    1355             :   /// Return true if this opcode has high latency to its result.
    1356      531730 :   virtual bool isHighLatencyDef(int opc) const { return false; }
    1357             : 
    1358             :   /// Compute operand latency between a def of 'Reg'
    1359             :   /// and a use in the current loop. Return true if the target considered
    1360             :   /// it 'high'. This is used by optimization passes such as machine LICM to
    1361             :   /// determine whether it makes sense to hoist an instruction out even in a
    1362             :   /// high register pressure situation.
    1363        1303 :   virtual bool hasHighOperandLatency(const TargetSchedModel &SchedModel,
    1364             :                                      const MachineRegisterInfo *MRI,
    1365             :                                      const MachineInstr &DefMI, unsigned DefIdx,
    1366             :                                      const MachineInstr &UseMI,
    1367             :                                      unsigned UseIdx) const {
    1368        1303 :     return false;
    1369             :   }
    1370             : 
    1371             :   /// Compute operand latency of a def of 'Reg'. Return true
    1372             :   /// if the target considered it 'low'.
    1373             :   virtual bool hasLowDefLatency(const TargetSchedModel &SchedModel,
    1374             :                                 const MachineInstr &DefMI,
    1375             :                                 unsigned DefIdx) const;
    1376             : 
    1377             :   /// Perform target-specific instruction verification.
    1378     5785002 :   virtual bool verifyInstruction(const MachineInstr &MI,
    1379             :                                  StringRef &ErrInfo) const {
    1380     5785002 :     return true;
    1381             :   }
    1382             : 
    1383             :   /// Return the current execution domain and bit mask of
    1384             :   /// possible domains for instruction.
    1385             :   ///
    1386             :   /// Some micro-architectures have multiple execution domains, and multiple
    1387             :   /// opcodes that perform the same operation in different domains.  For
    1388             :   /// example, the x86 architecture provides the por, orps, and orpd
    1389             :   /// instructions that all do the same thing.  There is a latency penalty if a
    1390             :   /// register is written in one domain and read in another.
    1391             :   ///
    1392             :   /// This function returns a pair (domain, mask) containing the execution
    1393             :   /// domain of MI, and a bit mask of possible domains.  The setExecutionDomain
    1394             :   /// function can be used to change the opcode to one of the domains in the
    1395             :   /// bit mask.  Instructions whose execution domain can't be changed should
    1396             :   /// return a 0 mask.
    1397             :   ///
    1398             :   /// The execution domain numbers don't have any special meaning except domain
    1399             :   /// 0 is used for instructions that are not associated with any interesting
    1400             :   /// execution domain.
    1401             :   ///
    1402             :   virtual std::pair<uint16_t, uint16_t>
    1403           0 :   getExecutionDomain(const MachineInstr &MI) const {
    1404           0 :     return std::make_pair(0, 0);
    1405             :   }
    1406             : 
    1407             :   /// Change the opcode of MI to execute in Domain.
    1408             :   ///
    1409             :   /// The bit (1 << Domain) must be set in the mask returned from
    1410             :   /// getExecutionDomain(MI).
    1411           0 :   virtual void setExecutionDomain(MachineInstr &MI, unsigned Domain) const {}
    1412             : 
    1413             :   /// Returns the preferred minimum clearance
    1414             :   /// before an instruction with an unwanted partial register update.
    1415             :   ///
    1416             :   /// Some instructions only write part of a register, and implicitly need to
    1417             :   /// read the other parts of the register.  This may cause unwanted stalls
    1418             :   /// preventing otherwise unrelated instructions from executing in parallel in
    1419             :   /// an out-of-order CPU.
    1420             :   ///
    1421             :   /// For example, the x86 instruction cvtsi2ss writes its result to bits
    1422             :   /// [31:0] of the destination xmm register. Bits [127:32] are unaffected, so
    1423             :   /// the instruction needs to wait for the old value of the register to become
    1424             :   /// available:
    1425             :   ///
    1426             :   ///   addps %xmm1, %xmm0
    1427             :   ///   movaps %xmm0, (%rax)
    1428             :   ///   cvtsi2ss %rbx, %xmm0
    1429             :   ///
    1430             :   /// In the code above, the cvtsi2ss instruction needs to wait for the addps
    1431             :   /// instruction before it can issue, even though the high bits of %xmm0
    1432             :   /// probably aren't needed.
    1433             :   ///
    1434             :   /// This hook returns the preferred clearance before MI, measured in
    1435             :   /// instructions.  Other defs of MI's operand OpNum are avoided in the last N
    1436             :   /// instructions before MI.  It should only return a positive value for
    1437             :   /// unwanted dependencies.  If the old bits of the defined register have
    1438             :   /// useful values, or if MI is determined to otherwise read the dependency,
    1439             :   /// the hook should return 0.
    1440             :   ///
    1441             :   /// The unwanted dependency may be handled by:
    1442             :   ///
    1443             :   /// 1. Allocating the same register for an MI def and use.  That makes the
    1444             :   ///    unwanted dependency identical to a required dependency.
    1445             :   ///
    1446             :   /// 2. Allocating a register for the def that has no defs in the previous N
    1447             :   ///    instructions.
    1448             :   ///
    1449             :   /// 3. Calling breakPartialRegDependency() with the same arguments.  This
    1450             :   ///    allows the target to insert a dependency breaking instruction.
    1451             :   ///
    1452             :   virtual unsigned
    1453           0 :   getPartialRegUpdateClearance(const MachineInstr &MI, unsigned OpNum,
    1454             :                                const TargetRegisterInfo *TRI) const {
    1455             :     // The default implementation returns 0 for no partial register dependency.
    1456           0 :     return 0;
    1457             :   }
    1458             : 
    1459             :   /// Return the minimum clearance before an instruction that reads an
    1460             :   /// unused register.
    1461             :   ///
    1462             :   /// For example, AVX instructions may copy part of a register operand into
    1463             :   /// the unused high bits of the destination register.
    1464             :   ///
    1465             :   /// vcvtsi2sdq %rax, undef %xmm0, %xmm14
    1466             :   ///
    1467             :   /// In the code above, vcvtsi2sdq copies %xmm0[127:64] into %xmm14 creating a
    1468             :   /// false dependence on any previous write to %xmm0.
    1469             :   ///
    1470             :   /// This hook works similarly to getPartialRegUpdateClearance, except that it
    1471             :   /// does not take an operand index. Instead sets \p OpNum to the index of the
    1472             :   /// unused register.
    1473      123331 :   virtual unsigned getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
    1474             :                                         const TargetRegisterInfo *TRI) const {
    1475             :     // The default implementation returns 0 for no undef register dependency.
    1476      123331 :     return 0;
    1477             :   }
    1478             : 
    1479             :   /// Insert a dependency-breaking instruction
    1480             :   /// before MI to eliminate an unwanted dependency on OpNum.
    1481             :   ///
    1482             :   /// If it wasn't possible to avoid a def in the last N instructions before MI
    1483             :   /// (see getPartialRegUpdateClearance), this hook will be called to break the
    1484             :   /// unwanted dependency.
    1485             :   ///
    1486             :   /// On x86, an xorps instruction can be used as a dependency breaker:
    1487             :   ///
    1488             :   ///   addps %xmm1, %xmm0
    1489             :   ///   movaps %xmm0, (%rax)
    1490             :   ///   xorps %xmm0, %xmm0
    1491             :   ///   cvtsi2ss %rbx, %xmm0
    1492             :   ///
    1493             :   /// An <imp-kill> operand should be added to MI if an instruction was
    1494             :   /// inserted.  This ties the instructions together in the post-ra scheduler.
    1495             :   ///
    1496           0 :   virtual void breakPartialRegDependency(MachineInstr &MI, unsigned OpNum,
    1497           0 :                                          const TargetRegisterInfo *TRI) const {}
    1498             : 
    1499             :   /// Create machine specific model for scheduling.
    1500             :   virtual DFAPacketizer *
    1501           0 :   CreateTargetScheduleState(const TargetSubtargetInfo &) const {
    1502           0 :     return nullptr;
    1503             :   }
    1504             : 
    1505             :   /// Sometimes, it is possible for the target
    1506             :   /// to tell, even without aliasing information, that two MIs access different
    1507             :   /// memory addresses. This function returns true if two MIs access different
    1508             :   /// memory addresses and false otherwise.
    1509             :   ///
    1510             :   /// Assumes any physical registers used to compute addresses have the same
    1511             :   /// value for both instructions. (This is the most useful assumption for
    1512             :   /// post-RA scheduling.)
    1513             :   ///
    1514             :   /// See also MachineInstr::mayAlias, which is implemented on top of this
    1515             :   /// function.
    1516             :   virtual bool
    1517     2224583 :   areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
    1518             :                                   AliasAnalysis *AA = nullptr) const {
    1519             :     assert((MIa.mayLoad() || MIa.mayStore()) &&
    1520             :            "MIa must load from or modify a memory location");
    1521             :     assert((MIb.mayLoad() || MIb.mayStore()) &&
    1522             :            "MIb must load from or modify a memory location");
    1523     2224583 :     return false;
    1524             :   }
    1525             : 
    1526             :   /// Return the value to use for the MachineCSE's LookAheadLimit,
    1527             :   /// which is a heuristic used for CSE'ing phys reg defs.
    1528      152508 :   virtual unsigned getMachineCSELookAheadLimit() const {
    1529             :     // The default lookahead is small to prevent unprofitable quadratic
    1530             :     // behavior.
    1531      152508 :     return 5;
    1532             :   }
    1533             : 
    1534             :   /// Return an array that contains the ids of the target indices (used for the
    1535             :   /// TargetIndex machine operand) and their names.
    1536             :   ///
    1537             :   /// MIR Serialization is able to serialize only the target indices that are
    1538             :   /// defined by this method.
    1539             :   virtual ArrayRef<std::pair<int, const char *>>
    1540           0 :   getSerializableTargetIndices() const {
    1541           0 :     return None;
    1542             :   }
    1543             : 
    1544             :   /// Decompose the machine operand's target flags into two values - the direct
    1545             :   /// target flag value and any of bit flags that are applied.
    1546             :   virtual std::pair<unsigned, unsigned>
    1547           0 :   decomposeMachineOperandsTargetFlags(unsigned /*TF*/) const {
    1548           0 :     return std::make_pair(0u, 0u);
    1549             :   }
    1550             : 
    1551             :   /// Return an array that contains the direct target flag values and their
    1552             :   /// names.
    1553             :   ///
    1554             :   /// MIR Serialization is able to serialize only the target flags that are
    1555             :   /// defined by this method.
    1556             :   virtual ArrayRef<std::pair<unsigned, const char *>>
    1557           0 :   getSerializableDirectMachineOperandTargetFlags() const {
    1558           0 :     return None;
    1559             :   }
    1560             : 
    1561             :   /// Return an array that contains the bitmask target flag values and their
    1562             :   /// names.
    1563             :   ///
    1564             :   /// MIR Serialization is able to serialize only the target flags that are
    1565             :   /// defined by this method.
    1566             :   virtual ArrayRef<std::pair<unsigned, const char *>>
    1567           1 :   getSerializableBitmaskMachineOperandTargetFlags() const {
    1568           1 :     return None;
    1569             :   }
    1570             : 
    1571             :   /// Return an array that contains the MMO target flag values and their
    1572             :   /// names.
    1573             :   ///
    1574             :   /// MIR Serialization is able to serialize only the MMO target flags that are
    1575             :   /// defined by this method.
    1576             :   virtual ArrayRef<std::pair<MachineMemOperand::Flags, const char *>>
    1577           0 :   getSerializableMachineMemOperandTargetFlags() const {
    1578           0 :     return None;
    1579             :   }
    1580             : 
    1581             :   /// Determines whether \p Inst is a tail call instruction. Override this
    1582             :   /// method on targets that do not properly set MCID::Return and MCID::Call on
    1583             :   /// tail call instructions."
    1584         354 :   virtual bool isTailCall(const MachineInstr &Inst) const {
    1585         454 :     return Inst.isReturn() && Inst.isCall();
    1586             :   }
    1587             : 
    1588             :   /// True if the instruction is bound to the top of its basic block and no
    1589             :   /// other instructions shall be inserted before it. This can be implemented
    1590             :   /// to prevent register allocator to insert spills before such instructions.
    1591       82791 :   virtual bool isBasicBlockPrologue(const MachineInstr &MI) const {
    1592       82791 :     return false;
    1593             :   }
    1594             : 
    1595             :   /// Returns true if the target implements the MachineOutliner.
    1596           0 :   virtual bool useMachineOutliner() const { return false; }
    1597             : 
    1598             :   /// Describes the number of instructions that it will take to call and
    1599             :   /// construct a frame for a given outlining candidate.
    1600             :   struct MachineOutlinerInfo {
    1601             :     /// Represents the size of a sequence in bytes. (Some instructions vary
    1602             :     /// widely in size, so just counting the instructions isn't very useful.)
    1603             :     unsigned SequenceSize;
    1604             : 
    1605             :     /// Number of instructions to call an outlined function for this candidate.
    1606             :     unsigned CallOverhead;
    1607             : 
    1608             :     /// Number of instructions to construct an outlined function frame
    1609             :     /// for this candidate.
    1610             :     unsigned FrameOverhead;
    1611             : 
    1612             :     /// Represents the specific instructions that must be emitted to
    1613             :     /// construct a call to this candidate.
    1614             :     unsigned CallConstructionID;
    1615             : 
    1616             :     /// Represents the specific instructions that must be emitted to
    1617             :     /// construct a frame for this candidate's outlined function.
    1618             :     unsigned FrameConstructionID;
    1619             : 
    1620         274 :     MachineOutlinerInfo() {}
    1621             :     MachineOutlinerInfo(unsigned SequenceSize, unsigned CallOverhead,
    1622             :                         unsigned FrameOverhead, unsigned CallConstructionID,
    1623             :                         unsigned FrameConstructionID)
    1624         119 :         : SequenceSize(SequenceSize), CallOverhead(CallOverhead),
    1625             :           FrameOverhead(FrameOverhead),
    1626             :           CallConstructionID(CallConstructionID),
    1627         119 :           FrameConstructionID(FrameConstructionID) {}
    1628             :   };
    1629             : 
    1630             :   /// Returns a \p MachineOutlinerInfo struct containing target-specific
    1631             :   /// information for a set of outlining candidates.
    1632           0 :   virtual MachineOutlinerInfo getOutlininingCandidateInfo(
    1633             :       std::vector<
    1634             :           std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>>
    1635             :           &RepeatedSequenceLocs) const {
    1636           0 :     llvm_unreachable(
    1637             :         "Target didn't implement TargetInstrInfo::getOutliningCandidateInfo!");
    1638             :   }
    1639             : 
    1640             :   /// Represents how an instruction should be mapped by the outliner.
    1641             :   /// \p Legal instructions are those which are safe to outline.
    1642             :   /// \p Illegal instructions are those which cannot be outlined.
    1643             :   /// \p Invisible instructions are instructions which can be outlined, but
    1644             :   /// shouldn't actually impact the outlining result.
    1645             :   enum MachineOutlinerInstrType { Legal, Illegal, Invisible };
    1646             : 
    1647             :   /// Returns how or if \p MI should be outlined.
    1648             :   virtual MachineOutlinerInstrType
    1649           0 :   getOutliningType(MachineBasicBlock::iterator &MIT, unsigned Flags) const {
    1650           0 :     llvm_unreachable(
    1651             :         "Target didn't implement TargetInstrInfo::getOutliningType!");
    1652             :   }
    1653             : 
    1654             :   /// Returns target-defined flags defining properties of the MBB for
    1655             :   /// the outliner.
    1656          26 :   virtual unsigned getMachineOutlinerMBBFlags(MachineBasicBlock &MBB) const {
    1657          26 :     return 0x0;
    1658             :   }
    1659             : 
    1660             :   /// Insert a custom epilogue for outlined functions.
    1661             :   /// This may be empty, in which case no epilogue or return statement will be
    1662             :   /// emitted.
    1663           0 :   virtual void insertOutlinerEpilogue(MachineBasicBlock &MBB,
    1664             :                                       MachineFunction &MF,
    1665             :                                       const MachineOutlinerInfo &MInfo) const {
    1666           0 :     llvm_unreachable(
    1667             :         "Target didn't implement TargetInstrInfo::insertOutlinerEpilogue!");
    1668             :   }
    1669             : 
    1670             :   /// Insert a call to an outlined function into the program.
    1671             :   /// Returns an iterator to the spot where we inserted the call. This must be
    1672             :   /// implemented by the target.
    1673             :   virtual MachineBasicBlock::iterator
    1674           0 :   insertOutlinedCall(Module &M, MachineBasicBlock &MBB,
    1675             :                      MachineBasicBlock::iterator &It, MachineFunction &MF,
    1676             :                      const MachineOutlinerInfo &MInfo) const {
    1677           0 :     llvm_unreachable(
    1678             :         "Target didn't implement TargetInstrInfo::insertOutlinedCall!");
    1679             :   }
    1680             : 
    1681             :   /// Insert a custom prologue for outlined functions.
    1682             :   /// This may be empty, in which case no prologue will be emitted.
    1683           0 :   virtual void insertOutlinerPrologue(MachineBasicBlock &MBB,
    1684             :                                       MachineFunction &MF,
    1685             :                                       const MachineOutlinerInfo &MInfo) const {
    1686           0 :     llvm_unreachable(
    1687             :         "Target didn't implement TargetInstrInfo::insertOutlinerPrologue!");
    1688             :   }
    1689             : 
    1690             :   /// Return true if the function can safely be outlined from.
    1691             :   /// A function \p MF is considered safe for outlining if an outlined function
    1692             :   /// produced from instructions in F will produce a program which produces the
    1693             :   /// same output for any set of given inputs.
    1694           0 :   virtual bool isFunctionSafeToOutlineFrom(MachineFunction &MF,
    1695             :                                            bool OutlineFromLinkOnceODRs) const {
    1696           0 :     llvm_unreachable("Target didn't implement "
    1697             :                      "TargetInstrInfo::isFunctionSafeToOutlineFrom!");
    1698             :   }
    1699             : 
    1700             : private:
    1701             :   unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
    1702             :   unsigned CatchRetOpcode;
    1703             :   unsigned ReturnOpcode;
    1704             : };
    1705             : 
    1706             : /// Provide DenseMapInfo for TargetInstrInfo::RegSubRegPair.
    1707             : template <> struct DenseMapInfo<TargetInstrInfo::RegSubRegPair> {
    1708             :   using RegInfo = DenseMapInfo<unsigned>;
    1709             : 
    1710             :   static inline TargetInstrInfo::RegSubRegPair getEmptyKey() {
    1711             :     return TargetInstrInfo::RegSubRegPair(RegInfo::getEmptyKey(),
    1712             :                                           RegInfo::getEmptyKey());
    1713             :   }
    1714             : 
    1715             :   static inline TargetInstrInfo::RegSubRegPair getTombstoneKey() {
    1716             :     return TargetInstrInfo::RegSubRegPair(RegInfo::getTombstoneKey(),
    1717             :                                           RegInfo::getTombstoneKey());
    1718             :   }
    1719             : 
    1720             :   /// Reuse getHashValue implementation from
    1721             :   /// std::pair<unsigned, unsigned>.
    1722             :   static unsigned getHashValue(const TargetInstrInfo::RegSubRegPair &Val) {
    1723     2170834 :     std::pair<unsigned, unsigned> PairVal = std::make_pair(Val.Reg, Val.SubReg);
    1724     2170834 :     return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
    1725             :   }
    1726             : 
    1727             :   static bool isEqual(const TargetInstrInfo::RegSubRegPair &LHS,
    1728             :                       const TargetInstrInfo::RegSubRegPair &RHS) {
    1729    14434544 :     return RegInfo::isEqual(LHS.Reg, RHS.Reg) &&
    1730     5603568 :            RegInfo::isEqual(LHS.SubReg, RHS.SubReg);
    1731             :   }
    1732             : };
    1733             : 
    1734             : } // end namespace llvm
    1735             : 
    1736             : #endif // LLVM_TARGET_TARGETINSTRINFO_H

Generated by: LCOV version 1.13