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" |
| 19 | |
| 20 | namespace llvm { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 21 | class ARMSubtarget; |
| 22 | |
| 23 | /// ARMII - This namespace holds all of the target specific flags that |
| 24 | /// instruction info tracks. |
| 25 | /// |
| 26 | namespace ARMII { |
| 27 | enum { |
| 28 | //===------------------------------------------------------------------===// |
| 29 | // Instruction Flags. |
| 30 | |
| 31 | //===------------------------------------------------------------------===// |
| 32 | // This three-bit field describes the addressing mode used. Zero is unused |
| 33 | // so that we can tell if we forgot to set a value. |
| 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, |
| 42 | AddrModeT1 = 6, |
| 43 | AddrModeT2 = 7, |
| 44 | AddrModeT4 = 8, |
| 45 | AddrModeTs = 9, // i8 * 4 for pc and sp relative data |
| 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 | |
| 62 | // Opcode |
| 63 | OpcodeShift = 9, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 64 | OpcodeMask = 0xf << OpcodeShift, |
| 65 | |
| 66 | // Format |
| 67 | FormShift = 13, |
| 68 | FormMask = 31 << FormShift, |
| 69 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 70 | // Pseudo instructions |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 71 | Pseudo = 1 << FormShift, |
| 72 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 73 | // Multiply instructions |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 74 | MulFrm = 2 << FormShift, |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 75 | MulSMLAW = 3 << FormShift, |
| 76 | MulSMULW = 4 << FormShift, |
| 77 | MulSMLA = 5 << FormShift, |
| 78 | MulSMUL = 6 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 79 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 80 | // Branch instructions |
| 81 | Branch = 7 << FormShift, |
| 82 | BranchMisc = 8 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 83 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 84 | // Data Processing instructions |
| 85 | DPRdIm = 9 << FormShift, |
| 86 | DPRdReg = 10 << FormShift, |
| 87 | DPRdSoReg = 11 << FormShift, |
| 88 | DPRdMisc = 12 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 89 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 90 | DPRnIm = 13 << FormShift, |
| 91 | DPRnReg = 14 << FormShift, |
| 92 | DPRnSoReg = 15 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 93 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 94 | DPRIm = 16 << FormShift, |
| 95 | DPRReg = 17 << FormShift, |
| 96 | DPRSoReg = 18 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 97 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 98 | DPRImS = 19 << FormShift, |
| 99 | DPRRegS = 20 << FormShift, |
| 100 | DPRSoRegS = 21 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 101 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 102 | // Load and Store |
| 103 | LdFrm = 22 << FormShift, |
| 104 | StFrm = 23 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 105 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 106 | // Miscellaneous arithmetic instructions |
| 107 | ArithMisc = 24 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 108 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 109 | // Thumb format |
| 110 | ThumbFrm = 25 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 111 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 112 | // VFP format |
| 113 | VPFFrm = 26 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 114 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame] | 115 | // Field shifts - such shifts are used to set field while generating |
| 116 | // machine instructions. |
| 117 | RegRsShift = 8, |
| 118 | RegRdShift = 12, |
| 119 | RegRnShift = 16, |
| 120 | L_BitShift = 20, |
| 121 | S_BitShift = 20, |
| 122 | U_BitShift = 23, |
| 123 | IndexShift = 24, |
| 124 | I_BitShift = 25 |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 125 | }; |
| 126 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 127 | |
| 128 | class ARMInstrInfo : public TargetInstrInfo { |
| 129 | const ARMRegisterInfo RI; |
| 130 | public: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 131 | ARMInstrInfo(const ARMSubtarget &STI); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 132 | |
| 133 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 134 | /// such, whenever a client has an instance of instruction info, it should |
| 135 | /// always be able to get register info as well (through this method). |
| 136 | /// |
| 137 | virtual const MRegisterInfo &getRegisterInfo() const { return RI; } |
| 138 | |
Rafael Espindola | 46adf81 | 2006-08-08 20:35:03 +0000 | [diff] [blame] | 139 | /// getPointerRegClass - Return the register class to use to hold pointers. |
| 140 | /// This is used for addressing modes. |
| 141 | virtual const TargetRegisterClass *getPointerRegClass() const; |
| 142 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 143 | /// Return true if the instruction is a register to register move and |
| 144 | /// leave the source and dest operands in the passed parameters. |
| 145 | /// |
| 146 | virtual bool isMoveInstr(const MachineInstr &MI, |
| 147 | unsigned &SrcReg, unsigned &DstReg) const; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 148 | virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 149 | virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 150 | |
| 151 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 152 | MachineBasicBlock::iterator &MBBI, |
| 153 | LiveVariables &LV) const; |
Chris Lattner | 578e64a | 2006-10-24 16:47:57 +0000 | [diff] [blame] | 154 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 155 | // Branch analysis. |
| 156 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 157 | MachineBasicBlock *&FBB, |
| 158 | std::vector<MachineOperand> &Cond) const; |
Evan Cheng | 6ae3626 | 2007-05-18 00:18:17 +0000 | [diff] [blame] | 159 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 160 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 161 | MachineBasicBlock *FBB, |
| 162 | const std::vector<MachineOperand> &Cond) const; |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame^] | 163 | virtual void copyRegToReg(MachineBasicBlock &MBB, |
| 164 | MachineBasicBlock::iterator I, |
| 165 | unsigned DestReg, unsigned SrcReg, |
| 166 | const TargetRegisterClass *DestRC, |
| 167 | const TargetRegisterClass *SrcRC) const; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 168 | virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const; |
| 169 | virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const; |
Evan Cheng | 9307292 | 2007-05-16 02:01:49 +0000 | [diff] [blame] | 170 | |
| 171 | // Predication support. |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 172 | virtual bool isPredicated(const MachineInstr *MI) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 173 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 174 | virtual |
| 175 | bool PredicateInstruction(MachineInstr *MI, |
| 176 | const std::vector<MachineOperand> &Pred) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 177 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 178 | virtual |
| 179 | bool SubsumesPredicate(const std::vector<MachineOperand> &Pred1, |
Christopher Lamb | a4c7910 | 2007-10-18 19:29:45 +0000 | [diff] [blame] | 180 | const std::vector<MachineOperand> &Pred2) const; |
Evan Cheng | 13ab020 | 2007-07-10 18:08:01 +0000 | [diff] [blame] | 181 | |
| 182 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 183 | std::vector<MachineOperand> &Pred) const; |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
Evan Cheng | 29836c3 | 2007-01-29 23:45:17 +0000 | [diff] [blame] | 186 | // Utility routines |
| 187 | namespace ARM { |
| 188 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 189 | /// |
| 190 | unsigned GetInstSize(MachineInstr *MI); |
| 191 | |
| 192 | /// GetFunctionSize - Returns the size of the specified MachineFunction. |
| 193 | /// |
| 194 | unsigned GetFunctionSize(MachineFunction &MF); |
| 195 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | #endif |