diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-13 13:18:05 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-13 13:18:05 +0800 |
| commit | 8558f80b4077536d6aa46b97328d6df1210e261f (patch) | |
| tree | 373a2242db00ddeb9a1af83dbd853e97e0bd12d3 /backend/lib/CodeGen/TwoAddressInstructionPass.cpp | |
| parent | 65321c12beb31c5743e0cf3f28e7aec178b730a2 (diff) | |
| download | rcc-project-8558f80b4077536d6aa46b97328d6df1210e261f.tar.gz rcc-project-8558f80b4077536d6aa46b97328d6df1210e261f.tar.xz | |
[Support] Centralize error context handling
Diffstat (limited to 'backend/lib/CodeGen/TwoAddressInstructionPass.cpp')
| -rw-r--r-- | backend/lib/CodeGen/TwoAddressInstructionPass.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp index b6f2a25..b9e1443 100644 --- a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -32,11 +32,6 @@ struct RegisterValue final { std::uint32_t TargetFlags = 0; }; -[[nodiscard]] Error prefixedError(const Error &Source, std::string Prefix) { - Prefix.append(Source.message()); - return Error(Source.code(), std::move(Prefix)); -} - [[nodiscard]] Expected<void> requireProperties(const MachineFunction &Function, const MachinePassContract &Contract) { const MachineFunctionProperties Missing = Contract.Requires.missingFrom(Function.properties()); @@ -67,7 +62,7 @@ buildCopy(MachineFunction &Function, const TargetDescription &Target, auto Legality = TargetInfo.validateCopy(Destination.Reg, Destination.SubReg, Source.Reg, Source.SubReg, Function, Target); if (!Legality) - return std::unexpected(prefixedError(Legality.error(), "illegal COPY: ")); + return std::unexpected(withErrorContext(Legality.error(), "illegal COPY: ")); MachineIRBuilder Builder(Function, Target); auto Point = @@ -470,7 +465,8 @@ TwoAddressInstructionPass::run(MachineFunction &Function, const TargetDescriptio Function, Target, MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); if (!Trial) { - return std::unexpected(prefixedError(Trial.error(), "two-address transaction setup failed: ")); + return std::unexpected( + withErrorContext(Trial.error(), "two-address transaction setup failed: ")); } MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs); auto TrialResult = runImplementation(*Trial->ClonedFunction, Target, Actions); @@ -480,7 +476,7 @@ TwoAddressInstructionPass::run(MachineFunction &Function, const TargetDescriptio Actions.beginReplay(); auto Result = runImplementation(Function, Target, Actions); if (!Result) { - return std::unexpected(prefixedError( + return std::unexpected(withErrorContext( Result.error(), "two-address rewrite diverged after a successful transaction preflight: ")); } auto Replayed = Actions.finishReplay(); @@ -652,7 +648,7 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( auto Repaired = repairTrackedLiveness(Function, Target, Result); if (!Repaired) return std::unexpected( - prefixedError(Repaired.error(), "two-address liveness repair failed: ")); + withErrorContext(Repaired.error(), "two-address liveness repair failed: ")); } Result.Preserved = Result.Changed ? PreservedAnalyses::none() : PreservedAnalyses::all(); return Result; |
