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 | // |
| 5 | // This file was developed by the "Instituto Nokia de Tecnologia" and |
| 6 | // is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
| 11 | // This file contains the ARM implementation of the TargetInstrInfo class. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef ARMINSTRUCTIONINFO_H |
| 16 | #define ARMINSTRUCTIONINFO_H |
| 17 | |
| 18 | #include "llvm/Target/TargetInstrInfo.h" |
| 19 | #include "ARMRegisterInfo.h" |
| 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 |
| 86 | DPRdIm = 9 << FormShift, |
| 87 | DPRdReg = 10 << FormShift, |
| 88 | DPRdSoReg = 11 << FormShift, |
| 89 | DPRdMisc = 12 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 90 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame^] | 91 | DPRnIm = 13 << FormShift, |
| 92 | DPRnReg = 14 << FormShift, |
| 93 | DPRnSoReg = 15 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 94 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame^] | 95 | DPRIm = 16 << FormShift, |
| 96 | DPRReg = 17 << FormShift, |
| 97 | DPRSoReg = 18 << FormShift, |
Evan Cheng | 0ff94f7 | 2007-08-07 01:37:15 +0000 | [diff] [blame] | 98 | |
Raul Herbster | 8c13263 | 2007-08-30 23:34:14 +0000 | [diff] [blame^] | 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 |
| 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 |
| 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 |
| 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 |
| 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. |
| 118 | RegRsShift = 8, |
| 119 | RegRdShift = 12, |
| 120 | RegRnShift = 16, |
| 121 | L_BitShift = 20, |
| 122 | S_BitShift = 20, |
| 123 | U_BitShift = 23, |
| 124 | IndexShift = 24, |
| 125 | I_BitShift = 25 |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 126 | }; |
| 127 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 128 | |
| 129 | class ARMInstrInfo : public TargetInstrInfo { |
| 130 | const ARMRegisterInfo RI; |
| 131 | public: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 132 | ARMInstrInfo(const ARMSubtarget &STI); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 133 | |
| 134 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 135 | /// such, whenever a client has an instance of instruction info, it should |
| 136 | /// always be able to get register info as well (through this method). |
| 137 | /// |
| 138 | virtual const MRegisterInfo &getRegisterInfo() const { return RI; } |
| 139 | |
Rafael Espindola | 46adf81 | 2006-08-08 20:35:03 +0000 | [diff] [blame] | 140 | /// getPointerRegClass - Return the register class to use to hold pointers. |
| 141 | /// This is used for addressing modes. |
| 142 | virtual const TargetRegisterClass *getPointerRegClass() const; |
| 143 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 144 | /// Return true if the instruction is a register to register move and |
| 145 | /// leave the source and dest operands in the passed parameters. |
| 146 | /// |
| 147 | virtual bool isMoveInstr(const MachineInstr &MI, |
| 148 | unsigned &SrcReg, unsigned &DstReg) const; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 149 | virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 150 | virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const; |
| 151 | |
| 152 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 153 | MachineBasicBlock::iterator &MBBI, |
| 154 | LiveVariables &LV) const; |
Chris Lattner | 578e64a | 2006-10-24 16:47:57 +0000 | [diff] [blame] | 155 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 156 | // Branch analysis. |
| 157 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 158 | MachineBasicBlock *&FBB, |
| 159 | std::vector<MachineOperand> &Cond) const; |
Evan Cheng | 6ae3626 | 2007-05-18 00:18:17 +0000 | [diff] [blame] | 160 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 161 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 162 | MachineBasicBlock *FBB, |
| 163 | const std::vector<MachineOperand> &Cond) const; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 164 | virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const; |
| 165 | virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const; |
Evan Cheng | 9307292 | 2007-05-16 02:01:49 +0000 | [diff] [blame] | 166 | |
| 167 | // Predication support. |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 168 | virtual bool isPredicated(const MachineInstr *MI) const; |
Evan Cheng | 69d5556 | 2007-05-23 07:22:05 +0000 | [diff] [blame] | 169 | |
Evan Cheng | 62ccdbf | 2007-05-29 18:42:18 +0000 | [diff] [blame] | 170 | virtual |
| 171 | bool PredicateInstruction(MachineInstr *MI, |
| 172 | const std::vector<MachineOperand> &Pred) 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 SubsumesPredicate(const std::vector<MachineOperand> &Pred1, |
| 176 | const std::vector<MachineOperand> &Pred1) const; |
Evan Cheng | 13ab020 | 2007-07-10 18:08:01 +0000 | [diff] [blame] | 177 | |
| 178 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 179 | std::vector<MachineOperand> &Pred) const; |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
Evan Cheng | 29836c3 | 2007-01-29 23:45:17 +0000 | [diff] [blame] | 182 | // Utility routines |
| 183 | namespace ARM { |
| 184 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 185 | /// |
| 186 | unsigned GetInstSize(MachineInstr *MI); |
| 187 | |
| 188 | /// GetFunctionSize - Returns the size of the specified MachineFunction. |
| 189 | /// |
| 190 | unsigned GetFunctionSize(MachineFunction &MF); |
| 191 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | #endif |