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

#ifndef RCC_CODEGEN_GLOBALISEL_COMBINER_H
#define RCC_CODEGEN_GLOBALISEL_COMBINER_H

#include "rcc/CodeGen/GlobalISel/GIMatchTableExecutor.h"
#include "rcc/CodeGen/MachinePassManager.h"

#include <cstddef>
#include <string>
#include <utility>

namespace rcc {

class GlobalISelCombinerPass final : public MachineFunctionPass {
public:
  GlobalISelCombinerPass(const GIMatchTable &Table, const GIMatchTableExecutor &Executor,
                         std::string PassName, std::size_t MaximumRewrites = 4096,
                         std::size_t MaximumIterations = 8) noexcept
      : Table(&Table), Executor(&Executor), PassName(std::move(PassName)),
        MaximumRewrites(MaximumRewrites), MaximumIterations(MaximumIterations) {
    Contract.Name = this->PassName;
    Contract.Requires = {MachineFunctionProperty::IsSSA};
    Contract.VerificationStage = PipelineStage::MachineIRInput;
    Contract.ThreadSafety = PassThreadSafety::ThreadSafe;
    Contract.DeclaredChanges = {MachinePassChange::Instructions, MachinePassChange::Operands,
                                MachinePassChange::Registers};
  }

  [[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 GIMatchTable *Table;
  const GIMatchTableExecutor *Executor;
  std::string PassName;
  std::size_t MaximumRewrites;
  std::size_t MaximumIterations;
  MachinePassContract Contract;
};

} // namespace rcc

#endif // RCC_CODEGEN_GLOBALISEL_COMBINER_H