aboutsummaryrefslogtreecommitdiff
path: root/backend/unittests
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-13 06:52:15 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-13 06:52:15 +0800
commitaa7c85ca71859aab15bdf1e6dc1ea3a5aa5d1e28 (patch)
tree20d94c4debfe4900e362c6c7f8443bcfbd58ec28 /backend/unittests
parentd62f022c92fcc3ebe2269273628943a0089683fd (diff)
downloadrcc-project-aa7c85ca71859aab15bdf1e6dc1ea3a5aa5d1e28.tar.gz
rcc-project-aa7c85ca71859aab15bdf1e6dc1ea3a5aa5d1e28.tar.xz
[Support] Split APInt and APFloat ownership
Diffstat (limited to 'backend/unittests')
-rw-r--r--backend/unittests/CodeGen/GenericOpcodesTest.cpp6
-rw-r--r--backend/unittests/CodeGen/MachineConstantPoolTest.cpp2
-rw-r--r--backend/unittests/CodeGen/MachineFunctionClonerTest.cpp2
-rw-r--r--backend/unittests/CodeGen/MachineIRBuilderTest.cpp2
-rw-r--r--backend/unittests/CodeGen/MachineIRCoreTest.cpp6
-rw-r--r--backend/unittests/CodeGen/MachineOperandTest.cpp31
-rw-r--r--backend/unittests/CodeGen/MachineVerifierTest.cpp2
-rw-r--r--backend/unittests/Target/RISCVAssemblyPrinterTest.cpp2
-rw-r--r--backend/unittests/Target/RISCVCodeGenTest.cpp10
-rw-r--r--backend/unittests/Target/RISCVMCTest.cpp2
-rw-r--r--backend/unittests/Target/RISCVObjectFileTest.cpp2
11 files changed, 33 insertions, 34 deletions
diff --git a/backend/unittests/CodeGen/GenericOpcodesTest.cpp b/backend/unittests/CodeGen/GenericOpcodesTest.cpp
index 6240c6d..73c1c36 100644
--- a/backend/unittests/CodeGen/GenericOpcodesTest.cpp
+++ b/backend/unittests/CodeGen/GenericOpcodesTest.cpp
@@ -326,7 +326,7 @@ void testShapesAndTypes(TestContext &Context) {
(*Function)->registerInfo()),
"G_ADD must reject a source from a different LLT equality group");
- auto ZeroImmediate = rcc::IntegerImmediate::fromUnsigned(64, 0);
+ auto ZeroImmediate = rcc::APInt::fromUnsigned(64, 0);
std::vector<rcc::MachineOperand> PointerConstant;
PointerConstant.push_back(registerOperand(*Address, true));
if (ZeroImmediate)
@@ -489,7 +489,7 @@ void testShapesAndTypes(TestContext &Context) {
"G_FPEXTLOAD must reject an integer result");
const std::array<std::uint64_t, 1> FloatWords{0};
- auto FloatBits = rcc::FloatingPointBits::create(rcc::FloatSemantics::IEEESingle, FloatWords);
+ auto FloatBits = rcc::APFloat::create(rcc::FloatSemantics::IEEESingle, FloatWords);
if (!FloatBits)
std::terminate();
std::vector<rcc::MachineOperand> FConstantOperands;
@@ -505,7 +505,7 @@ void testShapesAndTypes(TestContext &Context) {
"G_FCONSTANT must reject mismatched floating semantics");
const std::array<std::uint64_t, 1> BFloatWords{0};
- auto BFloatBits = rcc::FloatingPointBits::create(rcc::FloatSemantics::BFloat, BFloatWords);
+ auto BFloatBits = rcc::APFloat::create(rcc::FloatSemantics::BFloat, BFloatWords);
if (!BFloatBits)
std::terminate();
FConstantOperands[0] = registerOperand(Scalar16, true);
diff --git a/backend/unittests/CodeGen/MachineConstantPoolTest.cpp b/backend/unittests/CodeGen/MachineConstantPoolTest.cpp
index 08b69e2..39323d5 100644
--- a/backend/unittests/CodeGen/MachineConstantPoolTest.cpp
+++ b/backend/unittests/CodeGen/MachineConstantPoolTest.cpp
@@ -128,7 +128,7 @@ struct PoolTargetConstant final {
[[nodiscard]] rcc::MachineConstantPoolEntryDesc
genericDescription(rcc::ConstantPoolMergeKind Merge) {
rcc::MachineConstantPoolEntryDesc Description;
- auto Integer = rcc::IntegerImmediate::fromUnsigned(32, 0x04030201U);
+ auto Integer = rcc::APInt::fromUnsigned(32, 0x04030201U);
Description.Value = std::move(*rcc::GenericConstantData::integer(std::move(*Integer)));
Description.Size = 4;
Description.Align = *rcc::Alignment::create(4);
diff --git a/backend/unittests/CodeGen/MachineFunctionClonerTest.cpp b/backend/unittests/CodeGen/MachineFunctionClonerTest.cpp
index e923108..e5acc04 100644
--- a/backend/unittests/CodeGen/MachineFunctionClonerTest.cpp
+++ b/backend/unittests/CodeGen/MachineFunctionClonerTest.cpp
@@ -335,7 +335,7 @@ struct SourceFixture final {
return false;
rcc::MachineConstantPoolEntryDesc HistoricalConstant;
- auto HistoricalInteger = rcc::IntegerImmediate::fromUnsigned(32, 0x01010101U);
+ auto HistoricalInteger = rcc::APInt::fromUnsigned(32, 0x01010101U);
HistoricalConstant.Value =
std::move(*rcc::GenericConstantData::integer(std::move(*HistoricalInteger)));
HistoricalConstant.Size = 4;
diff --git a/backend/unittests/CodeGen/MachineIRBuilderTest.cpp b/backend/unittests/CodeGen/MachineIRBuilderTest.cpp
index c4d5767..44a0e32 100644
--- a/backend/unittests/CodeGen/MachineIRBuilderTest.cpp
+++ b/backend/unittests/CodeGen/MachineIRBuilderTest.cpp
@@ -426,7 +426,7 @@ void testImplicitAndMemoryValidation(TestContext &Context) {
"builder must reject unknown constant-pool and jump-table indices before allocation");
rcc::MachineConstantPoolEntryDesc ConstantDescription;
- auto Integer = rcc::IntegerImmediate::fromUnsigned(64, 0x2a2a2a2a2a2a2a2aULL);
+ auto Integer = rcc::APInt::fromUnsigned(64, 0x2a2a2a2a2a2a2a2aULL);
ConstantDescription.Value = std::move(*rcc::GenericConstantData::integer(std::move(*Integer)));
ConstantDescription.Size = 8;
ConstantDescription.Align = *rcc::Alignment::create(8);
diff --git a/backend/unittests/CodeGen/MachineIRCoreTest.cpp b/backend/unittests/CodeGen/MachineIRCoreTest.cpp
index 7982b04..6365e59 100644
--- a/backend/unittests/CodeGen/MachineIRCoreTest.cpp
+++ b/backend/unittests/CodeGen/MachineIRCoreTest.cpp
@@ -102,7 +102,7 @@ void testOperandKinds(TestContext &Context) {
return;
const std::array<std::uint64_t, 1> HalfWords{0x3c00};
- auto HalfBits = rcc::FloatingPointBits::create(rcc::FloatSemantics::IEEEHalf, HalfWords);
+ auto HalfBits = rcc::APFloat::create(rcc::FloatSemantics::IEEEHalf, HalfWords);
Context.expect(HalfBits.has_value(), "well-sized floating immediate must be accepted");
if (!HalfBits)
return;
@@ -110,10 +110,10 @@ void testOperandKinds(TestContext &Context) {
"floating immediate must preserve semantics and raw bits");
const std::array<std::uint64_t, 1> OverflowHalfWords{0x10000};
- Context.expect(!rcc::FloatingPointBits::create(rcc::FloatSemantics::IEEEHalf, OverflowHalfWords),
+ Context.expect(!rcc::APFloat::create(rcc::FloatSemantics::IEEEHalf, OverflowHalfWords),
"floating immediate bits above semantics width must be rejected");
const std::array<std::uint64_t, 2> TooManyHalfWords{0, 0};
- Context.expect(!rcc::FloatingPointBits::create(rcc::FloatSemantics::IEEEHalf, TooManyHalfWords),
+ Context.expect(!rcc::APFloat::create(rcc::FloatSemantics::IEEEHalf, TooManyHalfWords),
"floating immediate word-count mismatch must be rejected");
auto Virtual = Function->registerInfo().createVirtualRegister(*rcc::LLT::makeInteger(32));
diff --git a/backend/unittests/CodeGen/MachineOperandTest.cpp b/backend/unittests/CodeGen/MachineOperandTest.cpp
index 3cc7060..96f1f19 100644
--- a/backend/unittests/CodeGen/MachineOperandTest.cpp
+++ b/backend/unittests/CodeGen/MachineOperandTest.cpp
@@ -108,7 +108,7 @@ buildOperandInstruction(rcc::MachineFunction &Function, const rcc::TargetDescrip
0x0123456789abcdefULL,
0xfedcba9876543210ULL,
};
- auto Integer = rcc::IntegerImmediate::create(128, Words);
+ auto Integer = rcc::APInt::create(128, Words);
if (!Integer)
return std::unexpected(Integer.error());
@@ -149,35 +149,34 @@ void testIntegerImmediate(TestContext &Context) {
0x0123456789abcdefULL,
0x0000000000000001ULL,
};
- auto Integer = rcc::IntegerImmediate::create(65, Words);
+ auto Integer = rcc::APInt::create(65, Words);
Context.expect(Integer.has_value() && Integer->bitWidth() == 65 && Integer->words().size() == 2 &&
Integer->words()[0] == Words[0] && Integer->words()[1] == Words[1] &&
Integer->isNegative() && !Integer->isZero(),
"arbitrary-width integer must preserve exact little-endian words");
- Context.expect(!rcc::IntegerImmediate::create(0, std::span<const std::uint64_t>{}) &&
- !rcc::IntegerImmediate::create(rcc::IntegerImmediate::MaxBitWidth + 1,
- std::span<const std::uint64_t>{}),
- "integer immediate must reject unsupported bit widths");
+ Context.expect(
+ !rcc::APInt::create(0, std::span<const std::uint64_t>{}) &&
+ !rcc::APInt::create(rcc::APInt::MaxBitWidth + 1, std::span<const std::uint64_t>{}),
+ "integer immediate must reject unsupported bit widths");
const std::array<std::uint64_t, 2> TwoWords{1, 0};
const std::array<std::uint64_t, 1> HighBits{0x100};
- Context.expect(!rcc::IntegerImmediate::create(64, TwoWords) &&
- !rcc::IntegerImmediate::create(8, HighBits),
+ Context.expect(!rcc::APInt::create(64, TwoWords) && !rcc::APInt::create(8, HighBits),
"integer immediate must reject word-count and high-bit mismatches");
- auto UnsignedMaximum = rcc::IntegerImmediate::fromUnsigned(8, 255);
- auto UnsignedOverflow = rcc::IntegerImmediate::fromUnsigned(8, 256);
- auto SignedMinimum = rcc::IntegerImmediate::fromSigned(8, -128);
- auto SignedMaximum = rcc::IntegerImmediate::fromSigned(8, 127);
- auto SignedUnderflow = rcc::IntegerImmediate::fromSigned(8, -129);
- auto SignedOverflow = rcc::IntegerImmediate::fromSigned(8, 128);
+ auto UnsignedMaximum = rcc::APInt::fromUnsigned(8, 255);
+ auto UnsignedOverflow = rcc::APInt::fromUnsigned(8, 256);
+ auto SignedMinimum = rcc::APInt::fromSigned(8, -128);
+ auto SignedMaximum = rcc::APInt::fromSigned(8, 127);
+ auto SignedUnderflow = rcc::APInt::fromSigned(8, -129);
+ auto SignedOverflow = rcc::APInt::fromSigned(8, 128);
Context.expect(UnsignedMaximum && UnsignedMaximum->words()[0] == 255 && !UnsignedOverflow &&
SignedMinimum && SignedMinimum->words()[0] == 128 && SignedMaximum &&
SignedMaximum->words()[0] == 127 && !SignedUnderflow && !SignedOverflow,
"integer immediate scalar factories must enforce signedness and width");
- auto SignExtended = rcc::IntegerImmediate::fromSigned(128, -1);
- auto Zero = rcc::IntegerImmediate::fromUnsigned(128, 0);
+ auto SignExtended = rcc::APInt::fromSigned(128, -1);
+ auto Zero = rcc::APInt::fromUnsigned(128, 0);
Context.expect(SignExtended && SignExtended->isNegative() && SignExtended->words().size() == 2 &&
SignExtended->words()[0] == std::numeric_limits<std::uint64_t>::max() &&
SignExtended->words()[1] == std::numeric_limits<std::uint64_t>::max() &&
diff --git a/backend/unittests/CodeGen/MachineVerifierTest.cpp b/backend/unittests/CodeGen/MachineVerifierTest.cpp
index 528ff3b..c8c512f 100644
--- a/backend/unittests/CodeGen/MachineVerifierTest.cpp
+++ b/backend/unittests/CodeGen/MachineVerifierTest.cpp
@@ -642,7 +642,7 @@ void testTableReferenceFailures(TestContext &Context) {
return;
rcc::MachineConstantPoolEntryDesc ConstantDescription;
- auto Integer = rcc::IntegerImmediate::fromUnsigned(32, 0x01010101U);
+ auto Integer = rcc::APInt::fromUnsigned(32, 0x01010101U);
ConstantDescription.Value = std::move(*rcc::GenericConstantData::integer(std::move(*Integer)));
ConstantDescription.Size = 4;
ConstantDescription.Align = *rcc::Alignment::create(4);
diff --git a/backend/unittests/Target/RISCVAssemblyPrinterTest.cpp b/backend/unittests/Target/RISCVAssemblyPrinterTest.cpp
index e40ce8a..3794227 100644
--- a/backend/unittests/Target/RISCVAssemblyPrinterTest.cpp
+++ b/backend/unittests/Target/RISCVAssemblyPrinterTest.cpp
@@ -45,7 +45,7 @@ makeObject(std::string Symbol, std::uint64_t Size, std::uint64_t Alignment,
}
[[nodiscard]] rcc::Expected<void> addObjects(rcc::CompilationUnit &Unit) {
- auto AnswerValue = rcc::IntegerImmediate::fromUnsigned(32, 42);
+ auto AnswerValue = rcc::APInt::fromUnsigned(32, 42);
if (!AnswerValue)
return std::unexpected(AnswerValue.error());
auto Answer =
diff --git a/backend/unittests/Target/RISCVCodeGenTest.cpp b/backend/unittests/Target/RISCVCodeGenTest.cpp
index c5fc10a..1bc3361 100644
--- a/backend/unittests/Target/RISCVCodeGenTest.cpp
+++ b/backend/unittests/Target/RISCVCodeGenTest.cpp
@@ -347,8 +347,8 @@ void testClassification(TestContext &Context) {
return;
const std::array<std::uint64_t, 1> SingleWords{0x3f800000U};
const std::array<std::uint64_t, 1> DoubleWords{0x3ff0000000000000ULL};
- auto SingleBits = rcc::FloatingPointBits::create(rcc::FloatSemantics::IEEESingle, SingleWords);
- auto DoubleBits = rcc::FloatingPointBits::create(rcc::FloatSemantics::IEEEDouble, DoubleWords);
+ auto SingleBits = rcc::APFloat::create(rcc::FloatSemantics::IEEESingle, SingleWords);
+ auto DoubleBits = rcc::APFloat::create(rcc::FloatSemantics::IEEEDouble, DoubleWords);
Context.expect(SingleBits.has_value() && DoubleBits.has_value(),
"floating constant payloads must be constructible");
if (!SingleBits || !DoubleBits)
@@ -875,7 +875,7 @@ void testAtomicCompareExchangeLegalization(TestContext &Context) {
if (!AddressDefinition || !AddressDefinition->addDef(*Address) || !AddressDefinition->build())
return;
const auto BuildConstant = [&](rcc::Register Destination, std::uint64_t Value) -> bool {
- auto Immediate = rcc::IntegerImmediate::fromUnsigned(8, Value);
+ auto Immediate = rcc::APInt::fromUnsigned(8, Value);
auto Pending = Builder.buildInstr(rcc::opcode(rcc::GenericOpcode::G_CONSTANT));
return Immediate && Pending && Pending->addDef(Destination) &&
Pending->addIntegerImmediate(std::move(*Immediate)) && Pending->build();
@@ -1013,7 +1013,7 @@ void testConstantExtensionPreservesLiveSource(TestContext &Context) {
auto Source = (*Function)->registerInfo().createVirtualRegister(*I32);
auto Extended = (*Function)->registerInfo().createVirtualRegister(*I64);
auto PreservedUse = (*Function)->registerInfo().createVirtualRegister(*I32);
- auto Immediate = rcc::IntegerImmediate::fromUnsigned(32, 7);
+ auto Immediate = rcc::APInt::fromUnsigned(32, 7);
if (!Source || !Extended || !PreservedUse || !Immediate)
return;
@@ -1060,7 +1060,7 @@ void testIntegerCompareReusesConstantExtension(TestContext &Context) {
rcc::MachineInstr *Compare = Function->firstBlock()->firstInstruction();
const rcc::Register *Right = Compare->operandAt(3)->getIf<rcc::Register>();
auto WideRight = Function->registerInfo().createVirtualRegister(*I64);
- auto Immediate = rcc::IntegerImmediate::fromUnsigned(32, 0);
+ auto Immediate = rcc::APInt::fromUnsigned(32, 0);
if (Right == nullptr || !WideRight || !Immediate)
return;
diff --git a/backend/unittests/Target/RISCVMCTest.cpp b/backend/unittests/Target/RISCVMCTest.cpp
index d77899a..f43c574 100644
--- a/backend/unittests/Target/RISCVMCTest.cpp
+++ b/backend/unittests/Target/RISCVMCTest.cpp
@@ -260,7 +260,7 @@ symbolExpression(rcc::mc::MCContext &Context, std::string_view Name, std::uint32
[[nodiscard]] bool testObjectEmission(const rcc::TargetDescription &Target) {
auto Alignment = rcc::Alignment::create(8);
- auto Value = rcc::IntegerImmediate::fromUnsigned(64, 0x1122334455667788ULL);
+ auto Value = rcc::APInt::fromUnsigned(64, 0x1122334455667788ULL);
if (!Alignment || !Value)
return false;
rcc::GlobalObjectDesc Global;
diff --git a/backend/unittests/Target/RISCVObjectFileTest.cpp b/backend/unittests/Target/RISCVObjectFileTest.cpp
index 1b6d1f7..95ed5c8 100644
--- a/backend/unittests/Target/RISCVObjectFileTest.cpp
+++ b/backend/unittests/Target/RISCVObjectFileTest.cpp
@@ -293,7 +293,7 @@ private:
[[nodiscard]] rcc::Expected<rcc::GlobalInitializer> integer(std::uint32_t Bits,
std::uint64_t Value) {
- auto Immediate = rcc::IntegerImmediate::fromUnsigned(Bits, Value);
+ auto Immediate = rcc::APInt::fromUnsigned(Bits, Value);
if (!Immediate)
return std::unexpected(Immediate.error());
return rcc::GlobalInitializer::integer(std::move(*Immediate));