// SPDX-License-Identifier: GPL-3.0-or-later #ifndef RCC_CODEGEN_LIVEINTERVALS_H #define RCC_CODEGEN_LIVEINTERVALS_H #include "rcc/CodeGen/LiveInterval.h" #include "rcc/CodeGen/MachinePassManager.h" #include "rcc/CodeGen/RegisterMask.h" #include #include #include #include #include #include #include namespace rcc { class MachineFunction; class MachineInstr; class TargetDescription; struct RegMaskPosition final { SlotIndex Position; MachineInstrStableID Instruction; std::shared_ptr Mask; }; class LiveIntervalsAnalysis final { public: class Result final { public: [[nodiscard]] const SlotIndexesAnalysis::Result &slotIndexes() const noexcept { return Indexes; } [[nodiscard]] SlotIndex slot(const MachineInstr &Instruction) const noexcept { return Indexes.instructionIndex(Instruction); } [[nodiscard]] const LiveInterval *interval(Register Reg) const noexcept; [[nodiscard]] LiveInterval *interval(Register Reg) noexcept; [[nodiscard]] const LiveRange *regUnitRange(RegisterUnitID Unit) const noexcept; [[nodiscard]] std::span regMaskPositions() const noexcept { return RegMasks; } [[nodiscard]] bool interferes(Register Left, Register Right) const noexcept; [[nodiscard]] bool regMaskClobbers(const LiveInterval &Interval, PhysicalRegister Candidate) const noexcept; [[nodiscard]] Expected shrinkToUses(Register Reg, std::span Uses); [[nodiscard]] bool invalidate(const MachineFunction &, const PreservedAnalyses &Preserved) const noexcept; private: SlotIndexesAnalysis::Result Indexes; std::unordered_map Intervals; std::unordered_map RegisterUnitRanges; std::vector RegMasks; friend class LiveIntervalsAnalysis; }; [[nodiscard]] static constexpr std::string_view name() noexcept { return "LiveIntervals"; } [[nodiscard]] static Expected run(MachineFunction &Function, const TargetDescription &Target, MachineFunctionAnalysisManager &Analyses); }; } // namespace rcc #endif // RCC_CODEGEN_LIVEINTERVALS_H