aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/Tooling/PipelineDriver.h
blob: 2de341ceed5e449694f45264aa9ef11a2e453195 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_TOOLING_PIPELINEDRIVER_H
#define RCC_TOOLING_PIPELINEDRIVER_H

#include "rcc/CodeGen/MachinePass.h"
#include "rcc/MIR/MIRDocument.h"
#include "rcc/Tooling/BackendInvocation.h"

#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

namespace rcc {

class TargetDescription;

namespace tooling {

enum class BackendStage : std::uint8_t {
  PreLegalizerMIR,
  LegalizedMIR,
  RegisterBankMIR,
  SelectedMIR,
  PostSSAMIR,
  PostRegisterAllocationMIR,
  FinalMIR,
};

enum class SnapshotPhase : std::uint8_t {
  Stage,
  BeforePass,
  AfterPass,
};

struct PipelineControls final {
  std::optional<std::string> StopBefore;
  std::optional<std::string> StopAfter;
  std::vector<std::string> PrintBefore;
  std::vector<std::string> PrintAfter;
  std::optional<BackendStage> StopAtStage;
  bool CaptureStageSnapshots = false;
  bool VerifyEach = true;
  bool DetectUnreportedChanges = true;
};

struct PipelineSnapshot final {
  SnapshotPhase Phase = SnapshotPhase::Stage;
  BackendStage Stage = BackendStage::PreLegalizerMIR;
  std::string Function;
  std::string Pass;
  std::uint32_t Occurrence = 0;
  std::string MIR;
};

struct ExecutedPass final {
  std::string Function;
  std::string Pass;
  std::uint32_t Occurrence = 0;

  friend bool operator==(const ExecutedPass &, const ExecutedPass &) = default;
};

struct PipelineRunResult final {
  std::vector<ExecutedPass> ExecutedPasses;
  std::vector<PipelineSnapshot> Snapshots;
};

[[nodiscard]] Expected<void> verifyRV64GCInvocation(const BackendInvocation &Invocation);
[[nodiscard]] Expected<PipelineRunResult>
runRV64GCPipeline(mir::MIRDocument &Document, const TargetDescription &Target,
                  const BackendInvocation &Invocation, PipelineControls Controls = {},
                  MachinePassInstrumentation *Instrumentation = nullptr);
[[nodiscard]] BackendStage stageForFunction(const MachineFunction &Function) noexcept;
[[nodiscard]] std::string_view spelling(BackendStage Stage) noexcept;
[[nodiscard]] Expected<BackendStage> parseBackendStage(std::string_view Value);

} // namespace tooling
} // namespace rcc

#endif // RCC_TOOLING_PIPELINEDRIVER_H