aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h
blob: 2ba001206fdce3c236164287a4d1f0c5dcc9db37 (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
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_GLOBALISEL_LEGALIZER_H
#define RCC_CODEGEN_GLOBALISEL_LEGALIZER_H

#include "rcc/CodeGen/CommandFlags.h"
#include "rcc/CodeGen/GlobalISel/LegalizerInfo.h"
#include "rcc/CodeGen/MachinePassManager.h"
#include "rcc/CodeGen/TargetCallLowering.h"

#include <memory>

namespace rcc {

class Legalizer final : public MachineFunctionPass {
public:
  Legalizer(const LegalizerInfo *Info, OptimizationLevel Optimization,
            LibcallLoweringInfo Libcalls = {})
      : Info(Info), Optimization(Optimization), Libcalls(Libcalls) {}
  Legalizer(const LegalizerInfo &Info, OptimizationLevel Optimization,
            LibcallLoweringInfo Libcalls = {})
      : Info(&Info), Optimization(Optimization), Libcalls(Libcalls) {}
  Legalizer(std::unique_ptr<LegalizerInfo> Info, OptimizationLevel Optimization,
            LibcallLoweringInfo Libcalls = {})
      : OwnedInfo(std::move(Info)), Info(OwnedInfo.get()), Optimization(Optimization),
        Libcalls(Libcalls) {}

  [[nodiscard]] const MachinePassContract &contract() const noexcept override;
  [[nodiscard]] Expected<MachinePassResult> run(MachineFunction &Function,
                                                const TargetDescription &Target,
                                                MachineFunctionAnalysisManager &Analyses) override;

private:
  [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function,
                                                              const TargetDescription &Target,
                                                              MachineActionReplay &Actions);

  std::unique_ptr<LegalizerInfo> OwnedInfo;
  const LegalizerInfo *Info = nullptr;
  OptimizationLevel Optimization;
  LibcallLoweringInfo Libcalls;
};

} // namespace rcc

#endif // RCC_CODEGEN_GLOBALISEL_LEGALIZER_H