From 13129166eb08c874edcd9cf10e730c91e202af17 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Tue, 8 Mar 2016 01:17:03 +0000 Subject: [PATCH] [MIR] Teach the parser/printer that generic virtual registers do not need a register class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262893 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MIRParser/MIRParser.cpp | 19 +++++++++++++------ lib/CodeGen/MIRPrinter.cpp | 9 +++++++-- .../MIR/X86/generic-virtual-registers.mir | 17 ++++++++++------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/MIRParser/MIRParser.cpp b/lib/CodeGen/MIRParser/MIRParser.cpp index 422efbc5ce5..cfe3ab33116 100644 --- a/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/lib/CodeGen/MIRParser/MIRParser.cpp @@ -347,12 +347,19 @@ bool MIRParserImpl::initializeRegisterInfo(MachineFunction &MF, SMDiagnostic Error; // Parse the virtual register information. for (const auto &VReg : YamlMF.VirtualRegisters) { - const auto *RC = getRegClass(MF, VReg.Class.Value); - if (!RC) - return error(VReg.Class.SourceRange.Start, - Twine("use of undefined register class '") + - VReg.Class.Value + "'"); - unsigned Reg = RegInfo.createVirtualRegister(RC); + unsigned Reg; + if (StringRef(VReg.Class.Value).equals("_")) { + // This is a generic virtual register. + // The size will be set appropriately when we reach the definition. + Reg = RegInfo.createGenericVirtualRegister(/*Size*/ 1); + } else { + const auto *RC = getRegClass(MF, VReg.Class.Value); + if (!RC) + return error(VReg.Class.SourceRange.Start, + Twine("use of undefined register class '") + + VReg.Class.Value + "'"); + Reg = RegInfo.createVirtualRegister(RC); + } if (!PFS.VirtualRegisterSlots.insert(std::make_pair(VReg.ID.Value, Reg)) .second) return error(VReg.ID.SourceRange.Start, diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 58036016a1e..eee0c982caa 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -207,8 +207,13 @@ void MIRPrinter::convert(yaml::MachineFunction &MF, unsigned Reg = TargetRegisterInfo::index2VirtReg(I); yaml::VirtualRegisterDefinition VReg; VReg.ID = I; - VReg.Class = - StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower(); + if (RegInfo.getRegClass(Reg)) + VReg.Class = + StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower(); + else { + VReg.Class = std::string("_"); + assert(RegInfo.getSize(Reg) && "Generic registers must have a size"); + } unsigned PreferredReg = RegInfo.getSimpleHint(Reg); if (PreferredReg) printReg(PreferredReg, VReg.PreferredRegister, TRI); diff --git a/test/CodeGen/MIR/X86/generic-virtual-registers.mir b/test/CodeGen/MIR/X86/generic-virtual-registers.mir index 6fcc8ab1083..f3692e75870 100644 --- a/test/CodeGen/MIR/X86/generic-virtual-registers.mir +++ b/test/CodeGen/MIR/X86/generic-virtual-registers.mir @@ -19,14 +19,17 @@ name: bar isSSA: true # CHECK: registers: -# CHECK-NEXT: - { id: 0, class: gr32 } -# CHECK-NEXT: - { id: 1, class: gr64 } +# CHECK-NEXT: - { id: 0, class: _ } +# CHECK-NEXT: - { id: 1, class: _ } +# CHECK-NEXT: - { id: 2, class: _ } +# CHECK-NEXT: - { id: 3, class: _ } +# CHECK-NEXT: - { id: 4, class: _ } registers: - - { id: 0, class: gr32 } - - { id: 1, class: gr64 } - - { id: 2, class: gr64 } - - { id: 3, class: gr64 } - - { id: 4, class: gr64 } + - { id: 0, class: _ } + - { id: 1, class: _ } + - { id: 2, class: _ } + - { id: 3, class: _ } + - { id: 4, class: _ } body: | bb.0.entry: liveins: %edi