1 //===---- RISCVISelDAGToDAG.h - A dag to dag inst selector for RISCV ------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines an instruction selector for the RISCV target.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVISELDAGTODAG_H
14 #define LLVM_LIB_TARGET_RISCV_RISCVISELDAGTODAG_H
17 #include "RISCVTargetMachine.h"
18 #include "llvm/CodeGen/SelectionDAGISel.h"
20 // RISCV-specific code to select RISCV machine instructions for
21 // SelectionDAG operations.
23 class RISCVDAGToDAGISel
: public SelectionDAGISel
{
24 const RISCVSubtarget
*Subtarget
= nullptr;
27 explicit RISCVDAGToDAGISel(RISCVTargetMachine
&TargetMachine
)
28 : SelectionDAGISel(TargetMachine
) {}
30 StringRef
getPassName() const override
{
31 return "RISCV DAG->DAG Pattern Instruction Selection";
34 bool runOnMachineFunction(MachineFunction
&MF
) override
{
35 Subtarget
= &MF
.getSubtarget
<RISCVSubtarget
>();
36 return SelectionDAGISel::runOnMachineFunction(MF
);
39 void PreprocessISelDAG() override
;
40 void PostprocessISelDAG() override
;
42 void Select(SDNode
*Node
) override
;
44 bool SelectInlineAsmMemoryOperand(const SDValue
&Op
, unsigned ConstraintID
,
45 std::vector
<SDValue
> &OutOps
) override
;
47 bool SelectAddrFI(SDValue Addr
, SDValue
&Base
);
48 bool SelectBaseAddr(SDValue Addr
, SDValue
&Base
);
50 bool selectShiftMask(SDValue N
, unsigned ShiftWidth
, SDValue
&ShAmt
);
51 bool selectShiftMaskXLen(SDValue N
, SDValue
&ShAmt
) {
52 return selectShiftMask(N
, Subtarget
->getXLen(), ShAmt
);
54 bool selectShiftMask32(SDValue N
, SDValue
&ShAmt
) {
55 return selectShiftMask(N
, 32, ShAmt
);
58 bool selectSExti32(SDValue N
, SDValue
&Val
);
59 bool selectZExti32(SDValue N
, SDValue
&Val
);
61 bool hasAllNBitUsers(SDNode
*Node
, unsigned Bits
) const;
62 bool hasAllHUsers(SDNode
*Node
) const { return hasAllNBitUsers(Node
, 16); }
63 bool hasAllWUsers(SDNode
*Node
) const { return hasAllNBitUsers(Node
, 32); }
65 bool selectVLOp(SDValue N
, SDValue
&VL
);
67 bool selectVSplat(SDValue N
, SDValue
&SplatVal
);
68 bool selectVSplatSimm5(SDValue N
, SDValue
&SplatVal
);
69 bool selectVSplatUimm5(SDValue N
, SDValue
&SplatVal
);
70 bool selectVSplatSimm5Plus1(SDValue N
, SDValue
&SplatVal
);
71 bool selectVSplatSimm5Plus1NonZero(SDValue N
, SDValue
&SplatVal
);
73 bool selectRVVSimm5(SDValue N
, unsigned Width
, SDValue
&Imm
);
74 template <unsigned Width
> bool selectRVVSimm5(SDValue N
, SDValue
&Imm
) {
75 return selectRVVSimm5(N
, Width
, Imm
);
78 void addVectorLoadStoreOperands(SDNode
*Node
, unsigned SEWImm
,
79 const SDLoc
&DL
, unsigned CurOp
,
80 bool IsMasked
, bool IsStridedOrIndexed
,
81 SmallVectorImpl
<SDValue
> &Operands
,
82 MVT
*IndexVT
= nullptr);
84 void selectVLSEG(SDNode
*Node
, bool IsMasked
, bool IsStrided
);
85 void selectVLSEGFF(SDNode
*Node
, bool IsMasked
);
86 void selectVLXSEG(SDNode
*Node
, bool IsMasked
, bool IsOrdered
);
87 void selectVSSEG(SDNode
*Node
, bool IsMasked
, bool IsStrided
);
88 void selectVSXSEG(SDNode
*Node
, bool IsMasked
, bool IsOrdered
);
90 // Return the RISC-V condition code that matches the given DAG integer
91 // condition code. The CondCode must be one of those supported by the RISC-V
92 // ISA (see translateSetCCForBranch).
93 static RISCVCC::CondCode
getRISCVCCForIntCC(ISD::CondCode CC
) {
96 llvm_unreachable("Unsupported CondCode");
98 return RISCVCC::COND_EQ
;
100 return RISCVCC::COND_NE
;
102 return RISCVCC::COND_LT
;
104 return RISCVCC::COND_GE
;
106 return RISCVCC::COND_LTU
;
108 return RISCVCC::COND_GEU
;
112 // Include the pieces autogenerated from the target description.
113 #include "RISCVGenDAGISel.inc"
116 bool doPeepholeLoadStoreADDI(SDNode
*Node
);
117 bool doPeepholeSExtW(SDNode
*Node
);
124 uint16_t Strided
: 1;
126 uint16_t Log2SEW
: 3;
131 struct VLXSEGPseudo
{
134 uint16_t Ordered
: 1;
135 uint16_t Log2SEW
: 3;
137 uint16_t IndexLMUL
: 3;
144 uint16_t Strided
: 1;
145 uint16_t Log2SEW
: 3;
150 struct VSXSEGPseudo
{
153 uint16_t Ordered
: 1;
154 uint16_t Log2SEW
: 3;
156 uint16_t IndexLMUL
: 3;
162 uint16_t Strided
: 1;
164 uint16_t Log2SEW
: 3;
171 uint16_t Strided
: 1;
172 uint16_t Log2SEW
: 3;
177 struct VLX_VSXPseudo
{
179 uint16_t Ordered
: 1;
180 uint16_t Log2SEW
: 3;
182 uint16_t IndexLMUL
: 3;
186 #define GET_RISCVVSSEGTable_DECL
187 #define GET_RISCVVLSEGTable_DECL
188 #define GET_RISCVVLXSEGTable_DECL
189 #define GET_RISCVVSXSEGTable_DECL
190 #define GET_RISCVVLETable_DECL
191 #define GET_RISCVVSETable_DECL
192 #define GET_RISCVVLXTable_DECL
193 #define GET_RISCVVSXTable_DECL
194 #include "RISCVGenSearchableTables.inc"