2 //===- HexagonInstrInfo.h - Hexagon Instruction Information -----*- C++ -*-===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This file contains the Hexagon implementation of the TargetInstrInfo class.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONINSTRINFO_H
16 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONINSTRINFO_H
18 #include "HexagonRegisterInfo.h"
19 #include "MCTargetDesc/HexagonBaseInfo.h"
20 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
21 #include "llvm/Target/TargetFrameLowering.h"
22 #include "llvm/Target/TargetInstrInfo.h"
24 #define GET_INSTRINFO_HEADER
25 #include "HexagonGenInstrInfo.inc"
30 class HexagonSubtarget;
31 class HexagonInstrInfo : public HexagonGenInstrInfo {
32 virtual void anchor();
33 const HexagonRegisterInfo RI;
34 const HexagonSubtarget &Subtarget;
37 typedef unsigned Opcode_t;
39 explicit HexagonInstrInfo(HexagonSubtarget &ST);
41 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
42 /// such, whenever a client has an instance of instruction info, it should
43 /// always be able to get register info as well (through this method).
45 const HexagonRegisterInfo &getRegisterInfo() const { return RI; }
47 /// isLoadFromStackSlot - If the specified machine instruction is a direct
48 /// load from a stack slot, return the virtual or physical register number of
49 /// the destination along with the FrameIndex of the loaded stack slot. If
50 /// not, return 0. This predicate must return 0 if the instruction has
51 /// any side effects other than loading from the stack slot.
52 unsigned isLoadFromStackSlot(const MachineInstr *MI,
53 int &FrameIndex) const override;
55 /// isStoreToStackSlot - If the specified machine instruction is a direct
56 /// store to a stack slot, return the virtual or physical register number of
57 /// the source reg along with the FrameIndex of the loaded stack slot. If
58 /// not, return 0. This predicate must return 0 if the instruction has
59 /// any side effects other than storing to the stack slot.
60 unsigned isStoreToStackSlot(const MachineInstr *MI,
61 int &FrameIndex) const override;
64 bool AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
65 MachineBasicBlock *&FBB,
66 SmallVectorImpl<MachineOperand> &Cond,
67 bool AllowModify) const override;
69 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
71 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
72 MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
73 DebugLoc DL) const override;
75 bool analyzeCompare(const MachineInstr *MI,
76 unsigned &SrcReg, unsigned &SrcReg2,
77 int &Mask, int &Value) const override;
79 void copyPhysReg(MachineBasicBlock &MBB,
80 MachineBasicBlock::iterator I, DebugLoc DL,
81 unsigned DestReg, unsigned SrcReg,
82 bool KillSrc) const override;
84 void storeRegToStackSlot(MachineBasicBlock &MBB,
85 MachineBasicBlock::iterator MBBI,
86 unsigned SrcReg, bool isKill, int FrameIndex,
87 const TargetRegisterClass *RC,
88 const TargetRegisterInfo *TRI) const override;
90 void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
91 SmallVectorImpl<MachineOperand> &Addr,
92 const TargetRegisterClass *RC,
93 SmallVectorImpl<MachineInstr*> &NewMIs) const;
95 void loadRegFromStackSlot(MachineBasicBlock &MBB,
96 MachineBasicBlock::iterator MBBI,
97 unsigned DestReg, int FrameIndex,
98 const TargetRegisterClass *RC,
99 const TargetRegisterInfo *TRI) const override;
101 void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
102 SmallVectorImpl<MachineOperand> &Addr,
103 const TargetRegisterClass *RC,
104 SmallVectorImpl<MachineInstr*> &NewMIs) const;
106 /// expandPostRAPseudo - This function is called for all pseudo instructions
107 /// that remain after register allocation. Many pseudo instructions are
108 /// created to help register allocation. This is the place to convert them
109 /// into real instructions. The target can edit MI in place, or it can insert
110 /// new instructions and erase MI. The function should return true if
111 /// anything was changed.
112 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
114 MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
115 ArrayRef<unsigned> Ops,
116 MachineBasicBlock::iterator InsertPt,
117 int FrameIndex) const override;
119 MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
120 ArrayRef<unsigned> Ops,
121 MachineBasicBlock::iterator InsertPt,
122 MachineInstr *LoadMI) const override {
126 unsigned createVR(MachineFunction* MF, MVT VT) const;
128 bool isBranch(const MachineInstr *MI) const;
129 bool isPredicable(MachineInstr *MI) const override;
130 bool PredicateInstruction(MachineInstr *MI,
131 ArrayRef<MachineOperand> Cond) const override;
133 bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
134 unsigned ExtraPredCycles,
135 const BranchProbability &Probability) const override;
137 bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
138 unsigned NumTCycles, unsigned ExtraTCycles,
139 MachineBasicBlock &FMBB,
140 unsigned NumFCycles, unsigned ExtraFCycles,
141 const BranchProbability &Probability) const override;
143 bool isPredicated(const MachineInstr *MI) const override;
144 bool isPredicated(unsigned Opcode) const;
145 bool isPredicatedTrue(const MachineInstr *MI) const;
146 bool isPredicatedTrue(unsigned Opcode) const;
147 bool isPredicatedNew(const MachineInstr *MI) const;
148 bool isPredicatedNew(unsigned Opcode) const;
149 bool DefinesPredicate(MachineInstr *MI,
150 std::vector<MachineOperand> &Pred) const override;
151 bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
152 ArrayRef<MachineOperand> Pred2) const override;
155 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
157 bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
158 const BranchProbability &Probability) const override;
161 CreateTargetScheduleState(const TargetSubtargetInfo &STI) const override;
163 bool isSchedulingBoundary(const MachineInstr *MI,
164 const MachineBasicBlock *MBB,
165 const MachineFunction &MF) const override;
166 bool isValidOffset(unsigned Opcode, int Offset, bool Extend = true) const;
167 bool isValidAutoIncImm(const EVT VT, const int Offset) const;
168 bool isMemOp(const MachineInstr *MI) const;
169 bool isSpillPredRegOp(const MachineInstr *MI) const;
170 bool isU6_3Immediate(const int value) const;
171 bool isU6_2Immediate(const int value) const;
172 bool isU6_1Immediate(const int value) const;
173 bool isU6_0Immediate(const int value) const;
174 bool isS4_3Immediate(const int value) const;
175 bool isS4_2Immediate(const int value) const;
176 bool isS4_1Immediate(const int value) const;
177 bool isS4_0Immediate(const int value) const;
178 bool isS12_Immediate(const int value) const;
179 bool isU6_Immediate(const int value) const;
180 bool isS8_Immediate(const int value) const;
181 bool isS6_Immediate(const int value) const;
183 bool isSaveCalleeSavedRegsCall(const MachineInstr* MI) const;
184 bool isConditionalTransfer(const MachineInstr* MI) const;
185 bool isConditionalALU32 (const MachineInstr* MI) const;
186 bool isConditionalLoad (const MachineInstr* MI) const;
187 bool isConditionalStore(const MachineInstr* MI) const;
188 bool isNewValueInst(const MachineInstr* MI) const;
189 bool isNewValue(const MachineInstr* MI) const;
190 bool isNewValue(Opcode_t Opcode) const;
191 bool isDotNewInst(const MachineInstr* MI) const;
192 int GetDotOldOp(const int opc) const;
193 int GetDotNewOp(const MachineInstr* MI) const;
194 int GetDotNewPredOp(MachineInstr *MI,
195 const MachineBranchProbabilityInfo
197 bool mayBeNewStore(const MachineInstr* MI) const;
198 bool isDeallocRet(const MachineInstr *MI) const;
199 unsigned getInvertedPredicatedOpcode(const int Opc) const;
200 bool isExtendable(const MachineInstr* MI) const;
201 bool isExtended(const MachineInstr* MI) const;
202 bool isPostIncrement(const MachineInstr* MI) const;
203 bool isNewValueStore(const MachineInstr* MI) const;
204 bool isNewValueStore(unsigned Opcode) const;
205 bool isNewValueJump(const MachineInstr* MI) const;
206 bool isNewValueJump(Opcode_t Opcode) const;
207 bool isNewValueJumpCandidate(const MachineInstr *MI) const;
210 void immediateExtend(MachineInstr *MI) const;
211 bool isConstExtended(const MachineInstr *MI) const;
212 unsigned getSize(const MachineInstr *MI) const;
213 int getDotNewPredJumpOp(MachineInstr *MI,
214 const MachineBranchProbabilityInfo *MBPI) const;
215 unsigned getAddrMode(const MachineInstr* MI) const;
216 bool isOperandExtended(const MachineInstr *MI,
217 unsigned short OperandNum) const;
218 unsigned short getCExtOpNum(const MachineInstr *MI) const;
219 int getMinValue(const MachineInstr *MI) const;
220 int getMaxValue(const MachineInstr *MI) const;
221 bool NonExtEquivalentExists (const MachineInstr *MI) const;
222 short getNonExtOpcode(const MachineInstr *MI) const;
223 bool PredOpcodeHasJMP_c(Opcode_t Opcode) const;
224 bool predOpcodeHasNot(ArrayRef<MachineOperand> Cond) const;
225 bool isEndLoopN(Opcode_t Opcode) const;
226 bool getPredReg(ArrayRef<MachineOperand> Cond, unsigned &PredReg,
227 unsigned &PredRegPos, unsigned &PredRegFlags) const;
228 int getCondOpcode(int Opc, bool sense) const;