| Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMBaseInstrInfo.h - ARM Base Instruction Information ---*- C++ -*-===// |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 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 contains the Base ARM implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H |
| 15 | #define LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 16 | |
| Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 17 | #include "MCTargetDesc/ARMBaseInfo.h" |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/SmallSet.h" |
| Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CodeGen.h" |
| Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetInstrInfo.h" |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 23 | |
| Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 24 | #define GET_INSTRINFO_HEADER |
| 25 | #include "ARMGenInstrInfo.inc" |
| 26 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 27 | namespace llvm { |
| Chris Lattner | cbe9856 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 28 | class ARMSubtarget; |
| 29 | class ARMBaseRegisterInfo; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 30 | |
| Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 31 | class ARMBaseInstrInfo : public ARMGenInstrInfo { |
| Chris Lattner | cbe9856 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 32 | const ARMSubtarget &Subtarget; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 33 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 34 | protected: |
| 35 | // Can be only subclassed. |
| Anton Korobeynikov | 14635da | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 36 | explicit ARMBaseInstrInfo(const ARMSubtarget &STI); |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 37 | |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 38 | void expandLoadStackGuardBase(MachineBasicBlock::iterator MI, |
| 39 | unsigned LoadImmOpc, unsigned LoadOpc, |
| 40 | Reloc::Model RM) const; |
| 41 | |
| Quentin Colombet | d358e84 | 2014-08-22 18:05:22 +0000 | [diff] [blame] | 42 | /// Build the equivalent inputs of a REG_SEQUENCE for the given \p MI |
| 43 | /// and \p DefIdx. |
| 44 | /// \p [out] InputRegs of the equivalent REG_SEQUENCE. Each element of |
| 45 | /// the list is modeled as <Reg:SubReg, SubIdx>. |
| 46 | /// E.g., REG_SEQUENCE vreg1:sub1, sub0, vreg2, sub1 would produce |
| 47 | /// two elements: |
| 48 | /// - vreg1:sub1, sub0 |
| 49 | /// - vreg2<:0>, sub1 |
| 50 | /// |
| 51 | /// \returns true if it is possible to build such an input sequence |
| 52 | /// with the pair \p MI, \p DefIdx. False otherwise. |
| 53 | /// |
| 54 | /// \pre MI.isRegSequenceLike(). |
| 55 | bool getRegSequenceLikeInputs( |
| 56 | const MachineInstr &MI, unsigned DefIdx, |
| 57 | SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const override; |
| 58 | |
| 59 | /// Build the equivalent inputs of a EXTRACT_SUBREG for the given \p MI |
| 60 | /// and \p DefIdx. |
| 61 | /// \p [out] InputReg of the equivalent EXTRACT_SUBREG. |
| 62 | /// E.g., EXTRACT_SUBREG vreg1:sub1, sub0, sub1 would produce: |
| 63 | /// - vreg1:sub1, sub0 |
| 64 | /// |
| 65 | /// \returns true if it is possible to build such an input sequence |
| 66 | /// with the pair \p MI, \p DefIdx. False otherwise. |
| 67 | /// |
| 68 | /// \pre MI.isExtractSubregLike(). |
| 69 | bool getExtractSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx, |
| 70 | RegSubRegPairAndIdx &InputReg) const override; |
| 71 | |
| 72 | /// Build the equivalent inputs of a INSERT_SUBREG for the given \p MI |
| 73 | /// and \p DefIdx. |
| 74 | /// \p [out] BaseReg and \p [out] InsertedReg contain |
| 75 | /// the equivalent inputs of INSERT_SUBREG. |
| 76 | /// E.g., INSERT_SUBREG vreg0:sub0, vreg1:sub1, sub3 would produce: |
| 77 | /// - BaseReg: vreg0:sub0 |
| 78 | /// - InsertedReg: vreg1:sub1, sub3 |
| 79 | /// |
| 80 | /// \returns true if it is possible to build such an input sequence |
| 81 | /// with the pair \p MI, \p DefIdx. False otherwise. |
| 82 | /// |
| 83 | /// \pre MI.isInsertSubregLike(). |
| 84 | bool |
| 85 | getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx, |
| 86 | RegSubRegPair &BaseReg, |
| 87 | RegSubRegPairAndIdx &InsertedReg) const override; |
| 88 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 89 | public: |
| Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 90 | // Return whether the target has an explicit NOP encoding. |
| 91 | bool hasNOP() const; |
| 92 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 93 | // Return the non-pre/post incrementing version of 'Opc'. Return 0 |
| 94 | // if there is not such an opcode. |
| 95 | virtual unsigned getUnindexedOpcode(unsigned Opc) const =0; |
| 96 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 97 | MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 98 | MachineBasicBlock::iterator &MBBI, |
| 99 | LiveVariables *LV) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 100 | |
| Bill Wendling | f95178e | 2013-06-07 05:54:19 +0000 | [diff] [blame] | 101 | virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0; |
| Anton Korobeynikov | 14635da | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 102 | const ARMSubtarget &getSubtarget() const { return Subtarget; } |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 103 | |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 104 | ScheduleHazardRecognizer * |
| Eric Christopher | f047bfd | 2014-06-13 22:38:52 +0000 | [diff] [blame] | 105 | CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 106 | const ScheduleDAG *DAG) const override; |
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 107 | |
| 108 | ScheduleHazardRecognizer * |
| 109 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 110 | const ScheduleDAG *DAG) const override; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 111 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 112 | // Branch analysis. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 113 | bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 114 | MachineBasicBlock *&FBB, |
| 115 | SmallVectorImpl<MachineOperand> &Cond, |
| 116 | bool AllowModify = false) const override; |
| 117 | unsigned RemoveBranch(MachineBasicBlock &MBB) const override; |
| 118 | unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 119 | MachineBasicBlock *FBB, |
| 120 | const SmallVectorImpl<MachineOperand> &Cond, |
| 121 | DebugLoc DL) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 122 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 123 | bool |
| 124 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 125 | |
| 126 | // Predication support. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 127 | bool isPredicated(const MachineInstr *MI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 128 | |
| 129 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 130 | int PIdx = MI->findFirstPredOperandIdx(); |
| 131 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 132 | : ARMCC::AL; |
| 133 | } |
| 134 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 135 | bool PredicateInstruction(MachineInstr *MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 136 | const SmallVectorImpl<MachineOperand> &Pred) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 137 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 138 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 139 | const SmallVectorImpl<MachineOperand> &Pred2) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 140 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 141 | bool DefinesPredicate(MachineInstr *MI, |
| 142 | std::vector<MachineOperand> &Pred) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 143 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 144 | bool isPredicable(MachineInstr *MI) const override; |
| Evan Cheng | a33fc86 | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 145 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 146 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 147 | /// |
| 148 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
| 149 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 150 | unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 151 | int &FrameIndex) const override; |
| 152 | unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 153 | int &FrameIndex) const override; |
| 154 | unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI, |
| 155 | int &FrameIndex) const override; |
| 156 | unsigned isStoreToStackSlotPostFE(const MachineInstr *MI, |
| 157 | int &FrameIndex) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 158 | |
| Tim Northover | 5d72c5d | 2014-10-01 19:21:03 +0000 | [diff] [blame] | 159 | void copyToCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 160 | unsigned SrcReg, bool KillSrc, |
| 161 | const ARMSubtarget &Subtarget) const; |
| 162 | void copyFromCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 163 | unsigned DestReg, bool KillSrc, |
| 164 | const ARMSubtarget &Subtarget) const; |
| 165 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 166 | void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 167 | DebugLoc DL, unsigned DestReg, unsigned SrcReg, |
| 168 | bool KillSrc) const override; |
| Evan Cheng | c47e109 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 169 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 170 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 171 | MachineBasicBlock::iterator MBBI, |
| 172 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 173 | const TargetRegisterClass *RC, |
| 174 | const TargetRegisterInfo *TRI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 175 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 176 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 177 | MachineBasicBlock::iterator MBBI, |
| 178 | unsigned DestReg, int FrameIndex, |
| 179 | const TargetRegisterClass *RC, |
| 180 | const TargetRegisterInfo *TRI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 181 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 182 | bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override; |
| Jakob Stoklund Olesen | da7c0f8 | 2011-10-11 00:59:06 +0000 | [diff] [blame] | 183 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 184 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 185 | unsigned DestReg, unsigned SubIdx, |
| 186 | const MachineInstr *Orig, |
| 187 | const TargetRegisterInfo &TRI) const override; |
| Evan Cheng | fe86442 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 188 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 189 | MachineInstr *duplicate(MachineInstr *Orig, |
| 190 | MachineFunction &MF) const override; |
| Jakob Stoklund Olesen | 29a64c9 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 191 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 192 | MachineInstr *commuteInstruction(MachineInstr*, |
| 193 | bool=false) const override; |
| Jakob Stoklund Olesen | 0a5b72f | 2012-04-04 18:23:42 +0000 | [diff] [blame] | 194 | |
| Tim Northover | 798697d | 2013-04-21 11:57:07 +0000 | [diff] [blame] | 195 | const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg, |
| 196 | unsigned SubIdx, unsigned State, |
| 197 | const TargetRegisterInfo *TRI) const; |
| 198 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 199 | bool produceSameValue(const MachineInstr *MI0, const MachineInstr *MI1, |
| 200 | const MachineRegisterInfo *MRI) const override; |
| Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 201 | |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 202 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 203 | /// determine if two loads are loading from the same base address. It should |
| 204 | /// only return true if the base pointers are the same and the only |
| 205 | /// differences between the two addresses is the offset. It also returns the |
| 206 | /// offsets by reference. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 207 | bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1, |
| 208 | int64_t &Offset2) const override; |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 209 | |
| 210 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| Jim Grosbach | 7ef7ddd | 2011-06-13 22:54:22 +0000 | [diff] [blame] | 211 | /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads |
| 212 | /// should be scheduled togther. On some targets if two loads are loading from |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 213 | /// addresses in the same cache line, it's better if they are scheduled |
| 214 | /// together. This function takes two integers that represent the load offsets |
| 215 | /// from the common base address. It returns true if it decides it's desirable |
| 216 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 217 | /// have already been scheduled after Load1. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 218 | bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 219 | int64_t Offset1, int64_t Offset2, |
| 220 | unsigned NumLoads) const override; |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 221 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 222 | bool isSchedulingBoundary(const MachineInstr *MI, |
| 223 | const MachineBasicBlock *MBB, |
| 224 | const MachineFunction &MF) const override; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 225 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 226 | bool isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 227 | unsigned NumCycles, unsigned ExtraPredCycles, |
| 228 | const BranchProbability &Probability) const override; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 229 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 230 | bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT, |
| 231 | unsigned ExtraT, MachineBasicBlock &FMBB, |
| 232 | unsigned NumF, unsigned ExtraF, |
| 233 | const BranchProbability &Probability) const override; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 234 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 235 | bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 236 | const BranchProbability &Probability) const override { |
| Cameron Zwarich | 8001850 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 237 | return NumCycles == 1; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 238 | } |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 239 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 240 | bool isProfitableToUnpredicate(MachineBasicBlock &TMBB, |
| 241 | MachineBasicBlock &FMBB) const override; |
| Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 242 | |
| Manman Ren | 6fa76dc | 2012-06-29 21:33:59 +0000 | [diff] [blame] | 243 | /// analyzeCompare - For a comparison instruction, return the source registers |
| 244 | /// in SrcReg and SrcReg2 if having two register operands, and the value it |
| 245 | /// compares against in CmpValue. Return true if the comparison instruction |
| 246 | /// can be analyzed. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 247 | bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg, |
| 248 | unsigned &SrcReg2, int &CmpMask, |
| 249 | int &CmpValue) const override; |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 250 | |
| Manman Ren | 6fa76dc | 2012-06-29 21:33:59 +0000 | [diff] [blame] | 251 | /// optimizeCompareInstr - Convert the instruction to set the zero flag so |
| 252 | /// that we can remove a "comparison with zero"; Remove a redundant CMP |
| 253 | /// instruction if the flags can be updated in the same way by an earlier |
| 254 | /// instruction such as SUB. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 255 | bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, |
| 256 | unsigned SrcReg2, int CmpMask, int CmpValue, |
| 257 | const MachineRegisterInfo *MRI) const override; |
| Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 258 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 259 | bool analyzeSelect(const MachineInstr *MI, |
| 260 | SmallVectorImpl<MachineOperand> &Cond, |
| 261 | unsigned &TrueOp, unsigned &FalseOp, |
| 262 | bool &Optimizable) const override; |
| Jakob Stoklund Olesen | c19bf02 | 2012-08-16 23:14:20 +0000 | [diff] [blame] | 263 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 264 | MachineInstr *optimizeSelect(MachineInstr *MI, bool) const override; |
| Jakob Stoklund Olesen | c19bf02 | 2012-08-16 23:14:20 +0000 | [diff] [blame] | 265 | |
| Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 266 | /// FoldImmediate - 'Reg' is known to be defined by a move immediate |
| 267 | /// instruction, try to fold the immediate into the use instruction. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 268 | bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI, |
| 269 | unsigned Reg, MachineRegisterInfo *MRI) const override; |
| Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 270 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 271 | unsigned getNumMicroOps(const InstrItineraryData *ItinData, |
| 272 | const MachineInstr *MI) const override; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 273 | |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 274 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 275 | const MachineInstr *DefMI, unsigned DefIdx, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 276 | const MachineInstr *UseMI, |
| 277 | unsigned UseIdx) const override; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 278 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 279 | SDNode *DefNode, unsigned DefIdx, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 280 | SDNode *UseNode, unsigned UseIdx) const override; |
| Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 281 | |
| 282 | /// VFP/NEON execution domains. |
| 283 | std::pair<uint16_t, uint16_t> |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 284 | getExecutionDomain(const MachineInstr *MI) const override; |
| 285 | void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override; |
| Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 286 | |
| Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 287 | unsigned getPartialRegUpdateClearance(const MachineInstr*, unsigned, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 288 | const TargetRegisterInfo*) const override; |
| Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 289 | void breakPartialRegDependency(MachineBasicBlock::iterator, unsigned, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 290 | const TargetRegisterInfo *TRI) const override; |
| Tom Roeder | 44cb65f | 2014-06-05 19:29:43 +0000 | [diff] [blame] | 291 | |
| 292 | void |
| 293 | getUnconditionalBranch(MCInst &Branch, |
| 294 | const MCSymbolRefExpr *BranchTarget) const override; |
| 295 | |
| 296 | void getTrap(MCInst &MI) const override; |
| 297 | |
| Andrew Trick | 2ac6f7d | 2012-09-14 18:48:46 +0000 | [diff] [blame] | 298 | /// Get the number of addresses by LDM or VLDM or zero for unknown. |
| 299 | unsigned getNumLDMAddresses(const MachineInstr *MI) const; |
| 300 | |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 301 | private: |
| Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 302 | unsigned getInstBundleLength(const MachineInstr *MI) const; |
| 303 | |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 304 | int getVLDMDefCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 305 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 306 | unsigned DefClass, |
| 307 | unsigned DefIdx, unsigned DefAlign) const; |
| 308 | int getLDMDefCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 309 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 310 | unsigned DefClass, |
| 311 | unsigned DefIdx, unsigned DefAlign) const; |
| 312 | int getVSTMUseCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 313 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 314 | unsigned UseClass, |
| 315 | unsigned UseIdx, unsigned UseAlign) const; |
| 316 | int getSTMUseCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 317 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 318 | unsigned UseClass, |
| 319 | unsigned UseIdx, unsigned UseAlign) const; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 320 | int getOperandLatency(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 321 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 322 | unsigned DefIdx, unsigned DefAlign, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 323 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 324 | unsigned UseIdx, unsigned UseAlign) const; |
| Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 325 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 326 | unsigned getPredicationCost(const MachineInstr *MI) const override; |
| Arnold Schwaighofer | d2f96b9 | 2013-09-30 15:28:56 +0000 | [diff] [blame] | 327 | |
| Andrew Trick | 4544606 | 2012-06-05 21:11:27 +0000 | [diff] [blame] | 328 | unsigned getInstrLatency(const InstrItineraryData *ItinData, |
| 329 | const MachineInstr *MI, |
| Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 330 | unsigned *PredCost = nullptr) const override; |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 331 | |
| 332 | int getInstrLatency(const InstrItineraryData *ItinData, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 333 | SDNode *Node) const override; |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 334 | |
| Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 335 | bool hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 336 | const MachineRegisterInfo *MRI, |
| 337 | const MachineInstr *DefMI, unsigned DefIdx, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 338 | const MachineInstr *UseMI, |
| 339 | unsigned UseIdx) const override; |
| Evan Cheng | e96b8d7 | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 340 | bool hasLowDefLatency(const InstrItineraryData *ItinData, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 341 | const MachineInstr *DefMI, |
| 342 | unsigned DefIdx) const override; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 343 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 344 | /// verifyInstruction - Perform target specific instruction verification. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 345 | bool verifyInstruction(const MachineInstr *MI, |
| 346 | StringRef &ErrInfo) const override; |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 347 | |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 348 | virtual void expandLoadStackGuard(MachineBasicBlock::iterator MI, |
| 349 | Reloc::Model RM) const = 0; |
| 350 | |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 351 | private: |
| 352 | /// Modeling special VFP / NEON fp MLA / MLS hazards. |
| 353 | |
| 354 | /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal |
| 355 | /// MLx table. |
| 356 | DenseMap<unsigned, unsigned> MLxEntryMap; |
| 357 | |
| 358 | /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause |
| 359 | /// stalls when scheduled together with fp MLA / MLS opcodes. |
| 360 | SmallSet<unsigned, 16> MLxHazardOpcodes; |
| 361 | |
| 362 | public: |
| 363 | /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS |
| 364 | /// instruction. |
| 365 | bool isFpMLxInstruction(unsigned Opcode) const { |
| 366 | return MLxEntryMap.count(Opcode); |
| 367 | } |
| 368 | |
| 369 | /// isFpMLxInstruction - This version also returns the multiply opcode and the |
| 370 | /// addition / subtraction opcode to expand to. Return true for 'HasLane' for |
| 371 | /// the MLX instructions with an extra lane operand. |
| 372 | bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 373 | unsigned &AddSubOpc, bool &NegAcc, |
| 374 | bool &HasLane) const; |
| 375 | |
| 376 | /// canCauseFpMLxStall - Return true if an instruction of the specified opcode |
| 377 | /// will cause stalls when scheduled after (within 4-cycle window) a fp |
| 378 | /// MLA / MLS instruction. |
| 379 | bool canCauseFpMLxStall(unsigned Opcode) const { |
| 380 | return MLxHazardOpcodes.count(Opcode); |
| 381 | } |
| Arnold Schwaighofer | 5dde1f3 | 2013-04-05 04:42:00 +0000 | [diff] [blame] | 382 | |
| 383 | /// Returns true if the instruction has a shift by immediate that can be |
| 384 | /// executed in one cycle less. |
| 385 | bool isSwiftFastImmShift(const MachineInstr *MI) const; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 386 | }; |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 387 | |
| 388 | static inline |
| 389 | const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) { |
| 390 | return MIB.addImm((int64_t)ARMCC::AL).addReg(0); |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 393 | static inline |
| 394 | const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) { |
| 395 | return MIB.addReg(0); |
| 396 | } |
| 397 | |
| 398 | static inline |
| Evan Cheng | 51cbd2d | 2009-08-10 02:37:24 +0000 | [diff] [blame] | 399 | const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB, |
| 400 | bool isDead = false) { |
| 401 | return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead)); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static inline |
| Evan Cheng | 6ddd7bc | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 405 | const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) { |
| 406 | return MIB.addReg(0); |
| 407 | } |
| 408 | |
| 409 | static inline |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 410 | bool isUncondBranchOpcode(int Opc) { |
| 411 | return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B; |
| 412 | } |
| 413 | |
| 414 | static inline |
| 415 | bool isCondBranchOpcode(int Opc) { |
| 416 | return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc; |
| 417 | } |
| 418 | |
| 419 | static inline |
| 420 | bool isJumpTableBranchOpcode(int Opc) { |
| 421 | return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd || |
| 422 | Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT; |
| 423 | } |
| 424 | |
| Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 425 | static inline |
| 426 | bool isIndirectBranchOpcode(int Opc) { |
| Bill Wendling | 8294a30 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 427 | return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND; |
| Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 430 | static inline bool isPopOpcode(int Opc) { |
| 431 | return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET || |
| 432 | Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD || |
| 433 | Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD; |
| 434 | } |
| 435 | |
| 436 | static inline bool isPushOpcode(int Opc) { |
| 437 | return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD || |
| 438 | Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD; |
| 439 | } |
| 440 | |
| Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 441 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 442 | /// condition, otherwise returns AL. It also returns the condition code |
| 443 | /// register by reference. |
| Evan Cheng | 83e0d48 | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 444 | ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg); |
| Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 445 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 446 | int getMatchingCondBranchOpcode(int Opc); |
| 447 | |
| Jakob Stoklund Olesen | 6cb9612 | 2012-08-15 22:16:39 +0000 | [diff] [blame] | 448 | /// Determine if MI can be folded into an ARM MOVCC instruction, and return the |
| 449 | /// opcode of the SSA instruction representing the conditional MI. |
| 450 | unsigned canFoldARMInstrIntoMOVCC(unsigned Reg, |
| 451 | MachineInstr *&MI, |
| 452 | const MachineRegisterInfo &MRI); |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 453 | |
| 454 | /// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether |
| 455 | /// the instruction is encoded with an 'S' bit is determined by the optional |
| 456 | /// CPSR def operand. |
| 457 | unsigned convertAddSubFlagsOpcode(unsigned OldOpc); |
| 458 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 459 | /// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of |
| 460 | /// instructions to materializea destreg = basereg + immediate in ARM / Thumb2 |
| 461 | /// code. |
| 462 | void emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 463 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 464 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 465 | ARMCC::CondCodes Pred, unsigned PredReg, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 466 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 467 | |
| 468 | void emitT2RegPlusImmediate(MachineBasicBlock &MBB, |
| 469 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 470 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 471 | ARMCC::CondCodes Pred, unsigned PredReg, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 472 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 473 | void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 474 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 475 | unsigned DestReg, unsigned BaseReg, |
| 476 | int NumBytes, const TargetInstrInfo &TII, |
| 477 | const ARMBaseRegisterInfo& MRI, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 478 | unsigned MIFlags = 0); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 479 | |
| Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 480 | /// Tries to add registers to the reglist of a given base-updating |
| 481 | /// push/pop instruction to adjust the stack by an additional |
| 482 | /// NumBytes. This can save a few bytes per function in code-size, but |
| 483 | /// obviously generates more memory traffic. As such, it only takes |
| 484 | /// effect in functions being optimised for size. |
| Tim Northover | dee8604 | 2013-12-02 14:46:26 +0000 | [diff] [blame] | 485 | bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget, |
| 486 | MachineFunction &MF, MachineInstr *MI, |
| Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 487 | unsigned NumBytes); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 488 | |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 489 | /// rewriteARMFrameIndex / rewriteT2FrameIndex - |
| Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 490 | /// Rewrite MI to access 'Offset' bytes from the FP. Return false if the |
| 491 | /// offset could not be handled directly in MI, and return the left-over |
| 492 | /// portion by reference. |
| 493 | bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 494 | unsigned FrameReg, int &Offset, |
| 495 | const ARMBaseInstrInfo &TII); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 496 | |
| Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 497 | bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 498 | unsigned FrameReg, int &Offset, |
| 499 | const ARMBaseInstrInfo &TII); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 500 | |
| 501 | } // End llvm namespace |
| 502 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 503 | #endif |