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

#ifndef RCC_CODEGEN_MACHINEBRANCHRELAXATION_H
#define RCC_CODEGEN_MACHINEBRANCHRELAXATION_H

#include "rcc/CodeGen/MachinePassManager.h"

#include <cstddef>

namespace rcc {

class TargetInstrInfo;

struct MachineBranchRelaxationOptions final {
  std::size_t ConvergenceWatchdog = 1000000;
};

class MachineBranchRelaxationPass final : public MachineFunctionPass {
public:
  explicit MachineBranchRelaxationPass(const TargetInstrInfo &Info,
                                       MachineBranchRelaxationOptions Options = {}) noexcept
      : Info(&Info), Options(Options) {}

  [[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,
                                                              MachineFunctionAnalysisManager
                                                                  &Analyses) const;

  const TargetInstrInfo *Info;
  MachineBranchRelaxationOptions Options;
};

} // namespace rcc

#endif // RCC_CODEGEN_MACHINEBRANCHRELAXATION_H