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 = 1 << FormShift,
78 // Multiply instructions
79 MulFrm = 2 << FormShift,
81 // Branch instructions
82 BrFrm = 3 << FormShift,
83 BrMiscFrm = 4 << FormShift,
85 // Data Processing instructions
86 DPFrm = 5 << FormShift,
87 DPSoRegFrm = 6 << FormShift,
90 LdFrm = 7 << FormShift,
91 StFrm = 8 << FormShift,
92 LdMiscFrm = 9 << FormShift,
93 StMiscFrm = 10 << FormShift,
94 LdMulFrm = 11 << FormShift,
95 StMulFrm = 12 << FormShift,
97 // Miscellaneous arithmetic instructions
98 ArithMiscFrm = 13 << FormShift,
100 // Extend instructions
101 ExtFrm = 14 << FormShift,
104 VFPUnaryFrm = 15 << FormShift,
105 VFPBinaryFrm = 16 << FormShift,
106 VFPConv1Frm = 17 << FormShift,
107 VFPConv2Frm = 18 << FormShift,
108 VFPLdStFrm = 19 << FormShift,
109 VFPLdStMulFrm = 20 << FormShift,
110 VFPMiscFrm = 21 << FormShift,
113 ThumbFrm = 22 << FormShift,
115 //===------------------------------------------------------------------===//
116 // Field shifts - such shifts are used to set field while generating
117 // machine instructions.
139 class ARMInstrInfo : public TargetInstrInfoImpl {
140 const ARMRegisterInfo RI;
142 explicit ARMInstrInfo(const ARMSubtarget &STI);
144 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
145 /// such, whenever a client has an instance of instruction info, it should
146 /// always be able to get register info as well (through this method).
148 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
150 /// getPointerRegClass - Return the register class to use to hold pointers.
151 /// This is used for addressing modes.
152 virtual const TargetRegisterClass *getPointerRegClass() const;
154 /// Return true if the instruction is a register to register move and
155 /// leave the source and dest operands in the passed parameters.
157 virtual bool isMoveInstr(const MachineInstr &MI,
158 unsigned &SrcReg, unsigned &DstReg) const;
159 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
160 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
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) const;
173 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
174 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
175 MachineBasicBlock *FBB,
176 const SmallVectorImpl<MachineOperand> &Cond) const;
177 virtual bool copyRegToReg(MachineBasicBlock &MBB,
178 MachineBasicBlock::iterator I,
179 unsigned DestReg, unsigned SrcReg,
180 const TargetRegisterClass *DestRC,
181 const TargetRegisterClass *SrcRC) const;
182 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
183 MachineBasicBlock::iterator MBBI,
184 unsigned SrcReg, bool isKill, int FrameIndex,
185 const TargetRegisterClass *RC) const;
187 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
188 SmallVectorImpl<MachineOperand> &Addr,
189 const TargetRegisterClass *RC,
190 SmallVectorImpl<MachineInstr*> &NewMIs) const;
192 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
193 MachineBasicBlock::iterator MBBI,
194 unsigned DestReg, int FrameIndex,
195 const TargetRegisterClass *RC) const;
197 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
198 SmallVectorImpl<MachineOperand> &Addr,
199 const TargetRegisterClass *RC,
200 SmallVectorImpl<MachineInstr*> &NewMIs) const;
201 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
202 MachineBasicBlock::iterator MI,
203 const std::vector<CalleeSavedInfo> &CSI) const;
204 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
205 MachineBasicBlock::iterator MI,
206 const std::vector<CalleeSavedInfo> &CSI) const;
208 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
210 const SmallVectorImpl<unsigned> &Ops,
211 int FrameIndex) const;
213 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
215 const SmallVectorImpl<unsigned> &Ops,
216 MachineInstr* LoadMI) const {
220 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
221 const SmallVectorImpl<unsigned> &Ops) const;
223 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
225 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
227 // Predication support.
228 virtual bool isPredicated(const MachineInstr *MI) const;
230 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
231 int PIdx = MI->findFirstPredOperandIdx();
232 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
237 bool PredicateInstruction(MachineInstr *MI,
238 const SmallVectorImpl<MachineOperand> &Pred) const;
241 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
242 const SmallVectorImpl<MachineOperand> &Pred2) const;
244 virtual bool DefinesPredicate(MachineInstr *MI,
245 std::vector<MachineOperand> &Pred) const;
247 /// GetInstSize - Returns the size of the specified MachineInstr.
249 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;