From aa7c85ca71859aab15bdf1e6dc1ea3a5aa5d1e28 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Thu, 13 Aug 2026 06:52:15 +0800 Subject: [Support] Split APInt and APFloat ownership --- backend/lib/Target/RISCV/GISel/RISCVCallLowering.cpp | 2 +- .../Target/RISCV/GISel/RISCVInstructionSelector.cpp | 2 +- backend/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp | 18 ++++++++---------- backend/lib/Target/RISCV/RISCVMCTargetLowering.cpp | 10 +++++----- 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'backend/lib/Target') diff --git a/backend/lib/Target/RISCV/GISel/RISCVCallLowering.cpp b/backend/lib/Target/RISCV/GISel/RISCVCallLowering.cpp index cfe8bb6..71c7251 100644 --- a/backend/lib/Target/RISCV/GISel/RISCVCallLowering.cpp +++ b/backend/lib/Target/RISCV/GISel/RISCVCallLowering.cpp @@ -781,7 +781,7 @@ RISCVCallLowering::planReturn(const ReturnLoweringRequest &Request) const { [[nodiscard]] Expected addUnsignedImmediate(MachineInstrBuilder &Builder, std::uint64_t Value) { - auto Immediate = IntegerImmediate::fromUnsigned(64, Value); + auto Immediate = APInt::fromUnsigned(64, Value); if (!Immediate) return std::unexpected(Immediate.error()); return Builder.addIntegerImmediate(std::move(*Immediate)); diff --git a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp index a2c7194..2090496 100644 --- a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp +++ b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp @@ -2512,7 +2512,7 @@ private: const std::uint32_t BitWidth = Type->scalarBitWidth(); const std::uint64_t Bits = Floating->Bits.words().empty() ? 0 : Floating->Bits.words().front(); - auto Integer = IntegerImmediate::fromUnsigned(64, Bits); + auto Integer = APInt::fromUnsigned(64, Bits); if (!Integer) return std::unexpected(Integer.error()); auto IntegerType = LLT::makeInteger(64); diff --git a/backend/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/backend/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp index e9d72fd..da8d687 100644 --- a/backend/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp +++ b/backend/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp @@ -99,9 +99,8 @@ namespace { Destination.scalarBitWidth() <= 64; } -[[nodiscard]] Expected extendIntegerImmediate(const IntegerImmediate &Value, - std::uint32_t DestinationWidth, - bool SignExtend) { +[[nodiscard]] Expected +extendIntegerImmediate(const APInt &Value, std::uint32_t DestinationWidth, bool SignExtend) { if (DestinationWidth == 0 || DestinationWidth > 64) return makeUnexpected(ErrorCode::Unsupported, "RISC-V constant extension requires a destination no wider than 64 bits"); @@ -112,7 +111,7 @@ namespace { Raw |= ~std::uint64_t{0} << SourceWidth; if (DestinationWidth < 64) Raw &= (std::uint64_t{1} << DestinationWidth) - 1U; - return IntegerImmediate::create(DestinationWidth, std::span(&Raw, 1)); + return APInt::create(DestinationWidth, std::span(&Raw, 1)); } [[nodiscard]] Expected @@ -271,9 +270,8 @@ wideConstantUnmergePlan(const MachineInstr &Constant, const MachineFunction &Fun return Plan; } -[[nodiscard]] Expected wideConstantWord(const IntegerImmediate &Value, - std::size_t WordIndex, - std::uint32_t Width, bool SignExtend) { +[[nodiscard]] Expected wideConstantWord(const APInt &Value, std::size_t WordIndex, + std::uint32_t Width, bool SignExtend) { std::uint64_t Raw = 0; if (WordIndex < Value.words().size()) Raw = Value.words()[WordIndex]; @@ -287,7 +285,7 @@ wideConstantUnmergePlan(const MachineInstr &Constant, const MachineFunction &Fun } if (Width < 64) Raw &= (std::uint64_t{1} << Width) - 1U; - return IntegerImmediate::create(Width, std::span(&Raw, 1)); + return APInt::create(Width, std::span(&Raw, 1)); } [[nodiscard]] Expected foldWideConstant(MachineInstr &Instruction, MachineFunction &Function, @@ -303,7 +301,7 @@ wideConstantUnmergePlan(const MachineInstr &Constant, const MachineFunction &Fun return makeUnexpected(ErrorCode::VerificationError, "RISC-V wide constant has no integer immediate"); - std::vector Words; + std::vector Words; Words.reserve(Plan->Outputs.size()); for (std::size_t Index = 0; Index < Plan->Outputs.size(); ++Index) { const auto Info = Function.registerInfo().virtualRegisterInfo(Plan->Outputs[Index]); @@ -1240,7 +1238,7 @@ void eraseDeadArtifacts(std::span Candidates, auto Result = Builder.function().registerInfo().createVirtualRegister(*Type); if (!Result) return std::unexpected(Result.error()); - auto Immediate = IntegerImmediate::fromUnsigned(Width, Value); + auto Immediate = APInt::fromUnsigned(Width, Value); if (!Immediate) return std::unexpected(Immediate.error()); auto Point = Builder.setInsertPointBefore(Anchor); diff --git a/backend/lib/Target/RISCV/RISCVMCTargetLowering.cpp b/backend/lib/Target/RISCV/RISCVMCTargetLowering.cpp index ee41d47..0db51f0 100644 --- a/backend/lib/Target/RISCV/RISCVMCTargetLowering.cpp +++ b/backend/lib/Target/RISCV/RISCVMCTargetLowering.cpp @@ -252,7 +252,7 @@ struct TypeLayout final { return mc::MCOperand::expression(std::move(*TargetExpression)); } -[[nodiscard]] Expected lowerIntegerImmediate(const IntegerImmediate &Value) { +[[nodiscard]] Expected lowerIntegerImmediate(const APInt &Value) { if (Value.bitWidth() > 64 || Value.words().size() != 1) { return makeUnexpected(ErrorCode::AssemblyLoweringFailed, "RISC-V instruction has an integer immediate wider than 64 bits"); @@ -714,14 +714,14 @@ struct TypeLayout final { } switch (Initializer.kind()) { case GlobalInitializer::Kind::Integer: { - const auto *Value = Initializer.getIf(); + const auto *Value = Initializer.getIf(); if (Value == nullptr) return makeUnexpected(ErrorCode::InternalError, "integer initializer has no value"); const std::uint64_t Size = (static_cast(Value->bitWidth()) + 7U) / 8U; return Streamer.emitBytes(bytesFromWords(Value->words(), Size)); } case GlobalInitializer::Kind::Floating: { - const auto *Value = Initializer.getIf(); + const auto *Value = Initializer.getIf(); if (Value == nullptr) return makeUnexpected(ErrorCode::InternalError, "floating initializer has no value"); const std::uint64_t Size = (static_cast(Value->bitWidth()) + 7U) / 8U; @@ -839,12 +839,12 @@ struct TypeLayout final { return false; switch (Initializer.kind()) { case GlobalInitializer::Kind::Integer: { - const auto *Value = Initializer.getIf(); + const auto *Value = Initializer.getIf(); return Value != nullptr && std::ranges::all_of(Value->words(), [](std::uint64_t Word) { return Word == 0; }); } case GlobalInitializer::Kind::Floating: { - const auto *Value = Initializer.getIf(); + const auto *Value = Initializer.getIf(); return Value != nullptr && std::ranges::all_of(Value->words(), [](std::uint64_t Word) { return Word == 0; }); } -- cgit v1.2.3