// SPDX-License-Identifier: GPL-3.0-or-later #ifndef RCC_CODEGEN_MACHINEFUNCTIONRECORDS_H #define RCC_CODEGEN_MACHINEFUNCTIONRECORDS_H #include "rcc/CodeGen/MachineBasicBlockAttributes.h" #include "rcc/CodeGen/Register.h" #include "rcc/CodeGen/StableID.h" #include "rcc/Support/Error.h" #include #include #include #include #include namespace rcc { class MachineFunctionCloneContext; struct MachineCallSiteArgument final { PhysicalRegister Reg; std::uint16_t ArgumentNumber = 0; friend constexpr bool operator==(MachineCallSiteArgument Left, MachineCallSiteArgument Right) noexcept = default; }; struct MachineCallSiteInfo final { MachineInstrStableID CallInstruction; std::vector ForwardedArguments; std::vector CalleeTypeIDs; friend bool operator==(const MachineCallSiteInfo &Left, const MachineCallSiteInfo &Right) = default; }; struct MachineCalledGlobal final { MachineInstrStableID CallInstruction; std::string Callee; std::uint32_t Flags = 0; friend bool operator==(const MachineCalledGlobal &Left, const MachineCalledGlobal &Right) = default; }; struct MachinePrefetchTarget final { MachineBasicBlockProfileID Block; std::uint32_t CallsiteIndex = 0; friend constexpr bool operator==(MachinePrefetchTarget Left, MachinePrefetchTarget Right) noexcept = default; }; class MachineFunctionRecords final { public: MachineFunctionRecords() = default; MachineFunctionRecords(const MachineFunctionRecords &) = delete; MachineFunctionRecords &operator=(const MachineFunctionRecords &) = delete; MachineFunctionRecords(MachineFunctionRecords &&) noexcept = default; MachineFunctionRecords &operator=(MachineFunctionRecords &&) noexcept = default; ~MachineFunctionRecords() = default; [[nodiscard]] bool hasCalleeSavedRegisters() const noexcept { return CalleeSavedRegisters.has_value(); } [[nodiscard]] std::span calleeSavedRegisters() const noexcept { if (!CalleeSavedRegisters) return {}; return *CalleeSavedRegisters; } [[nodiscard]] Expected setCalleeSavedRegisters(std::vector Registers); void clearCalleeSavedRegisters() noexcept { CalleeSavedRegisters.reset(); } [[nodiscard]] std::span callSites() const noexcept { return CallSites; } [[nodiscard]] Expected addCallSite(MachineCallSiteInfo CallSite); [[nodiscard]] std::span calledGlobals() const noexcept { return CalledGlobals; } [[nodiscard]] Expected addCalledGlobal(MachineCalledGlobal CalledGlobal); [[nodiscard]] std::span prefetchTargets() const noexcept { return PrefetchTargets; } [[nodiscard]] Expected addPrefetchTarget(MachinePrefetchTarget Target); [[nodiscard]] Expected verify() const; [[nodiscard]] Expected clone(const MachineFunctionCloneContext &CloneContext) const; friend bool operator==(const MachineFunctionRecords &Left, const MachineFunctionRecords &Right) = default; private: std::optional> CalleeSavedRegisters; std::vector CallSites; std::vector CalledGlobals; std::vector PrefetchTargets; }; } // namespace rcc #endif // RCC_CODEGEN_MACHINEFUNCTIONRECORDS_H