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