LLVM 23.0.0git
MipsInstrInfo.h
Go to the documentation of this file.
1//===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the Mips implementation of the TargetInstrInfo class.
10//
11// FIXME: We need to override TargetInstrInfo::getInlineAsmLength method in
12// order for MipsLongBranch pass to work correctly when the code has inline
13// assembly. The returned value doesn't have to be the asm instruction's exact
14// size in bytes; MipsLongBranch only expects it to be the correct upper bound.
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
18#define LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
19
21#include "Mips.h"
22#include "MipsRegisterInfo.h"
23#include "llvm/ADT/ArrayRef.h"
28#include <cstdint>
29
30#define GET_INSTRINFO_HEADER
31#include "MipsGenInstrInfo.inc"
32
33namespace llvm {
34
35class MachineInstr;
36class MachineOperand;
37class MipsSubtarget;
38class MCRegisterClass;
39using TargetRegisterClass = MCRegisterClass;
40class TargetRegisterInfo;
41
43 virtual void anchor();
44
45protected:
47 unsigned UncondBrOpc;
48
49public:
51 BT_None, // Couldn't analyze branch.
52 BT_NoBranch, // No branches found.
53 BT_Uncond, // One unconditional branch.
54 BT_Cond, // One conditional branch.
55 BT_CondUncond, // A conditional branch followed by an unconditional branch.
56 BT_Indirect // One indirct branch.
57 };
58
59 explicit MipsInstrInfo(const MipsSubtarget &STI, const MipsRegisterInfo &RI,
60 unsigned UncondBrOpc);
61
62 MCInst getNop() const override;
63
64 static const MipsInstrInfo *create(MipsSubtarget &STI);
65
66 /// Branch Analysis
70 bool AllowModify) const override;
71
73 int *BytesRemoved = nullptr) const override;
74
77 const DebugLoc &DL,
78 int *BytesAdded = nullptr) const override;
79
80 bool
82
86 bool AllowModify,
87 SmallVectorImpl<MachineInstr *> &BranchInstrs) const;
88
89 /// Determine the opcode of a non-delay slot form for a branch if one exists.
91
92 /// Determine if the branch target is in range.
93 bool isBranchOffsetInRange(unsigned BranchOpc,
94 int64_t BrOffset) const override;
95
96 bool SafeAfterMflo(const MachineInstr &MI) const;
97
98 /// Predicate to determine if an instruction can go in a forbidden slot.
99 bool SafeInForbiddenSlot(const MachineInstr &MI) const;
100
101 /// Predicate to determine if an instruction can go in an FPU delay slot.
102 bool SafeInFPUDelaySlot(const MachineInstr &MIInSlot,
103 const MachineInstr &FPUMI) const;
104
105 /// Predicate to determine if an instruction can go in a load delay slot.
106 bool SafeInLoadDelaySlot(const MachineInstr &MIInSlot,
107 const MachineInstr &LoadMI) const;
108
109 bool IsMfloOrMfhi(const MachineInstr &MI) const;
110
111 /// Predicate to determine if an instruction has a forbidden slot.
112 bool HasForbiddenSlot(const MachineInstr &MI) const;
113
114 /// Predicate to determine if an instruction has an FPU delay slot.
115 bool HasFPUDelaySlot(const MachineInstr &MI) const;
116
117 /// Predicate to determine if an instruction has a load delay slot.
118 bool HasLoadDelaySlot(const MachineInstr &MI) const;
119
120 bool isAsCheapAsAMove(const MachineInstr &MI) const override;
121
122 /// Insert nop instruction when hazard condition is found
124 MachineBasicBlock::iterator MI) const override;
125
126 /// Insert an ISA appropriate `nop`.
127 // FIXME: Add support for MIPS16e.
130 DebugLoc DL) const;
131
132 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
133 /// such, whenever a client has an instance of instruction info, it should
134 /// always be able to get register info as well (through this method).
136 return static_cast<const MipsRegisterInfo &>(
138 }
139
140 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
141
142 virtual bool isBranchWithImm(unsigned Opc) const {
143 return false;
144 }
145
146 /// Return the number of bytes of code the specified instruction may be.
147 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
148
151 bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
152 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override {
153 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, 0, Flags);
154 }
155
158 Register DestReg, int FrameIndex, const TargetRegisterClass *RC,
159 Register VReg, unsigned SubReg = 0,
160 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override {
161 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, 0, Flags);
162 }
163
164 virtual void
166 Register SrcReg, bool isKill, int FrameIndex,
167 const TargetRegisterClass *RC, int64_t Offset,
169
170 virtual void loadRegFromStack(
172 int FrameIndex, const TargetRegisterClass *RC, int64_t Offset,
174
175 virtual void adjustStackPtr(unsigned SP, int64_t Amount,
178
179 /// Create an instruction which has the same operands and memory operands
180 /// as MI but has a new opcode.
183
184 bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,
185 unsigned &SrcOpIdx2) const override;
186
187 /// Perform target specific instruction verification.
189 StringRef &ErrInfo) const override;
190
191 std::pair<unsigned, unsigned>
192 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
193
196
197 std::optional<RegImmPair> isAddImmediate(const MachineInstr &MI,
198 Register Reg) const override;
199
200 std::optional<ParamLoadedValue>
201 describeLoadedValue(const MachineInstr &MI, Register Reg) const override;
202
203protected:
204 bool isZeroImm(const MachineOperand &op) const;
205
207 MachineMemOperand::Flags Flags) const;
208
209private:
210 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
211
212 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
215
216 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
218};
219
220/// Create MipsInstrInfo objects.
223
224namespace Mips {
225// Mask assignments for floating-point.
238
239} // namespace Mips
240
241} // end namespace llvm
242
243#endif // LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define op(i)
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:126
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
MachineOperand class - Representation of each machine instruction operand.
MCInst getNop() const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
bool SafeAfterMflo(const MachineInstr &MI) const
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
bool SafeInForbiddenSlot(const MachineInstr &MI) const
Predicate to determine if an instruction can go in a forbidden slot.
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
Return the number of bytes of code the specified instruction may be.
MachineInstrBuilder insertNop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, DebugLoc DL) const
Insert an ISA appropriate nop.
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
Determine if the branch target is in range.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Branch Analysis.
const MipsSubtarget & Subtarget
MachineMemOperand * GetMemOperand(MachineBasicBlock &MBB, int FI, MachineMemOperand::Flags Flags) const
MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc, MachineBasicBlock::iterator I) const
Create an instruction which has the same operands and memory operands as MI but has a new opcode.
virtual bool isBranchWithImm(unsigned Opc) const
bool HasForbiddenSlot(const MachineInstr &MI) const
Predicate to determine if an instruction has a forbidden slot.
bool SafeInFPUDelaySlot(const MachineInstr &MIInSlot, const MachineInstr &FPUMI) const
Predicate to determine if an instruction can go in an FPU delay slot.
bool isZeroImm(const MachineOperand &op) const
unsigned getEquivalentCompactForm(const MachineBasicBlock::iterator I) const
Determine the opcode of a non-delay slot form for a branch if one exists.
bool SafeInLoadDelaySlot(const MachineInstr &MIInSlot, const MachineInstr &LoadMI) const
Predicate to determine if an instruction can go in a load delay slot.
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
reverseBranchCondition - Return the inverse opcode of the specified Branch instruction.
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
virtual void loadRegFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, int64_t Offset, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const =0
std::optional< RegImmPair > isAddImmediate(const MachineInstr &MI, Register Reg) const override
bool HasFPUDelaySlot(const MachineInstr &MI) const
Predicate to determine if an instruction has an FPU delay slot.
const MipsRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const override
Perform target specific instruction verification.
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
virtual void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const =0
static const MipsInstrInfo * create(MipsSubtarget &STI)
bool IsMfloOrMfhi(const MachineInstr &MI) const
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
std::optional< ParamLoadedValue > describeLoadedValue(const MachineInstr &MI, Register Reg) const override
virtual void storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, int64_t Offset, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const =0
MipsInstrInfo(const MipsSubtarget &STI, const MipsRegisterInfo &RI, unsigned UncondBrOpc)
virtual unsigned getOppositeBranchOpc(unsigned Opc) const =0
bool HasLoadDelaySlot(const MachineInstr &MI) const
Predicate to determine if an instruction has a load delay slot.
bool isAsCheapAsAMove(const MachineInstr &MI) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
Insert nop instruction when hazard condition is found.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
const TargetRegisterInfo & getRegisterInfo() const
@ FClassMaskNegativeInfinity
@ FClassMaskPositiveNormal
@ FClassMaskPositiveInfinity
@ FClassMaskNegativeSubnormal
@ FClassMaskPositiveSubnormal
@ FClassMaskNegativeNormal
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:573
const MipsInstrInfo * createMipsSEInstrInfo(const MipsSubtarget &STI)
const MipsInstrInfo * createMips16InstrInfo(const MipsSubtarget &STI)
Create MipsInstrInfo objects.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58