From d54646c69a5117cbeef35f5c3f0d546f4c6bf0e7 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Wed, 26 Aug 2026 00:50:21 +0800 Subject: [CodeGen] Implement reaching-def analysis printing --- backend/include/rcc/CodeGen/ReachingDefAnalysis.h | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 backend/include/rcc/CodeGen/ReachingDefAnalysis.h (limited to 'backend/include/rcc/CodeGen/ReachingDefAnalysis.h') 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 +#include +#include +#include +#include + +namespace rcc { + +class MachineFunction; +class MachineInstr; +class MachineOperand; +class TargetDescription; + +class ReachingDefAnalysis final { +public: + using DefinitionSet = std::vector; + + class Result final { + public: + [[nodiscard]] std::span + 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 OperandDefinitions; + std::unordered_map InstructionNumbers; + + friend class ReachingDefAnalysis; + }; + + [[nodiscard]] static constexpr std::string_view name() noexcept { + return "ReachingDefAnalysis"; + } + + [[nodiscard]] static Expected run(MachineFunction &Function, + const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses); +}; + +} // namespace rcc + +#endif // RCC_CODEGEN_REACHINGDEFANALYSIS_H -- cgit v1.2.3