blob: 2591ca072d0da32c2d4e4206be74f35198d28cc1 [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).
Tim Northover3e525572014-03-30 07:25:18 +000045 const ARM64RegisterInfo &getRegisterInfo() const { return RI; }
Tim Northover00ed9962014-03-29 10:18:08 +000046
47 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
48
Tim Northover3e525572014-03-30 07:25:18 +000049 bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
50 unsigned &DstReg, unsigned &SubIdx) const override;
Tim Northover00ed9962014-03-29 10:18:08 +000051
Tim Northover3e525572014-03-30 07:25:18 +000052 unsigned isLoadFromStackSlot(const MachineInstr *MI,
53 int &FrameIndex) const override;
54 unsigned isStoreToStackSlot(const MachineInstr *MI,
55 int &FrameIndex) const override;
Tim Northover00ed9962014-03-29 10:18:08 +000056
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
Tim Northover3e525572014-03-30 07:25:18 +000078 bool getLdStBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
79 unsigned &Offset,
80 const TargetRegisterInfo *TRI) const override;
Tim Northover00ed9962014-03-29 10:18:08 +000081
Tim Northover3e525572014-03-30 07:25:18 +000082 bool enableClusterLoads() const override { return true; }
Tim Northover00ed9962014-03-29 10:18:08 +000083
Tim Northover3e525572014-03-30 07:25:18 +000084 bool shouldClusterLoads(MachineInstr *FirstLdSt, MachineInstr *SecondLdSt,
85 unsigned NumLoads) const override;
Tim Northover00ed9962014-03-29 10:18:08 +000086
Tim Northover3e525572014-03-30 07:25:18 +000087 bool shouldScheduleAdjacent(MachineInstr *First,
88 MachineInstr *Second) const override;
Tim Northover00ed9962014-03-29 10:18:08 +000089
90 MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
91 uint64_t Offset, const MDNode *MDPtr,
92 DebugLoc DL) const;
93 void copyPhysRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
94 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
95 bool KillSrc, unsigned Opcode,
96 llvm::ArrayRef<unsigned> Indices) const;
Tim Northover3e525572014-03-30 07:25:18 +000097 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
98 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
99 bool KillSrc) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000100
Tim Northover3e525572014-03-30 07:25:18 +0000101 void storeRegToStackSlot(MachineBasicBlock &MBB,
102 MachineBasicBlock::iterator MBBI, unsigned SrcReg,
103 bool isKill, int FrameIndex,
104 const TargetRegisterClass *RC,
105 const TargetRegisterInfo *TRI) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000106
Tim Northover3e525572014-03-30 07:25:18 +0000107 void loadRegFromStackSlot(MachineBasicBlock &MBB,
108 MachineBasicBlock::iterator MBBI, unsigned DestReg,
109 int FrameIndex, const TargetRegisterClass *RC,
110 const TargetRegisterInfo *TRI) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000111
Tim Northover3e525572014-03-30 07:25:18 +0000112 MachineInstr *
Tim Northover00ed9962014-03-29 10:18:08 +0000113 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
114 const SmallVectorImpl<unsigned> &Ops,
Tim Northover3e525572014-03-30 07:25:18 +0000115 int FrameIndex) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000116
Tim Northover3e525572014-03-30 07:25:18 +0000117 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
118 MachineBasicBlock *&FBB,
119 SmallVectorImpl<MachineOperand> &Cond,
120 bool AllowModify = false) const override;
121 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
122 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
123 MachineBasicBlock *FBB,
124 const SmallVectorImpl<MachineOperand> &Cond,
125 DebugLoc DL) const override;
126 bool
127 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
128 bool canInsertSelect(const MachineBasicBlock &,
129 const SmallVectorImpl<MachineOperand> &Cond, unsigned,
130 unsigned, int &, int &, int &) const override;
131 void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
132 DebugLoc DL, unsigned DstReg,
133 const SmallVectorImpl<MachineOperand> &Cond,
134 unsigned TrueReg, unsigned FalseReg) const override;
135 void getNoopForMachoTarget(MCInst &NopInst) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000136
137 /// analyzeCompare - For a comparison instruction, return the source registers
138 /// in SrcReg and SrcReg2, and the value it compares against in CmpValue.
139 /// Return true if the comparison instruction can be analyzed.
Tim Northover3e525572014-03-30 07:25:18 +0000140 bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
141 unsigned &SrcReg2, int &CmpMask,
142 int &CmpValue) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000143 /// optimizeCompareInstr - Convert the instruction supplying the argument to
144 /// the comparison into one that sets the zero bit in the flags register.
Tim Northover3e525572014-03-30 07:25:18 +0000145 bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
146 unsigned SrcReg2, int CmpMask, int CmpValue,
147 const MachineRegisterInfo *MRI) const override;
Tim Northover00ed9962014-03-29 10:18:08 +0000148
149private:
150 void instantiateCondBranch(MachineBasicBlock &MBB, DebugLoc DL,
151 MachineBasicBlock *TBB,
152 const SmallVectorImpl<MachineOperand> &Cond) const;
153};
154
155/// emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg
156/// plus Offset. This is intended to be used from within the prolog/epilog
157/// insertion (PEI) pass, where a virtual scratch register may be allocated
158/// if necessary, to be replaced by the scavenger at the end of PEI.
159void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
160 DebugLoc DL, unsigned DestReg, unsigned SrcReg, int Offset,
161 const ARM64InstrInfo *TII,
162 MachineInstr::MIFlag = MachineInstr::NoFlags,
163 bool SetCPSR = false);
164
165/// rewriteARM64FrameIndex - Rewrite MI to access 'Offset' bytes from the
166/// FP. Return false if the offset could not be handled directly in MI, and
167/// return the left-over portion by reference.
168bool rewriteARM64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
169 unsigned FrameReg, int &Offset,
170 const ARM64InstrInfo *TII);
171
172/// \brief Use to report the frame offset status in isARM64FrameOffsetLegal.
173enum ARM64FrameOffsetStatus {
174 ARM64FrameOffsetCannotUpdate = 0x0, ///< Offset cannot apply.
175 ARM64FrameOffsetIsLegal = 0x1, ///< Offset is legal.
176 ARM64FrameOffsetCanUpdate = 0x2 ///< Offset can apply, at least partly.
177};
178
179/// \brief Check if the @p Offset is a valid frame offset for @p MI.
180/// The returned value reports the validity of the frame offset for @p MI.
181/// It uses the values defined by ARM64FrameOffsetStatus for that.
182/// If result == ARM64FrameOffsetCannotUpdate, @p MI cannot be updated to
183/// use an offset.eq
184/// If result & ARM64FrameOffsetIsLegal, @p Offset can completely be
185/// rewriten in @p MI.
186/// If result & ARM64FrameOffsetCanUpdate, @p Offset contains the
187/// amount that is off the limit of the legal offset.
188/// If set, @p OutUseUnscaledOp will contain the whether @p MI should be
189/// turned into an unscaled operator, which opcode is in @p OutUnscaledOp.
190/// If set, @p EmittableOffset contains the amount that can be set in @p MI
191/// (possibly with @p OutUnscaledOp if OutUseUnscaledOp is true) and that
192/// is a legal offset.
193int isARM64FrameOffsetLegal(const MachineInstr &MI, int &Offset,
194 bool *OutUseUnscaledOp = NULL,
195 unsigned *OutUnscaledOp = NULL,
196 int *EmittableOffset = NULL);
197
198static inline bool isUncondBranchOpcode(int Opc) { return Opc == ARM64::B; }
199
200static inline bool isCondBranchOpcode(int Opc) {
201 switch (Opc) {
202 case ARM64::Bcc:
203 case ARM64::CBZW:
204 case ARM64::CBZX:
205 case ARM64::CBNZW:
206 case ARM64::CBNZX:
207 case ARM64::TBZ:
208 case ARM64::TBNZ:
209 return true;
210 default:
211 return false;
212 }
213}
214
215static inline bool isIndirectBranchOpcode(int Opc) { return Opc == ARM64::BR; }
216
217} // end namespace llvm
218
219#endif