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, |
| 54 | |
| 55 | // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load |
| 56 | // and store ops |
| 57 | IndexModeShift = 7, |
| 58 | IndexModeMask = 3 << IndexModeShift, |
| 59 | IndexModePre = 1, |
| 60 | IndexModePost = 2, |
| 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 | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 76 | Pseudo = 1 << 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 | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 79 | MulFrm = 2 << 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 | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 82 | BrFrm = 3 << FormShift, |
| 83 | BrMiscFrm = 4 << 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 | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 86 | DPFrm = 5 << FormShift, |
| 87 | DPSoRegFrm = 6 << 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 | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 90 | LdFrm = 7 << FormShift, |
| 91 | StFrm = 8 << FormShift, |
| 92 | LdMiscFrm = 9 << FormShift, |
| 93 | StMiscFrm = 10 << FormShift, |
| 94 | LdMulFrm = 11 << FormShift, |
| 95 | StMulFrm = 12 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 96 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 97 | // Miscellaneous arithmetic instructions |
Evan Cheng | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 98 | ArithMiscFrm = 13 << FormShift, |
Evan Cheng | 97f48c3 | 2008-11-06 22:15:19 +0000 | [diff] [blame] | 99 | |
| 100 | // Extend instructions |
Evan Cheng | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 101 | ExtFrm = 14 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 102 | |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 103 | // VFP formats |
Evan Cheng | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 104 | VFPUnaryFrm = 15 << FormShift, |
| 105 | VFPBinaryFrm = 16 << FormShift, |
| 106 | VFPConv1Frm = 17 << FormShift, |
| 107 | VFPConv2Frm = 18 << FormShift, |
| 108 | VFPLdStFrm = 19 << FormShift, |
| 109 | VFPLdStMulFrm = 20 << FormShift, |
| 110 | VFPMiscFrm = 21 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 111 | |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 112 | // Thumb format |
Evan Cheng | cd8e66a | 2008-11-11 21:48:44 +0000 | [diff] [blame^] | 113 | ThumbFrm = 22 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 114 | |
Evan Cheng | edda31c | 2008-11-05 18:35:52 +0000 | [diff] [blame] | 115 | //===------------------------------------------------------------------===// |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 116 | // Field shifts - such shifts are used to set field while generating |
| 117 | // machine instructions. |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 118 | M_BitShift = 5, |
Evan Cheng | 8b59db3 | 2008-11-07 01:41:35 +0000 | [diff] [blame] | 119 | ShiftShift = 7, |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 120 | N_BitShift = 7, |
Evan Cheng | 97f48c3 | 2008-11-06 22:15:19 +0000 | [diff] [blame] | 121 | SoRotImmShift = 8, |
| 122 | RegRsShift = 8, |
| 123 | ExtRotImmShift = 10, |
| 124 | RegRdLoShift = 12, |
| 125 | RegRdShift = 12, |
| 126 | RegRdHiShift = 16, |
| 127 | RegRnShift = 16, |
| 128 | S_BitShift = 20, |
| 129 | W_BitShift = 21, |
| 130 | AM3_I_BitShift = 22, |
Evan Cheng | 96581d3 | 2008-11-11 02:11:05 +0000 | [diff] [blame] | 131 | D_BitShift = 22, |
Evan Cheng | 97f48c3 | 2008-11-06 22:15:19 +0000 | [diff] [blame] | 132 | U_BitShift = 23, |
| 133 | P_BitShift = 24, |
| 134 | I_BitShift = 25, |
| 135 | CondShift = 28 |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 136 | }; |
| 137 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 139 | class ARMInstrInfo : public TargetInstrInfoImpl { |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 140 | const ARMRegisterInfo RI; |
| 141 | public: |
Dan Gohman | 950a4c4 | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 142 | explicit ARMInstrInfo(const ARMSubtarget &STI); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 143 | |
| 144 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 145 | /// such, whenever a client has an instance of instruction info, it should |
| 146 | /// always be able to get register info as well (through this method). |
| 147 | /// |
Dan Gohman | c9f5f3f | 2008-05-14 01:58:56 +0000 | [diff] [blame] | 148 | virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 149 | |
Rafael Espindola | 46adf81 | 2006-08-08 20:35:03 +0000 | [diff] [blame] | 150 | /// getPointerRegClass - Return the register class to use to hold pointers. |
| 151 | /// This is used for addressing modes. |
| 152 | virtual const TargetRegisterClass *getPointerRegClass() const; |
| 153 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 154 | /// Return true if the instruction is a register to register move and |
| 155 | /// leave the source and dest operands in the passed parameters. |
| 156 | /// |
| 157 | virtual bool isMoveInstr(const MachineInstr &MI, |
| 158 | unsigned &SrcReg, unsigned &DstReg) const; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 159 | virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 160 | virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 161 | |
Evan Cheng | ca1267c | 2008-03-31 20:40:39 +0000 | [diff] [blame] | 162 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 163 | unsigned DestReg, const MachineInstr *Orig) const; |
| 164 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 165 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 166 | MachineBasicBlock::iterator &MBBI, |
Owen Anderson | f660c17 | 2008-07-02 23:41:07 +0000 | [diff] [blame] | 167 | LiveVariables *LV) const; |
Chris Lattner | 578e64a | 2006-10-24 16:47:57 +0000 | [diff] [blame] | 168 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 169 | // Branch analysis. |
| 170 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 171 | MachineBasicBlock *&FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 172 | SmallVectorImpl<MachineOperand> &Cond) const; |
Evan Cheng | 6ae3626 | 2007-05-18 00:18:17 +0000 | [diff] [blame] | 173 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 174 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 175 | MachineBasicBlock *FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 176 | const SmallVectorImpl<MachineOperand> &Cond) const; |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 177 | virtual bool copyRegToReg(MachineBasicBlock &MBB, |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 178 | MachineBasicBlock::iterator I, |
| 179 | unsigned DestReg, unsigned SrcReg, |
| 180 | const TargetRegisterClass *DestRC, |
| 181 | const TargetRegisterClass *SrcRC) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 182 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 183 | MachineBasicBlock::iterator MBBI, |
| 184 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 185 | const TargetRegisterClass *RC) const; |
| 186 | |
| 187 | virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill, |
| 188 | SmallVectorImpl<MachineOperand> &Addr, |
| 189 | const TargetRegisterClass *RC, |
| 190 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
| 191 | |
| 192 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 193 | MachineBasicBlock::iterator MBBI, |
| 194 | unsigned DestReg, int FrameIndex, |
| 195 | const TargetRegisterClass *RC) const; |
| 196 | |
| 197 | virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
| 198 | SmallVectorImpl<MachineOperand> &Addr, |
| 199 | const TargetRegisterClass *RC, |
| 200 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
Owen Anderson | d94b6a1 | 2008-01-04 23:57:37 +0000 | [diff] [blame] | 201 | virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 202 | MachineBasicBlock::iterator MI, |
| 203 | const std::vector<CalleeSavedInfo> &CSI) const; |
| 204 | virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 205 | MachineBasicBlock::iterator MI, |
| 206 | const std::vector<CalleeSavedInfo> &CSI) const; |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 207 | |
Evan Cheng | 5fd79d0 | 2008-02-08 21:20:40 +0000 | [diff] [blame] | 208 | virtual MachineInstr* foldMemoryOperand(MachineFunction &MF, |
| 209 | MachineInstr* MI, |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 210 | const SmallVectorImpl<unsigned> &Ops, |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 211 | int FrameIndex) const; |
| 212 | |
Evan Cheng | 5fd79d0 | 2008-02-08 21:20:40 +0000 | [diff] [blame] | 213 | virtual MachineInstr* foldMemoryOperand(MachineFunction &MF, |
| 214 | MachineInstr* MI, |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 215 | const SmallVectorImpl<unsigned> &Ops, |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 216 | MachineInstr* LoadMI) const { |
| 217 | return 0; |
| 218 | } |
| 219 | |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 220 | virtual bool canFoldMemoryOperand(const MachineInstr *MI, |
| 221 | const SmallVectorImpl<unsigned> &Ops) const; |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 222 | |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 223 | virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const; |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 224 | virtual |
| 225 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
Evan Cheng | 9307292 | 2007-05-16 02:01:49 +0000 | [diff] [blame] | 226 | |
| 227 | // Predication support. |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 228 | virtual bool isPredicated(const MachineInstr *MI) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 229 | |
Jim Grosbach | 3341262 | 2008-10-07 19:05:35 +0000 | [diff] [blame] | 230 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 231 | int PIdx = MI->findFirstPredOperandIdx(); |
| 232 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 233 | : ARMCC::AL; |
| 234 | } |
| 235 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 236 | virtual |
| 237 | bool PredicateInstruction(MachineInstr *MI, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 238 | const SmallVectorImpl<MachineOperand> &Pred) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 239 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 240 | virtual |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 241 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 242 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
Evan Cheng | 13ab020 | 2007-07-10 18:08:01 +0000 | [diff] [blame] | 243 | |
| 244 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 245 | std::vector<MachineOperand> &Pred) const; |
Nicolas Geoffray | 52e724a | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 246 | |
| 247 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 248 | /// |
| 249 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 250 | }; |
| 251 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | #endif |