aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h
blob: 4bea4e71f8bca6e8459c4f3da5d628fe4e06302d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
#define RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H

#include "rcc/CodeGen/MachineIRTypes.h"
#include "rcc/Support/Error.h"

namespace rcc {

class MachineFunction;
class MachineInstr;
class TargetDescription;

class InstructionSelector {
public:
  virtual ~InstructionSelector() = default;

  [[nodiscard]] virtual Expected<void> select(MachineInstr &Instruction, MachineFunction &Function,
                                              const TargetDescription &Target) const = 0;

  // Selection matching is read-only and completes before select() mutates MachineIR.
  [[nodiscard]] virtual Expected<void> canSelect(const MachineInstr &, const MachineFunction &,
                                                 const TargetDescription &) const {
    return {};
  }

  [[nodiscard]] virtual Expected<void>
  constrainSelectedInstruction(MachineInstr &, MachineFunction &, const TargetDescription &) const {
    return {};
  }

  [[nodiscard]] Expected<void> propagateSelectionFlags(MachineInstr &Output,
                                                       MachineInstrFlags InputFlags,
                                                       bool InputMayRaiseFPException,
                                                       const TargetDescription &Target) const;

  [[nodiscard]] Expected<void> propagateSelectionFlags(MachineInstr &Output,
                                                       const MachineInstr &Input,
                                                       const TargetDescription &Target) const;
};

} // namespace rcc

#endif // RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H