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 const ARM64RegisterInfo &getRegisterInfo() const { return RI; }
47 const ARM64Subtarget &getSubTarget() const { return Subtarget; }
49 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
51 bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
52 unsigned &DstReg, unsigned &SubIdx) const override;
54 unsigned isLoadFromStackSlot(const MachineInstr *MI,
55 int &FrameIndex) const override;
56 unsigned isStoreToStackSlot(const MachineInstr *MI,
57 int &FrameIndex) const override;
59 /// \brief Does this instruction set its full destination register to zero?
60 bool isGPRZero(const MachineInstr *MI) const;
62 /// \brief Does this instruction rename a GPR without modifying bits?
63 bool isGPRCopy(const MachineInstr *MI) const;
65 /// \brief Does this instruction rename an FPR without modifying bits?
66 bool isFPRCopy(const MachineInstr *MI) const;
68 /// Return true if this is load/store scales or extends its register offset.
69 /// This refers to scaling a dynamic index as opposed to scaled immediates.
70 /// MI should be a memory op that allows scaled addressing.
71 bool isScaledAddr(const MachineInstr *MI) const;
73 /// Return true if pairing the given load or store is hinted to be
75 bool isLdStPairSuppressed(const MachineInstr *MI) const;
77 /// Hint that pairing the given load or store is unprofitable.
78 void suppressLdStPair(MachineInstr *MI) const;
80 bool getLdStBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
82 const TargetRegisterInfo *TRI) const override;
84 bool enableClusterLoads() const override { return true; }
86 bool shouldClusterLoads(MachineInstr *FirstLdSt, MachineInstr *SecondLdSt,
87 unsigned NumLoads) const override;
89 bool shouldScheduleAdjacent(MachineInstr *First,
90 MachineInstr *Second) const override;
92 MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
93 uint64_t Offset, const MDNode *MDPtr,
95 void copyPhysRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
96 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
97 bool KillSrc, unsigned Opcode,
98 llvm::ArrayRef<unsigned> Indices) const;
99 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
100 DebugLoc DL, unsigned DestReg, unsigned SrcReg,
101 bool KillSrc) const override;
103 void storeRegToStackSlot(MachineBasicBlock &MBB,
104 MachineBasicBlock::iterator MBBI, unsigned SrcReg,
105 bool isKill, int FrameIndex,
106 const TargetRegisterClass *RC,
107 const TargetRegisterInfo *TRI) const override;
109 void loadRegFromStackSlot(MachineBasicBlock &MBB,
110 MachineBasicBlock::iterator MBBI, unsigned DestReg,
111 int FrameIndex, const TargetRegisterClass *RC,
112 const TargetRegisterInfo *TRI) const override;
115 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
116 const SmallVectorImpl<unsigned> &Ops,
117 int FrameIndex) const override;
119 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
120 MachineBasicBlock *&FBB,
121 SmallVectorImpl<MachineOperand> &Cond,
122 bool AllowModify = false) const override;
123 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
124 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
125 MachineBasicBlock *FBB,
126 const SmallVectorImpl<MachineOperand> &Cond,
127 DebugLoc DL) const override;
129 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
130 bool canInsertSelect(const MachineBasicBlock &,
131 const SmallVectorImpl<MachineOperand> &Cond, unsigned,
132 unsigned, int &, int &, int &) const override;
133 void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
134 DebugLoc DL, unsigned DstReg,
135 const SmallVectorImpl<MachineOperand> &Cond,
136 unsigned TrueReg, unsigned FalseReg) const override;
137 void getNoopForMachoTarget(MCInst &NopInst) const override;
139 /// analyzeCompare - For a comparison instruction, return the source registers
140 /// in SrcReg and SrcReg2, and the value it compares against in CmpValue.
141 /// Return true if the comparison instruction can be analyzed.
142 bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
143 unsigned &SrcReg2, int &CmpMask,
144 int &CmpValue) const override;
145 /// optimizeCompareInstr - Convert the instruction supplying the argument to
146 /// the comparison into one that sets the zero bit in the flags register.
147 bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
148 unsigned SrcReg2, int CmpMask, int CmpValue,
149 const MachineRegisterInfo *MRI) const override;
152 void instantiateCondBranch(MachineBasicBlock &MBB, DebugLoc DL,
153 MachineBasicBlock *TBB,
154 const SmallVectorImpl<MachineOperand> &Cond) const;
157 /// emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg
158 /// plus Offset. This is intended to be used from within the prolog/epilog
159 /// insertion (PEI) pass, where a virtual scratch register may be allocated
160 /// if necessary, to be replaced by the scavenger at the end of PEI.
161 void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
162 DebugLoc DL, unsigned DestReg, unsigned SrcReg, int Offset,
163 const ARM64InstrInfo *TII,
164 MachineInstr::MIFlag = MachineInstr::NoFlags,
165 bool SetCPSR = false);
167 /// rewriteARM64FrameIndex - Rewrite MI to access 'Offset' bytes from the
168 /// FP. Return false if the offset could not be handled directly in MI, and
169 /// return the left-over portion by reference.
170 bool rewriteARM64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
171 unsigned FrameReg, int &Offset,
172 const ARM64InstrInfo *TII);
174 /// \brief Use to report the frame offset status in isARM64FrameOffsetLegal.
175 enum ARM64FrameOffsetStatus {
176 ARM64FrameOffsetCannotUpdate = 0x0, ///< Offset cannot apply.
177 ARM64FrameOffsetIsLegal = 0x1, ///< Offset is legal.
178 ARM64FrameOffsetCanUpdate = 0x2 ///< Offset can apply, at least partly.
181 /// \brief Check if the @p Offset is a valid frame offset for @p MI.
182 /// The returned value reports the validity of the frame offset for @p MI.
183 /// It uses the values defined by ARM64FrameOffsetStatus for that.
184 /// If result == ARM64FrameOffsetCannotUpdate, @p MI cannot be updated to
186 /// If result & ARM64FrameOffsetIsLegal, @p Offset can completely be
187 /// rewriten in @p MI.
188 /// If result & ARM64FrameOffsetCanUpdate, @p Offset contains the
189 /// amount that is off the limit of the legal offset.
190 /// If set, @p OutUseUnscaledOp will contain the whether @p MI should be
191 /// turned into an unscaled operator, which opcode is in @p OutUnscaledOp.
192 /// If set, @p EmittableOffset contains the amount that can be set in @p MI
193 /// (possibly with @p OutUnscaledOp if OutUseUnscaledOp is true) and that
194 /// is a legal offset.
195 int isARM64FrameOffsetLegal(const MachineInstr &MI, int &Offset,
196 bool *OutUseUnscaledOp = NULL,
197 unsigned *OutUnscaledOp = NULL,
198 int *EmittableOffset = NULL);
200 static inline bool isUncondBranchOpcode(int Opc) { return Opc == ARM64::B; }
202 static inline bool isCondBranchOpcode(int Opc) {
217 static inline bool isIndirectBranchOpcode(int Opc) { return Opc == ARM64::BR; }
219 } // end namespace llvm