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
52
53 bool SelectAddrRegRegScale(SDValue Addr, unsigned MaxShiftAmount,
54 SDValue &Base, SDValue &Index, SDValue &Scale);
55
56 template <unsigned MaxShift>
58 SDValue &Scale) {
59 return SelectAddrRegRegScale(Addr, MaxShift, Base, Index, Scale);
60 }
61
62 bool SelectAddrRegZextRegScale(SDValue Addr, unsigned MaxShiftAmount,
63 unsigned Bits, SDValue &Base, SDValue &Index,
64 SDValue &Scale);
65
66 template <unsigned MaxShift, unsigned Bits>
68 SDValue &Scale) {
69 return SelectAddrRegZextRegScale(Addr, MaxShift, Bits, Base, Index, Scale);
70 }
71
73
81 SDValue X, unsigned Msb, unsigned Lsb);
83 SDValue X, unsigned Msb, unsigned Lsb);
85
86 bool selectShiftMask(SDValue N, unsigned ShiftWidth, SDValue &ShAmt);
88 return selectShiftMask(N, Subtarget->getXLen(), ShAmt);
89 }
91 return selectShiftMask(N, 32, ShAmt);
92 }
93
94 bool selectSETCC(SDValue N, ISD::CondCode ExpectedCCVal, SDValue &Val);
96 return selectSETCC(N, ISD::SETNE, Val);
97 }
99 return selectSETCC(N, ISD::SETEQ, Val);
100 }
101
102 bool selectSExtBits(SDValue N, unsigned Bits, SDValue &Val);
103 template <unsigned Bits> bool selectSExtBits(SDValue N, SDValue &Val) {
104 return selectSExtBits(N, Bits, Val);
105 }
106 bool selectZExtBits(SDValue N, unsigned Bits, SDValue &Val);
107 template <unsigned Bits> bool selectZExtBits(SDValue N, SDValue &Val) {
108 return selectZExtBits(N, Bits, Val);
109 }
110
111 bool selectSHXADDOp(SDValue N, unsigned ShAmt, SDValue &Val);
112 template <unsigned ShAmt> bool selectSHXADDOp(SDValue N, SDValue &Val) {
113 return selectSHXADDOp(N, ShAmt, Val);
114 }
115
116 bool selectSHXADD_UWOp(SDValue N, unsigned ShAmt, SDValue &Val);
117 template <unsigned ShAmt> bool selectSHXADD_UWOp(SDValue N, SDValue &Val) {
118 return selectSHXADD_UWOp(N, ShAmt, Val);
119 }
120
121 bool selectZExtImm32(SDValue N, SDValue &Val);
122 bool selectNegImm(SDValue N, SDValue &Val);
124
125 bool orDisjoint(const SDNode *Node) const;
126 bool hasAllNBitUsers(SDNode *Node, unsigned Bits,
127 const unsigned Depth = 0) const;
128 bool hasAllBUsers(SDNode *Node) const { return hasAllNBitUsers(Node, 8); }
129 bool hasAllHUsers(SDNode *Node) const { return hasAllNBitUsers(Node, 16); }
130 bool hasAllWUsers(SDNode *Node) const { return hasAllNBitUsers(Node, 32); }
131
132 bool selectSimm5Shl2(SDValue N, SDValue &Simm5, SDValue &Shl2);
133
134 bool selectVLOp(SDValue N, SDValue &VL);
135
136 bool selectVSplat(SDValue N, SDValue &SplatVal);
137 bool selectVSplatSimm5(SDValue N, SDValue &SplatVal);
138 bool selectVSplatUimm(SDValue N, unsigned Bits, SDValue &SplatVal);
139 template <unsigned Bits> bool selectVSplatUimmBits(SDValue N, SDValue &Val) {
140 return selectVSplatUimm(N, Bits, Val);
141 }
142 bool selectVSplatSimm5Plus1(SDValue N, SDValue &SplatVal);
145 bool selectVSplatImm64Neg(SDValue N, SDValue &SplatVal);
146 // Matches the splat of a value which can be extended or truncated, such that
147 // only the bottom 8 bits are preserved.
148 bool selectLow8BitsVSplat(SDValue N, SDValue &SplatVal);
150
151 bool selectRVVSimm5(SDValue N, unsigned Width, SDValue &Imm);
152 template <unsigned Width> bool selectRVVSimm5(SDValue N, SDValue &Imm) {
153 return selectRVVSimm5(N, Width, Imm);
154 }
155
156 void addVectorLoadStoreOperands(SDNode *Node, unsigned SEWImm,
157 const SDLoc &DL, unsigned CurOp,
158 bool IsMasked, bool IsStridedOrIndexed,
160 bool IsLoad = false, MVT *IndexVT = nullptr);
161
162 void selectVLSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsStrided);
163 void selectVLSEGFF(SDNode *Node, unsigned NF, bool IsMasked);
164 void selectVLXSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsOrdered);
165 void selectVSSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsStrided);
166 void selectVSXSEG(SDNode *Node, unsigned NF, bool IsMasked, bool IsOrdered);
167
169
171
172 // Return the RISC-V condition code that matches the given DAG integer
173 // condition code. The CondCode must be one of those supported by the RISC-V
174 // ISA (see translateSetCCForBranch).
176 switch (CC) {
177 default:
178 llvm_unreachable("Unsupported CondCode");
179 case ISD::SETEQ:
180 return RISCVCC::COND_EQ;
181 case ISD::SETNE:
182 return RISCVCC::COND_NE;
183 case ISD::SETLT:
184 return RISCVCC::COND_LT;
185 case ISD::SETGE:
186 return RISCVCC::COND_GE;
187 case ISD::SETULT:
188 return RISCVCC::COND_LTU;
189 case ISD::SETUGE:
190 return RISCVCC::COND_GEU;
191 }
192 }
193
194// Include the pieces autogenerated from the target description.
195#define GET_DAGISEL_DECL
196#include "RISCVGenDAGISel.inc"
197
198private:
199 bool doPeepholeSExtW(SDNode *Node);
200 bool doPeepholeMaskedRVV(MachineSDNode *Node);
201 bool doPeepholeNoRegPassThru();
202 bool performCombineVMergeAndVOps(SDNode *N);
203 bool selectImm64IfCheaper(int64_t Imm, int64_t OrigImm, SDValue N,
204 SDValue &Val);
205};
206
208public:
209 static char ID;
211 CodeGenOptLevel OptLevel);
212};
213
214} // namespace llvm
215
216#endif
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t Addr
uint32_t Index
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
mir Rename Register Operands
This class represents an Operation in the Expression.
Machine Value Type.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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 hasAllNBitUsers(SDNode *Node, unsigned Bits, const unsigned Depth=0) const
bool trySignedBitfieldInsertInMask(SDNode *Node)
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 tryBitfieldInsertOpFromXor(SDNode *Node)
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 tryBitfieldInsertOpFromOrAndImm(SDNode *Node)
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)
unsigned getXLen() const
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.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
MachineFunction * MF
CodeGenOptLevel OptLevel
virtual bool runOnMachineFunction(MachineFunction &mf)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
#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,...
Definition: ISDOpcodes.h:1685
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:82
#define N