// SPDX-License-Identifier: GPL-3.0-or-later #ifndef RCC_CODEGEN_GLOBALISEL_CSEMIRBUILDER_H #define RCC_CODEGEN_GLOBALISEL_CSEMIRBUILDER_H #include "rcc/CodeGen/MachineIRBuilder.h" #include #include namespace rcc { class CSEMIRBuilder final : public MachineIRBuilder { public: using MachineIRBuilder::buildConstant; using MachineIRBuilder::buildInstr; using MachineIRBuilder::MachineIRBuilder; [[nodiscard]] Expected buildInstr(Opcode InstructionOpcode, std::span Destinations, std::span Sources) const override; [[nodiscard]] Expected buildConstant(MachineIRBuilderResult Destination, APInt Value) const override; [[nodiscard]] Expected buildSExtInReg(MachineIRBuilderResult Destination, Register Source, std::uint32_t Width) const override; [[nodiscard]] Expected buildExtract(MachineIRBuilderResult Destination, Register Source, std::uint64_t Offset) const override; private: [[nodiscard]] bool canPerformCSE(Opcode InstructionOpcode) const noexcept; [[nodiscard]] bool dominatesInsertionPoint(const MachineInstr &Instruction) const noexcept; [[nodiscard]] Expected makeInstructionDominate(MachineInstr &Instruction) const; [[nodiscard]] Expected generateCopyIfRequired(const MachineIRBuilderResult &Destination, MachineInstr &Instruction) const; [[nodiscard]] Expected memoize(MachineInstr &Instruction) const; }; } // namespace rcc #endif // RCC_CODEGEN_GLOBALISEL_CSEMIRBUILDER_H