summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/MIRPrinter.cpp6
-rw-r--r--llvm/lib/CodeGen/MachineOperand.cpp2
-rw-r--r--llvm/unittests/CodeGen/MachineOperandTest.cpp25
3 files changed, 27 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index fcf59adb7b3..723e57b4444 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -798,7 +798,8 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
case MachineOperand::MO_JumpTableIndex:
case MachineOperand::MO_ExternalSymbol:
case MachineOperand::MO_GlobalAddress:
- case MachineOperand::MO_RegisterLiveOut: {
+ case MachineOperand::MO_RegisterLiveOut:
+ case MachineOperand::MO_Metadata: {
unsigned TiedOperandIdx = 0;
if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -830,9 +831,6 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
printCustomRegMask(Op.getRegMask(), OS, TRI);
break;
}
- case MachineOperand::MO_Metadata:
- Op.getMetadata()->printAsOperand(OS, MST);
- break;
case MachineOperand::MO_MCSymbol:
OS << "<mcsymbol " << *Op.getMCSymbol() << ">";
break;
diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index 009722b981a..a1ae5d396c2 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -657,9 +657,7 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
break;
}
case MachineOperand::MO_Metadata:
- OS << '<';
getMetadata()->printAsOperand(OS, MST);
- OS << '>';
break;
case MachineOperand::MO_MCSymbol:
OS << "<MCSym=" << *getMCSymbol() << '>';
diff --git a/llvm/unittests/CodeGen/MachineOperandTest.cpp b/llvm/unittests/CodeGen/MachineOperandTest.cpp
index 5c13ddc4b8c..192229be065 100644
--- a/llvm/unittests/CodeGen/MachineOperandTest.cpp
+++ b/llvm/unittests/CodeGen/MachineOperandTest.cpp
@@ -289,4 +289,29 @@ TEST(MachineOperandTest, PrintRegisterLiveOut) {
ASSERT_TRUE(OS.str() == "liveout(<unknown>)");
}
+TEST(MachineOperandTest, PrintMetadata) {
+ LLVMContext Ctx;
+ Module M("MachineOperandMDNodeTest", Ctx);
+ NamedMDNode *MD = M.getOrInsertNamedMetadata("namedmd");
+ ModuleSlotTracker DummyMST(&M);
+ Metadata *MDS = MDString::get(Ctx, "foo");
+ MDNode *Node = MDNode::get(Ctx, MDS);
+ MD->addOperand(Node);
+
+ // Create a MachineOperand with a metadata and print it.
+ MachineOperand MO = MachineOperand::CreateMetadata(Node);
+
+ // Checking some preconditions on the newly created
+ // MachineOperand.
+ ASSERT_TRUE(MO.isMetadata());
+ ASSERT_TRUE(MO.getMetadata() == Node);
+
+ std::string str;
+ // Print a MachineOperand containing a metadata node.
+ raw_string_ostream OS(str);
+ MO.print(OS, DummyMST, LLT{}, false, false, 0, /*TRI=*/nullptr,
+ /*IntrinsicInfo=*/nullptr);
+ ASSERT_TRUE(OS.str() == "!0");
+}
+
} // end namespace
OpenPOWER on IntegriCloud