aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'backend/include/rcc/CodeGen')
-rw-r--r--backend/include/rcc/CodeGen/MIRPrinter.h13
-rw-r--r--backend/include/rcc/CodeGen/ReachingDefAnalysis.h52
2 files changed, 65 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/MIRPrinter.h b/backend/include/rcc/CodeGen/MIRPrinter.h
index 4c20bed..ea58434 100644
--- a/backend/include/rcc/CodeGen/MIRPrinter.h
+++ b/backend/include/rcc/CodeGen/MIRPrinter.h
@@ -13,6 +13,8 @@ namespace rcc {
class MachineFunction;
class MachineBasicBlock;
+class MachineInstr;
+class MachineOperand;
class TargetDescription;
namespace mir {
@@ -36,6 +38,17 @@ struct MIPrinterOptions final {
const MIParserContext &Context = {},
MIPrinterOptions Options = {});
+[[nodiscard]] Expected<MIParserContext>
+createMachineFunctionPrintContext(const MachineFunction &Function);
+[[nodiscard]] Expected<std::string> printMachineInstruction(const MachineInstr &Instruction,
+ const TargetDescription &Target,
+ const MIParserContext &Context,
+ MIPrinterOptions Options = {});
+[[nodiscard]] Expected<std::string> printMachineOperand(const MachineOperand &Operand,
+ const TargetDescription &Target,
+ const MIParserContext &Context,
+ MIPrinterOptions Options = {});
+
struct MIRDocumentPrinterOptions final {
MIPrintMode Mode = MIPrintMode::Complete;
bool EmitEmbeddedIR = true;
diff --git a/backend/include/rcc/CodeGen/ReachingDefAnalysis.h b/backend/include/rcc/CodeGen/ReachingDefAnalysis.h
new file mode 100644
index 0000000..64eb462
--- /dev/null
+++ b/backend/include/rcc/CodeGen/ReachingDefAnalysis.h
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_CODEGEN_REACHINGDEFANALYSIS_H
+#define RCC_CODEGEN_REACHINGDEFANALYSIS_H
+
+#include "rcc/CodeGen/MachineFunctionAnalysisManager.h"
+#include "rcc/Support/Error.h"
+
+#include <cstddef>
+#include <span>
+#include <string_view>
+#include <unordered_map>
+#include <vector>
+
+namespace rcc {
+
+class MachineFunction;
+class MachineInstr;
+class MachineOperand;
+class TargetDescription;
+
+class ReachingDefAnalysis final {
+public:
+ using DefinitionSet = std::vector<const MachineInstr *>;
+
+ class Result final {
+ public:
+ [[nodiscard]] std::span<const MachineInstr *const>
+ reachingDefinitions(const MachineOperand &Operand) const noexcept;
+ [[nodiscard]] std::size_t instructionNumber(const MachineInstr &Instruction) const noexcept;
+ [[nodiscard]] bool invalidate(const MachineFunction &,
+ const PreservedAnalyses &Preserved) const noexcept;
+
+ private:
+ std::unordered_map<const MachineOperand *, DefinitionSet> OperandDefinitions;
+ std::unordered_map<const MachineInstr *, std::size_t> InstructionNumbers;
+
+ friend class ReachingDefAnalysis;
+ };
+
+ [[nodiscard]] static constexpr std::string_view name() noexcept {
+ return "ReachingDefAnalysis";
+ }
+
+ [[nodiscard]] static Expected<Result> run(MachineFunction &Function,
+ const TargetDescription &Target,
+ MachineFunctionAnalysisManager &Analyses);
+};
+
+} // namespace rcc
+
+#endif // RCC_CODEGEN_REACHINGDEFANALYSIS_H