aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h
blob: 218a4c6bd37cf53202cf596609e6733510175b65 (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
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
#define RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H

#include "rcc/Support/Error.h"

#include <cstdint>

namespace rcc {

class MachineFunction;
class MachineInstr;
class TargetDescription;

enum class LegalizationAction : std::uint8_t {
  Legal,
  Unsupported,
  Custom,
  Lower,
  Libcall,
  WidenScalar,
  NarrowScalar,
  MoreElements,
  FewerElements,
  Bitcast,
  ChangeElementType,
  ChangeAddressSpace,
};

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

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

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

  // This hook performs read-only target checks before a lowering mutation is committed.
  [[nodiscard]] virtual Expected<void> validateLowering(const MachineInstr &,
                                                        const MachineFunction &,
                                                        const TargetDescription &,
                                                        LegalizationAction) const {
    return {};
  }
};

} // namespace rcc

#endif // RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H