aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h
blob: 70771bb23f1d0596476befd99ea0646ffb6d98a4 (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/GlobalISel/GIMatchTableExecutor.h"
#include "rcc/Support/Error.h"

namespace rcc {

class MachineFunction;
class MachineInstr;
class TargetDescription;

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

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

  [[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;

protected:
  [[nodiscard]] Expected<void>
  finalizeGeneratedInstruction(MachineInstr &Output, MachineFunction &Function,
                               const TargetDescription &Target, MachineInstrFlags InputFlags,
                               bool InputMayRaiseFPException) const override;
};

} // namespace rcc

#endif // RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H