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