Jim Grosbach | 31c24bf | 2009-11-07 22:00:39 +0000 | [diff] [blame] | 1 | //===- ARMBaseInstrInfo.h - ARM Base Instruction Information ----*- C++ -*-===// |
David Goodwin | 334c264 | 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 | |
| 14 | #ifndef ARMBASEINSTRUCTIONINFO_H |
| 15 | #define ARMBASEINSTRUCTIONINFO_H |
| 16 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 17 | #include "ARM.h" |
Anton Korobeynikov | b8e9ac8 | 2009-07-16 23:26:06 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 19 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #include "llvm/ADT/SmallSet.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
Chris Lattner | 4dbbe34 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 24 | class ARMSubtarget; |
| 25 | class ARMBaseRegisterInfo; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 26 | |
| 27 | /// ARMII - This namespace holds all of the target specific flags that |
| 28 | /// instruction info tracks. |
| 29 | /// |
| 30 | namespace ARMII { |
| 31 | enum { |
| 32 | //===------------------------------------------------------------------===// |
| 33 | // Instruction Flags. |
| 34 | |
| 35 | //===------------------------------------------------------------------===// |
| 36 | // This four-bit field describes the addressing mode used. |
| 37 | |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 38 | AddrModeMask = 0x1f, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 39 | AddrModeNone = 0, |
| 40 | AddrMode1 = 1, |
| 41 | AddrMode2 = 2, |
| 42 | AddrMode3 = 3, |
| 43 | AddrMode4 = 4, |
| 44 | AddrMode5 = 5, |
| 45 | AddrMode6 = 6, |
| 46 | AddrModeT1_1 = 7, |
| 47 | AddrModeT1_2 = 8, |
| 48 | AddrModeT1_4 = 9, |
| 49 | AddrModeT1_s = 10, // i8 * 4 for pc and sp relative data |
| 50 | AddrModeT2_i12 = 11, |
| 51 | AddrModeT2_i8 = 12, |
| 52 | AddrModeT2_so = 13, |
| 53 | AddrModeT2_pc = 14, // +/- i12 for pc relative data |
| 54 | AddrModeT2_i8s4 = 15, // i8 * 4 |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 55 | AddrMode_i12 = 16, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 56 | |
| 57 | // Size* - Flags to keep track of the size of an instruction. |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 58 | SizeShift = 5, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 59 | SizeMask = 7 << SizeShift, |
| 60 | SizeSpecial = 1, // 0 byte pseudo or special case. |
| 61 | Size8Bytes = 2, |
| 62 | Size4Bytes = 3, |
| 63 | Size2Bytes = 4, |
| 64 | |
Bob Wilson | bffb5b3 | 2010-03-13 07:34:35 +0000 | [diff] [blame] | 65 | // IndexMode - Unindex, pre-indexed, or post-indexed are valid for load |
| 66 | // and store ops only. Generic "updating" flag is used for ld/st multiple. |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 67 | IndexModeShift = 8, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 68 | IndexModeMask = 3 << IndexModeShift, |
| 69 | IndexModePre = 1, |
| 70 | IndexModePost = 2, |
Bob Wilson | bffb5b3 | 2010-03-13 07:34:35 +0000 | [diff] [blame] | 71 | IndexModeUpd = 3, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 72 | |
| 73 | //===------------------------------------------------------------------===// |
| 74 | // Instruction encoding formats. |
| 75 | // |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 76 | FormShift = 10, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 77 | FormMask = 0x3f << FormShift, |
| 78 | |
| 79 | // Pseudo instructions |
| 80 | Pseudo = 0 << FormShift, |
| 81 | |
| 82 | // Multiply instructions |
| 83 | MulFrm = 1 << FormShift, |
| 84 | |
| 85 | // Branch instructions |
| 86 | BrFrm = 2 << FormShift, |
| 87 | BrMiscFrm = 3 << FormShift, |
| 88 | |
| 89 | // Data Processing instructions |
| 90 | DPFrm = 4 << FormShift, |
| 91 | DPSoRegFrm = 5 << FormShift, |
| 92 | |
| 93 | // Load and Store |
| 94 | LdFrm = 6 << FormShift, |
| 95 | StFrm = 7 << FormShift, |
| 96 | LdMiscFrm = 8 << FormShift, |
| 97 | StMiscFrm = 9 << FormShift, |
| 98 | LdStMulFrm = 10 << FormShift, |
| 99 | |
Johnny Chen | 81f04d5 | 2010-03-19 17:39:00 +0000 | [diff] [blame] | 100 | LdStExFrm = 11 << FormShift, |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 101 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 102 | // Miscellaneous arithmetic instructions |
Johnny Chen | 81f04d5 | 2010-03-19 17:39:00 +0000 | [diff] [blame] | 103 | ArithMiscFrm = 12 << FormShift, |
Bob Wilson | 9a1c189 | 2010-08-11 00:01:18 +0000 | [diff] [blame] | 104 | SatFrm = 13 << FormShift, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 105 | |
| 106 | // Extend instructions |
Bob Wilson | 9a1c189 | 2010-08-11 00:01:18 +0000 | [diff] [blame] | 107 | ExtFrm = 14 << FormShift, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 108 | |
| 109 | // VFP formats |
Bob Wilson | 9a1c189 | 2010-08-11 00:01:18 +0000 | [diff] [blame] | 110 | VFPUnaryFrm = 15 << FormShift, |
| 111 | VFPBinaryFrm = 16 << FormShift, |
| 112 | VFPConv1Frm = 17 << FormShift, |
| 113 | VFPConv2Frm = 18 << FormShift, |
| 114 | VFPConv3Frm = 19 << FormShift, |
| 115 | VFPConv4Frm = 20 << FormShift, |
| 116 | VFPConv5Frm = 21 << FormShift, |
| 117 | VFPLdStFrm = 22 << FormShift, |
| 118 | VFPLdStMulFrm = 23 << FormShift, |
| 119 | VFPMiscFrm = 24 << FormShift, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 120 | |
| 121 | // Thumb format |
Bob Wilson | 9a1c189 | 2010-08-11 00:01:18 +0000 | [diff] [blame] | 122 | ThumbFrm = 25 << FormShift, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 123 | |
Bob Wilson | 2653263 | 2010-06-25 23:45:37 +0000 | [diff] [blame] | 124 | // Miscelleaneous format |
Bob Wilson | 9a1c189 | 2010-08-11 00:01:18 +0000 | [diff] [blame] | 125 | MiscFrm = 26 << FormShift, |
Bob Wilson | 2653263 | 2010-06-25 23:45:37 +0000 | [diff] [blame] | 126 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 127 | // NEON formats |
Bob Wilson | 9a1c189 | 2010-08-11 00:01:18 +0000 | [diff] [blame] | 128 | NGetLnFrm = 27 << FormShift, |
| 129 | NSetLnFrm = 28 << FormShift, |
| 130 | NDupFrm = 29 << FormShift, |
| 131 | NLdStFrm = 30 << FormShift, |
| 132 | N1RegModImmFrm= 31 << FormShift, |
| 133 | N2RegFrm = 32 << FormShift, |
| 134 | NVCVTFrm = 33 << FormShift, |
| 135 | NVDupLnFrm = 34 << FormShift, |
| 136 | N2RegVShLFrm = 35 << FormShift, |
| 137 | N2RegVShRFrm = 36 << FormShift, |
| 138 | N3RegFrm = 37 << FormShift, |
| 139 | N3RegVShFrm = 38 << FormShift, |
| 140 | NVExtFrm = 39 << FormShift, |
| 141 | NVMulSLFrm = 40 << FormShift, |
| 142 | NVTBLFrm = 41 << FormShift, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 143 | |
| 144 | //===------------------------------------------------------------------===// |
| 145 | // Misc flags. |
| 146 | |
| 147 | // UnaryDP - Indicates this is a unary data processing instruction, i.e. |
| 148 | // it doesn't have a Rn operand. |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 149 | UnaryDP = 1 << 16, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 150 | |
| 151 | // Xform16Bit - Indicates this Thumb2 instruction may be transformed into |
| 152 | // a 16-bit Thumb instruction if certain conditions are met. |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 153 | Xform16Bit = 1 << 17, |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 154 | |
| 155 | //===------------------------------------------------------------------===// |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 156 | // Code domain. |
Jim Grosbach | d86609f | 2010-10-05 18:14:55 +0000 | [diff] [blame] | 157 | DomainShift = 18, |
Evan Cheng | 6557bce | 2011-02-22 19:53:14 +0000 | [diff] [blame] | 158 | DomainMask = 7 << DomainShift, |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 159 | DomainGeneral = 0 << DomainShift, |
| 160 | DomainVFP = 1 << DomainShift, |
| 161 | DomainNEON = 2 << DomainShift, |
Evan Cheng | 6557bce | 2011-02-22 19:53:14 +0000 | [diff] [blame] | 162 | DomainNEONA8 = 4 << DomainShift, |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 163 | |
| 164 | //===------------------------------------------------------------------===// |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 165 | // Field shifts - such shifts are used to set field while generating |
| 166 | // machine instructions. |
Jim Grosbach | 42fac8e | 2010-10-11 23:16:21 +0000 | [diff] [blame] | 167 | // |
| 168 | // FIXME: This list will need adjusting/fixing as the MC code emitter |
| 169 | // takes shape and the ARMCodeEmitter.cpp bits go away. |
| 170 | ShiftTypeShift = 4, |
| 171 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 172 | M_BitShift = 5, |
| 173 | ShiftImmShift = 5, |
| 174 | ShiftShift = 7, |
| 175 | N_BitShift = 7, |
| 176 | ImmHiShift = 8, |
| 177 | SoRotImmShift = 8, |
| 178 | RegRsShift = 8, |
| 179 | ExtRotImmShift = 10, |
| 180 | RegRdLoShift = 12, |
| 181 | RegRdShift = 12, |
| 182 | RegRdHiShift = 16, |
| 183 | RegRnShift = 16, |
| 184 | S_BitShift = 20, |
| 185 | W_BitShift = 21, |
| 186 | AM3_I_BitShift = 22, |
| 187 | D_BitShift = 22, |
| 188 | U_BitShift = 23, |
| 189 | P_BitShift = 24, |
| 190 | I_BitShift = 25, |
| 191 | CondShift = 28 |
| 192 | }; |
Evan Cheng | b46aaa3 | 2009-07-19 19:16:46 +0000 | [diff] [blame] | 193 | } |
| 194 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 195 | class ARMBaseInstrInfo : public TargetInstrInfoImpl { |
Chris Lattner | 4dbbe34 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 196 | const ARMSubtarget &Subtarget; |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 197 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 198 | protected: |
| 199 | // Can be only subclassed. |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 200 | explicit ARMBaseInstrInfo(const ARMSubtarget &STI); |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 201 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 202 | public: |
| 203 | // Return the non-pre/post incrementing version of 'Opc'. Return 0 |
| 204 | // if there is not such an opcode. |
| 205 | virtual unsigned getUnindexedOpcode(unsigned Opc) const =0; |
| 206 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 207 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 208 | MachineBasicBlock::iterator &MBBI, |
| 209 | LiveVariables *LV) const; |
| 210 | |
| 211 | virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0; |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 212 | const ARMSubtarget &getSubtarget() const { return Subtarget; } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 213 | |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 214 | ScheduleHazardRecognizer * |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 215 | CreateTargetHazardRecognizer(const TargetMachine *TM, |
| 216 | const ScheduleDAG *DAG) const; |
| 217 | |
| 218 | ScheduleHazardRecognizer * |
| 219 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| 220 | const ScheduleDAG *DAG) const; |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 221 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 222 | // Branch analysis. |
| 223 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 224 | MachineBasicBlock *&FBB, |
| 225 | SmallVectorImpl<MachineOperand> &Cond, |
Chris Lattner | 2062875 | 2010-07-22 21:27:00 +0000 | [diff] [blame] | 226 | bool AllowModify = false) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 227 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 228 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 229 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 230 | const SmallVectorImpl<MachineOperand> &Cond, |
| 231 | DebugLoc DL) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 232 | |
| 233 | virtual |
| 234 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
| 235 | |
| 236 | // Predication support. |
Evan Cheng | ab33150 | 2009-07-10 01:38:27 +0000 | [diff] [blame] | 237 | bool isPredicated(const MachineInstr *MI) const { |
| 238 | int PIdx = MI->findFirstPredOperandIdx(); |
| 239 | return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL; |
| 240 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 241 | |
| 242 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 243 | int PIdx = MI->findFirstPredOperandIdx(); |
| 244 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 245 | : ARMCC::AL; |
| 246 | } |
| 247 | |
| 248 | virtual |
| 249 | bool PredicateInstruction(MachineInstr *MI, |
| 250 | const SmallVectorImpl<MachineOperand> &Pred) const; |
| 251 | |
| 252 | virtual |
| 253 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 254 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
| 255 | |
| 256 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 257 | std::vector<MachineOperand> &Pred) const; |
| 258 | |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 259 | virtual bool isPredicable(MachineInstr *MI) const; |
| 260 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 261 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 262 | /// |
| 263 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
| 264 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 265 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 266 | int &FrameIndex) const; |
| 267 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 268 | int &FrameIndex) const; |
| 269 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 270 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 271 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 272 | unsigned DestReg, unsigned SrcReg, |
| 273 | bool KillSrc) const; |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 274 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 275 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 276 | MachineBasicBlock::iterator MBBI, |
| 277 | unsigned SrcReg, bool isKill, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 278 | const TargetRegisterClass *RC, |
| 279 | const TargetRegisterInfo *TRI) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 280 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 281 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 282 | MachineBasicBlock::iterator MBBI, |
| 283 | unsigned DestReg, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 284 | const TargetRegisterClass *RC, |
| 285 | const TargetRegisterInfo *TRI) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 286 | |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 287 | virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 288 | int FrameIx, |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 289 | uint64_t Offset, |
| 290 | const MDNode *MDPtr, |
| 291 | DebugLoc DL) const; |
| 292 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 293 | virtual void reMaterialize(MachineBasicBlock &MBB, |
| 294 | MachineBasicBlock::iterator MI, |
| 295 | unsigned DestReg, unsigned SubIdx, |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 296 | const MachineInstr *Orig, |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 297 | const TargetRegisterInfo &TRI) const; |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 298 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 299 | MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const; |
| 300 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 301 | virtual bool produceSameValue(const MachineInstr *MI0, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 302 | const MachineInstr *MI1, |
| 303 | const MachineRegisterInfo *MRI) const; |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 304 | |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 305 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 306 | /// determine if two loads are loading from the same base address. It should |
| 307 | /// only return true if the base pointers are the same and the only |
| 308 | /// differences between the two addresses is the offset. It also returns the |
| 309 | /// offsets by reference. |
| 310 | virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, |
| 311 | int64_t &Offset1, int64_t &Offset2)const; |
| 312 | |
| 313 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| 314 | /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should |
| 315 | /// be scheduled togther. On some targets if two loads are loading from |
| 316 | /// addresses in the same cache line, it's better if they are scheduled |
| 317 | /// together. This function takes two integers that represent the load offsets |
| 318 | /// from the common base address. It returns true if it decides it's desirable |
| 319 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 320 | /// have already been scheduled after Load1. |
| 321 | virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 322 | int64_t Offset1, int64_t Offset2, |
| 323 | unsigned NumLoads) const; |
| 324 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 325 | virtual bool isSchedulingBoundary(const MachineInstr *MI, |
| 326 | const MachineBasicBlock *MBB, |
| 327 | const MachineFunction &MF) const; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 328 | |
| 329 | virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 330 | unsigned NumCyles, unsigned ExtraPredCycles, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 331 | float Prob, float Confidence) const; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 332 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 333 | virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 334 | unsigned NumT, unsigned ExtraT, |
| 335 | MachineBasicBlock &FMBB, |
| 336 | unsigned NumF, unsigned ExtraF, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 337 | float Probability, float Confidence) const; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 338 | |
| 339 | virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 340 | unsigned NumCyles, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 341 | float Probability, |
| 342 | float Confidence) const { |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 343 | return NumCyles == 1; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 344 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 345 | |
Bill Wendling | c98af33 | 2010-08-08 05:04:59 +0000 | [diff] [blame] | 346 | /// AnalyzeCompare - For a comparison instruction, return the source register |
| 347 | /// in SrcReg and the value it compares against in CmpValue. Return true if |
| 348 | /// the comparison instruction can be analyzed. |
| 349 | virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 350 | int &CmpMask, int &CmpValue) const; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 351 | |
Bill Wendling | a655686 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 352 | /// OptimizeCompareInstr - Convert the instruction to set the zero flag so |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 353 | /// that we can remove a "comparison with zero". |
Bill Wendling | a655686 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 354 | virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 355 | int CmpMask, int CmpValue, |
Evan Cheng | eb96a2f | 2010-11-15 21:20:45 +0000 | [diff] [blame] | 356 | const MachineRegisterInfo *MRI) const; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 357 | |
Evan Cheng | c4af463 | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 358 | /// FoldImmediate - 'Reg' is known to be defined by a move immediate |
| 359 | /// instruction, try to fold the immediate into the use instruction. |
| 360 | virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI, |
| 361 | unsigned Reg, MachineRegisterInfo *MRI) const; |
| 362 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 363 | virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, |
| 364 | const MachineInstr *MI) const; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 365 | |
| 366 | virtual |
| 367 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 368 | const MachineInstr *DefMI, unsigned DefIdx, |
| 369 | const MachineInstr *UseMI, unsigned UseIdx) const; |
| 370 | virtual |
| 371 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 372 | SDNode *DefNode, unsigned DefIdx, |
| 373 | SDNode *UseNode, unsigned UseIdx) const; |
| 374 | private: |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 375 | int getVLDMDefCycle(const InstrItineraryData *ItinData, |
| 376 | const TargetInstrDesc &DefTID, |
| 377 | unsigned DefClass, |
| 378 | unsigned DefIdx, unsigned DefAlign) const; |
| 379 | int getLDMDefCycle(const InstrItineraryData *ItinData, |
| 380 | const TargetInstrDesc &DefTID, |
| 381 | unsigned DefClass, |
| 382 | unsigned DefIdx, unsigned DefAlign) const; |
| 383 | int getVSTMUseCycle(const InstrItineraryData *ItinData, |
| 384 | const TargetInstrDesc &UseTID, |
| 385 | unsigned UseClass, |
| 386 | unsigned UseIdx, unsigned UseAlign) const; |
| 387 | int getSTMUseCycle(const InstrItineraryData *ItinData, |
| 388 | const TargetInstrDesc &UseTID, |
| 389 | unsigned UseClass, |
| 390 | unsigned UseIdx, unsigned UseAlign) const; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 391 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 392 | const TargetInstrDesc &DefTID, |
| 393 | unsigned DefIdx, unsigned DefAlign, |
| 394 | const TargetInstrDesc &UseTID, |
| 395 | unsigned UseIdx, unsigned UseAlign) const; |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 396 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 397 | int getInstrLatency(const InstrItineraryData *ItinData, |
| 398 | const MachineInstr *MI, unsigned *PredCost = 0) const; |
| 399 | |
| 400 | int getInstrLatency(const InstrItineraryData *ItinData, |
| 401 | SDNode *Node) const; |
| 402 | |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 403 | bool hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 404 | const MachineRegisterInfo *MRI, |
| 405 | const MachineInstr *DefMI, unsigned DefIdx, |
| 406 | const MachineInstr *UseMI, unsigned UseIdx) const; |
Evan Cheng | c8141df | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 407 | bool hasLowDefLatency(const InstrItineraryData *ItinData, |
| 408 | const MachineInstr *DefMI, unsigned DefIdx) const; |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 409 | |
| 410 | private: |
| 411 | /// Modeling special VFP / NEON fp MLA / MLS hazards. |
| 412 | |
| 413 | /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal |
| 414 | /// MLx table. |
| 415 | DenseMap<unsigned, unsigned> MLxEntryMap; |
| 416 | |
| 417 | /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause |
| 418 | /// stalls when scheduled together with fp MLA / MLS opcodes. |
| 419 | SmallSet<unsigned, 16> MLxHazardOpcodes; |
| 420 | |
| 421 | public: |
| 422 | /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS |
| 423 | /// instruction. |
| 424 | bool isFpMLxInstruction(unsigned Opcode) const { |
| 425 | return MLxEntryMap.count(Opcode); |
| 426 | } |
| 427 | |
| 428 | /// isFpMLxInstruction - This version also returns the multiply opcode and the |
| 429 | /// addition / subtraction opcode to expand to. Return true for 'HasLane' for |
| 430 | /// the MLX instructions with an extra lane operand. |
| 431 | bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 432 | unsigned &AddSubOpc, bool &NegAcc, |
| 433 | bool &HasLane) const; |
| 434 | |
| 435 | /// canCauseFpMLxStall - Return true if an instruction of the specified opcode |
| 436 | /// will cause stalls when scheduled after (within 4-cycle window) a fp |
| 437 | /// MLA / MLS instruction. |
| 438 | bool canCauseFpMLxStall(unsigned Opcode) const { |
| 439 | return MLxHazardOpcodes.count(Opcode); |
| 440 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 441 | }; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 442 | |
| 443 | static inline |
| 444 | const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) { |
| 445 | return MIB.addImm((int64_t)ARMCC::AL).addReg(0); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 448 | static inline |
| 449 | const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) { |
| 450 | return MIB.addReg(0); |
| 451 | } |
| 452 | |
| 453 | static inline |
Evan Cheng | e8af1f9 | 2009-08-10 02:37:24 +0000 | [diff] [blame] | 454 | const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB, |
| 455 | bool isDead = false) { |
| 456 | return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead)); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static inline |
Evan Cheng | bc9b754 | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 460 | const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) { |
| 461 | return MIB.addReg(0); |
| 462 | } |
| 463 | |
| 464 | static inline |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 465 | bool isUncondBranchOpcode(int Opc) { |
| 466 | return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B; |
| 467 | } |
| 468 | |
| 469 | static inline |
| 470 | bool isCondBranchOpcode(int Opc) { |
| 471 | return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc; |
| 472 | } |
| 473 | |
| 474 | static inline |
| 475 | bool isJumpTableBranchOpcode(int Opc) { |
| 476 | return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd || |
| 477 | Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT; |
| 478 | } |
| 479 | |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 480 | static inline |
| 481 | bool isIndirectBranchOpcode(int Opc) { |
Bill Wendling | 6e46d84 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 482 | return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND; |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 485 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 486 | /// condition, otherwise returns AL. It also returns the condition code |
| 487 | /// register by reference. |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 488 | ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg); |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 489 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 490 | int getMatchingCondBranchOpcode(int Opc); |
| 491 | |
| 492 | /// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of |
| 493 | /// instructions to materializea destreg = basereg + immediate in ARM / Thumb2 |
| 494 | /// code. |
| 495 | void emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 496 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 497 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 498 | ARMCC::CondCodes Pred, unsigned PredReg, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame^] | 499 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 500 | |
| 501 | void emitT2RegPlusImmediate(MachineBasicBlock &MBB, |
| 502 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 503 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 504 | ARMCC::CondCodes Pred, unsigned PredReg, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame^] | 505 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 506 | void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame^] | 507 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 508 | unsigned DestReg, unsigned BaseReg, |
| 509 | int NumBytes, const TargetInstrInfo &TII, |
| 510 | const ARMBaseRegisterInfo& MRI, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame^] | 511 | unsigned MIFlags = 0); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 512 | |
| 513 | |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 514 | /// rewriteARMFrameIndex / rewriteT2FrameIndex - |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 515 | /// Rewrite MI to access 'Offset' bytes from the FP. Return false if the |
| 516 | /// offset could not be handled directly in MI, and return the left-over |
| 517 | /// portion by reference. |
| 518 | bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 519 | unsigned FrameReg, int &Offset, |
| 520 | const ARMBaseInstrInfo &TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 521 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 522 | bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 523 | unsigned FrameReg, int &Offset, |
| 524 | const ARMBaseInstrInfo &TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 525 | |
| 526 | } // End llvm namespace |
| 527 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 528 | #endif |