blob: 6f1bf3831dd94c0bd7c2718fe30cda0c8e827858 [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,
77 FormMask = 0x1f << 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 Cheng86a926a2008-11-05 18:35:52 +000083 MulFrm1 = 2 << FormShift,
84 MulFrm2 = 3 << FormShift,
85 MulSMLAW = 4 << FormShift,
86 MulSMULW = 5 << FormShift,
87 MulSMLA = 6 << FormShift,
88 MulSMUL = 7 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000089
Raul Herbster85f45612007-08-30 23:34:14 +000090 // Branch instructions
Evan Cheng86a926a2008-11-05 18:35:52 +000091 Branch = 8 << FormShift,
92 BranchMisc = 9 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000093
Raul Herbster85f45612007-08-30 23:34:14 +000094 // Data Processing instructions
Evan Cheng86a926a2008-11-05 18:35:52 +000095 DPFrm = 10 << FormShift,
96 DPSoRegFrm = 11 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +000097
Raul Herbster85f45612007-08-30 23:34:14 +000098 // Load and Store
Evan Cheng86a926a2008-11-05 18:35:52 +000099 LdFrm = 12 << FormShift,
100 StFrm = 13 << FormShift,
101 LdMiscFrm = 14 << FormShift,
102 StMiscFrm = 15 << FormShift,
103 LdMulFrm = 16 << FormShift,
104 StMulFrm = 17 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000105
Raul Herbster85f45612007-08-30 23:34:14 +0000106 // Miscellaneous arithmetic instructions
Evan Cheng86a926a2008-11-05 18:35:52 +0000107 ArithMisc = 18 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000108
Raul Herbster85f45612007-08-30 23:34:14 +0000109 // Thumb format
Evan Cheng86a926a2008-11-05 18:35:52 +0000110 ThumbFrm = 19 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000111
Raul Herbster85f45612007-08-30 23:34:14 +0000112 // VFP format
Evan Cheng86a926a2008-11-05 18:35:52 +0000113 VPFFrm = 20 << FormShift,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000114
Evan Cheng86a926a2008-11-05 18:35:52 +0000115 //===------------------------------------------------------------------===//
Raul Herbster85f45612007-08-30 23:34:14 +0000116 // Field shifts - such shifts are used to set field while generating
117 // machine instructions.
Jim Grosbach1feed042008-11-03 18:38:31 +0000118 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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129 };
130}
131
Chris Lattnerd2fd6db2008-01-01 01:03:04 +0000132class ARMInstrInfo : public TargetInstrInfoImpl {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133 const ARMRegisterInfo RI;
134public:
Dan Gohman40bd38e2008-03-25 22:06:05 +0000135 explicit ARMInstrInfo(const ARMSubtarget &STI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136
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 ///
Dan Gohmanb41dfba2008-05-14 01:58:56 +0000141 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142
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
Evan Cheng7d73efc2008-03-31 20:40:39 +0000155 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
156 unsigned DestReg, const MachineInstr *Orig) const;
157
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
159 MachineBasicBlock::iterator &MBBI,
Owen Andersonc6959722008-07-02 23:41:07 +0000160 LiveVariables *LV) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161
162 // Branch analysis.
163 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
164 MachineBasicBlock *&FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000165 SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
167 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
168 MachineBasicBlock *FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000169 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson9fa72d92008-08-26 18:03:31 +0000170 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Owen Anderson8f2c8932007-12-31 06:32:00 +0000171 MachineBasicBlock::iterator I,
172 unsigned DestReg, unsigned SrcReg,
173 const TargetRegisterClass *DestRC,
174 const TargetRegisterClass *SrcRC) const;
Owen Anderson81875432008-01-01 21:11:32 +0000175 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;
Owen Anderson6690c7f2008-01-04 23:57:37 +0000194 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;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000200
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 int FrameIndex) const;
205
Evan Cheng4f2f3f62008-02-08 21:20:40 +0000206 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
207 MachineInstr* MI,
Dan Gohman46b948e2008-10-16 01:49:15 +0000208 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson9a184ef2008-01-07 01:35:02 +0000209 MachineInstr* LoadMI) const {
210 return 0;
211 }
212
Dan Gohman46b948e2008-10-16 01:49:15 +0000213 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
214 const SmallVectorImpl<unsigned> &Ops) const;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000215
Dan Gohman46b948e2008-10-16 01:49:15 +0000216 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
Owen Andersond131b5b2008-08-14 22:49:33 +0000217 virtual
218 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219
220 // Predication support.
221 virtual bool isPredicated(const MachineInstr *MI) const;
222
Jim Grosbach320c1482008-10-07 19:05:35 +0000223 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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 virtual
230 bool PredicateInstruction(MachineInstr *MI,
Owen Andersond131b5b2008-08-14 22:49:33 +0000231 const SmallVectorImpl<MachineOperand> &Pred) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232
233 virtual
Owen Andersond131b5b2008-08-14 22:49:33 +0000234 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
235 const SmallVectorImpl<MachineOperand> &Pred2) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236
237 virtual bool DefinesPredicate(MachineInstr *MI,
238 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000239
240 /// GetInstSize - Returns the size of the specified MachineInstr.
241 ///
242 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243};
244
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245}
246
247#endif