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

#ifndef RCC_TOOLING_BACKENDDRIVER_H
#define RCC_TOOLING_BACKENDDRIVER_H

#include "rcc/CodeGen/MachinePass.h"
#include "rcc/Support/Error.h"
#include "rcc/Tooling/ArtifactStore.h"
#include "rcc/Tooling/PipelineDriver.h"

#include <cstdint>
#include <span>
#include <string_view>
#include <vector>

namespace rcc {

class TargetDescription;

namespace tooling {

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

struct BackendRunResult final {
  BackendOutputKind Kind = BackendOutputKind::FinalMIR;
  std::vector<std::uint8_t> Output;
  PipelineRunResult Pipeline;
  std::vector<MachineActionEvent> Actions;

  [[nodiscard]] std::string_view text() const noexcept;
};

[[nodiscard]] Expected<BackendRunResult>
runBackend(CanonicalMIR Input, const TargetDescription &Target, const BackendInvocation &Invocation,
           BackendOutputKind Output, PipelineControls Controls = {},
           MachinePassInstrumentation *Instrumentation = nullptr);

[[nodiscard]] std::string_view spelling(BackendOutputKind Output) noexcept;
[[nodiscard]] Expected<BackendOutputKind> parseBackendOutputKind(std::string_view Value);
[[nodiscard]] ArtifactKind manifestArtifactKind(BackendOutputKind Output) noexcept;
[[nodiscard]] Expected<ArtifactKind> cacheArtifactKind(BackendOutputKind Output);

} // namespace tooling
} // namespace rcc

#endif // RCC_TOOLING_BACKENDDRIVER_H