Remove opcode from instruction TS flags; add MOVCC support; fix addrmode3 encoding...
[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    = 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     //===------------------------------------------------------------------===//
63     // Misc flags.
64
65     // UnaryDP - Indicates this is a unary data processing instruction, i.e.
66     // it doesn't have a Rn operand.
67     UnaryDP       = 1 << 9,
68
69     //===------------------------------------------------------------------===//
70     // Instruction encoding formats.
71     //
72     FormShift   = 10,
73     FormMask    = 0xf << FormShift,
74
75     // Pseudo instructions
76     Pseudo      = 1 << FormShift,
77
78     // Multiply instructions
79     MulFrm      = 2 << FormShift,
80
81     // Branch instructions
82     Branch      = 3 << FormShift,
83     BranchMisc  = 4 << FormShift,
84
85     // Data Processing instructions
86     DPFrm       = 5 << FormShift,
87     DPSoRegFrm  = 6 << FormShift,
88
89     // Load and Store
90     LdFrm       = 7  << FormShift,
91     StFrm       = 8  << FormShift,
92     LdMiscFrm   = 9  << FormShift,
93     StMiscFrm   = 10 << FormShift,
94     LdMulFrm    = 11 << FormShift,
95     StMulFrm    = 12 << FormShift,
96
97     // Miscellaneous arithmetic instructions
98     ArithMisc   = 13 << FormShift,
99
100     // Thumb format
101     ThumbFrm    = 14 << FormShift,
102
103     // VFP format
104     VPFFrm      = 15 << FormShift,
105
106     //===------------------------------------------------------------------===//
107     // Field shifts - such shifts are used to set field while generating
108     // machine instructions.
109     RotImmShift  = 8,
110     RegRsShift   = 8,
111     RegRdLoShift = 12,
112     RegRdShift   = 12,
113     RegRdHiShift = 16,
114     RegRnShift   = 16,
115     L_BitShift   = 20,
116     S_BitShift   = 20,
117     U_BitShift   = 23,
118     IndexShift   = 24,
119     I_BitShift   = 25
120   };
121 }
122
123 class ARMInstrInfo : public TargetInstrInfoImpl {
124   const ARMRegisterInfo RI;
125 public:
126   explicit ARMInstrInfo(const ARMSubtarget &STI);
127
128   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
129   /// such, whenever a client has an instance of instruction info, it should
130   /// always be able to get register info as well (through this method).
131   ///
132   virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
133
134   /// getPointerRegClass - Return the register class to use to hold pointers.
135   /// This is used for addressing modes.
136   virtual const TargetRegisterClass *getPointerRegClass() const;
137
138   /// Return true if the instruction is a register to register move and
139   /// leave the source and dest operands in the passed parameters.
140   ///
141   virtual bool isMoveInstr(const MachineInstr &MI,
142                            unsigned &SrcReg, unsigned &DstReg) const;
143   virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
144   virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
145   
146   void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
147                      unsigned DestReg, const MachineInstr *Orig) const;
148
149   virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
150                                               MachineBasicBlock::iterator &MBBI,
151                                               LiveVariables *LV) const;
152
153   // Branch analysis.
154   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
155                              MachineBasicBlock *&FBB,
156                              SmallVectorImpl<MachineOperand> &Cond) const;
157   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
158   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
159                                 MachineBasicBlock *FBB,
160                             const SmallVectorImpl<MachineOperand> &Cond) const;
161   virtual bool copyRegToReg(MachineBasicBlock &MBB,
162                             MachineBasicBlock::iterator I,
163                             unsigned DestReg, unsigned SrcReg,
164                             const TargetRegisterClass *DestRC,
165                             const TargetRegisterClass *SrcRC) const;
166   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
167                                    MachineBasicBlock::iterator MBBI,
168                                    unsigned SrcReg, bool isKill, int FrameIndex,
169                                    const TargetRegisterClass *RC) const;
170
171   virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
172                               SmallVectorImpl<MachineOperand> &Addr,
173                               const TargetRegisterClass *RC,
174                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
175
176   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
177                                     MachineBasicBlock::iterator MBBI,
178                                     unsigned DestReg, int FrameIndex,
179                                     const TargetRegisterClass *RC) const;
180
181   virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
182                                SmallVectorImpl<MachineOperand> &Addr,
183                                const TargetRegisterClass *RC,
184                                SmallVectorImpl<MachineInstr*> &NewMIs) const;
185   virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
186                                          MachineBasicBlock::iterator MI,
187                                  const std::vector<CalleeSavedInfo> &CSI) const;
188   virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
189                                            MachineBasicBlock::iterator MI,
190                                  const std::vector<CalleeSavedInfo> &CSI) const;
191   
192   virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
193                                           MachineInstr* MI,
194                                           const SmallVectorImpl<unsigned> &Ops,
195                                           int FrameIndex) const;
196
197   virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
198                                           MachineInstr* MI,
199                                           const SmallVectorImpl<unsigned> &Ops,
200                                           MachineInstr* LoadMI) const {
201     return 0;
202   }
203
204   virtual bool canFoldMemoryOperand(const MachineInstr *MI,
205                                     const SmallVectorImpl<unsigned> &Ops) const;
206   
207   virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
208   virtual
209   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
210
211   // Predication support.
212   virtual bool isPredicated(const MachineInstr *MI) const;
213
214   ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
215     int PIdx = MI->findFirstPredOperandIdx();
216     return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() 
217                       : ARMCC::AL;
218   }
219
220   virtual
221   bool PredicateInstruction(MachineInstr *MI,
222                             const SmallVectorImpl<MachineOperand> &Pred) const;
223
224   virtual
225   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
226                          const SmallVectorImpl<MachineOperand> &Pred2) const;
227
228   virtual bool DefinesPredicate(MachineInstr *MI,
229                                 std::vector<MachineOperand> &Pred) const;
230     
231   /// GetInstSize - Returns the size of the specified MachineInstr.
232   ///
233   virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
234 };
235
236 }
237
238 #endif