From 3341938bb644e6fc39afa6a8fcb1306604999e42 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Wed, 12 Aug 2026 22:37:49 +0800 Subject: [RISCV] Split the GlobalISel target components --- backend/lib/Target/RISCV/RISCVFunctionInfo.cpp | 38 +++++++++++--------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'backend/lib/Target/RISCV/RISCVFunctionInfo.cpp') diff --git a/backend/lib/Target/RISCV/RISCVFunctionInfo.cpp b/backend/lib/Target/RISCV/RISCVFunctionInfo.cpp index f25bb8c..bd72103 100644 --- a/backend/lib/Target/RISCV/RISCVFunctionInfo.cpp +++ b/backend/lib/Target/RISCV/RISCVFunctionInfo.cpp @@ -21,24 +21,22 @@ namespace { [[nodiscard]] Expected parseSignedField(const MIRTargetNode &Node, std::string_view Name) { if (Node.Kind != MIRTargetNodeKind::Scalar) - return makeUnexpected(ErrorCode::ParseError, - "RISC-V machineFunctionInfo field '" + std::string(Name) + - "' must be a scalar"); + return makeUnexpected(ErrorCode::ParseError, "RISC-V machineFunctionInfo field '" + + std::string(Name) + "' must be a scalar"); std::int32_t Value = 0; const auto Result = std::from_chars(Node.Scalar.data(), Node.Scalar.data() + Node.Scalar.size(), Value, 10); if (Result.ec != std::errc{} || Result.ptr != Node.Scalar.data() + Node.Scalar.size()) { - return makeUnexpected(ErrorCode::ParseError, - "RISC-V machineFunctionInfo field '" + std::string(Name) + - "' must be a 32-bit signed integer"); + return makeUnexpected(ErrorCode::ParseError, "RISC-V machineFunctionInfo field '" + + std::string(Name) + + "' must be a 32-bit signed integer"); } return Value; } [[nodiscard]] Expected parseFunctionInfo(const MIRTargetNode &Node) { if (Node.Kind != MIRTargetNodeKind::Mapping) - return makeUnexpected(ErrorCode::ParseError, - "RISC-V machineFunctionInfo must be a mapping"); + return makeUnexpected(ErrorCode::ParseError, "RISC-V machineFunctionInfo must be a mapping"); std::int32_t VarArgsFrameIndex = 0; std::int32_t VarArgsSaveSize = 0; @@ -60,21 +58,19 @@ namespace { return makeUnexpected(ErrorCode::ParseError, "unknown RISC-V machineFunctionInfo field '" + Entry.Key + "'"); } - return TargetFunctionState::create( - RISCVFunctionInfo(VarArgsFrameIndex, VarArgsSaveSize)); + return TargetFunctionState::create(RISCVFunctionInfo(VarArgsFrameIndex, VarArgsSaveSize)); } -[[nodiscard]] Expected -printFunctionInfo(const TargetFunctionState &State) { +[[nodiscard]] Expected printFunctionInfo(const TargetFunctionState &State) { const auto *Info = State.getIf(); if (Info == nullptr) return makeUnexpected(ErrorCode::InvalidArgument, "target function state is not RISC-V function information"); std::vector Entries; - Entries.push_back({"varArgsFrameIndex", - MIRTargetNode::scalar(std::to_string(Info->varArgsFrameIndex()))}); - Entries.push_back({"varArgsSaveSize", - MIRTargetNode::scalar(std::to_string(Info->varArgsSaveSize()))}); + Entries.push_back( + {"varArgsFrameIndex", MIRTargetNode::scalar(std::to_string(Info->varArgsFrameIndex()))}); + Entries.push_back( + {"varArgsSaveSize", MIRTargetNode::scalar(std::to_string(Info->varArgsSaveSize()))}); return MIRTargetNode::mapping(std::move(Entries)); } @@ -99,8 +95,7 @@ Expected RISCVFunctionInfo::verify() const { return {}; } -Expected -RISCVFunctionInfo::clone(const MachineFunctionCloneContext &) const { +Expected RISCVFunctionInfo::clone(const MachineFunctionCloneContext &) const { return RISCVFunctionInfo(VarArgsFrameIndex, VarArgsSaveSize); } @@ -117,11 +112,10 @@ Expected> RISCVFunctionInfo::encode() const { return Payload; } -Expected -RISCVFunctionInfo::decode(std::uint32_t Version, std::span Payload) { +Expected RISCVFunctionInfo::decode(std::uint32_t Version, + std::span Payload) { if (Version != schemaVersion()) - return makeUnexpected(ErrorCode::ParseError, - "unsupported RISC-V function-info schema version"); + return makeUnexpected(ErrorCode::ParseError, "unsupported RISC-V function-info schema version"); if (Payload.size() != 8) return makeUnexpected(ErrorCode::ParseError, "RISC-V function-info payload must contain eight bytes"); -- cgit v1.2.3