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 three-bit field describes the addressing mode used. Zero is unused
34 // so that we can tell if we forgot to set a value.
46 AddrModeTs = 9, // i8 * 4 for pc and sp relative data
48 // Size* - Flags to keep track of the size of an instruction.
50 SizeMask = 7 << SizeShift,
51 SizeSpecial = 1, // 0 byte pseudo or special case.
56 // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
59 IndexModeMask = 3 << IndexModeShift,
65 OpcodeMask = 0xf << OpcodeShift,
69 FormMask = 31 << FormShift,
71 // Pseudo instructions
72 Pseudo = 1 << FormShift,
74 // Multiply instructions
75 MulFrm = 2 << FormShift,
76 MulSMLAW = 3 << FormShift,
77 MulSMULW = 4 << FormShift,
78 MulSMLA = 5 << FormShift,
79 MulSMUL = 6 << FormShift,
81 // Branch instructions
82 Branch = 7 << FormShift,
83 BranchMisc = 8 << FormShift,
85 // Data Processing instructions
86 DPRdIm = 9 << FormShift,
87 DPRdReg = 10 << FormShift,
88 DPRdSoReg = 11 << FormShift,
89 DPRdMisc = 12 << FormShift,
91 DPRnIm = 13 << FormShift,
92 DPRnReg = 14 << FormShift,
93 DPRnSoReg = 15 << FormShift,
95 DPRIm = 16 << FormShift,
96 DPRReg = 17 << FormShift,
97 DPRSoReg = 18 << FormShift,
99 DPRImS = 19 << FormShift,
100 DPRRegS = 20 << FormShift,
101 DPRSoRegS = 21 << FormShift,
104 LdFrm = 22 << FormShift,
105 StFrm = 23 << FormShift,
107 // Miscellaneous arithmetic instructions
108 ArithMisc = 24 << FormShift,
111 ThumbFrm = 25 << FormShift,
114 VPFFrm = 26 << FormShift,
116 // Field shifts - such shifts are used to set field while generating
117 // machine instructions.
130 class ARMInstrInfo : public TargetInstrInfoImpl {
131 const ARMRegisterInfo RI;
133 explicit ARMInstrInfo(const ARMSubtarget &STI);
135 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
136 /// such, whenever a client has an instance of instruction info, it should
137 /// always be able to get register info as well (through this method).
139 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
141 /// getPointerRegClass - Return the register class to use to hold pointers.
142 /// This is used for addressing modes.
143 virtual const TargetRegisterClass *getPointerRegClass() const;
145 /// Return true if the instruction is a register to register move and
146 /// leave the source and dest operands in the passed parameters.
148 virtual bool isMoveInstr(const MachineInstr &MI,
149 unsigned &SrcReg, unsigned &DstReg) const;
150 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
151 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
153 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
154 unsigned DestReg, const MachineInstr *Orig) const;
156 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
157 MachineBasicBlock::iterator &MBBI,
158 LiveVariables *LV) const;
161 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
162 MachineBasicBlock *&FBB,
163 SmallVectorImpl<MachineOperand> &Cond) const;
164 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
165 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
166 MachineBasicBlock *FBB,
167 const SmallVectorImpl<MachineOperand> &Cond) const;
168 virtual bool copyRegToReg(MachineBasicBlock &MBB,
169 MachineBasicBlock::iterator I,
170 unsigned DestReg, unsigned SrcReg,
171 const TargetRegisterClass *DestRC,
172 const TargetRegisterClass *SrcRC) const;
173 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
174 MachineBasicBlock::iterator MBBI,
175 unsigned SrcReg, bool isKill, int FrameIndex,
176 const TargetRegisterClass *RC) const;
178 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
179 SmallVectorImpl<MachineOperand> &Addr,
180 const TargetRegisterClass *RC,
181 SmallVectorImpl<MachineInstr*> &NewMIs) const;
183 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
184 MachineBasicBlock::iterator MBBI,
185 unsigned DestReg, int FrameIndex,
186 const TargetRegisterClass *RC) const;
188 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
189 SmallVectorImpl<MachineOperand> &Addr,
190 const TargetRegisterClass *RC,
191 SmallVectorImpl<MachineInstr*> &NewMIs) const;
192 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
193 MachineBasicBlock::iterator MI,
194 const std::vector<CalleeSavedInfo> &CSI) const;
195 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
196 MachineBasicBlock::iterator MI,
197 const std::vector<CalleeSavedInfo> &CSI) const;
199 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
201 SmallVectorImpl<unsigned> &Ops,
202 int FrameIndex) const;
204 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
206 SmallVectorImpl<unsigned> &Ops,
207 MachineInstr* LoadMI) const {
211 virtual bool canFoldMemoryOperand(MachineInstr *MI,
212 SmallVectorImpl<unsigned> &Ops) const;
214 virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
216 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
218 // Predication support.
219 virtual bool isPredicated(const MachineInstr *MI) const;
221 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
222 int PIdx = MI->findFirstPredOperandIdx();
223 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
228 bool PredicateInstruction(MachineInstr *MI,
229 const SmallVectorImpl<MachineOperand> &Pred) const;
232 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
233 const SmallVectorImpl<MachineOperand> &Pred2) const;
235 virtual bool DefinesPredicate(MachineInstr *MI,
236 std::vector<MachineOperand> &Pred) const;
238 /// GetInstSize - Returns the size of the specified MachineInstr.
240 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;