summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRPrinter.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2017-10-24 18:04:54 +0000
committerJustin Bogner <mail@justinbogner.com>2017-10-24 18:04:54 +0000
commit6c452834a114c8752d2547ef24a710550a7a65da (patch)
tree1aca33803dee5c0e310818d8555b4aa2eaac726a /llvm/lib/CodeGen/MIRPrinter.cpp
parent8f0c78309562cef845cf0e130c8be2ff2a19295b (diff)
downloadbcm5719-llvm-6c452834a114c8752d2547ef24a710550a7a65da.tar.gz
bcm5719-llvm-6c452834a114c8752d2547ef24a710550a7a65da.zip
MIR: Print the register class or bank in vreg defs
This updates the MIRPrinter to include the regclass when printing virtual register defs, which is already valid syntax for the parser. That is, given 64 bit %0 and %1 in a "gpr" regbank, %1(s64) = COPY %0(s64) would now be written as %1:gpr(s64) = COPY %0(s64) While this change alone introduces a bit of redundancy with the registers block, it allows us to update the tests to be more concise and understandable and brings us closer to being able to remove the registers block completely. Note: We generally only print the class in defs, but there is one exception. If there are uses without any defs whatsoever, we'll print the class on all uses. I'm not completely convinced this comes up in meaningful machine IR, but for now the MIRParser and MachineVerifier both accept that kind of stuff, so we don't want to have a situation where we can print something we can't parse. llvm-svn: 316479
Diffstat (limited to 'llvm/lib/CodeGen/MIRPrinter.cpp')
-rw-r--r--llvm/lib/CodeGen/MIRPrinter.cpp46
1 files changed, 34 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index 528140234ee..f8da8d32d6a 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -270,6 +270,28 @@ static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
OS << ')';
}
+static void printRegClassOrBank(unsigned Reg, raw_ostream &OS,
+ const MachineRegisterInfo &RegInfo,
+ const TargetRegisterInfo *TRI) {
+ if (RegInfo.getRegClassOrNull(Reg))
+ OS << StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
+ else if (RegInfo.getRegBankOrNull(Reg))
+ OS << StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
+ else {
+ OS << "_";
+ assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
+ "Generic registers must have a valid type");
+ }
+}
+
+static void printRegClassOrBank(unsigned Reg, yaml::StringValue &Dest,
+ const MachineRegisterInfo &RegInfo,
+ const TargetRegisterInfo *TRI) {
+ raw_string_ostream OS(Dest.Value);
+ printRegClassOrBank(Reg, OS, RegInfo, TRI);
+}
+
+
void MIRPrinter::convert(yaml::MachineFunction &MF,
const MachineRegisterInfo &RegInfo,
const TargetRegisterInfo *TRI) {
@@ -280,16 +302,7 @@ void MIRPrinter::convert(yaml::MachineFunction &MF,
unsigned Reg = TargetRegisterInfo::index2VirtReg(I);
yaml::VirtualRegisterDefinition VReg;
VReg.ID = I;
- if (RegInfo.getRegClassOrNull(Reg))
- VReg.Class =
- StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
- else if (RegInfo.getRegBankOrNull(Reg))
- VReg.Class = StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
- else {
- VReg.Class = std::string("_");
- assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
- "Generic registers must have a valid type");
- }
+ printRegClassOrBank(Reg, VReg.Class, RegInfo, TRI);
unsigned PreferredReg = RegInfo.getSimpleHint(Reg);
if (PreferredReg)
printReg(PreferredReg, VReg.PreferredRegister, TRI);
@@ -915,7 +928,8 @@ void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
bool IsDef) {
printTargetFlags(Op);
switch (Op.getType()) {
- case MachineOperand::MO_Register:
+ case MachineOperand::MO_Register: {
+ unsigned Reg = Op.getReg();
if (Op.isImplicit())
OS << (Op.isDef() ? "implicit-def " : "implicit ");
else if (!IsDef && Op.isDef())
@@ -933,15 +947,23 @@ void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
OS << "early-clobber ";
if (Op.isDebug())
OS << "debug-use ";
- printReg(Op.getReg(), OS, TRI);
+ printReg(Reg, OS, TRI);
// Print the sub register.
if (Op.getSubReg() != 0)
OS << '.' << TRI->getSubRegIndexName(Op.getSubReg());
+ if (TargetRegisterInfo::isVirtualRegister(Reg)) {
+ const MachineRegisterInfo &MRI = Op.getParent()->getMF()->getRegInfo();
+ if (IsDef || MRI.def_empty(Reg)) {
+ OS << ':';
+ printRegClassOrBank(Reg, OS, MRI, TRI);
+ }
+ }
if (ShouldPrintRegisterTies && Op.isTied() && !Op.isDef())
OS << "(tied-def " << Op.getParent()->findTiedOperandIdx(I) << ")";
if (TypeToPrint.isValid())
OS << '(' << TypeToPrint << ')';
break;
+ }
case MachineOperand::MO_Immediate:
OS << Op.getImm();
break;
OpenPOWER on IntegriCloud