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
50 AddrModeT2_i8s4 = 14, // i8 * 4
52 // Size* - Flags to keep track of the size of an instruction.
54 SizeMask = 7 << SizeShift,
55 SizeSpecial = 1, // 0 byte pseudo or special case.
60 // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
63 IndexModeMask = 3 << IndexModeShift,
67 //===------------------------------------------------------------------===//
70 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
71 // it doesn't have a Rn operand.
74 //===------------------------------------------------------------------===//
75 // Instruction encoding formats.
78 FormMask = 0x1f << FormShift,
80 // Pseudo instructions
81 Pseudo = 0 << FormShift,
83 // Multiply instructions
84 MulFrm = 1 << FormShift,
86 // Branch instructions
87 BrFrm = 2 << FormShift,
88 BrMiscFrm = 3 << FormShift,
90 // Data Processing instructions
91 DPFrm = 4 << FormShift,
92 DPSoRegFrm = 5 << FormShift,
95 LdFrm = 6 << FormShift,
96 StFrm = 7 << FormShift,
97 LdMiscFrm = 8 << FormShift,
98 StMiscFrm = 9 << FormShift,
99 LdStMulFrm = 10 << FormShift,
101 // Miscellaneous arithmetic instructions
102 ArithMiscFrm = 11 << FormShift,
104 // Extend instructions
105 ExtFrm = 12 << FormShift,
108 VFPUnaryFrm = 13 << FormShift,
109 VFPBinaryFrm = 14 << FormShift,
110 VFPConv1Frm = 15 << FormShift,
111 VFPConv2Frm = 16 << FormShift,
112 VFPConv3Frm = 17 << FormShift,
113 VFPConv4Frm = 18 << FormShift,
114 VFPConv5Frm = 19 << FormShift,
115 VFPLdStFrm = 20 << FormShift,
116 VFPLdStMulFrm = 21 << FormShift,
117 VFPMiscFrm = 22 << FormShift,
120 ThumbFrm = 23 << FormShift,
123 NEONFrm = 24 << FormShift,
124 NEONGetLnFrm = 25 << FormShift,
125 NEONSetLnFrm = 26 << FormShift,
126 NEONDupFrm = 27 << FormShift,
128 //===------------------------------------------------------------------===//
129 // Field shifts - such shifts are used to set field while generating
130 // machine instructions.
154 class ARMBaseInstrInfo : public TargetInstrInfoImpl {
156 // Can be only subclassed.
157 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
159 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
160 MachineBasicBlock::iterator &MBBI,
161 LiveVariables *LV) const;
164 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
165 MachineBasicBlock *&FBB,
166 SmallVectorImpl<MachineOperand> &Cond,
167 bool AllowModify) const;
168 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
169 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
170 MachineBasicBlock *FBB,
171 const SmallVectorImpl<MachineOperand> &Cond) const;
173 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
175 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
177 // Predication support.
178 virtual bool isPredicated(const MachineInstr *MI) const;
180 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
181 int PIdx = MI->findFirstPredOperandIdx();
182 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
187 bool PredicateInstruction(MachineInstr *MI,
188 const SmallVectorImpl<MachineOperand> &Pred) const;
191 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
192 const SmallVectorImpl<MachineOperand> &Pred2) const;
194 virtual bool DefinesPredicate(MachineInstr *MI,
195 std::vector<MachineOperand> &Pred) const;
197 /// GetInstSize - Returns the size of the specified MachineInstr.
199 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
202 class ARMInstrInfo : public ARMBaseInstrInfo {
205 explicit ARMInstrInfo(const ARMSubtarget &STI);
207 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
208 /// such, whenever a client has an instance of instruction info, it should
209 /// always be able to get register info as well (through this method).
211 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
213 /// Return true if the instruction is a register to register move and return
214 /// the source and dest operands and their sub-register indices by reference.
215 virtual bool isMoveInstr(const MachineInstr &MI,
216 unsigned &SrcReg, unsigned &DstReg,
217 unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
219 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
220 int &FrameIndex) const;
221 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
222 int &FrameIndex) const;
224 virtual bool copyRegToReg(MachineBasicBlock &MBB,
225 MachineBasicBlock::iterator I,
226 unsigned DestReg, unsigned SrcReg,
227 const TargetRegisterClass *DestRC,
228 const TargetRegisterClass *SrcRC) const;
229 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
230 MachineBasicBlock::iterator MBBI,
231 unsigned SrcReg, bool isKill, int FrameIndex,
232 const TargetRegisterClass *RC) const;
234 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
235 SmallVectorImpl<MachineOperand> &Addr,
236 const TargetRegisterClass *RC,
237 SmallVectorImpl<MachineInstr*> &NewMIs) const;
239 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
240 MachineBasicBlock::iterator MBBI,
241 unsigned DestReg, int FrameIndex,
242 const TargetRegisterClass *RC) const;
244 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
245 SmallVectorImpl<MachineOperand> &Addr,
246 const TargetRegisterClass *RC,
247 SmallVectorImpl<MachineInstr*> &NewMIs) const;
249 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
250 unsigned DestReg, const MachineInstr *Orig) const;
252 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
253 const SmallVectorImpl<unsigned> &Ops) const;
255 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
257 const SmallVectorImpl<unsigned> &Ops,
258 int FrameIndex) const;
260 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
262 const SmallVectorImpl<unsigned> &Ops,
263 MachineInstr* LoadMI) const {