1 //===- ARMInstrInfo.h - ARM Instruction Information -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the ARM implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef ARMINSTRUCTIONINFO_H
15 #define ARMINSTRUCTIONINFO_H
17 #include "llvm/Target/TargetInstrInfo.h"
18 #include "ARMRegisterInfo.h"
24 /// ARMII - This namespace holds all of the target specific flags that
25 /// instruction info tracks.
29 //===------------------------------------------------------------------===//
32 //===------------------------------------------------------------------===//
33 // This four-bit field describes the addressing mode used.
45 AddrModeT1_s = 9, // i8 * 4 for pc and sp relative data
49 AddrModeT2_pc = 13, // +/- i12 for pc relative data
51 // Size* - Flags to keep track of the size of an instruction.
53 SizeMask = 7 << SizeShift,
54 SizeSpecial = 1, // 0 byte pseudo or special case.
59 // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
62 IndexModeMask = 3 << IndexModeShift,
66 //===------------------------------------------------------------------===//
69 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
70 // it doesn't have a Rn operand.
73 //===------------------------------------------------------------------===//
74 // Instruction encoding formats.
77 FormMask = 0x1f << FormShift,
79 // Pseudo instructions
80 Pseudo = 0 << FormShift,
82 // Multiply instructions
83 MulFrm = 1 << FormShift,
85 // Branch instructions
86 BrFrm = 2 << FormShift,
87 BrMiscFrm = 3 << FormShift,
89 // Data Processing instructions
90 DPFrm = 4 << FormShift,
91 DPSoRegFrm = 5 << FormShift,
94 LdFrm = 6 << FormShift,
95 StFrm = 7 << FormShift,
96 LdMiscFrm = 8 << FormShift,
97 StMiscFrm = 9 << FormShift,
98 LdStMulFrm = 10 << FormShift,
100 // Miscellaneous arithmetic instructions
101 ArithMiscFrm = 11 << FormShift,
103 // Extend instructions
104 ExtFrm = 12 << FormShift,
107 VFPUnaryFrm = 13 << FormShift,
108 VFPBinaryFrm = 14 << FormShift,
109 VFPConv1Frm = 15 << FormShift,
110 VFPConv2Frm = 16 << FormShift,
111 VFPConv3Frm = 17 << FormShift,
112 VFPConv4Frm = 18 << FormShift,
113 VFPConv5Frm = 19 << FormShift,
114 VFPLdStFrm = 20 << FormShift,
115 VFPLdStMulFrm = 21 << FormShift,
116 VFPMiscFrm = 22 << FormShift,
119 ThumbFrm = 23 << FormShift,
122 NEONFrm = 24 << FormShift,
123 NEONGetLnFrm = 25 << FormShift,
124 NEONSetLnFrm = 26 << FormShift,
125 NEONDupFrm = 27 << FormShift,
127 //===------------------------------------------------------------------===//
128 // Field shifts - such shifts are used to set field while generating
129 // machine instructions.
153 class ARMBaseInstrInfo : public TargetInstrInfoImpl {
155 // Can be only subclassed.
156 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
158 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
159 MachineBasicBlock::iterator &MBBI,
160 LiveVariables *LV) const;
163 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
164 MachineBasicBlock *&FBB,
165 SmallVectorImpl<MachineOperand> &Cond,
166 bool AllowModify) const;
167 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
168 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
169 MachineBasicBlock *FBB,
170 const SmallVectorImpl<MachineOperand> &Cond) const;
172 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
174 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
176 // Predication support.
177 virtual bool isPredicated(const MachineInstr *MI) const;
179 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
180 int PIdx = MI->findFirstPredOperandIdx();
181 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
186 bool PredicateInstruction(MachineInstr *MI,
187 const SmallVectorImpl<MachineOperand> &Pred) const;
190 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
191 const SmallVectorImpl<MachineOperand> &Pred2) const;
193 virtual bool DefinesPredicate(MachineInstr *MI,
194 std::vector<MachineOperand> &Pred) const;
196 /// GetInstSize - Returns the size of the specified MachineInstr.
198 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
201 class ARMInstrInfo : public ARMBaseInstrInfo {
204 explicit ARMInstrInfo(const ARMSubtarget &STI);
206 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
207 /// such, whenever a client has an instance of instruction info, it should
208 /// always be able to get register info as well (through this method).
210 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
212 /// Return true if the instruction is a register to register move and return
213 /// the source and dest operands and their sub-register indices by reference.
214 virtual bool isMoveInstr(const MachineInstr &MI,
215 unsigned &SrcReg, unsigned &DstReg,
216 unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
218 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
219 int &FrameIndex) const;
220 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
221 int &FrameIndex) const;
223 virtual bool copyRegToReg(MachineBasicBlock &MBB,
224 MachineBasicBlock::iterator I,
225 unsigned DestReg, unsigned SrcReg,
226 const TargetRegisterClass *DestRC,
227 const TargetRegisterClass *SrcRC) const;
228 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
229 MachineBasicBlock::iterator MBBI,
230 unsigned SrcReg, bool isKill, int FrameIndex,
231 const TargetRegisterClass *RC) const;
233 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
234 SmallVectorImpl<MachineOperand> &Addr,
235 const TargetRegisterClass *RC,
236 SmallVectorImpl<MachineInstr*> &NewMIs) const;
238 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
239 MachineBasicBlock::iterator MBBI,
240 unsigned DestReg, int FrameIndex,
241 const TargetRegisterClass *RC) const;
243 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
244 SmallVectorImpl<MachineOperand> &Addr,
245 const TargetRegisterClass *RC,
246 SmallVectorImpl<MachineInstr*> &NewMIs) const;
248 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
249 unsigned DestReg, const MachineInstr *Orig) const;
251 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
252 const SmallVectorImpl<unsigned> &Ops) const;
254 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
256 const SmallVectorImpl<unsigned> &Ops,
257 int FrameIndex) const;
259 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
261 const SmallVectorImpl<unsigned> &Ops,
262 MachineInstr* LoadMI) const {