LLVM 22.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 TargetRegisterClass;
39class TargetRegisterInfo;
40
42 virtual void anchor();
43
44protected:
46 unsigned UncondBrOpc;
47
48public:
50 BT_None, // Couldn't analyze branch.
51 BT_NoBranch, // No branches found.
52 BT_Uncond, // One unconditional branch.
53 BT_Cond, // One conditional branch.
54 BT_CondUncond, // A conditional branch followed by an unconditional branch.
55 BT_Indirect // One indirct branch.
56 };
57
58 explicit MipsInstrInfo(const MipsSubtarget &STI, const MipsRegisterInfo &RI,
59 unsigned UncondBrOpc);
60
61 MCInst getNop() const override;
62
63 static const MipsInstrInfo *create(MipsSubtarget &STI);
64
65 /// Branch Analysis
69 bool AllowModify) const override;
70
72 int *BytesRemoved = nullptr) const override;
73
76 const DebugLoc &DL,
77 int *BytesAdded = nullptr) const override;
78
79 bool
81
85 bool AllowModify,
86 SmallVectorImpl<MachineInstr *> &BranchInstrs) const;
87
88 /// Determine the opcode of a non-delay slot form for a branch if one exists.
90
91 /// Determine if the branch target is in range.
92 bool isBranchOffsetInRange(unsigned BranchOpc,
93 int64_t BrOffset) const override;
94
95 bool SafeAfterMflo(const MachineInstr &MI) const;
96
97 /// Predicate to determine if an instruction can go in a forbidden slot.
98 bool SafeInForbiddenSlot(const MachineInstr &MI) const;
99
100 /// Predicate to determine if an instruction can go in an FPU delay slot.
101 bool SafeInFPUDelaySlot(const MachineInstr &MIInSlot,
102 const MachineInstr &FPUMI) const;
103
104 /// Predicate to determine if an instruction can go in a load delay slot.
105 bool SafeInLoadDelaySlot(const MachineInstr &MIInSlot,
106 const MachineInstr &LoadMI) const;
107
108 bool IsMfloOrMfhi(const MachineInstr &MI) const;
109
110 /// Predicate to determine if an instruction has a forbidden slot.
111 bool HasForbiddenSlot(const MachineInstr &MI) const;
112
113 /// Predicate to determine if an instruction has an FPU delay slot.
114 bool HasFPUDelaySlot(const MachineInstr &MI) const;
115
116 /// Predicate to determine if an instruction has a load delay slot.
117 bool HasLoadDelaySlot(const MachineInstr &MI) const;
118
119 bool isAsCheapAsAMove(const MachineInstr &MI) const override;
120
121 /// Insert nop instruction when hazard condition is found
123 MachineBasicBlock::iterator MI) const override;
124
125 /// Insert an ISA appropriate `nop`.
126 // FIXME: Add support for MIPS16e.
129 DebugLoc DL) const;
130
131 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
132 /// such, whenever a client has an instance of instruction info, it should
133 /// always be able to get register info as well (through this method).
135 return static_cast<const MipsRegisterInfo &>(
137 }
138
139 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
140
141 virtual bool isBranchWithImm(unsigned Opc) const {
142 return false;
143 }
144
145 /// Return the number of bytes of code the specified instruction may be.
146 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
147
150 bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
151 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override {
152 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, 0, Flags);
153 }
154
157 Register DestReg, int FrameIndex, const TargetRegisterClass *RC,
158 Register VReg,
159 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override {
160 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, 0, Flags);
161 }
162
163 virtual void
165 Register SrcReg, bool isKill, int FrameIndex,
166 const TargetRegisterClass *RC, int64_t Offset,
168
169 virtual void loadRegFromStack(
171 int FrameIndex, const TargetRegisterClass *RC, int64_t Offset,
173
174 virtual void adjustStackPtr(unsigned SP, int64_t Amount,
177
178 /// Create an instruction which has the same operands and memory operands
179 /// as MI but has a new opcode.
182
183 bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,
184 unsigned &SrcOpIdx2) const override;
185
186 /// Perform target specific instruction verification.
188 StringRef &ErrInfo) const override;
189
190 std::pair<unsigned, unsigned>
191 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
192
195
196 std::optional<RegImmPair> isAddImmediate(const MachineInstr &MI,
197 Register Reg) const override;
198
199 std::optional<ParamLoadedValue>
200 describeLoadedValue(const MachineInstr &MI, Register Reg) const override;
201
202protected:
203 bool isZeroImm(const MachineOperand &op) const;
204
206 MachineMemOperand::Flags Flags) const;
207
208private:
209 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
210
211 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
214
215 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
217};
218
219/// Create MipsInstrInfo objects.
222
223namespace Mips {
224// Mask assignments for floating-point.
237
238} // namespace Mips
239
240} // end namespace llvm
241
242#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
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
A debug info location.
Definition DebugLoc.h:124
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
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
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) 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...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
const TargetRegisterInfo & getRegisterInfo() const
@ FClassMaskNegativeInfinity
@ FClassMaskPositiveNormal
@ FClassMaskPositiveInfinity
@ FClassMaskNegativeSubnormal
@ FClassMaskPositiveSubnormal
@ FClassMaskNegativeNormal
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
const MipsInstrInfo * createMipsSEInstrInfo(const MipsSubtarget &STI)
const MipsInstrInfo * createMips16InstrInfo(const MipsSubtarget &STI)
Create MipsInstrInfo objects.