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 | //===------------------------------------------------------------------===// |
| 33 | // This three-bit field describes the addressing mode used. Zero is unused |
| 34 | // so that we can tell if we forgot to set a value. |
| 35 | |
| 36 | AddrModeMask = 0xf, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 37 | AddrModeNone = 0, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 38 | AddrMode1 = 1, |
| 39 | AddrMode2 = 2, |
| 40 | AddrMode3 = 3, |
| 41 | AddrMode4 = 4, |
| 42 | AddrMode5 = 5, |
| 43 | AddrModeT1 = 6, |
| 44 | AddrModeT2 = 7, |
| 45 | AddrModeT4 = 8, |
| 46 | AddrModeTs = 9, // i8 * 4 for pc and sp relative data |
| 47 | |
| 48 | // Size* - Flags to keep track of the size of an instruction. |
| 49 | SizeShift = 4, |
| 50 | SizeMask = 7 << SizeShift, |
| 51 | SizeSpecial = 1, // 0 byte pseudo or special case. |
| 52 | Size8Bytes = 2, |
| 53 | Size4Bytes = 3, |
| 54 | Size2Bytes = 4, |
| 55 | |
| 56 | // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load |
| 57 | // and store ops |
| 58 | IndexModeShift = 7, |
| 59 | IndexModeMask = 3 << IndexModeShift, |
| 60 | IndexModePre = 1, |
| 61 | IndexModePost = 2, |
| 62 | |
| 63 | // Opcode |
| 64 | OpcodeShift = 9, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 65 | OpcodeMask = 0xf << OpcodeShift, |
| 66 | |
| 67 | // Format |
| 68 | FormShift = 13, |
| 69 | FormMask = 31 << FormShift, |
| 70 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 71 | // Pseudo instructions |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 72 | Pseudo = 1 << FormShift, |
| 73 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 74 | // Multiply instructions |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 75 | MulFrm = 2 << FormShift, |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 76 | MulSMLAW = 3 << FormShift, |
| 77 | MulSMULW = 4 << FormShift, |
| 78 | MulSMLA = 5 << FormShift, |
| 79 | MulSMUL = 6 << 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 |
| 82 | Branch = 7 << FormShift, |
| 83 | BranchMisc = 8 << 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 | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 86 | DPRdIm = 9 << FormShift, |
| 87 | DPRdReg = 10 << FormShift, |
| 88 | DPRdSoReg = 11 << FormShift, |
| 89 | DPRdMisc = 12 << FormShift, |
| 90 | |
| 91 | DPRnIm = 13 << FormShift, |
| 92 | DPRnReg = 14 << FormShift, |
| 93 | DPRnSoReg = 15 << FormShift, |
| 94 | |
| 95 | DPRIm = 16 << FormShift, |
| 96 | DPRReg = 17 << FormShift, |
| 97 | DPRSoReg = 18 << FormShift, |
| 98 | |
| 99 | DPRImS = 19 << FormShift, |
| 100 | DPRRegS = 20 << FormShift, |
| 101 | DPRSoRegS = 21 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 102 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 103 | // Load and Store |
Evan Cheng | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 104 | LdFrm = 22 << FormShift, |
| 105 | StFrm = 23 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 106 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 107 | // Miscellaneous arithmetic instructions |
Evan Cheng | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 108 | ArithMisc = 24 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 109 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 110 | // Thumb format |
Evan Cheng | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 111 | ThumbFrm = 25 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 112 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 113 | // VFP format |
Evan Cheng | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 114 | VPFFrm = 26 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +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 | 5f1db7b | 2008-09-12 22:01:15 +0000 | [diff] [blame] | 118 | RotImmShift = 8, |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 119 | RegRsShift = 8, |
| 120 | RegRdShift = 12, |
| 121 | RegRnShift = 16, |
Evan Cheng | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 122 | L_BitShift = 20, |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 123 | S_BitShift = 20, |
| 124 | U_BitShift = 23, |
Evan Cheng | 05fc966 | 2008-09-13 01:35:33 +0000 | [diff] [blame] | 125 | IndexShift = 24, |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 126 | I_BitShift = 25 |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 127 | }; |
| 128 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 130 | class ARMInstrInfo : public TargetInstrInfoImpl { |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 131 | const ARMRegisterInfo RI; |
| 132 | public: |
Dan Gohman | 950a4c4 | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 133 | explicit ARMInstrInfo(const ARMSubtarget &STI); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 134 | |
| 135 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 136 | /// such, whenever a client has an instance of instruction info, it should |
| 137 | /// always be able to get register info as well (through this method). |
| 138 | /// |
Dan Gohman | c9f5f3f | 2008-05-14 01:58:56 +0000 | [diff] [blame] | 139 | virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 140 | |
Rafael Espindola | 46adf81 | 2006-08-08 20:35:03 +0000 | [diff] [blame] | 141 | /// getPointerRegClass - Return the register class to use to hold pointers. |
| 142 | /// This is used for addressing modes. |
| 143 | virtual const TargetRegisterClass *getPointerRegClass() const; |
| 144 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 145 | /// Return true if the instruction is a register to register move and |
| 146 | /// leave the source and dest operands in the passed parameters. |
| 147 | /// |
| 148 | virtual bool isMoveInstr(const MachineInstr &MI, |
| 149 | unsigned &SrcReg, unsigned &DstReg) const; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 150 | virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 151 | virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 152 | |
Evan Cheng | ca1267c | 2008-03-31 20:40:39 +0000 | [diff] [blame] | 153 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 154 | unsigned DestReg, const MachineInstr *Orig) const; |
| 155 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 156 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 157 | MachineBasicBlock::iterator &MBBI, |
Owen Anderson | f660c17 | 2008-07-02 23:41:07 +0000 | [diff] [blame] | 158 | LiveVariables *LV) const; |
Chris Lattner | 578e64a | 2006-10-24 16:47:57 +0000 | [diff] [blame] | 159 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 160 | // Branch analysis. |
| 161 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 162 | MachineBasicBlock *&FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 163 | SmallVectorImpl<MachineOperand> &Cond) const; |
Evan Cheng | 6ae3626 | 2007-05-18 00:18:17 +0000 | [diff] [blame] | 164 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 165 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 166 | MachineBasicBlock *FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 167 | const SmallVectorImpl<MachineOperand> &Cond) const; |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 168 | virtual bool copyRegToReg(MachineBasicBlock &MBB, |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 169 | MachineBasicBlock::iterator I, |
| 170 | unsigned DestReg, unsigned SrcReg, |
| 171 | const TargetRegisterClass *DestRC, |
| 172 | const TargetRegisterClass *SrcRC) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 173 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 174 | MachineBasicBlock::iterator MBBI, |
| 175 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 176 | const TargetRegisterClass *RC) const; |
| 177 | |
| 178 | virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill, |
| 179 | SmallVectorImpl<MachineOperand> &Addr, |
| 180 | const TargetRegisterClass *RC, |
| 181 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
| 182 | |
| 183 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 184 | MachineBasicBlock::iterator MBBI, |
| 185 | unsigned DestReg, int FrameIndex, |
| 186 | const TargetRegisterClass *RC) const; |
| 187 | |
| 188 | virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
| 189 | SmallVectorImpl<MachineOperand> &Addr, |
| 190 | const TargetRegisterClass *RC, |
| 191 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
Owen Anderson | d94b6a1 | 2008-01-04 23:57:37 +0000 | [diff] [blame] | 192 | virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 193 | MachineBasicBlock::iterator MI, |
| 194 | const std::vector<CalleeSavedInfo> &CSI) const; |
| 195 | virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 196 | MachineBasicBlock::iterator MI, |
| 197 | const std::vector<CalleeSavedInfo> &CSI) const; |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 198 | |
Evan Cheng | 5fd79d0 | 2008-02-08 21:20:40 +0000 | [diff] [blame] | 199 | virtual MachineInstr* foldMemoryOperand(MachineFunction &MF, |
| 200 | MachineInstr* MI, |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame^] | 201 | const SmallVectorImpl<unsigned> &Ops, |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 202 | int FrameIndex) const; |
| 203 | |
Evan Cheng | 5fd79d0 | 2008-02-08 21:20:40 +0000 | [diff] [blame] | 204 | virtual MachineInstr* foldMemoryOperand(MachineFunction &MF, |
| 205 | MachineInstr* MI, |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame^] | 206 | const SmallVectorImpl<unsigned> &Ops, |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 207 | MachineInstr* LoadMI) const { |
| 208 | return 0; |
| 209 | } |
| 210 | |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame^] | 211 | virtual bool canFoldMemoryOperand(const MachineInstr *MI, |
| 212 | const SmallVectorImpl<unsigned> &Ops) const; |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 213 | |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame^] | 214 | virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const; |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 215 | virtual |
| 216 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
Evan Cheng | 9307292 | 2007-05-16 02:01:49 +0000 | [diff] [blame] | 217 | |
| 218 | // Predication support. |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 219 | virtual bool isPredicated(const MachineInstr *MI) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 220 | |
Jim Grosbach | 3341262 | 2008-10-07 19:05:35 +0000 | [diff] [blame] | 221 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 222 | int PIdx = MI->findFirstPredOperandIdx(); |
| 223 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 224 | : ARMCC::AL; |
| 225 | } |
| 226 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 227 | virtual |
| 228 | bool PredicateInstruction(MachineInstr *MI, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 229 | const SmallVectorImpl<MachineOperand> &Pred) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 230 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 231 | virtual |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 232 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 233 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
Evan Cheng | 13ab020 | 2007-07-10 18:08:01 +0000 | [diff] [blame] | 234 | |
| 235 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 236 | std::vector<MachineOperand> &Pred) const; |
Nicolas Geoffray | 52e724a | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 237 | |
| 238 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 239 | /// |
| 240 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | #endif |