1 //===- ARMBaseInstrInfo.h - ARM Base 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 Base ARM implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef ARMBASEINSTRUCTIONINFO_H
15 #define ARMBASEINSTRUCTIONINFO_H
18 #include "ARMRegisterInfo.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/Target/TargetInstrInfo.h"
25 /// ARMII - This namespace holds all of the target specific flags that
26 /// instruction info tracks.
30 //===------------------------------------------------------------------===//
33 //===------------------------------------------------------------------===//
34 // This four-bit field describes the addressing mode used.
47 AddrModeT1_s = 10, // i8 * 4 for pc and sp relative data
51 AddrModeT2_pc = 14, // +/- i12 for pc relative data
52 AddrModeT2_i8s4 = 15, // i8 * 4
54 // Size* - Flags to keep track of the size of an instruction.
56 SizeMask = 7 << SizeShift,
57 SizeSpecial = 1, // 0 byte pseudo or special case.
62 // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
65 IndexModeMask = 3 << IndexModeShift,
69 //===------------------------------------------------------------------===//
70 // Instruction encoding formats.
73 FormMask = 0x3f << 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 //===------------------------------------------------------------------===//
126 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
127 // it doesn't have a Rn operand.
130 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
131 // a 16-bit Thumb instruction if certain conditions are met.
132 Xform16Bit = 1 << 16,
134 //===------------------------------------------------------------------===//
135 // Field shifts - such shifts are used to set field while generating
136 // machine instructions.
159 /// ARMII::Op - Holds all of the instruction types required by
160 /// target specific instruction and register code. ARMBaseInstrInfo
161 /// and subclasses should return a specific opcode that implements
162 /// the instruction type.
192 const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
193 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
197 const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
198 return MIB.addReg(0);
202 const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB) {
203 return MIB.addReg(ARM::CPSR);
206 class ARMBaseInstrInfo : public TargetInstrInfoImpl {
208 // Can be only subclassed.
209 explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
211 // Return the non-pre/post incrementing version of 'Opc'. Return 0
212 // if there is not such an opcode.
213 virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
215 // Return the opcode that implements 'Op', or 0 if no opcode
216 virtual unsigned getOpcode(ARMII::Op Op) const =0;
218 // If 'opcode' is an instruction with an unsigned offset that also
219 // has a version with a signed offset, return the opcode for the
220 // version with the signed offset. In 'NumBits' return the number of
221 // bits for the signed offset.
222 virtual unsigned unsignedOffsetOpcodeToSigned(unsigned opcode,
223 unsigned *NumBits) const = 0;
225 // Return true if the block does not fall through.
226 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const =0;
228 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
229 MachineBasicBlock::iterator &MBBI,
230 LiveVariables *LV) const;
232 virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0;
235 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
236 MachineBasicBlock *&FBB,
237 SmallVectorImpl<MachineOperand> &Cond,
238 bool AllowModify) const;
239 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
240 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
241 MachineBasicBlock *FBB,
242 const SmallVectorImpl<MachineOperand> &Cond) const;
245 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
247 // Predication support.
248 bool isPredicated(const MachineInstr *MI) const {
249 int PIdx = MI->findFirstPredOperandIdx();
250 return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
253 ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
254 int PIdx = MI->findFirstPredOperandIdx();
255 return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
260 bool PredicateInstruction(MachineInstr *MI,
261 const SmallVectorImpl<MachineOperand> &Pred) const;
264 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
265 const SmallVectorImpl<MachineOperand> &Pred2) const;
267 virtual bool DefinesPredicate(MachineInstr *MI,
268 std::vector<MachineOperand> &Pred) const;
270 /// GetInstSize - Returns the size of the specified MachineInstr.
272 virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
274 /// Return true if the instruction is a register to register move and return
275 /// the source and dest operands and their sub-register indices by reference.
276 virtual bool isMoveInstr(const MachineInstr &MI,
277 unsigned &SrcReg, unsigned &DstReg,
278 unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
280 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
281 int &FrameIndex) const;
282 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
283 int &FrameIndex) const;
285 virtual bool copyRegToReg(MachineBasicBlock &MBB,
286 MachineBasicBlock::iterator I,
287 unsigned DestReg, unsigned SrcReg,
288 const TargetRegisterClass *DestRC,
289 const TargetRegisterClass *SrcRC) const;
290 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
291 MachineBasicBlock::iterator MBBI,
292 unsigned SrcReg, bool isKill, int FrameIndex,
293 const TargetRegisterClass *RC) const;
295 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
296 SmallVectorImpl<MachineOperand> &Addr,
297 const TargetRegisterClass *RC,
298 SmallVectorImpl<MachineInstr*> &NewMIs) const;
300 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
301 MachineBasicBlock::iterator MBBI,
302 unsigned DestReg, int FrameIndex,
303 const TargetRegisterClass *RC) const;
305 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
306 SmallVectorImpl<MachineOperand> &Addr,
307 const TargetRegisterClass *RC,
308 SmallVectorImpl<MachineInstr*> &NewMIs) const;
310 virtual bool canFoldMemoryOperand(const MachineInstr *MI,
311 const SmallVectorImpl<unsigned> &Ops) const;
313 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
315 const SmallVectorImpl<unsigned> &Ops,
316 int FrameIndex) const;
318 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
320 const SmallVectorImpl<unsigned> &Ops,
321 MachineInstr* LoadMI) const;