diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-13 21:11:10 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-13 21:11:10 +0800 |
| commit | cd30fb546e389d1fb78ce8e579b3dba3a8fdb52a (patch) | |
| tree | 891d7065c52e56d3f559b146f3a07055105d9d4e /backend/include/rcc/CodeGen | |
| parent | 98cae0e8835a1eb8fcb0e43870c04ed934cc51ac (diff) | |
| download | rcc-project-cd30fb546e389d1fb78ce8e579b3dba3a8fdb52a.tar.gz rcc-project-cd30fb546e389d1fb78ce8e579b3dba3a8fdb52a.tar.xz | |
[CodeGen] Match LLVM machine copy propagation
Diffstat (limited to 'backend/include/rcc/CodeGen')
4 files changed, 28 insertions, 11 deletions
diff --git a/backend/include/rcc/CodeGen/MachineCopyPropagation.h b/backend/include/rcc/CodeGen/MachineCopyPropagation.h index ab8b23f..59a3a77 100644 --- a/backend/include/rcc/CodeGen/MachineCopyPropagation.h +++ b/backend/include/rcc/CodeGen/MachineCopyPropagation.h @@ -6,26 +6,21 @@ #include "rcc/CodeGen/MachinePassManager.h" #include <cstddef> -#include <cstdint> namespace rcc { class TargetInstrInfo; -enum class MachineCopyPropagationStage : std::uint8_t { - PreRegisterAllocation, - PostRegisterAllocation, -}; - struct MachineCopyPropagationOptions final { std::size_t MaximumPropagatedCopies = 10'000; + bool UseTargetCopyInstructions = false; }; class MachineCopyPropagationPass final : public MachineFunctionPass { public: - MachineCopyPropagationPass(const TargetInstrInfo &Info, MachineCopyPropagationStage Stage, - MachineCopyPropagationOptions Options = {}) noexcept - : Info(&Info), Stage(Stage), Options(Options) {} + explicit MachineCopyPropagationPass(const TargetInstrInfo &Info, + MachineCopyPropagationOptions Options = {}) noexcept + : Info(&Info), Options(Options) {} [[nodiscard]] const MachinePassContract &contract() const noexcept override; [[nodiscard]] Expected<MachinePassResult> run(MachineFunction &Function, @@ -38,7 +33,6 @@ private: MachineActionReplay &Actions) const; const TargetInstrInfo *Info; - MachineCopyPropagationStage Stage; MachineCopyPropagationOptions Options; }; diff --git a/backend/include/rcc/CodeGen/MachineOperand.h b/backend/include/rcc/CodeGen/MachineOperand.h index ef14638..db04795 100644 --- a/backend/include/rcc/CodeGen/MachineOperand.h +++ b/backend/include/rcc/CodeGen/MachineOperand.h @@ -382,6 +382,8 @@ public: [[nodiscard]] bool isImplicit() const noexcept; [[nodiscard]] Expected<void> setRegister(Register Reg); + [[nodiscard]] Expected<void> changeToImmediate(std::int64_t Value); + [[nodiscard]] Expected<void> setImmediate(std::int64_t Value); [[nodiscard]] Expected<void> setRegisterFlags(RegisterOperandFlags Flags); [[nodiscard]] Expected<void> setSubReg(SubRegIndex SubReg); [[nodiscard]] Expected<void> setBasicBlock(MachineBasicBlock &Block); diff --git a/backend/include/rcc/CodeGen/MachineOptimizationPipeline.h b/backend/include/rcc/CodeGen/MachineOptimizationPipeline.h index 51b4ed2..911cb86 100644 --- a/backend/include/rcc/CodeGen/MachineOptimizationPipeline.h +++ b/backend/include/rcc/CodeGen/MachineOptimizationPipeline.h @@ -23,6 +23,10 @@ struct MachineOptimizationPipelineTargetInfo final { const TargetSchedulingModel &SchedulingModel; }; +struct MachineOptimizationPipelineOptions final { + bool UseTargetCopyInstructions = false; +}; + [[nodiscard]] Expected<void> registerMachineOptimizationAnalyses(MachineFunctionAnalysisManager &Analyses); @@ -35,7 +39,8 @@ addSelectedSSAOptimizationPipeline(MachineFunctionPassManager &Pipeline, [[nodiscard]] Expected<void> addPostRegisterAllocationPipeline(MachineFunctionPassManager &Pipeline, - const MachineOptimizationPipelineTargetInfo &TargetInfo); + const MachineOptimizationPipelineTargetInfo &TargetInfo, + MachineOptimizationPipelineOptions Options = {}); } // namespace rcc diff --git a/backend/include/rcc/CodeGen/TargetInstrInfo.h b/backend/include/rcc/CodeGen/TargetInstrInfo.h index 34752c5..8457ede 100644 --- a/backend/include/rcc/CodeGen/TargetInstrInfo.h +++ b/backend/include/rcc/CodeGen/TargetInstrInfo.h @@ -16,8 +16,14 @@ namespace rcc { class MachineBasicBlock; class MachineFunction; class MachineInstr; +class MachineOperand; class TargetDescription; +struct MachineCopyOperands final { + MachineOperand *Destination = nullptr; + MachineOperand *Source = nullptr; +}; + struct MachineBranchAnalysis final { MachineInstr *Conditional = nullptr; MachineInstr *Unconditional = nullptr; @@ -57,6 +63,16 @@ public: const MachineFunction &Function, const TargetDescription &Target) const = 0; + [[nodiscard]] virtual std::optional<MachineCopyOperands> + getCopyOperands(MachineInstr &) const noexcept { + return std::nullopt; + } + + [[nodiscard]] virtual Expected<bool> simplifyInstruction(MachineInstr &, MachineFunction &, + const TargetDescription &) const { + return false; + } + [[nodiscard]] virtual Expected<bool> tryConvertToThreeAddress(MachineInstr &, std::size_t, std::size_t, MachineFunction &, const TargetDescription &) const { |
