diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 01:31:09 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 01:31:09 +0800 |
| commit | be04617b2196bf62077909f21ea9df7723aae74f (patch) | |
| tree | db84a45498f761850b04fe5f16ed6a424a09a5cb /backend/unittests/MIR/MIRDocumentTest.cpp | |
| parent | 0e43f63ac7fa5e28497760a0dfec2fe20557bce0 (diff) | |
| download | rcc-project-be04617b2196bf62077909f21ea9df7723aae74f.tar.gz rcc-project-be04617b2196bf62077909f21ea9df7723aae74f.tar.xz | |
[MIR] Create virtual registers referenced by live-ins
Diffstat (limited to 'backend/unittests/MIR/MIRDocumentTest.cpp')
| -rw-r--r-- | backend/unittests/MIR/MIRDocumentTest.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/unittests/MIR/MIRDocumentTest.cpp b/backend/unittests/MIR/MIRDocumentTest.cpp index 88f92bc..c655e64 100644 --- a/backend/unittests/MIR/MIRDocumentTest.cpp +++ b/backend/unittests/MIR/MIRDocumentTest.cpp @@ -949,6 +949,48 @@ body: | printDiagnostics(Invalid); } +void testLiveInCreatesVirtualRegister(TestContext &Context) { + auto Target = createTarget(); + Context.expect(Target.has_value(), "live-in virtual-register target must be valid"); + if (!Target) + return; + + constexpr std::string_view DocumentText = R"(--- +name: live_in_vreg +liveins: + - { reg: '$g0', virtual-reg: '%0' } +body: | + bb.0: + %0:gpr64 = TEST_COPY $g0 +)"; + auto Parsed = rcc::mir::parseMIRDocument(*Target, "live-in-vreg.mir", std::string(DocumentText)); + const rcc::MachineFunction *Function = + Parsed.succeeded() ? Parsed.document()->unit().function("live_in_vreg") : nullptr; + const auto Registers = Function != nullptr ? Function->registerInfo().virtualRegisters() + : std::span<const rcc::VirtualRegisterInfo>{}; + const auto LiveIns = Function != nullptr ? Function->registerInfo().liveIns() + : std::span<const rcc::PhysicalRegisterLiveIn>{}; + Context.expect(Parsed.succeeded() && Function != nullptr && Registers.size() == 1 && + Registers.front().RegClass.has_value() && LiveIns.size() == 1 && + LiveIns.front().InitialVirtualRegister.has_value(), + "a live-in must create a virtual register before the body constrains it"); + if (!Parsed.succeeded()) { + printDiagnostics(Parsed); + return; + } + + auto Printed = rcc::mir::printMIRDocument(*Parsed.document(), *Target); + Context.expect(Printed.has_value(), + "an implicitly created live-in virtual register must be printable"); + if (!Printed) + return; + auto RoundTrip = rcc::mir::parseMIRDocument(*Target, "live-in-vreg-round-trip.mir", *Printed); + Context.expect(RoundTrip.succeeded(), + "an implicitly created live-in virtual register must round-trip"); + if (!RoundTrip.succeeded()) + printDiagnostics(RoundTrip); +} + void testBodyDiagnosticLocation(TestContext &Context) { auto Target = createTarget(); Context.expect(Target.has_value(), "body-diagnostic target must be valid"); @@ -1067,6 +1109,7 @@ int main() { testFixedWidthDocumentFields(Context); testAtomicFailure(Context); testLLVMPropertySemantics(Context); + testLiveInCreatesVirtualRegister(Context); testBodyDiagnosticLocation(Context); testAnonymousFunctionsAndIRBlocks(Context); return Context.result(); |
