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,
73 const SmallVectorImpl<MachineOperand> &Cond,
74 DebugLoc DL) const override;
76 bool analyzeCompare(const MachineInstr *MI,
77 unsigned &SrcReg, unsigned &SrcReg2,
78 int &Mask, int &Value) const override;
80 void copyPhysReg(MachineBasicBlock &MBB,
81 MachineBasicBlock::iterator I, DebugLoc DL,
82 unsigned DestReg, unsigned SrcReg,
83 bool KillSrc) const override;
85 void storeRegToStackSlot(MachineBasicBlock &MBB,
86 MachineBasicBlock::iterator MBBI,
87 unsigned SrcReg, bool isKill, int FrameIndex,
88 const TargetRegisterClass *RC,
89 const TargetRegisterInfo *TRI) const override;
91 void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
92 SmallVectorImpl<MachineOperand> &Addr,
93 const TargetRegisterClass *RC,
94 SmallVectorImpl<MachineInstr*> &NewMIs) const;
96 void loadRegFromStackSlot(MachineBasicBlock &MBB,
97 MachineBasicBlock::iterator MBBI,
98 unsigned DestReg, int FrameIndex,
99 const TargetRegisterClass *RC,
100 const TargetRegisterInfo *TRI) const override;
102 void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
103 SmallVectorImpl<MachineOperand> &Addr,
104 const TargetRegisterClass *RC,
105 SmallVectorImpl<MachineInstr*> &NewMIs) const;
107 /// expandPostRAPseudo - This function is called for all pseudo instructions
108 /// that remain after register allocation. Many pseudo instructions are
109 /// created to help register allocation. This is the place to convert them
110 /// into real instructions. The target can edit MI in place, or it can insert
111 /// new instructions and erase MI. The function should return true if
112 /// anything was changed.
113 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
115 MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
116 ArrayRef<unsigned> Ops,
117 int FrameIndex) const override;
119 MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
120 ArrayRef<unsigned> Ops,
121 MachineInstr *LoadMI) const override {
125 unsigned createVR(MachineFunction* MF, MVT VT) const;
127 bool isBranch(const MachineInstr *MI) const;
128 bool isPredicable(MachineInstr *MI) const override;
129 bool PredicateInstruction(MachineInstr *MI,
130 const SmallVectorImpl<MachineOperand> &Cond) const override;
132 bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
133 unsigned ExtraPredCycles,
134 const BranchProbability &Probability) const override;
136 bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
137 unsigned NumTCycles, unsigned ExtraTCycles,
138 MachineBasicBlock &FMBB,
139 unsigned NumFCycles, unsigned ExtraFCycles,
140 const BranchProbability &Probability) const override;
142 bool isPredicated(const MachineInstr *MI) const override;
143 bool isPredicated(unsigned Opcode) const;
144 bool isPredicatedTrue(const MachineInstr *MI) const;
145 bool isPredicatedTrue(unsigned Opcode) const;
146 bool isPredicatedNew(const MachineInstr *MI) const;
147 bool isPredicatedNew(unsigned Opcode) const;
148 bool DefinesPredicate(MachineInstr *MI,
149 std::vector<MachineOperand> &Pred) const override;
150 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
151 const SmallVectorImpl<MachineOperand> &Pred2) const override;
154 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
156 bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
157 const BranchProbability &Probability) const override;
160 CreateTargetScheduleState(const TargetSubtargetInfo &STI) const override;
162 bool isSchedulingBoundary(const MachineInstr *MI,
163 const MachineBasicBlock *MBB,
164 const MachineFunction &MF) const override;
165 bool isValidOffset(unsigned Opcode, int Offset, bool Extend = true) const;
166 bool isValidAutoIncImm(const EVT VT, const int Offset) const;
167 bool isMemOp(const MachineInstr *MI) const;
168 bool isSpillPredRegOp(const MachineInstr *MI) const;
169 bool isU6_3Immediate(const int value) const;
170 bool isU6_2Immediate(const int value) const;
171 bool isU6_1Immediate(const int value) const;
172 bool isU6_0Immediate(const int value) const;
173 bool isS4_3Immediate(const int value) const;
174 bool isS4_2Immediate(const int value) const;
175 bool isS4_1Immediate(const int value) const;
176 bool isS4_0Immediate(const int value) const;
177 bool isS12_Immediate(const int value) const;
178 bool isU6_Immediate(const int value) const;
179 bool isS8_Immediate(const int value) const;
180 bool isS6_Immediate(const int value) const;
182 bool isSaveCalleeSavedRegsCall(const MachineInstr* MI) const;
183 bool isConditionalTransfer(const MachineInstr* MI) const;
184 bool isConditionalALU32 (const MachineInstr* MI) const;
185 bool isConditionalLoad (const MachineInstr* MI) const;
186 bool isConditionalStore(const MachineInstr* MI) const;
187 bool isNewValueInst(const MachineInstr* MI) const;
188 bool isNewValue(const MachineInstr* MI) const;
189 bool isNewValue(Opcode_t Opcode) const;
190 bool isDotNewInst(const MachineInstr* MI) const;
191 int GetDotOldOp(const int opc) const;
192 int GetDotNewOp(const MachineInstr* MI) const;
193 int GetDotNewPredOp(MachineInstr *MI,
194 const MachineBranchProbabilityInfo
196 bool mayBeNewStore(const MachineInstr* MI) const;
197 bool isDeallocRet(const MachineInstr *MI) const;
198 unsigned getInvertedPredicatedOpcode(const int Opc) const;
199 bool isExtendable(const MachineInstr* MI) const;
200 bool isExtended(const MachineInstr* MI) const;
201 bool isPostIncrement(const MachineInstr* MI) const;
202 bool isNewValueStore(const MachineInstr* MI) const;
203 bool isNewValueStore(unsigned Opcode) const;
204 bool isNewValueJump(const MachineInstr* MI) const;
205 bool isNewValueJump(Opcode_t Opcode) const;
206 bool isNewValueJumpCandidate(const MachineInstr *MI) const;
209 void immediateExtend(MachineInstr *MI) const;
210 bool isConstExtended(const MachineInstr *MI) const;
211 unsigned getSize(const MachineInstr *MI) const;
212 int getDotNewPredJumpOp(MachineInstr *MI,
213 const MachineBranchProbabilityInfo *MBPI) const;
214 unsigned getAddrMode(const MachineInstr* MI) const;
215 bool isOperandExtended(const MachineInstr *MI,
216 unsigned short OperandNum) const;
217 unsigned short getCExtOpNum(const MachineInstr *MI) const;
218 int getMinValue(const MachineInstr *MI) const;
219 int getMaxValue(const MachineInstr *MI) const;
220 bool NonExtEquivalentExists (const MachineInstr *MI) const;
221 short getNonExtOpcode(const MachineInstr *MI) const;
222 bool PredOpcodeHasJMP_c(Opcode_t Opcode) const;
223 bool predOpcodeHasNot(const SmallVectorImpl<MachineOperand> &Cond) const;
224 bool isEndLoopN(Opcode_t Opcode) const;
225 bool getPredReg(const SmallVectorImpl<MachineOperand> &Cond,
226 unsigned &PredReg, unsigned &PredRegPos,
227 unsigned &PredRegFlags) const;
228 int getCondOpcode(int Opc, bool sense) const;