diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-26 00:50:21 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-26 00:50:21 +0800 |
| commit | d54646c69a5117cbeef35f5c3f0d546f4c6bf0e7 (patch) | |
| tree | 422b1c96cefaf0315a73ad8328ffe0d6e578fe9f /backend/include/rcc/CodeGen/ReachingDefAnalysis.h | |
| parent | 73ff142aa16a29c18d09564f0b7e41940fcf786c (diff) | |
| download | rcc-project-d54646c69a5117cbeef35f5c3f0d546f4c6bf0e7.tar.gz rcc-project-d54646c69a5117cbeef35f5c3f0d546f4c6bf0e7.tar.xz | |
[CodeGen] Implement reaching-def analysis printing
Diffstat (limited to 'backend/include/rcc/CodeGen/ReachingDefAnalysis.h')
| -rw-r--r-- | backend/include/rcc/CodeGen/ReachingDefAnalysis.h | 52 |
1 files changed, 52 insertions, 0 deletions
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 |
