diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-01 13:37:56 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-01 13:37:56 +0800 |
| commit | 786ccc115f851962f3a7d234846a50f4af8aad64 (patch) | |
| tree | 199c7e78ec361ac9a2c466a3ded5788b0995063c /backend/include/rcc/CodeGen | |
| parent | 19d8e4f562a8583b002dbaa837ec0083e7768a4f (diff) | |
| download | rcc-project-786ccc115f851962f3a7d234846a50f4af8aad64.tar.gz rcc-project-786ccc115f851962f3a7d234846a50f4af8aad64.tar.xz | |
[CodeGen] Add explicit MachineFunction cloning
Deep-clone the live MachineIR graph with deterministic identity maps while rebuilding CFG, def-use, ties, register configuration, and memory operand ownership. Verify both source and destination and omit detached arena history.
Diffstat (limited to 'backend/include/rcc/CodeGen')
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineFunctionCloner.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/MachineFunctionCloner.h b/backend/include/rcc/CodeGen/MachineFunctionCloner.h new file mode 100644 index 0000000..3abdf78 --- /dev/null +++ b/backend/include/rcc/CodeGen/MachineFunctionCloner.h @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_CODEGEN_MACHINEFUNCTIONCLONER_H +#define RCC_CODEGEN_MACHINEFUNCTIONCLONER_H + +#include "rcc/CodeGen/MachineIRTypes.h" +#include "rcc/CodeGen/Register.h" +#include "rcc/CodeGen/StableID.h" +#include "rcc/Support/Error.h" + +#include <memory> +#include <optional> +#include <string> +#include <unordered_map> + +namespace rcc { + +class InstructionSet; +class MachineFunction; + +struct MachineFunctionCloneOptions final { + MachineFunctionStableID NewStableID; + std::optional<std::string> NewName; +}; + +struct MachineFunctionCloneResult final { + MachineFunctionCloneResult(); + MachineFunctionCloneResult(const MachineFunctionCloneResult &) = delete; + MachineFunctionCloneResult &operator=(const MachineFunctionCloneResult &) = delete; + MachineFunctionCloneResult(MachineFunctionCloneResult &&) noexcept; + MachineFunctionCloneResult &operator=(MachineFunctionCloneResult &&) noexcept; + ~MachineFunctionCloneResult(); + + std::unique_ptr<MachineFunction> ClonedFunction; + std::unordered_map<MachineBlockStableID, MachineBlockStableID> BlockStableIDs; + std::unordered_map<MachineInstrStableID, MachineInstrStableID> InstructionStableIDs; + std::unordered_map<Register, Register> VirtualRegisters; + std::unordered_map<FrameIndex, FrameIndex> FrameIndices; + std::unordered_map<ConstantPoolIndex, ConstantPoolIndex> ConstantPoolIndices; + std::unordered_map<JumpTableIndex, JumpTableIndex> JumpTableIndices; +}; + +[[nodiscard]] Expected<MachineFunctionCloneResult> +cloneMachineFunction(const MachineFunction &Source, const InstructionSet &Instructions, + MachineFunctionCloneOptions Options); + +} // namespace rcc + +#endif // RCC_CODEGEN_MACHINEFUNCTIONCLONER_H |
