From 76d89700953ddd81cf31ab8f260eddf67e93aa85 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 7 Aug 2026 01:27:41 +0800 Subject: [MIR] Complete document parsing and printing Implement the single LLVM-compatible MIR document path with structured\nembedded-IR references, YAML mappings, constants, and deterministic printing.\n\nKeep pointer LLT widths DataLayout-derived, reject layout-dependent output\nwhen embedded IR is omitted, and record the fixed-baseline compatibility\ncontract and regression coverage. --- backend/lib/CodeGen/MachineFunctionCloner.cpp | 55 +++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'backend/lib/CodeGen/MachineFunctionCloner.cpp') diff --git a/backend/lib/CodeGen/MachineFunctionCloner.cpp b/backend/lib/CodeGen/MachineFunctionCloner.cpp index 9342c5a..ced3b1a 100644 --- a/backend/lib/CodeGen/MachineFunctionCloner.cpp +++ b/backend/lib/CodeGen/MachineFunctionCloner.cpp @@ -263,10 +263,29 @@ cloneMemOperand(const MachineMemOperand &SourceOperand, CloneState &State) { return std::unexpected(DestinationIndex.error()); State.Result.FrameIndices.emplace(SourceObject.index(), *DestinationIndex); } - auto CallFrameResult = State.Destination.frameInfo().setMaxCallFrameSize( - State.Source.frameInfo().maxCallFrameSize()); - if (!CallFrameResult) - return std::unexpected(CallFrameResult.error()); + MachineFrameState FrameState = State.Source.frameInfo().state(); + FrameState.SavePoints.clear(); + FrameState.RestorePoints.clear(); + auto MapFrameReference = [&State](std::optional &Reference) -> Expected { + if (!Reference) + return {}; + const auto Position = State.Result.FrameIndices.find(*Reference); + if (Position == State.Result.FrameIndices.end()) { + return makeUnexpected(ErrorCode::VerificationError, + "source frame state references an unmapped stack object"); + } + Reference = Position->second; + return {}; + }; + auto StackProtectorResult = MapFrameReference(FrameState.StackProtector); + if (!StackProtectorResult) + return StackProtectorResult; + auto FunctionContextResult = MapFrameReference(FrameState.FunctionContext); + if (!FunctionContextResult) + return FunctionContextResult; + auto StateResult = State.Destination.frameInfo().setState(std::move(FrameState)); + if (!StateResult) + return std::unexpected(StateResult.error()); return {}; } @@ -491,6 +510,34 @@ cloneMemOperand(const MachineMemOperand &SourceOperand, CloneState &State) { return std::unexpected(UpdateResult.error()); } + MachineFrameState FrameState = State.Destination.frameInfo().state(); + auto ClonePoints = + [&State](std::span SourcePoints, + std::vector &DestinationPoints) -> Expected { + DestinationPoints.clear(); + DestinationPoints.reserve(SourcePoints.size()); + for (const MachineFrameSaveRestorePoint &Point : SourcePoints) { + const auto Position = State.Result.BlockStableIDs.find(Point.Block); + if (Position == State.Result.BlockStableIDs.end()) { + return makeUnexpected(ErrorCode::VerificationError, + "source frame save/restore point references an unmapped block"); + } + DestinationPoints.push_back({Position->second, Point.Registers}); + } + return {}; + }; + auto SaveResult = + ClonePoints(State.Source.frameInfo().state().SavePoints, FrameState.SavePoints); + if (!SaveResult) + return SaveResult; + auto RestoreResult = + ClonePoints(State.Source.frameInfo().state().RestorePoints, FrameState.RestorePoints); + if (!RestoreResult) + return RestoreResult; + auto StateResult = State.Destination.frameInfo().setState(std::move(FrameState)); + if (!StateResult) + return std::unexpected(StateResult.error()); + if (State.Source.frameInfo().isFrozen()) { const auto StackSize = State.Source.frameInfo().staticStackSize(); if (!StackSize) { -- cgit v1.2.3