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/lib/MIR/MIRDocumentParser.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/lib/MIR/MIRDocumentParser.cpp')
| -rw-r--r-- | backend/lib/MIR/MIRDocumentParser.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/backend/lib/MIR/MIRDocumentParser.cpp b/backend/lib/MIR/MIRDocumentParser.cpp index 954d0d8..9c4728a 100644 --- a/backend/lib/MIR/MIRDocumentParser.cpp +++ b/backend/lib/MIR/MIRDocumentParser.cpp @@ -172,15 +172,22 @@ bool MIRDocumentParser::physicalRegister(const yaml::Node &Node, PhysicalRegiste } bool MIRDocumentParser::virtualRegister(std::string_view Text, const TextRange &Range, - const MIParserContext &Context, Register &Reg) { + MachineFunction &Function, MIParserContext &Context, + Register &Reg) { const auto ID = parsePrefixedID(Text, "%"); if (!ID) return fail(Range, "virtual register must use the '%N' MIR spelling"); - const auto Found = + auto Found = std::ranges::find_if(Context.VirtualRegisters, [ID](const MIVirtualRegisterSlot &Slot) { return Slot.TextID == *ID; }); - if (Found == Context.VirtualRegisters.end()) - return fail(Range, "reference to undefined virtual register '%" + std::to_string(*ID) + "'"); + if (Found == Context.VirtualRegisters.end()) { + auto Created = Function.registerInfo().createVirtualRegister(); + if (!Created) + return importError(Range, Created.error()); + Context.VirtualRegisters.push_back({*ID, *Created}); + Reg = *Created; + return false; + } Reg = Found->Reg; return false; } |
