blob: c2eb54c8b62c0b05dae7018841a7deb7f9f9bf7a [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMInstrInfo.h - ARM Instruction Information -------------*- C++ -*-===//
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Rafael Espindola7bc59bc2006-05-14 22:18:28 +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 Grosbachcbc47b82008-10-07 21:01:51 +000019#include "ARM.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020
21namespace llvm {
Evan Chenga8e29892007-01-19 07:51:42 +000022 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 Grosbach0a4b9dc2008-11-03 18:38:31 +000033 // This four-bit field describes the addressing mode used.
Evan Chenga8e29892007-01-19 07:51:42 +000034
35 AddrModeMask = 0xf,
Evan Cheng0ff94f72007-08-07 01:37:15 +000036 AddrModeNone = 0,
Evan Chenga8e29892007-01-19 07:51:42 +000037 AddrMode1 = 1,
38 AddrMode2 = 2,
39 AddrMode3 = 3,
40 AddrMode4 = 4,
41 AddrMode5 = 5,
Evan Chengedda31c2008-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
Evan Chenga8e29892007-01-19 07:51:42 +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 Chengedda31c2008-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 Chengd87293c2008-11-06 08:47:38 +000067 UnaryDP = 1 << 9,
Evan Chengedda31c2008-11-05 18:35:52 +000068
69 //===------------------------------------------------------------------===//
70 // Instruction encoding formats.
71 //
Evan Chengd87293c2008-11-06 08:47:38 +000072 FormShift = 10,
Evan Chengeb4f52e2008-11-06 03:35:07 +000073 FormMask = 0xf << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000074
Raul Herbster8c132632007-08-30 23:34:14 +000075 // Pseudo instructions
Evan Cheng0ff94f72007-08-07 01:37:15 +000076 Pseudo = 1 << FormShift,
77
Raul Herbster8c132632007-08-30 23:34:14 +000078 // Multiply instructions
Evan Chengfbc9d412008-11-06 01:21:28 +000079 MulFrm = 2 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000080
Raul Herbster8c132632007-08-30 23:34:14 +000081 // Branch instructions
Evan Cheng12c3a532008-11-06 17:48:05 +000082 BrFrm = 3 << FormShift,
83 BrMiscFrm = 4 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000084
Raul Herbster8c132632007-08-30 23:34:14 +000085 // Data Processing instructions
Evan Chengeb4f52e2008-11-06 03:35:07 +000086 DPFrm = 5 << FormShift,
87 DPSoRegFrm = 6 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000088
Raul Herbster8c132632007-08-30 23:34:14 +000089 // Load and Store
Evan Chengeb4f52e2008-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 Cheng0ff94f72007-08-07 01:37:15 +000096
Raul Herbster8c132632007-08-30 23:34:14 +000097 // Miscellaneous arithmetic instructions
Evan Chengeb4f52e2008-11-06 03:35:07 +000098 ArithMisc = 13 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000099
Raul Herbster8c132632007-08-30 23:34:14 +0000100 // Thumb format
Evan Chengeb4f52e2008-11-06 03:35:07 +0000101 ThumbFrm = 14 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000102
Raul Herbster8c132632007-08-30 23:34:14 +0000103 // VFP format
Evan Chengeb4f52e2008-11-06 03:35:07 +0000104 VPFFrm = 15 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000105
Evan Chengedda31c2008-11-05 18:35:52 +0000106 //===------------------------------------------------------------------===//
Raul Herbster8c132632007-08-30 23:34:14 +0000107 // Field shifts - such shifts are used to set field while generating
108 // machine instructions.
Jim Grosbach0a4b9dc2008-11-03 18:38:31 +0000109 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
Evan Chenga8e29892007-01-19 07:51:42 +0000120 };
121}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000122
Chris Lattner64105522008-01-01 01:03:04 +0000123class ARMInstrInfo : public TargetInstrInfoImpl {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000124 const ARMRegisterInfo RI;
125public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000126 explicit ARMInstrInfo(const ARMSubtarget &STI);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000127
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 ///
Dan Gohmanc9f5f3f2008-05-14 01:58:56 +0000132 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000133
Rafael Espindola46adf812006-08-08 20:35:03 +0000134 /// getPointerRegClass - Return the register class to use to hold pointers.
135 /// This is used for addressing modes.
136 virtual const TargetRegisterClass *getPointerRegClass() const;
137
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000138 /// 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;
Evan Chenga8e29892007-01-19 07:51:42 +0000143 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
144 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
145
Evan Chengca1267c2008-03-31 20:40:39 +0000146 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
147 unsigned DestReg, const MachineInstr *Orig) const;
148
Evan Chenga8e29892007-01-19 07:51:42 +0000149 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
150 MachineBasicBlock::iterator &MBBI,
Owen Andersonf660c172008-07-02 23:41:07 +0000151 LiveVariables *LV) const;
Chris Lattner578e64a2006-10-24 16:47:57 +0000152
Evan Chenga8e29892007-01-19 07:51:42 +0000153 // Branch analysis.
154 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
155 MachineBasicBlock *&FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000156 SmallVectorImpl<MachineOperand> &Cond) const;
Evan Cheng6ae36262007-05-18 00:18:17 +0000157 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
158 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
159 MachineBasicBlock *FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000160 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson940f83e2008-08-26 18:03:31 +0000161 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Owen Andersond10fd972007-12-31 06:32:00 +0000162 MachineBasicBlock::iterator I,
163 unsigned DestReg, unsigned SrcReg,
164 const TargetRegisterClass *DestRC,
165 const TargetRegisterClass *SrcRC) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000166 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;
Owen Andersond94b6a12008-01-04 23:57:37 +0000185 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;
Owen Anderson43dbe052008-01-07 01:35:02 +0000191
Evan Cheng5fd79d02008-02-08 21:20:40 +0000192 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
193 MachineInstr* MI,
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000194 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson43dbe052008-01-07 01:35:02 +0000195 int FrameIndex) const;
196
Evan Cheng5fd79d02008-02-08 21:20:40 +0000197 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
198 MachineInstr* MI,
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000199 const SmallVectorImpl<unsigned> &Ops,
Owen Anderson43dbe052008-01-07 01:35:02 +0000200 MachineInstr* LoadMI) const {
201 return 0;
202 }
203
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000204 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
205 const SmallVectorImpl<unsigned> &Ops) const;
Owen Anderson43dbe052008-01-07 01:35:02 +0000206
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000207 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
Owen Anderson44eb65c2008-08-14 22:49:33 +0000208 virtual
209 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Evan Cheng93072922007-05-16 02:01:49 +0000210
211 // Predication support.
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000212 virtual bool isPredicated(const MachineInstr *MI) const;
Evan Cheng69d55562007-05-23 07:22:05 +0000213
Jim Grosbach33412622008-10-07 19:05:35 +0000214 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
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000220 virtual
221 bool PredicateInstruction(MachineInstr *MI,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000222 const SmallVectorImpl<MachineOperand> &Pred) const;
Evan Cheng69d55562007-05-23 07:22:05 +0000223
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000224 virtual
Owen Anderson44eb65c2008-08-14 22:49:33 +0000225 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
226 const SmallVectorImpl<MachineOperand> &Pred2) const;
Evan Cheng13ab0202007-07-10 18:08:01 +0000227
228 virtual bool DefinesPredicate(MachineInstr *MI,
229 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffray52e724a2008-04-16 20:10:13 +0000230
231 /// GetInstSize - Returns the size of the specified MachineInstr.
232 ///
233 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000234};
235
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000236}
237
238#endif