aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-13 13:18:05 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-13 13:18:05 +0800
commit8558f80b4077536d6aa46b97328d6df1210e261f (patch)
tree373a2242db00ddeb9a1af83dbd853e97e0bd12d3 /backend/lib/CodeGen/PrologueEpilogueInsertion.cpp
parent65321c12beb31c5743e0cf3f28e7aec178b730a2 (diff)
downloadrcc-project-8558f80b4077536d6aa46b97328d6df1210e261f.tar.gz
rcc-project-8558f80b4077536d6aa46b97328d6df1210e261f.tar.xz
[Support] Centralize error context handling
Diffstat (limited to 'backend/lib/CodeGen/PrologueEpilogueInsertion.cpp')
-rw-r--r--backend/lib/CodeGen/PrologueEpilogueInsertion.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp b/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp
index c935d6a..d51a93b 100644
--- a/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp
+++ b/backend/lib/CodeGen/PrologueEpilogueInsertion.cpp
@@ -3,11 +3,11 @@
#include "rcc/CodeGen/PrologueEpilogueInsertion.h"
#include "rcc/CodeGen/FrameIndexElimination.h"
+#include "rcc/CodeGen/LiveVariables.h"
#include "rcc/CodeGen/MachineBasicBlock.h"
#include "rcc/CodeGen/MachineFunction.h"
#include "rcc/CodeGen/MachineFunctionCloner.h"
#include "rcc/CodeGen/MachineInstr.h"
-#include "rcc/CodeGen/LiveVariables.h"
#include "rcc/CodeGen/MachineMemOperand.h"
#include "rcc/CodeGen/MachineOperand.h"
#include "rcc/CodeGen/MachineVerifier.h"
@@ -19,14 +19,7 @@
#include <vector>
namespace rcc {
-namespace {
-
-[[nodiscard]] Error prefixedError(const Error &Source, std::string Prefix) {
- Prefix.append(Source.message());
- return Error(Source.code(), std::move(Prefix));
-}
-
-} // namespace
+namespace {} // namespace
const MachinePassContract &PrologueEpilogueInsertionPass::contract() const noexcept {
static const MachinePassContract Contract = [] {
@@ -63,15 +56,16 @@ Expected<MachinePassResult> PrologueEpilogueInsertionPass::run(MachineFunction &
Function, Target,
MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt});
if (!Trial)
- return std::unexpected(prefixedError(Trial.error(), "frame transaction setup failed: "));
+ return std::unexpected(withErrorContext(Trial.error(), "frame transaction setup failed: "));
auto TrialRun = runImplementation(*Trial->ClonedFunction, Target);
if (!TrialRun)
- return std::unexpected(prefixedError(TrialRun.error(), "frame transaction rejected input: "));
+ return std::unexpected(
+ withErrorContext(TrialRun.error(), "frame transaction rejected input: "));
auto Transition = Trial->ClonedFunction->properties().applyTransition(
contract().Requires, contract().Sets, contract().Clears);
if (!Transition) {
return std::unexpected(
- prefixedError(Transition.error(), "frame transaction property update failed: "));
+ withErrorContext(Transition.error(), "frame transaction property update failed: "));
}
auto Verified =
MachineVerifier::verify(*Trial->ClonedFunction, Target,
@@ -80,12 +74,12 @@ Expected<MachinePassResult> PrologueEpilogueInsertionPass::run(MachineFunction &
.VerifyProperties = true});
if (!Verified) {
return std::unexpected(
- prefixedError(Verified.error(), "frame transaction postcondition failed: "));
+ withErrorContext(Verified.error(), "frame transaction postcondition failed: "));
}
auto Result = runImplementation(Function, Target);
if (!Result) {
- return std::unexpected(prefixedError(
+ return std::unexpected(withErrorContext(
Result.error(), "frame lowering diverged after successful transaction preflight: "));
}
return Result;