Add binary encoding support for multiply instructions. Some blanks left to fill in...
[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     AddrMode6     = 6,
43     AddrModeT1    = 7,
44     AddrModeT2    = 8,
45     AddrModeT4    = 9,
46     AddrModeTs    = 10,  // 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,
65     OpcodeMask    = 0xf << OpcodeShift,
66     
67     // Format
68     FormShift   = 13,
69     FormMask    = 31 << FormShift,
70
71     // Pseudo instructions
72     Pseudo      = 1 << FormShift,
73
74     // Multiply instructions
75     MulFrm      = 2 << FormShift,
76     MulSMLAW    = 3 << FormShift,
77     MulSMULW    = 4 << FormShift,
78     MulSMLA     = 5 << FormShift,
79     MulSMUL     = 6 << FormShift,
80
81     // Branch instructions
82     Branch      = 7 << FormShift,
83     BranchMisc  = 8 << FormShift,
84
85     // Data Processing instructions
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,
102
103     // Load and Store
104     LdFrm       = 22 << FormShift,
105     StFrm       = 23 << FormShift,
106
107     // Miscellaneous arithmetic instructions
108     ArithMisc   = 24 << FormShift,
109
110     // Thumb format
111     ThumbFrm    = 25 << FormShift,
112
113     // VFP format
114     VPFFrm      = 26 << FormShift,
115
116     // Field shifts - such shifts are used to set field while generating
117     // machine instructions.
118     RotImmShift  = 8,
119     RegRsShift   = 8,
120     RegRdLoShift = 12,
121     RegRdShift   = 12,
122     RegRdHiShift = 16,
123     RegRnShift   = 16,
124     L_BitShift   = 20,
125     S_BitShift   = 20,
126     U_BitShift   = 23,
127     IndexShift   = 24,
128     I_BitShift   = 25
129   };
130 }
131
132 class ARMInstrInfo : public TargetInstrInfoImpl {
133   const ARMRegisterInfo RI;
134 public:
135   explicit ARMInstrInfo(const ARMSubtarget &STI);
136
137   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
138   /// such, whenever a client has an instance of instruction info, it should
139   /// always be able to get register info as well (through this method).
140   ///
141   virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
142
143   /// getPointerRegClass - Return the register class to use to hold pointers.
144   /// This is used for addressing modes.
145   virtual const TargetRegisterClass *getPointerRegClass() const;
146
147   /// Return true if the instruction is a register to register move and
148   /// leave the source and dest operands in the passed parameters.
149   ///
150   virtual bool isMoveInstr(const MachineInstr &MI,
151                            unsigned &SrcReg, unsigned &DstReg) const;
152   virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
153   virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
154   
155   void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
156                      unsigned DestReg, const MachineInstr *Orig) const;
157
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) const;
166   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
167   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
168                                 MachineBasicBlock *FBB,
169                             const SmallVectorImpl<MachineOperand> &Cond) const;
170   virtual bool copyRegToReg(MachineBasicBlock &MBB,
171                             MachineBasicBlock::iterator I,
172                             unsigned DestReg, unsigned SrcReg,
173                             const TargetRegisterClass *DestRC,
174                             const TargetRegisterClass *SrcRC) const;
175   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
176                                    MachineBasicBlock::iterator MBBI,
177                                    unsigned SrcReg, bool isKill, int FrameIndex,
178                                    const TargetRegisterClass *RC) const;
179
180   virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
181                               SmallVectorImpl<MachineOperand> &Addr,
182                               const TargetRegisterClass *RC,
183                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
184
185   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
186                                     MachineBasicBlock::iterator MBBI,
187                                     unsigned DestReg, int FrameIndex,
188                                     const TargetRegisterClass *RC) const;
189
190   virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
191                                SmallVectorImpl<MachineOperand> &Addr,
192                                const TargetRegisterClass *RC,
193                                SmallVectorImpl<MachineInstr*> &NewMIs) const;
194   virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
195                                          MachineBasicBlock::iterator MI,
196                                  const std::vector<CalleeSavedInfo> &CSI) const;
197   virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
198                                            MachineBasicBlock::iterator MI,
199                                  const std::vector<CalleeSavedInfo> &CSI) const;
200   
201   virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
202                                           MachineInstr* MI,
203                                           const SmallVectorImpl<unsigned> &Ops,
204                                           int FrameIndex) const;
205
206   virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
207                                           MachineInstr* MI,
208                                           const SmallVectorImpl<unsigned> &Ops,
209                                           MachineInstr* LoadMI) const {
210     return 0;
211   }
212
213   virtual bool canFoldMemoryOperand(const MachineInstr *MI,
214                                     const SmallVectorImpl<unsigned> &Ops) const;
215   
216   virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
217   virtual
218   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
219
220   // Predication support.
221   virtual bool isPredicated(const MachineInstr *MI) const;
222
223   ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
224     int PIdx = MI->findFirstPredOperandIdx();
225     return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() 
226                       : ARMCC::AL;
227   }
228
229   virtual
230   bool PredicateInstruction(MachineInstr *MI,
231                             const SmallVectorImpl<MachineOperand> &Pred) const;
232
233   virtual
234   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
235                          const SmallVectorImpl<MachineOperand> &Pred2) const;
236
237   virtual bool DefinesPredicate(MachineInstr *MI,
238                                 std::vector<MachineOperand> &Pred) const;
239     
240   /// GetInstSize - Returns the size of the specified MachineInstr.
241   ///
242   virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
243 };
244
245 }
246
247 #endif