aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/GlobalISel/Legalizer.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/GlobalISel/Legalizer.cpp
parent65321c12beb31c5743e0cf3f28e7aec178b730a2 (diff)
downloadrcc-project-8558f80b4077536d6aa46b97328d6df1210e261f.tar.gz
rcc-project-8558f80b4077536d6aa46b97328d6df1210e261f.tar.xz
[Support] Centralize error context handling
Diffstat (limited to 'backend/lib/CodeGen/GlobalISel/Legalizer.cpp')
-rw-r--r--backend/lib/CodeGen/GlobalISel/Legalizer.cpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/Legalizer.cpp b/backend/lib/CodeGen/GlobalISel/Legalizer.cpp
index 7781818..83efb6a 100644
--- a/backend/lib/CodeGen/GlobalISel/Legalizer.cpp
+++ b/backend/lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -106,11 +106,6 @@ void combineFingerprint(std::uint64_t &State, std::uint64_t Value) noexcept {
return Error(Code, std::move(Message));
}
-[[nodiscard]] Error prefixedError(const Error &Source, std::string Prefix) {
- Prefix.append(Source.message());
- return Error(Source.code(), std::move(Prefix));
-}
-
[[nodiscard]] std::string_view legalizationActionName(LegalizationAction Action) noexcept {
switch (Action) {
case LegalizationAction::Legal:
@@ -187,7 +182,7 @@ Expected<MachinePassResult> Legalizer::run(MachineFunction &Function,
Function, Target,
MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt});
if (!Trial)
- return std::unexpected(prefixedError(Trial.error(), "legalizer transaction setup failed: "));
+ return std::unexpected(withErrorContext(Trial.error(), "legalizer transaction setup failed: "));
MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs);
auto TrialResult = runImplementation(*Trial->ClonedFunction, Target, Actions);
if (!TrialResult)
@@ -195,7 +190,7 @@ Expected<MachinePassResult> Legalizer::run(MachineFunction &Function,
Actions.beginReplay();
auto Result = runImplementation(Function, Target, Actions);
if (!Result) {
- return std::unexpected(prefixedError(
+ return std::unexpected(withErrorContext(
Result.error(), "legalizer diverged after a successful transaction preflight: "));
}
auto Replayed = Actions.finishReplay();
@@ -231,7 +226,7 @@ Expected<MachinePassResult> Legalizer::runImplementation(MachineFunction &Functi
auto Validation = Target.validateInstruction(*Instruction, Function.registerInfo());
if (!Validation)
- return std::unexpected(prefixedError(Validation.error(), "legalizer input is invalid: "));
+ return std::unexpected(withErrorContext(Validation.error(), "legalizer input is invalid: "));
auto Action = Info->classify(*Instruction, Function, Target);
if (!Action)
@@ -253,7 +248,7 @@ Expected<MachinePassResult> Legalizer::runImplementation(MachineFunction &Functi
auto LoweringValidation = Info->validateLowering(*Instruction, Function, Target, *Action);
if (!LoweringValidation)
return std::unexpected(
- prefixedError(LoweringValidation.error(), "legalizer lowering precondition failed: "));
+ withErrorContext(LoweringValidation.error(), "legalizer lowering precondition failed: "));
std::string Rule = "legalize.";
Rule.append(legalizationActionName(*Action));
Rule.push_back('.');
@@ -311,12 +306,12 @@ Expected<MachinePassResult> Legalizer::runImplementation(MachineFunction &Functi
auto FinalValidation = Target.validateInstruction(*Instruction, Function.registerInfo());
if (!FinalValidation)
return std::unexpected(
- prefixedError(FinalValidation.error(), "legalizer produced invalid MachineIR: "));
+ withErrorContext(FinalValidation.error(), "legalizer produced invalid MachineIR: "));
}
auto Liveness = clearTrackedLivenessFlags(Function, Result);
if (!Liveness)
return std::unexpected(
- prefixedError(Liveness.error(), "legalizer liveness-flag invalidation failed: "));
+ withErrorContext(Liveness.error(), "legalizer liveness-flag invalidation failed: "));
Result.Preserved = Result.Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
return Result;
}