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