xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h (revision 59948e95d8deadafca3acd659b6dfc78b708f117)
1 //===---- RISCVISelDAGToDAG.h - A dag to dag inst selector for RISCV ------===//
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 RISCV 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"
18 #include "llvm/CodeGen/SelectionDAGISel.h"
19 
20 // RISCV-specific code to select RISCV machine instructions for
21 // SelectionDAG operations.
22 namespace llvm {
23 class RISCVDAGToDAGISel : public SelectionDAGISel {
24   const RISCVSubtarget *Subtarget = nullptr;
25 
26 public:
27   explicit RISCVDAGToDAGISel(RISCVTargetMachine &TargetMachine)
28       : SelectionDAGISel(TargetMachine) {}
29 
30   StringRef getPassName() const override {
31     return "RISCV DAG->DAG Pattern Instruction Selection";
32   }
33 
34   bool runOnMachineFunction(MachineFunction &MF) override {
35     Subtarget = &MF.getSubtarget<RISCVSubtarget>();
36     return SelectionDAGISel::runOnMachineFunction(MF);
37   }
38 
39   void PostprocessISelDAG() override;
40 
41   void Select(SDNode *Node) override;
42 
43   bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
44                                     std::vector<SDValue> &OutOps) override;
45 
46   bool SelectAddrFI(SDValue Addr, SDValue &Base);
47 
48   bool SelectSLOI(SDValue N, SDValue &RS1, SDValue &Shamt);
49   bool SelectSROI(SDValue N, SDValue &RS1, SDValue &Shamt);
50   bool SelectRORI(SDValue N, SDValue &RS1, SDValue &Shamt);
51   bool SelectSLLIUW(SDValue N, SDValue &RS1, SDValue &Shamt);
52   bool SelectSLOIW(SDValue N, SDValue &RS1, SDValue &Shamt);
53   bool SelectSROIW(SDValue N, SDValue &RS1, SDValue &Shamt);
54   bool SelectRORIW(SDValue N, SDValue &RS1, SDValue &Shamt);
55   bool SelectFSRIW(SDValue N, SDValue &RS1, SDValue &RS2, SDValue &Shamt);
56 
57 // Include the pieces autogenerated from the target description.
58 #include "RISCVGenDAGISel.inc"
59 
60 private:
61   void doPeepholeLoadStoreADDI();
62 };
63 }
64 
65 #endif
66