blob: f3ca27f7210dbd90d7cad22ab123562abb0486cc [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
62 // Opcode
63 OpcodeShift = 9,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000064 OpcodeMask = 0xf << OpcodeShift,
Evan Cheng86a926a2008-11-05 18:35:52 +000065
66 //===------------------------------------------------------------------===//
67 // Misc flags.
68
69 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
70 // it doesn't have a Rn operand.
71 UnaryDP = 1 << 13,
72
73 //===------------------------------------------------------------------===//
74 // Instruction encoding formats.
75 //
76 FormShift = 14,
Evan Cheng38396be2008-11-06 03:35:07 +000077 FormMask = 0xf << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000078
Raul Herbster85f45612007-08-30 23:34:14 +000079 // Pseudo instructions
Evan Chenga7b3e7c2007-08-07 01:37:15 +000080 Pseudo = 1 << FormShift,
81
Raul Herbster85f45612007-08-30 23:34:14 +000082 // Multiply instructions
Evan Chengee80fb72008-11-06 01:21:28 +000083 MulFrm = 2 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000084
Raul Herbster85f45612007-08-30 23:34:14 +000085 // Branch instructions
Evan Cheng38396be2008-11-06 03:35:07 +000086 Branch = 3 << FormShift,
87 BranchMisc = 4 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000088
Raul Herbster85f45612007-08-30 23:34:14 +000089 // Data Processing instructions
Evan Cheng38396be2008-11-06 03:35:07 +000090 DPFrm = 5 << FormShift,
91 DPSoRegFrm = 6 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000092
Raul Herbster85f45612007-08-30 23:34:14 +000093 // Load and Store
Evan Cheng38396be2008-11-06 03:35:07 +000094 LdFrm = 7 << FormShift,
95 StFrm = 8 << FormShift,
96 LdMiscFrm = 9 << FormShift,
97 StMiscFrm = 10 << FormShift,
98 LdMulFrm = 11 << FormShift,
99 StMulFrm = 12 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000100
Raul Herbster85f45612007-08-30 23:34:14 +0000101 // Miscellaneous arithmetic instructions
Evan Cheng38396be2008-11-06 03:35:07 +0000102 ArithMisc = 13 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000103
Raul Herbster85f45612007-08-30 23:34:14 +0000104 // Thumb format
Evan Cheng38396be2008-11-06 03:35:07 +0000105 ThumbFrm = 14 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000106
Raul Herbster85f45612007-08-30 23:34:14 +0000107 // VFP format
Evan Cheng38396be2008-11-06 03:35:07 +0000108 VPFFrm = 15 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000109
Evan Cheng86a926a2008-11-05 18:35:52 +0000110 //===------------------------------------------------------------------===//
Raul Herbster85f45612007-08-30 23:34:14 +0000111 // Field shifts - such shifts are used to set field while generating
112 // machine instructions.
Jim Grosbach1feed042008-11-03 18:38:31 +0000113 RotImmShift = 8,
114 RegRsShift = 8,
115 RegRdLoShift = 12,
116 RegRdShift = 12,
117 RegRdHiShift = 16,
118 RegRnShift = 16,
119 L_BitShift = 20,
120 S_BitShift = 20,
121 U_BitShift = 23,
122 IndexShift = 24,
123 I_BitShift = 25
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 };
125}
126
Chris Lattnerd2fd6db2008-01-01 01:03:04 +0000127class ARMInstrInfo : public TargetInstrInfoImpl {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000128 const ARMRegisterInfo RI;
129public:
Dan Gohman40bd38e2008-03-25 22:06:05 +0000130 explicit ARMInstrInfo(const ARMSubtarget &STI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000131
132 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
133 /// such, whenever a client has an instance of instruction info, it should
134 /// always be able to get register info as well (through this method).
135 ///
Dan Gohmanb41dfba2008-05-14 01:58:56 +0000136 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137
138 /// getPointerRegClass - Return the register class to use to hold pointers.
139 /// This is used for addressing modes.
140 virtual const TargetRegisterClass *getPointerRegClass() const;
141
142 /// Return true if the instruction is a register to register move and
143 /// leave the source and dest operands in the passed parameters.
144 ///
145 virtual bool isMoveInstr(const MachineInstr &MI,
146 unsigned &SrcReg, unsigned &DstReg) const;
147 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
148 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
149
Evan Cheng7d73efc2008-03-31 20:40:39 +0000150 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
151 unsigned DestReg, const MachineInstr *Orig) const;
152
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
154 MachineBasicBlock::iterator &MBBI,
Owen Andersonc6959722008-07-02 23:41:07 +0000155 LiveVariables *LV) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156
157 // Branch analysis.
158 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
159 MachineBasicBlock *&FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000160 SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
162 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
163 MachineBasicBlock *FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000164 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson9fa72d92008-08-26 18:03:31 +0000165 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Owen Anderson8f2c8932007-12-31 06:32:00 +0000166 MachineBasicBlock::iterator I,
167 unsigned DestReg, unsigned SrcReg,
168 const TargetRegisterClass *DestRC,
169 const TargetRegisterClass *SrcRC) const;
Owen Anderson81875432008-01-01 21:11:32 +0000170 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
171 MachineBasicBlock::iterator MBBI,
172 unsigned SrcReg, bool isKill, int FrameIndex,
173 const TargetRegisterClass *RC) const;
174
175 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
176 SmallVectorImpl<MachineOperand> &Addr,
177 const TargetRegisterClass *RC,
178 SmallVectorImpl<MachineInstr*> &NewMIs) const;
179
180 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
181 MachineBasicBlock::iterator MBBI,
182 unsigned DestReg, int FrameIndex,
183 const TargetRegisterClass *RC) const;
184
185 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
186 SmallVectorImpl<MachineOperand> &Addr,
187 const TargetRegisterClass *RC,
188 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Anderson6690c7f2008-01-04 23:57:37 +0000189 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
190 MachineBasicBlock::iterator MI,
191 const std::vector<CalleeSavedInfo> &CSI) const;
192 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
193 MachineBasicBlock::iterator MI,
194 const std::vector<CalleeSavedInfo> &CSI) const;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000195
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000196 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
197 MachineInstr* MI,
Dan Gohman46b948e2008-10-16 01:49:15 +0000198 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000199 int FrameIndex) const;
200
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000201 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
202 MachineInstr* MI,
Dan Gohman46b948e2008-10-16 01:49:15 +0000203 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000204 MachineInstr* LoadMI) const {
205 return 0;
206 }
207
Dan Gohman46b948e2008-10-16 01:49:15 +0000208 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
209 const SmallVectorImpl<unsigned> &Ops) const;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000210
Dan Gohman46b948e2008-10-16 01:49:15 +0000211 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
Owen Andersond131b5b2008-08-14 22:49:33 +0000212 virtual
213 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214
215 // Predication support.
216 virtual bool isPredicated(const MachineInstr *MI) const;
217
Jim Grosbach320c1482008-10-07 19:05:35 +0000218 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
219 int PIdx = MI->findFirstPredOperandIdx();
220 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
221 : ARMCC::AL;
222 }
223
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 virtual
225 bool PredicateInstruction(MachineInstr *MI,
Owen Andersond131b5b2008-08-14 22:49:33 +0000226 const SmallVectorImpl<MachineOperand> &Pred) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227
228 virtual
Owen Andersond131b5b2008-08-14 22:49:33 +0000229 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
230 const SmallVectorImpl<MachineOperand> &Pred2) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231
232 virtual bool DefinesPredicate(MachineInstr *MI,
233 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000234
235 /// GetInstSize - Returns the size of the specified MachineInstr.
236 ///
237 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238};
239
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240}
241
242#endif