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 AddrModeTs = 9, // i8 * 4 for pc and sp relative data
47 // Size* - Flags to keep track of the size of an instruction.
49 SizeMask = 7 << SizeShift,
50 SizeSpecial = 1, // 0 byte pseudo or special case.
55 // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
58 IndexModeMask = 3 << IndexModeShift,
62 //===------------------------------------------------------------------===//
65 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
66 // it doesn't have a Rn operand.
69 //===------------------------------------------------------------------===//
70 // Instruction encoding formats.
73 FormMask = 0x1f << FormShift,
75 // Pseudo instructions
76 Pseudo = 0 << FormShift,
78 // Multiply instructions
79 MulFrm = 1 << FormShift,
81 // Branch instructions
82 BrFrm = 2 << FormShift,
83 BrMiscFrm = 3 << FormShift,
85 // Data Processing instructions
86 DPFrm = 4 << FormShift,
87 DPSoRegFrm = 5 << FormShift,
90 LdFrm = 6 << FormShift,
91 StFrm = 7 << FormShift,
92 LdMiscFrm = 8 << FormShift,
93 StMiscFrm = 9 << FormShift,
94 LdStMulFrm = 10 << FormShift,
96 // Miscellaneous arithmetic instructions
97 ArithMiscFrm = 11 << FormShift,
99 // Extend instructions
100 ExtFrm = 12 << FormShift,
103 VFPUnaryFrm = 13 << FormShift,
104 VFPBinaryFrm = 14 << FormShift,
105 VFPConv1Frm = 15 << FormShift,
106 VFPConv2Frm = 16 << FormShift,
107 VFPConv3Frm = 17 << FormShift,
108 VFPConv4Frm = 18 << FormShift,
109 VFPConv5Frm = 19 << FormShift,
110 VFPLdStFrm = 20 << FormShift,
111 VFPLdStMulFrm = 21 << FormShift,
112 VFPMiscFrm = 22 << FormShift,
115 ThumbFrm = 23 << FormShift,
118 NEONFrm = 24 << FormShift,
119 NEONGetLnFrm = 25 << FormShift,
120 NEONSetLnFrm = 26 << FormShift,
121 NEONDupFrm = 27 << FormShift,
123 //===------------------------------------------------------------------===//
124 // Field shifts - such shifts are used to set field while generating
125 // machine instructions.
149 class ARMBaseInstrInfo : public TargetInstrInfoImpl {
150 const ARMRegisterInfo RI;
152 // Can be only subclassed.
153 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
156 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
157 /// such, whenever a client has an instance of instruction info, it should
158 /// always be able to get register info as well (through this method).
160 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
162 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
163 unsigned DestReg, const MachineInstr *Orig) const;
165 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
166 MachineBasicBlock::iterator &MBBI,
167 LiveVariables *LV) const;
170 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
171 MachineBasicBlock *&FBB,
172 SmallVectorImpl<MachineOperand> &Cond,
173 bool AllowModify) const;
174 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
175 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
176 MachineBasicBlock *FBB,
177 const SmallVectorImpl<MachineOperand> &Cond) const;
179 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
180 const SmallVectorImpl<unsigned> &Ops) const;
182 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
184 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
186 // Predication support.
187 virtual bool isPredicated(const MachineInstr *MI) const;
189 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
190 int PIdx = MI->findFirstPredOperandIdx();
191 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
196 bool PredicateInstruction(MachineInstr *MI,
197 const SmallVectorImpl<MachineOperand> &Pred) const;
200 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
201 const SmallVectorImpl<MachineOperand> &Pred2) const;
203 virtual bool DefinesPredicate(MachineInstr *MI,
204 std::vector<MachineOperand> &Pred) const;
206 /// GetInstSize - Returns the size of the specified MachineInstr.
208 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
211 class ARMInstrInfo : public ARMBaseInstrInfo {
213 explicit ARMInstrInfo(const ARMSubtarget &STI);
215 /// Return true if the instruction is a register to register move and return
216 /// the source and dest operands and their sub-register indices by reference.
217 virtual bool isMoveInstr(const MachineInstr &MI,
218 unsigned &SrcReg, unsigned &DstReg,
219 unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
221 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
222 int &FrameIndex) const;
223 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
224 int &FrameIndex) const;
226 virtual bool copyRegToReg(MachineBasicBlock &MBB,
227 MachineBasicBlock::iterator I,
228 unsigned DestReg, unsigned SrcReg,
229 const TargetRegisterClass *DestRC,
230 const TargetRegisterClass *SrcRC) const;
231 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
232 MachineBasicBlock::iterator MBBI,
233 unsigned SrcReg, bool isKill, int FrameIndex,
234 const TargetRegisterClass *RC) const;
236 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
237 SmallVectorImpl<MachineOperand> &Addr,
238 const TargetRegisterClass *RC,
239 SmallVectorImpl<MachineInstr*> &NewMIs) const;
241 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
242 MachineBasicBlock::iterator MBBI,
243 unsigned DestReg, int FrameIndex,
244 const TargetRegisterClass *RC) const;
246 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
247 SmallVectorImpl<MachineOperand> &Addr,
248 const TargetRegisterClass *RC,
249 SmallVectorImpl<MachineInstr*> &NewMIs) const;
251 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
253 const SmallVectorImpl<unsigned> &Ops,
254 int FrameIndex) const;
256 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
258 const SmallVectorImpl<unsigned> &Ops,
259 MachineInstr* LoadMI) const {