blob: be95d56a69ac0f5671e7d535e1f411c5460142f1 [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"
19
20namespace llvm {
Evan Chenga8e29892007-01-19 07:51:42 +000021 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 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,
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 Cheng0ff94f72007-08-07 01:37:15 +000064 OpcodeMask = 0xf << OpcodeShift,
65
66 // Format
67 FormShift = 13,
68 FormMask = 31 << FormShift,
69
Raul Herbster8c132632007-08-30 23:34:14 +000070 // Pseudo instructions
Evan Cheng0ff94f72007-08-07 01:37:15 +000071 Pseudo = 1 << FormShift,
72
Raul Herbster8c132632007-08-30 23:34:14 +000073 // Multiply instructions
Evan Cheng0ff94f72007-08-07 01:37:15 +000074 MulFrm = 2 << FormShift,
Raul Herbster8c132632007-08-30 23:34:14 +000075 MulSMLAW = 3 << FormShift,
76 MulSMULW = 4 << FormShift,
77 MulSMLA = 5 << FormShift,
78 MulSMUL = 6 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000079
Raul Herbster8c132632007-08-30 23:34:14 +000080 // Branch instructions
81 Branch = 7 << FormShift,
82 BranchMisc = 8 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000083
Raul Herbster8c132632007-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 Cheng0ff94f72007-08-07 01:37:15 +000089
Raul Herbster8c132632007-08-30 23:34:14 +000090 DPRnIm = 13 << FormShift,
91 DPRnReg = 14 << FormShift,
92 DPRnSoReg = 15 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000093
Raul Herbster8c132632007-08-30 23:34:14 +000094 DPRIm = 16 << FormShift,
95 DPRReg = 17 << FormShift,
96 DPRSoReg = 18 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000097
Raul Herbster8c132632007-08-30 23:34:14 +000098 DPRImS = 19 << FormShift,
99 DPRRegS = 20 << FormShift,
100 DPRSoRegS = 21 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000101
Raul Herbster8c132632007-08-30 23:34:14 +0000102 // Load and Store
103 LdFrm = 22 << FormShift,
104 StFrm = 23 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000105
Raul Herbster8c132632007-08-30 23:34:14 +0000106 // Miscellaneous arithmetic instructions
107 ArithMisc = 24 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000108
Raul Herbster8c132632007-08-30 23:34:14 +0000109 // Thumb format
110 ThumbFrm = 25 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000111
Raul Herbster8c132632007-08-30 23:34:14 +0000112 // VFP format
113 VPFFrm = 26 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000114
Raul Herbster8c132632007-08-30 23:34:14 +0000115 // Field shifts - such shifts are used to set field while generating
116 // machine instructions.
117 RegRsShift = 8,
118 RegRdShift = 12,
119 RegRnShift = 16,
120 L_BitShift = 20,
121 S_BitShift = 20,
122 U_BitShift = 23,
123 IndexShift = 24,
124 I_BitShift = 25
Evan Chenga8e29892007-01-19 07:51:42 +0000125 };
126}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000127
Chris Lattner64105522008-01-01 01:03:04 +0000128class ARMInstrInfo : public TargetInstrInfoImpl {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000129 const ARMRegisterInfo RI;
130public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000131 explicit ARMInstrInfo(const ARMSubtarget &STI);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000132
133 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
134 /// such, whenever a client has an instance of instruction info, it should
135 /// always be able to get register info as well (through this method).
136 ///
Dan Gohmanc9f5f3f2008-05-14 01:58:56 +0000137 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000138
Rafael Espindola46adf812006-08-08 20:35:03 +0000139 /// getPointerRegClass - Return the register class to use to hold pointers.
140 /// This is used for addressing modes.
141 virtual const TargetRegisterClass *getPointerRegClass() const;
142
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000143 /// Return true if the instruction is a register to register move and
144 /// leave the source and dest operands in the passed parameters.
145 ///
146 virtual bool isMoveInstr(const MachineInstr &MI,
147 unsigned &SrcReg, unsigned &DstReg) const;
Evan Chenga8e29892007-01-19 07:51:42 +0000148 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
149 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
150
Evan Chengca1267c2008-03-31 20:40:39 +0000151 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
152 unsigned DestReg, const MachineInstr *Orig) const;
153
Evan Chenga8e29892007-01-19 07:51:42 +0000154 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
155 MachineBasicBlock::iterator &MBBI,
156 LiveVariables &LV) const;
Chris Lattner578e64a2006-10-24 16:47:57 +0000157
Evan Chenga8e29892007-01-19 07:51:42 +0000158 // Branch analysis.
159 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
160 MachineBasicBlock *&FBB,
161 std::vector<MachineOperand> &Cond) const;
Evan Cheng6ae36262007-05-18 00:18:17 +0000162 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
163 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
164 MachineBasicBlock *FBB,
165 const std::vector<MachineOperand> &Cond) const;
Owen Andersond10fd972007-12-31 06:32:00 +0000166 virtual void copyRegToReg(MachineBasicBlock &MBB,
167 MachineBasicBlock::iterator I,
168 unsigned DestReg, unsigned SrcReg,
169 const TargetRegisterClass *DestRC,
170 const TargetRegisterClass *SrcRC) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000171 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
172 MachineBasicBlock::iterator MBBI,
173 unsigned SrcReg, bool isKill, int FrameIndex,
174 const TargetRegisterClass *RC) const;
175
176 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
177 SmallVectorImpl<MachineOperand> &Addr,
178 const TargetRegisterClass *RC,
179 SmallVectorImpl<MachineInstr*> &NewMIs) const;
180
181 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
182 MachineBasicBlock::iterator MBBI,
183 unsigned DestReg, int FrameIndex,
184 const TargetRegisterClass *RC) const;
185
186 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
187 SmallVectorImpl<MachineOperand> &Addr,
188 const TargetRegisterClass *RC,
189 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Andersond94b6a12008-01-04 23:57:37 +0000190 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
191 MachineBasicBlock::iterator MI,
192 const std::vector<CalleeSavedInfo> &CSI) const;
193 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
194 MachineBasicBlock::iterator MI,
195 const std::vector<CalleeSavedInfo> &CSI) const;
Owen Anderson43dbe052008-01-07 01:35:02 +0000196
Evan Cheng5fd79d02008-02-08 21:20:40 +0000197 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
198 MachineInstr* MI,
Owen Anderson43dbe052008-01-07 01:35:02 +0000199 SmallVectorImpl<unsigned> &Ops,
200 int FrameIndex) const;
201
Evan Cheng5fd79d02008-02-08 21:20:40 +0000202 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
203 MachineInstr* MI,
Owen Anderson43dbe052008-01-07 01:35:02 +0000204 SmallVectorImpl<unsigned> &Ops,
205 MachineInstr* LoadMI) const {
206 return 0;
207 }
208
209 virtual bool canFoldMemoryOperand(MachineInstr *MI,
210 SmallVectorImpl<unsigned> &Ops) const;
211
Evan Chenga8e29892007-01-19 07:51:42 +0000212 virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
213 virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const;
Evan Cheng93072922007-05-16 02:01:49 +0000214
215 // Predication support.
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000216 virtual bool isPredicated(const MachineInstr *MI) const;
Evan Cheng69d55562007-05-23 07:22:05 +0000217
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000218 virtual
219 bool PredicateInstruction(MachineInstr *MI,
220 const std::vector<MachineOperand> &Pred) const;
Evan Cheng69d55562007-05-23 07:22:05 +0000221
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000222 virtual
223 bool SubsumesPredicate(const std::vector<MachineOperand> &Pred1,
Christopher Lamba4c79102007-10-18 19:29:45 +0000224 const std::vector<MachineOperand> &Pred2) const;
Evan Cheng13ab0202007-07-10 18:08:01 +0000225
226 virtual bool DefinesPredicate(MachineInstr *MI,
227 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffray52e724a2008-04-16 20:10:13 +0000228
229 /// GetInstSize - Returns the size of the specified MachineInstr.
230 ///
231 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000232};
233
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000234}
235
236#endif