aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineFunctionCloner.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-07 01:27:41 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-07 01:27:41 +0800
commit76d89700953ddd81cf31ab8f260eddf67e93aa85 (patch)
treec96a453164154b2d1559cea36910df52103f0f19 /backend/lib/CodeGen/MachineFunctionCloner.cpp
parent183e2354e9fdd107be420cbb185c1d239434aa48 (diff)
downloadrcc-project-76d89700953ddd81cf31ab8f260eddf67e93aa85.tar.gz
rcc-project-76d89700953ddd81cf31ab8f260eddf67e93aa85.tar.xz
[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.
Diffstat (limited to 'backend/lib/CodeGen/MachineFunctionCloner.cpp')
-rw-r--r--backend/lib/CodeGen/MachineFunctionCloner.cpp55
1 files changed, 51 insertions, 4 deletions
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<FrameIndex> &Reference) -> Expected<void> {
+ 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<const MachineFrameSaveRestorePoint> SourcePoints,
+ std::vector<MachineFrameSaveRestorePoint> &DestinationPoints) -> Expected<void> {
+ 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) {