blob: 55f443ad78438a7d4cbb8534f9bdf40fa2d3a5d3 [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
Evan Chenga964b7d2008-09-12 23:15:39 +000085 UnaryFrm = 9 << FormShift,
86 BinaryFrm = 10 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000087
Raul Herbster8c132632007-08-30 23:34:14 +000088 // Load and Store
Evan Chenga964b7d2008-09-12 23:15:39 +000089 LdFrm = 11 << FormShift,
90 StFrm = 12 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000091
Raul Herbster8c132632007-08-30 23:34:14 +000092 // Miscellaneous arithmetic instructions
Evan Chenga964b7d2008-09-12 23:15:39 +000093 ArithMisc = 13 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000094
Raul Herbster8c132632007-08-30 23:34:14 +000095 // Thumb format
Evan Chenga964b7d2008-09-12 23:15:39 +000096 ThumbFrm = 14 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +000097
Raul Herbster8c132632007-08-30 23:34:14 +000098 // VFP format
Evan Chenga964b7d2008-09-12 23:15:39 +000099 VPFFrm = 15 << FormShift,
Evan Cheng0ff94f72007-08-07 01:37:15 +0000100
Raul Herbster8c132632007-08-30 23:34:14 +0000101 // Field shifts - such shifts are used to set field while generating
102 // machine instructions.
Evan Cheng5f1db7b2008-09-12 22:01:15 +0000103 RotImmShift = 8,
Raul Herbster8c132632007-08-30 23:34:14 +0000104 RegRsShift = 8,
105 RegRdShift = 12,
106 RegRnShift = 16,
Raul Herbster8c132632007-08-30 23:34:14 +0000107 S_BitShift = 20,
108 U_BitShift = 23,
Raul Herbster8c132632007-08-30 23:34:14 +0000109 I_BitShift = 25
Evan Chenga8e29892007-01-19 07:51:42 +0000110 };
111}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000112
Chris Lattner64105522008-01-01 01:03:04 +0000113class ARMInstrInfo : public TargetInstrInfoImpl {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000114 const ARMRegisterInfo RI;
115public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000116 explicit ARMInstrInfo(const ARMSubtarget &STI);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000117
118 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
119 /// such, whenever a client has an instance of instruction info, it should
120 /// always be able to get register info as well (through this method).
121 ///
Dan Gohmanc9f5f3f2008-05-14 01:58:56 +0000122 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000123
Rafael Espindola46adf812006-08-08 20:35:03 +0000124 /// getPointerRegClass - Return the register class to use to hold pointers.
125 /// This is used for addressing modes.
126 virtual const TargetRegisterClass *getPointerRegClass() const;
127
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000128 /// Return true if the instruction is a register to register move and
129 /// leave the source and dest operands in the passed parameters.
130 ///
131 virtual bool isMoveInstr(const MachineInstr &MI,
132 unsigned &SrcReg, unsigned &DstReg) const;
Evan Chenga8e29892007-01-19 07:51:42 +0000133 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
134 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
135
Evan Chengca1267c2008-03-31 20:40:39 +0000136 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
137 unsigned DestReg, const MachineInstr *Orig) const;
138
Evan Chenga8e29892007-01-19 07:51:42 +0000139 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
140 MachineBasicBlock::iterator &MBBI,
Owen Andersonf660c172008-07-02 23:41:07 +0000141 LiveVariables *LV) const;
Chris Lattner578e64a2006-10-24 16:47:57 +0000142
Evan Chenga8e29892007-01-19 07:51:42 +0000143 // Branch analysis.
144 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
145 MachineBasicBlock *&FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000146 SmallVectorImpl<MachineOperand> &Cond) const;
Evan Cheng6ae36262007-05-18 00:18:17 +0000147 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
148 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
149 MachineBasicBlock *FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000150 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson940f83e2008-08-26 18:03:31 +0000151 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Owen Andersond10fd972007-12-31 06:32:00 +0000152 MachineBasicBlock::iterator I,
153 unsigned DestReg, unsigned SrcReg,
154 const TargetRegisterClass *DestRC,
155 const TargetRegisterClass *SrcRC) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000156 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
157 MachineBasicBlock::iterator MBBI,
158 unsigned SrcReg, bool isKill, int FrameIndex,
159 const TargetRegisterClass *RC) const;
160
161 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
162 SmallVectorImpl<MachineOperand> &Addr,
163 const TargetRegisterClass *RC,
164 SmallVectorImpl<MachineInstr*> &NewMIs) const;
165
166 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
167 MachineBasicBlock::iterator MBBI,
168 unsigned DestReg, int FrameIndex,
169 const TargetRegisterClass *RC) const;
170
171 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
172 SmallVectorImpl<MachineOperand> &Addr,
173 const TargetRegisterClass *RC,
174 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Andersond94b6a12008-01-04 23:57:37 +0000175 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
176 MachineBasicBlock::iterator MI,
177 const std::vector<CalleeSavedInfo> &CSI) const;
178 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
179 MachineBasicBlock::iterator MI,
180 const std::vector<CalleeSavedInfo> &CSI) const;
Owen Anderson43dbe052008-01-07 01:35:02 +0000181
Evan Cheng5fd79d02008-02-08 21:20:40 +0000182 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
183 MachineInstr* MI,
Owen Anderson43dbe052008-01-07 01:35:02 +0000184 SmallVectorImpl<unsigned> &Ops,
185 int FrameIndex) const;
186
Evan Cheng5fd79d02008-02-08 21:20:40 +0000187 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
188 MachineInstr* MI,
Owen Anderson43dbe052008-01-07 01:35:02 +0000189 SmallVectorImpl<unsigned> &Ops,
190 MachineInstr* LoadMI) const {
191 return 0;
192 }
193
194 virtual bool canFoldMemoryOperand(MachineInstr *MI,
195 SmallVectorImpl<unsigned> &Ops) const;
196
Evan Chenga8e29892007-01-19 07:51:42 +0000197 virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
Owen Anderson44eb65c2008-08-14 22:49:33 +0000198 virtual
199 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Evan Cheng93072922007-05-16 02:01:49 +0000200
201 // Predication support.
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000202 virtual bool isPredicated(const MachineInstr *MI) const;
Evan Cheng69d55562007-05-23 07:22:05 +0000203
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000204 virtual
205 bool PredicateInstruction(MachineInstr *MI,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000206 const SmallVectorImpl<MachineOperand> &Pred) const;
Evan Cheng69d55562007-05-23 07:22:05 +0000207
Evan Cheng62ccdbf2007-05-29 18:42:18 +0000208 virtual
Owen Anderson44eb65c2008-08-14 22:49:33 +0000209 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
210 const SmallVectorImpl<MachineOperand> &Pred2) const;
Evan Cheng13ab0202007-07-10 18:08:01 +0000211
212 virtual bool DefinesPredicate(MachineInstr *MI,
213 std::vector<MachineOperand> &Pred) const;
Nicolas Geoffray52e724a2008-04-16 20:10:13 +0000214
215 /// GetInstSize - Returns the size of the specified MachineInstr.
216 ///
217 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000218};
219
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000220}
221
222#endif