blob: 0a8432ce985656eac81aa50f2ea3e1a07932fd61 [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"
Jim Grosbach94a552c2008-10-07 21:01:51 +000019#include "ARM.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020
21namespace llvm {
22 class ARMSubtarget;
23
24/// ARMII - This namespace holds all of the target specific flags that
25/// instruction info tracks.
26///
27namespace ARMII {
28 enum {
29 //===------------------------------------------------------------------===//
30 // Instruction Flags.
31
32 //===------------------------------------------------------------------===//
Jim Grosbach1feed042008-11-03 18:38:31 +000033 // This four-bit field describes the addressing mode used.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034
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,
Evan Cheng86a926a2008-11-05 18:35:52 +000042 AddrModeT1 = 6,
43 AddrModeT2 = 7,
44 AddrModeT4 = 8,
45 AddrModeTs = 9, // i8 * 4 for pc and sp relative data
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046
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
Evan Cheng86a926a2008-11-05 18:35:52 +000062 //===------------------------------------------------------------------===//
63 // Misc flags.
64
65 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
66 // it doesn't have a Rn operand.
Evan Chengbe998242008-11-06 08:47:38 +000067 UnaryDP = 1 << 9,
Evan Cheng86a926a2008-11-05 18:35:52 +000068
69 //===------------------------------------------------------------------===//
70 // Instruction encoding formats.
71 //
Evan Chengbe998242008-11-06 08:47:38 +000072 FormShift = 10,
Evan Cheng38396be2008-11-06 03:35:07 +000073 FormMask = 0xf << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000074
Raul Herbster85f45612007-08-30 23:34:14 +000075 // Pseudo instructions
Evan Chenga7b3e7c2007-08-07 01:37:15 +000076 Pseudo = 1 << FormShift,
77
Raul Herbster85f45612007-08-30 23:34:14 +000078 // Multiply instructions
Evan Chengee80fb72008-11-06 01:21:28 +000079 MulFrm = 2 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000080
Raul Herbster85f45612007-08-30 23:34:14 +000081 // Branch instructions
Evan Chengf8e8b622008-11-06 17:48:05 +000082 BrFrm = 3 << FormShift,
83 BrMiscFrm = 4 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000084
Raul Herbster85f45612007-08-30 23:34:14 +000085 // Data Processing instructions
Evan Cheng38396be2008-11-06 03:35:07 +000086 DPFrm = 5 << FormShift,
87 DPSoRegFrm = 6 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000088
Raul Herbster85f45612007-08-30 23:34:14 +000089 // Load and Store
Evan Cheng38396be2008-11-06 03:35:07 +000090 LdFrm = 7 << FormShift,
91 StFrm = 8 << FormShift,
92 LdMiscFrm = 9 << FormShift,
93 StMiscFrm = 10 << FormShift,
94 LdMulFrm = 11 << FormShift,
95 StMulFrm = 12 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000096
Raul Herbster85f45612007-08-30 23:34:14 +000097 // Miscellaneous arithmetic instructions
Evan Cheng37afa432008-11-06 22:15:19 +000098 ArithMiscFrm= 13 << FormShift,
99
100 // Extend instructions
101 ExtFrm = 14 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000102
Raul Herbster85f45612007-08-30 23:34:14 +0000103 // Thumb format
Evan Cheng37afa432008-11-06 22:15:19 +0000104 ThumbFrm = 15 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000105
Raul Herbster85f45612007-08-30 23:34:14 +0000106 // VFP format
Evan Cheng37afa432008-11-06 22:15:19 +0000107 VPFFrm = 16 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000108
Evan Cheng86a926a2008-11-05 18:35:52 +0000109 //===------------------------------------------------------------------===//
Raul Herbster85f45612007-08-30 23:34:14 +0000110 // Field shifts - such shifts are used to set field while generating
111 // machine instructions.
Evan Chengc2121a22008-11-07 01:41:35 +0000112 ShiftShift = 7,
Evan Cheng37afa432008-11-06 22:15:19 +0000113 SoRotImmShift = 8,
114 RegRsShift = 8,
115 ExtRotImmShift = 10,
116 RegRdLoShift = 12,
117 RegRdShift = 12,
118 RegRdHiShift = 16,
119 RegRnShift = 16,
120 S_BitShift = 20,
121 W_BitShift = 21,
122 AM3_I_BitShift = 22,
123 U_BitShift = 23,
124 P_BitShift = 24,
125 I_BitShift = 25,
126 CondShift = 28
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 };
128}
129
Chris Lattnerd2fd6db2008-01-01 01:03:04 +0000130class ARMInstrInfo : public TargetInstrInfoImpl {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000131 const ARMRegisterInfo RI;
132public:
Dan Gohman40bd38e2008-03-25 22:06:05 +0000133 explicit ARMInstrInfo(const ARMSubtarget &STI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000134
135 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
136 /// such, whenever a client has an instance of instruction info, it should
137 /// always be able to get register info as well (through this method).
138 ///
Dan Gohmanb41dfba2008-05-14 01:58:56 +0000139 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140
141 /// getPointerRegClass - Return the register class to use to hold pointers.
142 /// This is used for addressing modes.
143 virtual const TargetRegisterClass *getPointerRegClass() const;
144
145 /// Return true if the instruction is a register to register move and
146 /// leave the source and dest operands in the passed parameters.
147 ///
148 virtual bool isMoveInstr(const MachineInstr &MI,
149 unsigned &SrcReg, unsigned &DstReg) const;
150 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
151 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
152
Evan Cheng7d73efc2008-03-31 20:40:39 +0000153 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
154 unsigned DestReg, const MachineInstr *Orig) const;
155
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
157 MachineBasicBlock::iterator &MBBI,
Owen Andersonc6959722008-07-02 23:41:07 +0000158 LiveVariables *LV) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159
160 // Branch analysis.
161 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
162 MachineBasicBlock *&FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000163 SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
165 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
166 MachineBasicBlock *FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000167 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson9fa72d92008-08-26 18:03:31 +0000168 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Owen Anderson8f2c8932007-12-31 06:32:00 +0000169 MachineBasicBlock::iterator I,
170 unsigned DestReg, unsigned SrcReg,
171 const TargetRegisterClass *DestRC,
172 const TargetRegisterClass *SrcRC) const;
Owen Anderson81875432008-01-01 21:11:32 +0000173 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
174 MachineBasicBlock::iterator MBBI,
175 unsigned SrcReg, bool isKill, int FrameIndex,
176 const TargetRegisterClass *RC) const;
177
178 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
179 SmallVectorImpl<MachineOperand> &Addr,
180 const TargetRegisterClass *RC,
181 SmallVectorImpl<MachineInstr*> &NewMIs) const;
182
183 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
184 MachineBasicBlock::iterator MBBI,
185 unsigned DestReg, int FrameIndex,
186 const TargetRegisterClass *RC) const;
187
188 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
189 SmallVectorImpl<MachineOperand> &Addr,
190 const TargetRegisterClass *RC,
191 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Anderson6690c7f2008-01-04 23:57:37 +0000192 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
193 MachineBasicBlock::iterator MI,
194 const std::vector<CalleeSavedInfo> &CSI) const;
195 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
196 MachineBasicBlock::iterator MI,
197 const std::vector<CalleeSavedInfo> &CSI) const;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000198
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000199 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
200 MachineInstr* MI,
Dan Gohman46b948e2008-10-16 01:49:15 +0000201 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000202 int FrameIndex) const;
203
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000204 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
205 MachineInstr* MI,
Dan Gohman46b948e2008-10-16 01:49:15 +0000206 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000207 MachineInstr* LoadMI) const {
208 return 0;
209 }
210
Dan Gohman46b948e2008-10-16 01:49:15 +0000211 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
212 const SmallVectorImpl<unsigned> &Ops) const;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000213
Dan Gohman46b948e2008-10-16 01:49:15 +0000214 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
Owen Andersond131b5b2008-08-14 22:49:33 +0000215 virtual
216 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
218 // Predication support.
219 virtual bool isPredicated(const MachineInstr *MI) const;
220
Jim Grosbach320c1482008-10-07 19:05:35 +0000221 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
222 int PIdx = MI->findFirstPredOperandIdx();
223 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
224 : ARMCC::AL;
225 }
226
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227 virtual
228 bool PredicateInstruction(MachineInstr *MI,
Owen Andersond131b5b2008-08-14 22:49:33 +0000229 const SmallVectorImpl<MachineOperand> &Pred) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
231 virtual
Owen Andersond131b5b2008-08-14 22:49:33 +0000232 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
233 const SmallVectorImpl<MachineOperand> &Pred2) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
235 virtual bool DefinesPredicate(MachineInstr *MI,
236 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000237
238 /// GetInstSize - Returns the size of the specified MachineInstr.
239 ///
240 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241};
242
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243}
244
245#endif