Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===- ARMInstrInfo.h - ARM Instruction Information -------------*- C++ -*-===// |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the ARM implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef ARMINSTRUCTIONINFO_H |
| 15 | #define ARMINSTRUCTIONINFO_H |
| 16 | |
| 17 | #include "llvm/Target/TargetInstrInfo.h" |
| 18 | #include "ARMRegisterInfo.h" |
Jim Grosbach | cbc47b8 | 2008-10-07 21:01:51 +0000 | [diff] [blame] | 19 | #include "ARM.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 22 | class ARMSubtarget; |
| 23 | |
| 24 | /// ARMII - This namespace holds all of the target specific flags that |
| 25 | /// instruction info tracks. |
| 26 | /// |
| 27 | namespace ARMII { |
| 28 | enum { |
| 29 | //===------------------------------------------------------------------===// |
| 30 | // Instruction Flags. |
| 31 | |
| 32 | //===------------------------------------------------------------------===// |
Jim Grosbach | 0a4b9dc | 2008-11-03 18:38:31 +0000 | [diff] [blame] | 33 | // This four-bit field describes the addressing mode used. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 34 | |
| 35 | AddrModeMask = 0xf, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 36 | AddrModeNone = 0, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 37 | AddrMode1 = 1, |
| 38 | AddrMode2 = 2, |
| 39 | AddrMode3 = 3, |
| 40 | AddrMode4 = 4, |
| 41 | AddrMode5 = 5, |
Evan Cheng | edda31c | 2008-11-05 18:35:52 +0000 | [diff] [blame] | 42 | AddrModeT1 = 6, |
| 43 | AddrModeT2 = 7, |
| 44 | AddrModeT4 = 8, |
| 45 | AddrModeTs = 9, // i8 * 4 for pc and sp relative data |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 46 | |
| 47 | // Size* - Flags to keep track of the size of an instruction. |
| 48 | SizeShift = 4, |
| 49 | SizeMask = 7 << SizeShift, |
| 50 | SizeSpecial = 1, // 0 byte pseudo or special case. |
| 51 | Size8Bytes = 2, |
| 52 | Size4Bytes = 3, |
| 53 | Size2Bytes = 4, |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 54 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 55 | // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 56 | // and store ops |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 57 | IndexModeShift = 7, |
| 58 | IndexModeMask = 3 << IndexModeShift, |
| 59 | IndexModePre = 1, |
| 60 | IndexModePost = 2, |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 61 | |
Evan Cheng | edda31c | 2008-11-05 18:35:52 +0000 | [diff] [blame] | 62 | //===------------------------------------------------------------------===// |
| 63 | // Misc flags. |
| 64 | |
| 65 | // UnaryDP - Indicates this is a unary data processing instruction, i.e. |
| 66 | // it doesn't have a Rn operand. |
Evan Cheng | d87293c | 2008-11-06 08:47:38 +0000 | [diff] [blame] | 67 | UnaryDP = 1 << 9, |
Evan Cheng | edda31c | 2008-11-05 18:35:52 +0000 | [diff] [blame] | 68 | |
| 69 | //===------------------------------------------------------------------===// |
| 70 | // Instruction encoding formats. |
| 71 | // |
Evan Cheng | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame] | 72 | FormShift = 10, |
| 73 | FormMask = 0x1f << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 74 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 75 | // Pseudo instructions |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 76 | Pseudo = 0 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 77 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 78 | // Multiply instructions |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 79 | MulFrm = 1 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 80 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 81 | // Branch instructions |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 82 | BrFrm = 2 << FormShift, |
| 83 | BrMiscFrm = 3 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 84 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 85 | // Data Processing instructions |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 86 | DPFrm = 4 << FormShift, |
| 87 | DPSoRegFrm = 5 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 88 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 89 | // Load and Store |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 90 | LdFrm = 6 << FormShift, |
| 91 | StFrm = 7 << FormShift, |
| 92 | LdMiscFrm = 8 << FormShift, |
| 93 | StMiscFrm = 9 << FormShift, |
| 94 | LdStMulFrm = 10 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 95 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 96 | // Miscellaneous arithmetic instructions |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 97 | ArithMiscFrm = 11 << FormShift, |
Evan Cheng | 97f48c3 | 2008-11-06 22:15:19 +0000 | [diff] [blame] | 98 | |
| 99 | // Extend instructions |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 100 | ExtFrm = 12 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 101 | |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 102 | // VFP formats |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 103 | VFPUnaryFrm = 13 << FormShift, |
| 104 | VFPBinaryFrm = 14 << FormShift, |
| 105 | VFPConv1Frm = 15 << FormShift, |
| 106 | VFPConv2Frm = 16 << FormShift, |
| 107 | VFPConv3Frm = 17 << FormShift, |
| 108 | VFPConv4Frm = 18 << FormShift, |
| 109 | VFPConv5Frm = 19 << FormShift, |
| 110 | VFPLdStFrm = 20 << FormShift, |
| 111 | VFPLdStMulFrm = 21 << FormShift, |
| 112 | VFPMiscFrm = 22 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 113 | |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 114 | // Thumb format |
Evan Cheng | ffa6d96 | 2008-11-13 23:36:57 +0000 | [diff] [blame] | 115 | ThumbFrm = 23 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 116 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 117 | // NEON format |
| 118 | NEONFrm = 24 << FormShift, |
| 119 | NEONGetLnFrm = 25 << FormShift, |
| 120 | NEONSetLnFrm = 26 << FormShift, |
| 121 | NEONDupFrm = 27 << FormShift, |
| 122 | |
Evan Cheng | edda31c | 2008-11-05 18:35:52 +0000 | [diff] [blame] | 123 | //===------------------------------------------------------------------===// |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 124 | // Field shifts - such shifts are used to set field while generating |
| 125 | // machine instructions. |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 126 | M_BitShift = 5, |
Evan Cheng | 7063291 | 2008-11-12 07:34:37 +0000 | [diff] [blame] | 127 | ShiftImmShift = 5, |
Evan Cheng | 8b59db3 | 2008-11-07 01:41:35 +0000 | [diff] [blame] | 128 | ShiftShift = 7, |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 129 | N_BitShift = 7, |
Evan Cheng | 7063291 | 2008-11-12 07:34:37 +0000 | [diff] [blame] | 130 | ImmHiShift = 8, |
Evan Cheng | 97f48c3 | 2008-11-06 22:15:19 +0000 | [diff] [blame] | 131 | SoRotImmShift = 8, |
| 132 | RegRsShift = 8, |
| 133 | ExtRotImmShift = 10, |
| 134 | RegRdLoShift = 12, |
| 135 | RegRdShift = 12, |
| 136 | RegRdHiShift = 16, |
| 137 | RegRnShift = 16, |
| 138 | S_BitShift = 20, |
| 139 | W_BitShift = 21, |
| 140 | AM3_I_BitShift = 22, |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 141 | D_BitShift = 22, |
Evan Cheng | 97f48c3 | 2008-11-06 22:15:19 +0000 | [diff] [blame] | 142 | U_BitShift = 23, |
| 143 | P_BitShift = 24, |
| 144 | I_BitShift = 25, |
| 145 | CondShift = 28 |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 146 | }; |
| 147 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 148 | |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 149 | class ARMBaseInstrInfo : public TargetInstrInfoImpl { |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 150 | protected: |
| 151 | // Can be only subclassed. |
| 152 | explicit ARMBaseInstrInfo(const ARMSubtarget &STI); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 153 | public: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 154 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 155 | MachineBasicBlock::iterator &MBBI, |
Owen Anderson | f660c17 | 2008-07-02 23:41:07 +0000 | [diff] [blame] | 156 | LiveVariables *LV) const; |
Chris Lattner | 578e64a | 2006-10-24 16:47:57 +0000 | [diff] [blame] | 157 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 158 | // Branch analysis. |
| 159 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 160 | MachineBasicBlock *&FBB, |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 161 | SmallVectorImpl<MachineOperand> &Cond, |
| 162 | bool AllowModify) const; |
Evan Cheng | 6ae3626 | 2007-05-18 00:18:17 +0000 | [diff] [blame] | 163 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 164 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 165 | MachineBasicBlock *FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 166 | const SmallVectorImpl<MachineOperand> &Cond) const; |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 167 | |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 168 | virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const; |
| 169 | virtual |
| 170 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
| 171 | |
| 172 | // Predication support. |
| 173 | virtual bool isPredicated(const MachineInstr *MI) const; |
| 174 | |
| 175 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 176 | int PIdx = MI->findFirstPredOperandIdx(); |
| 177 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 178 | : ARMCC::AL; |
| 179 | } |
| 180 | |
| 181 | virtual |
| 182 | bool PredicateInstruction(MachineInstr *MI, |
| 183 | const SmallVectorImpl<MachineOperand> &Pred) const; |
| 184 | |
| 185 | virtual |
| 186 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 187 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
| 188 | |
| 189 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 190 | std::vector<MachineOperand> &Pred) const; |
| 191 | |
| 192 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 193 | /// |
| 194 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
| 195 | }; |
| 196 | |
| 197 | class ARMInstrInfo : public ARMBaseInstrInfo { |
Anton Korobeynikov | a98cbc5 | 2009-06-27 12:16:40 +0000 | [diff] [blame^] | 198 | ARMRegisterInfo RI; |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 199 | public: |
| 200 | explicit ARMInstrInfo(const ARMSubtarget &STI); |
| 201 | |
Anton Korobeynikov | a98cbc5 | 2009-06-27 12:16:40 +0000 | [diff] [blame^] | 202 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 203 | /// such, whenever a client has an instance of instruction info, it should |
| 204 | /// always be able to get register info as well (through this method). |
| 205 | /// |
| 206 | virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; } |
| 207 | |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 208 | /// Return true if the instruction is a register to register move and return |
| 209 | /// the source and dest operands and their sub-register indices by reference. |
| 210 | virtual bool isMoveInstr(const MachineInstr &MI, |
| 211 | unsigned &SrcReg, unsigned &DstReg, |
| 212 | unsigned &SrcSubIdx, unsigned &DstSubIdx) const; |
| 213 | |
| 214 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 215 | int &FrameIndex) const; |
| 216 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 217 | int &FrameIndex) const; |
| 218 | |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 219 | virtual bool copyRegToReg(MachineBasicBlock &MBB, |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 220 | MachineBasicBlock::iterator I, |
| 221 | unsigned DestReg, unsigned SrcReg, |
| 222 | const TargetRegisterClass *DestRC, |
| 223 | const TargetRegisterClass *SrcRC) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 224 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 225 | MachineBasicBlock::iterator MBBI, |
| 226 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 227 | const TargetRegisterClass *RC) const; |
| 228 | |
| 229 | virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill, |
| 230 | SmallVectorImpl<MachineOperand> &Addr, |
| 231 | const TargetRegisterClass *RC, |
| 232 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
| 233 | |
| 234 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 235 | MachineBasicBlock::iterator MBBI, |
| 236 | unsigned DestReg, int FrameIndex, |
| 237 | const TargetRegisterClass *RC) const; |
| 238 | |
| 239 | virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
| 240 | SmallVectorImpl<MachineOperand> &Addr, |
| 241 | const TargetRegisterClass *RC, |
| 242 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
Anton Korobeynikov | d49ea77 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 243 | |
Anton Korobeynikov | a98cbc5 | 2009-06-27 12:16:40 +0000 | [diff] [blame^] | 244 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 245 | unsigned DestReg, const MachineInstr *Orig) const; |
| 246 | |
| 247 | virtual bool canFoldMemoryOperand(const MachineInstr *MI, |
| 248 | const SmallVectorImpl<unsigned> &Ops) const; |
| 249 | |
Dan Gohman | c54baa2 | 2008-12-03 18:43:12 +0000 | [diff] [blame] | 250 | virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, |
| 251 | MachineInstr* MI, |
| 252 | const SmallVectorImpl<unsigned> &Ops, |
| 253 | int FrameIndex) const; |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 254 | |
Dan Gohman | c54baa2 | 2008-12-03 18:43:12 +0000 | [diff] [blame] | 255 | virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, |
| 256 | MachineInstr* MI, |
| 257 | const SmallVectorImpl<unsigned> &Ops, |
| 258 | MachineInstr* LoadMI) const { |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 259 | return 0; |
| 260 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | #endif |