blob: 736d6f6bde4f40f77e0ad9051df2e53fe1d22d80 [file] [log] [blame]
Tim Northover00ed9962014-03-29 10:18:08 +00001//===- ARM64InstrInfo.h - ARM64 Instruction Information ---------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the ARM64 implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGET_ARM64INSTRINFO_H
15#define LLVM_TARGET_ARM64INSTRINFO_H
16
17#include "ARM64.h"
18#include "ARM64RegisterInfo.h"
19#include "llvm/Target/TargetInstrInfo.h"
20
21#define GET_INSTRINFO_HEADER
22#include "ARM64GenInstrInfo.inc"
23
24namespace llvm {
25
26class ARM64Subtarget;
27class ARM64TargetMachine;
28
29class ARM64InstrInfo : public ARM64GenInstrInfo {
30 // Reserve bits in the MachineMemOperand target hint flags, starting at 1.
31 // They will be shifted into MOTargetHintStart when accessed.
32 enum TargetMemOperandFlags {
33 MOSuppressPair = 1
34 };
35
36 const ARM64RegisterInfo RI;
37 const ARM64Subtarget &Subtarget;
38
39public:
40 explicit ARM64InstrInfo(const ARM64Subtarget &STI);
41
42 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
43 /// such, whenever a client has an instance of instruction info, it should
44 /// always be able to get register info as well (through this method).
45 virtual const ARM64RegisterInfo &getRegisterInfo() const { return RI; }
46
47 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
48
49 virtual bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
50 unsigned &DstReg, unsigned &SubIdx) const;
51
52 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
53 int &FrameIndex) const;
54 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
55 int &FrameIndex) const;
56
57 /// \brief Does this instruction set its full destination register to zero?
58 bool isGPRZero(const MachineInstr *MI) const;
59
60 /// \brief Does this instruction rename a GPR without modifying bits?
61 bool isGPRCopy(const MachineInstr *MI) const;
62
63 /// \brief Does this instruction rename an FPR without modifying bits?
64 bool isFPRCopy(const MachineInstr *MI) const;
65
66 /// Return true if this is load/store scales or extends its register offset.
67 /// This refers to scaling a dynamic index as opposed to scaled immediates.
68 /// MI should be a memory op that allows scaled addressing.
69 bool isScaledAddr(const MachineInstr *MI) const;
70
71 /// Return true if pairing the given load or store is hinted to be
72 /// unprofitable.
73 bool isLdStPairSuppressed(const MachineInstr *MI) const;
74
75 /// Hint that pairing the given load or store is unprofitable.
76 void suppressLdStPair(MachineInstr *MI) const;
77
78 virtual bool getLdStBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
79 unsigned &Offset,
80 const TargetRegisterInfo *TRI) const;
81
82 virtual bool enableClusterLoads() const { return true; }
83
84 virtual bool shouldClusterLoads(MachineInstr *FirstLdSt,
85 MachineInstr *SecondLdSt,
86 unsigned NumLoads) const;
87
88 virtual bool shouldScheduleAdjacent(MachineInstr *First,
89 MachineInstr *Second) const;
90
91 MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
92 uint64_t Offset, const MDNode *MDPtr,
93 DebugLoc DL) const;
94 void copyPhysRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
95 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
96 bool KillSrc, unsigned Opcode,
97 llvm::ArrayRef<unsigned> Indices) const;
98 virtual void copyPhysReg(MachineBasicBlock &MBB,
99 MachineBasicBlock::iterator I, DebugLoc DL,
100 unsigned DestReg, unsigned SrcReg,
101 bool KillSrc) const;
102
103 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
104 MachineBasicBlock::iterator MBBI,
105 unsigned SrcReg, bool isKill, int FrameIndex,
106 const TargetRegisterClass *RC,
107 const TargetRegisterInfo *TRI) const;
108
109 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
110 MachineBasicBlock::iterator MBBI,
111 unsigned DestReg, int FrameIndex,
112 const TargetRegisterClass *RC,
113 const TargetRegisterInfo *TRI) const;
114
115 virtual MachineInstr *
116 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
117 const SmallVectorImpl<unsigned> &Ops,
118 int FrameIndex) const;
119
120 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
121 MachineBasicBlock *&FBB,
122 SmallVectorImpl<MachineOperand> &Cond,
123 bool AllowModify = false) const;
124 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
125 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
126 MachineBasicBlock *FBB,
127 const SmallVectorImpl<MachineOperand> &Cond,
128 DebugLoc DL) const;
129 virtual bool
130 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
131 virtual bool canInsertSelect(const MachineBasicBlock &,
132 const SmallVectorImpl<MachineOperand> &Cond,
133 unsigned, unsigned, int &, int &, int &) const;
134 virtual void insertSelect(MachineBasicBlock &MBB,
135 MachineBasicBlock::iterator MI, DebugLoc DL,
136 unsigned DstReg,
137 const SmallVectorImpl<MachineOperand> &Cond,
138 unsigned TrueReg, unsigned FalseReg) const;
139 virtual void getNoopForMachoTarget(MCInst &NopInst) const;
140
141 /// analyzeCompare - For a comparison instruction, return the source registers
142 /// in SrcReg and SrcReg2, and the value it compares against in CmpValue.
143 /// Return true if the comparison instruction can be analyzed.
144 virtual bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
145 unsigned &SrcReg2, int &CmpMask,
146 int &CmpValue) const;
147 /// optimizeCompareInstr - Convert the instruction supplying the argument to
148 /// the comparison into one that sets the zero bit in the flags register.
149 virtual bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
150 unsigned SrcReg2, int CmpMask, int CmpValue,
151 const MachineRegisterInfo *MRI) const;
152
153private:
154 void instantiateCondBranch(MachineBasicBlock &MBB, DebugLoc DL,
155 MachineBasicBlock *TBB,
156 const SmallVectorImpl<MachineOperand> &Cond) const;
157};
158
159/// emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg
160/// plus Offset. This is intended to be used from within the prolog/epilog
161/// insertion (PEI) pass, where a virtual scratch register may be allocated
162/// if necessary, to be replaced by the scavenger at the end of PEI.
163void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
164 DebugLoc DL, unsigned DestReg, unsigned SrcReg, int Offset,
165 const ARM64InstrInfo *TII,
166 MachineInstr::MIFlag = MachineInstr::NoFlags,
167 bool SetCPSR = false);
168
169/// rewriteARM64FrameIndex - Rewrite MI to access 'Offset' bytes from the
170/// FP. Return false if the offset could not be handled directly in MI, and
171/// return the left-over portion by reference.
172bool rewriteARM64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
173 unsigned FrameReg, int &Offset,
174 const ARM64InstrInfo *TII);
175
176/// \brief Use to report the frame offset status in isARM64FrameOffsetLegal.
177enum ARM64FrameOffsetStatus {
178 ARM64FrameOffsetCannotUpdate = 0x0, ///< Offset cannot apply.
179 ARM64FrameOffsetIsLegal = 0x1, ///< Offset is legal.
180 ARM64FrameOffsetCanUpdate = 0x2 ///< Offset can apply, at least partly.
181};
182
183/// \brief Check if the @p Offset is a valid frame offset for @p MI.
184/// The returned value reports the validity of the frame offset for @p MI.
185/// It uses the values defined by ARM64FrameOffsetStatus for that.
186/// If result == ARM64FrameOffsetCannotUpdate, @p MI cannot be updated to
187/// use an offset.eq
188/// If result & ARM64FrameOffsetIsLegal, @p Offset can completely be
189/// rewriten in @p MI.
190/// If result & ARM64FrameOffsetCanUpdate, @p Offset contains the
191/// amount that is off the limit of the legal offset.
192/// If set, @p OutUseUnscaledOp will contain the whether @p MI should be
193/// turned into an unscaled operator, which opcode is in @p OutUnscaledOp.
194/// If set, @p EmittableOffset contains the amount that can be set in @p MI
195/// (possibly with @p OutUnscaledOp if OutUseUnscaledOp is true) and that
196/// is a legal offset.
197int isARM64FrameOffsetLegal(const MachineInstr &MI, int &Offset,
198 bool *OutUseUnscaledOp = NULL,
199 unsigned *OutUnscaledOp = NULL,
200 int *EmittableOffset = NULL);
201
202static inline bool isUncondBranchOpcode(int Opc) { return Opc == ARM64::B; }
203
204static inline bool isCondBranchOpcode(int Opc) {
205 switch (Opc) {
206 case ARM64::Bcc:
207 case ARM64::CBZW:
208 case ARM64::CBZX:
209 case ARM64::CBNZW:
210 case ARM64::CBNZX:
211 case ARM64::TBZ:
212 case ARM64::TBNZ:
213 return true;
214 default:
215 return false;
216 }
217}
218
219static inline bool isIndirectBranchOpcode(int Opc) { return Opc == ARM64::BR; }
220
221} // end namespace llvm
222
223#endif