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.
46 AddrModeTs = 10, // 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.
132 class ARMInstrInfo : public TargetInstrInfoImpl {
133 const ARMRegisterInfo RI;
135 explicit ARMInstrInfo(const ARMSubtarget &STI);
137 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
138 /// such, whenever a client has an instance of instruction info, it should
139 /// always be able to get register info as well (through this method).
141 virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
143 /// getPointerRegClass - Return the register class to use to hold pointers.
144 /// This is used for addressing modes.
145 virtual const TargetRegisterClass *getPointerRegClass() const;
147 /// Return true if the instruction is a register to register move and
148 /// leave the source and dest operands in the passed parameters.
150 virtual bool isMoveInstr(const MachineInstr &MI,
151 unsigned &SrcReg, unsigned &DstReg) const;
152 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
153 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
155 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
156 unsigned DestReg, const MachineInstr *Orig) const;
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) const;
166 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
167 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
168 MachineBasicBlock *FBB,
169 const SmallVectorImpl<MachineOperand> &Cond) const;
170 virtual bool copyRegToReg(MachineBasicBlock &MBB,
171 MachineBasicBlock::iterator I,
172 unsigned DestReg, unsigned SrcReg,
173 const TargetRegisterClass *DestRC,
174 const TargetRegisterClass *SrcRC) const;
175 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
176 MachineBasicBlock::iterator MBBI,
177 unsigned SrcReg, bool isKill, int FrameIndex,
178 const TargetRegisterClass *RC) const;
180 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
181 SmallVectorImpl<MachineOperand> &Addr,
182 const TargetRegisterClass *RC,
183 SmallVectorImpl<MachineInstr*> &NewMIs) const;
185 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
186 MachineBasicBlock::iterator MBBI,
187 unsigned DestReg, int FrameIndex,
188 const TargetRegisterClass *RC) const;
190 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
191 SmallVectorImpl<MachineOperand> &Addr,
192 const TargetRegisterClass *RC,
193 SmallVectorImpl<MachineInstr*> &NewMIs) const;
194 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
195 MachineBasicBlock::iterator MI,
196 const std::vector<CalleeSavedInfo> &CSI) const;
197 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
198 MachineBasicBlock::iterator MI,
199 const std::vector<CalleeSavedInfo> &CSI) const;
201 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
203 const SmallVectorImpl<unsigned> &Ops,
204 int FrameIndex) const;
206 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
208 const SmallVectorImpl<unsigned> &Ops,
209 MachineInstr* LoadMI) const {
213 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
214 const SmallVectorImpl<unsigned> &Ops) const;
216 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
218 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
220 // Predication support.
221 virtual bool isPredicated(const MachineInstr *MI) const;
223 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
224 int PIdx = MI->findFirstPredOperandIdx();
225 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
230 bool PredicateInstruction(MachineInstr *MI,
231 const SmallVectorImpl<MachineOperand> &Pred) const;
234 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
235 const SmallVectorImpl<MachineOperand> &Pred2) const;
237 virtual bool DefinesPredicate(MachineInstr *MI,
238 std::vector<MachineOperand> &Pred) const;
240 /// GetInstSize - Returns the size of the specified MachineInstr.
242 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;