aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel
diff options
context:
space:
mode:
Diffstat (limited to 'backend/include/rcc/CodeGen/GlobalISel')
-rw-r--r--backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h31
-rw-r--r--backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h35
-rw-r--r--backend/include/rcc/CodeGen/GlobalISel/Legalizer.h36
-rw-r--r--backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h54
-rw-r--r--backend/include/rcc/CodeGen/GlobalISel/RegBankSelect.h27
5 files changed, 183 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h
new file mode 100644
index 0000000..0c034cd
--- /dev/null
+++ b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECT_H
+#define RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECT_H
+
+#include "rcc/CodeGen/GlobalISel/InstructionSelector.h"
+#include "rcc/CodeGen/MachinePass.h"
+
+namespace rcc {
+
+class InstructionSelect final : public MachineFunctionPass {
+public:
+ explicit InstructionSelect(const InstructionSelector *Info) : Info(Info) {}
+ explicit InstructionSelect(const InstructionSelector &Info) : Info(&Info) {}
+
+ [[nodiscard]] const MachinePassContract &contract() const noexcept override;
+ [[nodiscard]] Expected<MachinePassResult> run(MachineFunction &Function,
+ const TargetDescription &Target,
+ MachineAnalysisManager &Analyses) override;
+
+private:
+ [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function,
+ const TargetDescription &Target,
+ MachineActionReplay &Actions);
+
+ const InstructionSelector *Info;
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECT_H
diff --git a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h
new file mode 100644
index 0000000..4c69606
--- /dev/null
+++ b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
+#define RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
+
+#include "rcc/Support/Error.h"
+
+namespace rcc {
+
+class MachineFunction;
+class MachineInstr;
+class TargetDescription;
+
+class InstructionSelector {
+public:
+ virtual ~InstructionSelector() = default;
+
+ [[nodiscard]] virtual Expected<void> select(MachineInstr &Instruction, MachineFunction &Function,
+ const TargetDescription &Target) const = 0;
+
+ // Selection matching is read-only and completes before select() mutates MachineIR.
+ [[nodiscard]] virtual Expected<void> canSelect(const MachineInstr &, const MachineFunction &,
+ const TargetDescription &) const {
+ return {};
+ }
+
+ [[nodiscard]] virtual Expected<void>
+ constrainSelectedInstruction(MachineInstr &, MachineFunction &, const TargetDescription &) const {
+ return {};
+ }
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTOR_H
diff --git a/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h b/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h
new file mode 100644
index 0000000..7f86d16
--- /dev/null
+++ b/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_GLOBALISEL_LEGALIZER_H
+#define RCC_CODEGEN_GLOBALISEL_LEGALIZER_H
+
+#include "rcc/CodeGen/GlobalISel/LegalizerInfo.h"
+#include "rcc/CodeGen/MachinePass.h"
+
+#include <memory>
+
+namespace rcc {
+
+class Legalizer final : public MachineFunctionPass {
+public:
+ explicit Legalizer(const LegalizerInfo *Info) : Info(Info) {}
+ explicit Legalizer(const LegalizerInfo &Info) : Info(&Info) {}
+ explicit Legalizer(std::unique_ptr<LegalizerInfo> Info)
+ : OwnedInfo(std::move(Info)), Info(OwnedInfo.get()) {}
+
+ [[nodiscard]] const MachinePassContract &contract() const noexcept override;
+ [[nodiscard]] Expected<MachinePassResult> run(MachineFunction &Function,
+ const TargetDescription &Target,
+ MachineAnalysisManager &Analyses) override;
+
+private:
+ [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function,
+ const TargetDescription &Target,
+ MachineActionReplay &Actions);
+
+ std::unique_ptr<LegalizerInfo> OwnedInfo;
+ const LegalizerInfo *Info = nullptr;
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_GLOBALISEL_LEGALIZER_H
diff --git a/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h b/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h
new file mode 100644
index 0000000..218a4c6
--- /dev/null
+++ b/backend/include/rcc/CodeGen/GlobalISel/LegalizerInfo.h
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
+#define RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
+
+#include "rcc/Support/Error.h"
+
+#include <cstdint>
+
+namespace rcc {
+
+class MachineFunction;
+class MachineInstr;
+class TargetDescription;
+
+enum class LegalizationAction : std::uint8_t {
+ Legal,
+ Unsupported,
+ Custom,
+ Lower,
+ Libcall,
+ WidenScalar,
+ NarrowScalar,
+ MoreElements,
+ FewerElements,
+ Bitcast,
+ ChangeElementType,
+ ChangeAddressSpace,
+};
+
+class LegalizerInfo {
+public:
+ virtual ~LegalizerInfo() = default;
+
+ [[nodiscard]] virtual Expected<LegalizationAction>
+ classify(const MachineInstr &Instruction, const MachineFunction &Function,
+ const TargetDescription &Target) const = 0;
+
+ [[nodiscard]] virtual Expected<void> lower(MachineInstr &Instruction, MachineFunction &Function,
+ const TargetDescription &Target,
+ LegalizationAction Action) const = 0;
+
+ // This hook performs read-only target checks before a lowering mutation is committed.
+ [[nodiscard]] virtual Expected<void> validateLowering(const MachineInstr &,
+ const MachineFunction &,
+ const TargetDescription &,
+ LegalizationAction) const {
+ return {};
+ }
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_GLOBALISEL_LEGALIZERINFO_H
diff --git a/backend/include/rcc/CodeGen/GlobalISel/RegBankSelect.h b/backend/include/rcc/CodeGen/GlobalISel/RegBankSelect.h
new file mode 100644
index 0000000..256d748
--- /dev/null
+++ b/backend/include/rcc/CodeGen/GlobalISel/RegBankSelect.h
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_GLOBALISEL_REGBANKSELECT_H
+#define RCC_CODEGEN_GLOBALISEL_REGBANKSELECT_H
+
+#include "rcc/CodeGen/MachinePass.h"
+#include "rcc/CodeGen/RegisterBankInfo.h"
+
+namespace rcc {
+
+class RegBankSelect final : public MachineFunctionPass {
+public:
+ explicit RegBankSelect(const RegisterBankInfo *Info) : Info(Info) {}
+ explicit RegBankSelect(const RegisterBankInfo &Info) : Info(&Info) {}
+
+ [[nodiscard]] const MachinePassContract &contract() const noexcept override;
+ [[nodiscard]] Expected<MachinePassResult> run(MachineFunction &Function,
+ const TargetDescription &Target,
+ MachineAnalysisManager &Analyses) override;
+
+private:
+ const RegisterBankInfo *Info;
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_GLOBALISEL_REGBANKSELECT_H