blob: 0b27bfbcdc0292cd795ae2f4869888d104255074 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrInfo.h - ARM Instruction Information -------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006// 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
20namespace llvm {
21 class ARMSubtarget;
22
23/// ARMII - This namespace holds all of the target specific flags that
24/// instruction info tracks.
25///
26namespace ARMII {
27 enum {
28 //===------------------------------------------------------------------===//
29 // Instruction Flags.
30
31 //===------------------------------------------------------------------===//
32 // This three-bit field describes the addressing mode used. Zero is unused
33 // so that we can tell if we forgot to set a value.
34
35 AddrModeMask = 0xf,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000036 AddrModeNone = 0,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037 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 // Opcode
63 OpcodeShift = 9,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000064 OpcodeMask = 0xf << OpcodeShift,
65
66 // Format
67 FormShift = 13,
68 FormMask = 31 << FormShift,
69
Raul Herbster85f45612007-08-30 23:34:14 +000070 // Pseudo instructions
Evan Chenga7b3e7c2007-08-07 01:37:15 +000071 Pseudo = 1 << FormShift,
72
Raul Herbster85f45612007-08-30 23:34:14 +000073 // Multiply instructions
Evan Chenga7b3e7c2007-08-07 01:37:15 +000074 MulFrm = 2 << FormShift,
Raul Herbster85f45612007-08-30 23:34:14 +000075 MulSMLAW = 3 << FormShift,
76 MulSMULW = 4 << FormShift,
77 MulSMLA = 5 << FormShift,
78 MulSMUL = 6 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000079
Raul Herbster85f45612007-08-30 23:34:14 +000080 // Branch instructions
81 Branch = 7 << FormShift,
82 BranchMisc = 8 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000083
Raul Herbster85f45612007-08-30 23:34:14 +000084 // Data Processing instructions
85 DPRdIm = 9 << FormShift,
86 DPRdReg = 10 << FormShift,
87 DPRdSoReg = 11 << FormShift,
88 DPRdMisc = 12 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000089
Raul Herbster85f45612007-08-30 23:34:14 +000090 DPRnIm = 13 << FormShift,
91 DPRnReg = 14 << FormShift,
92 DPRnSoReg = 15 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000093
Raul Herbster85f45612007-08-30 23:34:14 +000094 DPRIm = 16 << FormShift,
95 DPRReg = 17 << FormShift,
96 DPRSoReg = 18 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000097
Raul Herbster85f45612007-08-30 23:34:14 +000098 DPRImS = 19 << FormShift,
99 DPRRegS = 20 << FormShift,
100 DPRSoRegS = 21 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000101
Raul Herbster85f45612007-08-30 23:34:14 +0000102 // Load and Store
103 LdFrm = 22 << FormShift,
104 StFrm = 23 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000105
Raul Herbster85f45612007-08-30 23:34:14 +0000106 // Miscellaneous arithmetic instructions
107 ArithMisc = 24 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000108
Raul Herbster85f45612007-08-30 23:34:14 +0000109 // Thumb format
110 ThumbFrm = 25 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000111
Raul Herbster85f45612007-08-30 23:34:14 +0000112 // VFP format
113 VPFFrm = 26 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000114
Raul Herbster85f45612007-08-30 23:34:14 +0000115 // Field shifts - such shifts are used to set field while generating
116 // machine instructions.
Evan Cheng00dc31b2008-09-12 22:01:15 +0000117 RotImmShift = 8,
Raul Herbster85f45612007-08-30 23:34:14 +0000118 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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000126 };
127}
128
Chris Lattnerd2fd6db2008-01-01 01:03:04 +0000129class ARMInstrInfo : public TargetInstrInfoImpl {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000130 const ARMRegisterInfo RI;
131public:
Dan Gohman40bd38e2008-03-25 22:06:05 +0000132 explicit ARMInstrInfo(const ARMSubtarget &STI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133
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 ///
Dan Gohmanb41dfba2008-05-14 01:58:56 +0000138 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139
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
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;
149 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
150 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
151
Evan Cheng7d73efc2008-03-31 20:40:39 +0000152 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
153 unsigned DestReg, const MachineInstr *Orig) const;
154
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
156 MachineBasicBlock::iterator &MBBI,
Owen Andersonc6959722008-07-02 23:41:07 +0000157 LiveVariables *LV) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158
159 // Branch analysis.
160 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
161 MachineBasicBlock *&FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000162 SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
164 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
165 MachineBasicBlock *FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000166 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson9fa72d92008-08-26 18:03:31 +0000167 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Owen Anderson8f2c8932007-12-31 06:32:00 +0000168 MachineBasicBlock::iterator I,
169 unsigned DestReg, unsigned SrcReg,
170 const TargetRegisterClass *DestRC,
171 const TargetRegisterClass *SrcRC) const;
Owen Anderson81875432008-01-01 21:11:32 +0000172 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
173 MachineBasicBlock::iterator MBBI,
174 unsigned SrcReg, bool isKill, int FrameIndex,
175 const TargetRegisterClass *RC) const;
176
177 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
178 SmallVectorImpl<MachineOperand> &Addr,
179 const TargetRegisterClass *RC,
180 SmallVectorImpl<MachineInstr*> &NewMIs) const;
181
182 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
183 MachineBasicBlock::iterator MBBI,
184 unsigned DestReg, int FrameIndex,
185 const TargetRegisterClass *RC) const;
186
187 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
188 SmallVectorImpl<MachineOperand> &Addr,
189 const TargetRegisterClass *RC,
190 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Anderson6690c7f2008-01-04 23:57:37 +0000191 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
192 MachineBasicBlock::iterator MI,
193 const std::vector<CalleeSavedInfo> &CSI) const;
194 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
195 MachineBasicBlock::iterator MI,
196 const std::vector<CalleeSavedInfo> &CSI) const;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000197
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000198 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
199 MachineInstr* MI,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000200 SmallVectorImpl<unsigned> &Ops,
201 int FrameIndex) const;
202
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000203 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
204 MachineInstr* MI,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000205 SmallVectorImpl<unsigned> &Ops,
206 MachineInstr* LoadMI) const {
207 return 0;
208 }
209
210 virtual bool canFoldMemoryOperand(MachineInstr *MI,
211 SmallVectorImpl<unsigned> &Ops) const;
212
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213 virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
Owen Andersond131b5b2008-08-14 22:49:33 +0000214 virtual
215 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216
217 // Predication support.
218 virtual bool isPredicated(const MachineInstr *MI) const;
219
220 virtual
221 bool PredicateInstruction(MachineInstr *MI,
Owen Andersond131b5b2008-08-14 22:49:33 +0000222 const SmallVectorImpl<MachineOperand> &Pred) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000223
224 virtual
Owen Andersond131b5b2008-08-14 22:49:33 +0000225 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
226 const SmallVectorImpl<MachineOperand> &Pred2) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227
228 virtual bool DefinesPredicate(MachineInstr *MI,
229 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000230
231 /// GetInstSize - Returns the size of the specified MachineInstr.
232 ///
233 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234};
235
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236}
237
238#endif