LLVM 22.0.0git
RISCVISelDAGToDAG.h
Go to the documentation of this file.
1//===---- RISCVISelDAGToDAG.h - A dag to dag inst selector for RISC-V -----===//
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 defines an instruction selector for the RISC-V target.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_RISCV_RISCVISELDAGTODAG_H
14#define LLVM_LIB_TARGET_RISCV_RISCVISELDAGTODAG_H
15
16#include "RISCV.h"
17#include "RISCVTargetMachine.h"
20
21// RISC-V specific code to select RISC-V machine instructions for
22// SelectionDAG operations.
23namespace llvm {
25 const RISCVSubtarget *Subtarget = nullptr;
26
27public:
29
33
35 Subtarget = &MF.getSubtarget<RISCVSubtarget>();
37 }
38
39 void PreprocessISelDAG() override;
40 void PostprocessISelDAG() override;
41
42 void Select(SDNode *Node) override;
43
45 InlineAsm::ConstraintCode ConstraintID,
46 std::vector<SDValue> &OutOps) override;
47
48 bool areOffsetsWithinAlignment(SDValue Addr, Align Alignment);
49
54
55 bool SelectAddrRegRegScale(SDValue Addr, unsigned MaxShiftAmount,
56 SDValue &Base, SDValue &Index, SDValue &Scale);
57
58 template <unsigned MaxShift>
60 SDValue &Scale) {
61 return SelectAddrRegRegScale(Addr, MaxShift, Base, Index, Scale);
62 }
63
64 bool SelectAddrRegZextRegScale(SDValue Addr, unsigned MaxShiftAmount,
65 unsigned Bits, SDValue &Base, SDValue &Index,
66 SDValue &Scale);
67
68 template <unsigned MaxShift, unsigned Bits>
70 SDValue &Scale) {
71 return SelectAddrRegZextRegScale(Addr, MaxShift, Bits, Base, Index, Scale);
72 }
73
75
80 SDValue X, unsigned Msb, unsigned Lsb);
82 SDValue X, unsigned Msb, unsigned Lsb);
84
85 bool selectShiftMask(SDValue N, unsigned ShiftWidth, SDValue &ShAmt);
87 return selectShiftMask(N, Subtarget->getXLen(), ShAmt);
88 }
90 return selectShiftMask(N, 32, ShAmt);
91 }
92
93 bool selectSETCC(SDValue N, ISD::CondCode ExpectedCCVal, SDValue &Val);
95 return selectSETCC(N, ISD::SETNE, Val);
96 }
98 return selectSETCC(N, ISD::SETEQ, Val);
99 }
100
101 bool selectSExtBits(SDValue N, unsigned Bits, SDValue &Val);
102 template <unsigned Bits> bool selectSExtBits(SDValue N, SDValue &Val) {
103 return selectSExtBits(N, Bits, Val);
104 }
105 bool selectZExtBits(SDValue N, unsigned Bits, SDValue &Val);
106 template <unsigned Bits> bool selectZExtBits(SDValue N, SDValue &Val) {
107 return selectZExtBits(N, Bits, Val);
108 }
109
110 bool selectSHXADDOp(SDValue N, unsigned ShAmt, SDValue &Val);
111 template <unsigned ShAmt> bool selectSHXADDOp(SDValue N, SDValue &Val) {
112 return selectSHXADDOp(N, ShAmt, Val);
113 }
114
115 bool selectSHXADD_UWOp(SDValue N, unsigned ShAmt, SDValue &Val);
116 template <unsigned ShAmt> bool selectSHXADD_UWOp(SDValue N, SDValue &Val) {
117 return selectSHXADD_UWOp(N, ShAmt, Val);
118 }
119
120 bool selectZExtImm32(SDValue N, SDValue &Val);
121 bool selectNegImm(SDValue N, SDValue &Val);
123
124 bool orDisjoint(const SDNode *Node) const;
125 bool hasAllNBitUsers(SDNode *Node, unsigned Bits,
126 const unsigned Depth = 0) const;
127 bool hasAllBUsers(SDNode *Node) const { return hasAllNBitUsers(Node, 8); }
128 bool hasAllHUsers(SDNode *Node) const { return hasAllNBitUsers(Node, 16); }
129 bool hasAllWUsers(SDNode *Node) const { return hasAllNBitUsers(Node, 32); }
130
131 bool selectSimm5Shl2(SDValue N, SDValue &Simm5, SDValue &Shl2);
132
133 bool selectVLOp(SDValue N, SDValue &VL);
134
135 bool selectVSplat(SDValue N, SDValue &SplatVal);
136 bool selectVSplatSimm5(SDValue N, SDValue &SplatVal);
137 bool selectVSplatUimm(SDValue N, unsigned Bits, SDValue &SplatVal);
138 template <unsigned Bits> bool selectVSplatUimmBits(SDValue N, SDValue &Val) {
139 return selectVSplatUimm(N, Bits, Val);
140 }
141 bool selectVSplatSimm5Plus1(SDValue N, SDValue &SplatVal);
144 bool selectVSplatImm64Neg(SDValue N, SDValue &SplatVal);
145 // Matches the splat of a value which can be extended or truncated, such that
146 // only the bottom 8 bits are preserved.
147 bool selectLow8BitsVSplat(SDValue N, SDValue &SplatVal);
149
150 bool selectRVVSimm5(SDValue N, unsigned Width, SDValue &Imm);
151 template <unsigned Width> bool selectRVVSimm5(SDValue N, SDValue &Imm) {
152 return selectRVVSimm5(N, Width, Imm);
153 }
154
155 void addVectorLoadStoreOperands(SDNode *Node, unsigned SEWImm,
156 const SDLoc &DL, unsigned CurOp,
157 bool IsMasked, bool IsStridedOrIndexed,
159 bool IsLoad = false, MVT *IndexVT = nullptr);
160
161 void selectVLSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsStrided);
162 void selectVLSEGFF(SDNode *Node, unsigned NF, bool IsMasked);
163 void selectVLXSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsOrdered);
164 void selectVSSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsStrided);
165 void selectVSXSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsOrdered);
166
168
170
171 // Return the RISC-V condition code that matches the given DAG integer
172 // condition code. The CondCode must be one of those supported by the RISC-V
173 // ISA (see translateSetCCForBranch).
175 switch (CC) {
176 default:
177 llvm_unreachable("Unsupported CondCode");
178 case ISD::SETEQ:
179 return RISCVCC::COND_EQ;
180 case ISD::SETNE:
181 return RISCVCC::COND_NE;
182 case ISD::SETLT:
183 return RISCVCC::COND_LT;
184 case ISD::SETGE:
185 return RISCVCC::COND_GE;
186 case ISD::SETULT:
187 return RISCVCC::COND_LTU;
188 case ISD::SETUGE:
189 return RISCVCC::COND_GEU;
190 }
191 }
192
193// Include the pieces autogenerated from the target description.
194#define GET_DAGISEL_DECL
195#include "RISCVGenDAGISel.inc"
196
197private:
198 bool doPeepholeSExtW(SDNode *Node);
199 bool doPeepholeMaskedRVV(MachineSDNode *Node);
200 bool doPeepholeNoRegPassThru();
201 bool performCombineVMergeAndVOps(SDNode *N);
202 bool selectImm64IfCheaper(int64_t Imm, int64_t OrigImm, SDValue N,
203 SDValue &Val);
204};
205
207public:
208 static char ID;
210 CodeGenOptLevel OptLevel);
211};
212
213} // namespace llvm
214
215#endif
return SDValue()
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
mir Rename Register Operands
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
Machine Value Type.
RISCVDAGToDAGISelLegacy(RISCVTargetMachine &TargetMachine, CodeGenOptLevel OptLevel)
bool selectSETCC(SDValue N, ISD::CondCode ExpectedCCVal, SDValue &Val)
RISC-V doesn't have general instructions for integer setne/seteq, but we can check for equality with ...
bool selectSExtBits(SDValue N, unsigned Bits, SDValue &Val)
bool selectNegImm(SDValue N, SDValue &Val)
bool selectSHXADD_UWOp(SDValue N, SDValue &Val)
bool selectZExtBits(SDValue N, unsigned Bits, SDValue &Val)
bool selectSHXADD_UWOp(SDValue N, unsigned ShAmt, SDValue &Val)
Look for various patterns that can be done with a SHL that can be folded into a SHXADD_UW.
bool areOffsetsWithinAlignment(SDValue Addr, Align Alignment)
bool hasAllNBitUsers(SDNode *Node, unsigned Bits, const unsigned Depth=0) const
bool selectVSplatUimmBits(SDValue N, SDValue &Val)
bool SelectAddrRegImmLsb00000(SDValue Addr, SDValue &Base, SDValue &Offset)
Similar to SelectAddrRegImm, except that the least significant 5 bits of Offset should be all zeros.
bool selectZExtImm32(SDValue N, SDValue &Val)
bool selectShiftMaskXLen(SDValue N, SDValue &ShAmt)
bool SelectAddrRegZextRegScale(SDValue Addr, unsigned MaxShiftAmount, unsigned Bits, SDValue &Base, SDValue &Index, SDValue &Scale)
bool SelectAddrRegReg(SDValue Addr, SDValue &Base, SDValue &Offset)
bool selectSETEQ(SDValue N, SDValue &Val)
void selectVSXSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsOrdered)
RISCVDAGToDAGISel(RISCVTargetMachine &TargetMachine, CodeGenOptLevel OptLevel)
void selectVLSEGFF(SDNode *Node, unsigned NF, bool IsMasked)
bool selectVSplatSimm5Plus1NoDec(SDValue N, SDValue &SplatVal)
bool selectSimm5Shl2(SDValue N, SDValue &Simm5, SDValue &Shl2)
void selectSF_VC_X_SE(SDNode *Node)
bool orDisjoint(const SDNode *Node) const
bool selectLow8BitsVSplat(SDValue N, SDValue &SplatVal)
bool hasAllHUsers(SDNode *Node) const
bool SelectInlineAsmMemoryOperand(const SDValue &Op, InlineAsm::ConstraintCode ConstraintID, std::vector< SDValue > &OutOps) override
SelectInlineAsmMemoryOperand - Select the specified address as a target addressing mode,...
bool selectVSplatSimm5(SDValue N, SDValue &SplatVal)
bool selectRVVSimm5(SDValue N, unsigned Width, SDValue &Imm)
bool SelectAddrFrameIndex(SDValue Addr, SDValue &Base, SDValue &Offset)
bool tryUnsignedBitfieldInsertInZero(SDNode *Node, const SDLoc &DL, MVT VT, SDValue X, unsigned Msb, unsigned Lsb)
bool hasAllWUsers(SDNode *Node) const
void PreprocessISelDAG() override
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
bool runOnMachineFunction(MachineFunction &MF) override
bool selectInvLogicImm(SDValue N, SDValue &Val)
bool SelectAddrRegImm(SDValue Addr, SDValue &Base, SDValue &Offset)
bool selectSExtBits(SDValue N, SDValue &Val)
bool trySignedBitfieldInsertInSign(SDNode *Node)
bool selectVSplat(SDValue N, SDValue &SplatVal)
void addVectorLoadStoreOperands(SDNode *Node, unsigned SEWImm, const SDLoc &DL, unsigned CurOp, bool IsMasked, bool IsStridedOrIndexed, SmallVectorImpl< SDValue > &Operands, bool IsLoad=false, MVT *IndexVT=nullptr)
void PostprocessISelDAG() override
PostprocessISelDAG() - This hook allows the target to hack on the graph right after selection.
bool SelectAddrRegImm9(SDValue Addr, SDValue &Base, SDValue &Offset)
Similar to SelectAddrRegImm, except that the offset is restricted to uimm9.
bool selectScalarFPAsInt(SDValue N, SDValue &Imm)
bool hasAllBUsers(SDNode *Node) const
void selectVLSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsStrided)
bool tryShrinkShlLogicImm(SDNode *Node)
bool selectSETNE(SDValue N, SDValue &Val)
bool SelectAddrRegRegScale(SDValue Addr, SDValue &Base, SDValue &Index, SDValue &Scale)
void selectVSETVLI(SDNode *Node)
bool selectShiftMask32(SDValue N, SDValue &ShAmt)
bool selectVLOp(SDValue N, SDValue &VL)
bool trySignedBitfieldExtract(SDNode *Node)
bool selectVSplatSimm5Plus1(SDValue N, SDValue &SplatVal)
bool selectRVVSimm5(SDValue N, SDValue &Imm)
void selectVSSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsStrided)
bool selectVSplatImm64Neg(SDValue N, SDValue &SplatVal)
bool selectVSplatSimm5Plus1NonZero(SDValue N, SDValue &SplatVal)
bool SelectAddrRegZextRegScale(SDValue Addr, SDValue &Base, SDValue &Index, SDValue &Scale)
bool selectSHXADDOp(SDValue N, SDValue &Val)
bool tryUnsignedBitfieldExtract(SDNode *Node, const SDLoc &DL, MVT VT, SDValue X, unsigned Msb, unsigned Lsb)
bool selectZExtBits(SDValue N, SDValue &Val)
void selectVLXSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsOrdered)
bool selectShiftMask(SDValue N, unsigned ShiftWidth, SDValue &ShAmt)
bool selectSHXADDOp(SDValue N, unsigned ShAmt, SDValue &Val)
Look for various patterns that can be done with a SHL that can be folded into a SHXADD.
bool tryIndexedLoad(SDNode *Node)
bool SelectAddrRegRegScale(SDValue Addr, unsigned MaxShiftAmount, SDValue &Base, SDValue &Index, SDValue &Scale)
static RISCVCC::CondCode getRISCVCCForIntCC(ISD::CondCode CC)
bool selectVSplatUimm(SDValue N, unsigned Bits, SDValue &SplatVal)
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SelectionDAGISelLegacy(char &ID, std::unique_ptr< SelectionDAGISel > S)
SelectionDAGISel(TargetMachine &tm, CodeGenOptLevel OL=CodeGenOptLevel::Default)
virtual bool runOnMachineFunction(MachineFunction &mf)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Primary interface to the complete machine description for the target machine.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
DWARFExpression::Operation Op
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39