1 //===- ARM64InstrInfo.h - ARM64 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 ARM64 implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_ARM64INSTRINFO_H
15 #define LLVM_TARGET_ARM64INSTRINFO_H
18 #include "ARM64RegisterInfo.h"
19 #include "llvm/Target/TargetInstrInfo.h"
21 #define GET_INSTRINFO_HEADER
22 #include "ARM64GenInstrInfo.inc"
27 class ARM64TargetMachine;
29 class 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 {
36 const ARM64RegisterInfo RI;
37 const ARM64Subtarget &Subtarget;
40 explicit ARM64InstrInfo(const ARM64Subtarget &STI);
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; }
47 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
49 virtual bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
50 unsigned &DstReg, unsigned &SubIdx) const;
52 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
53 int &FrameIndex) const;
54 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
55 int &FrameIndex) const;
57 /// \brief Does this instruction set its full destination register to zero?
58 bool isGPRZero(const MachineInstr *MI) const;
60 /// \brief Does this instruction rename a GPR without modifying bits?
61 bool isGPRCopy(const MachineInstr *MI) const;
63 /// \brief Does this instruction rename an FPR without modifying bits?
64 bool isFPRCopy(const MachineInstr *MI) const;
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;
71 /// Return true if pairing the given load or store is hinted to be
73 bool isLdStPairSuppressed(const MachineInstr *MI) const;
75 /// Hint that pairing the given load or store is unprofitable.
76 void suppressLdStPair(MachineInstr *MI) const;
78 virtual bool getLdStBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
80 const TargetRegisterInfo *TRI) const;
82 virtual bool enableClusterLoads() const { return true; }
84 virtual bool shouldClusterLoads(MachineInstr *FirstLdSt,
85 MachineInstr *SecondLdSt,
86 unsigned NumLoads) const;
88 virtual bool shouldScheduleAdjacent(MachineInstr *First,
89 MachineInstr *Second) const;
91 MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
92 uint64_t Offset, const MDNode *MDPtr,
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,
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;
109 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
110 MachineBasicBlock::iterator MBBI,
111 unsigned DestReg, int FrameIndex,
112 const TargetRegisterClass *RC,
113 const TargetRegisterInfo *TRI) const;
115 virtual MachineInstr *
116 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
117 const SmallVectorImpl<unsigned> &Ops,
118 int FrameIndex) const;
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,
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,
137 const SmallVectorImpl<MachineOperand> &Cond,
138 unsigned TrueReg, unsigned FalseReg) const;
139 virtual void getNoopForMachoTarget(MCInst &NopInst) const;
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;
154 void instantiateCondBranch(MachineBasicBlock &MBB, DebugLoc DL,
155 MachineBasicBlock *TBB,
156 const SmallVectorImpl<MachineOperand> &Cond) const;
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.
163 void 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);
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.
172 bool rewriteARM64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
173 unsigned FrameReg, int &Offset,
174 const ARM64InstrInfo *TII);
176 /// \brief Use to report the frame offset status in isARM64FrameOffsetLegal.
177 enum ARM64FrameOffsetStatus {
178 ARM64FrameOffsetCannotUpdate = 0x0, ///< Offset cannot apply.
179 ARM64FrameOffsetIsLegal = 0x1, ///< Offset is legal.
180 ARM64FrameOffsetCanUpdate = 0x2 ///< Offset can apply, at least partly.
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
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.
197 int isARM64FrameOffsetLegal(const MachineInstr &MI, int &Offset,
198 bool *OutUseUnscaledOp = NULL,
199 unsigned *OutUnscaledOp = NULL,
200 int *EmittableOffset = NULL);
202 static inline bool isUncondBranchOpcode(int Opc) { return Opc == ARM64::B; }
204 static inline bool isCondBranchOpcode(int Opc) {
219 static inline bool isIndirectBranchOpcode(int Opc) { return Opc == ARM64::BR; }
221 } // end namespace llvm