diff options
author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2017-12-14 10:03:18 +0000 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2017-12-14 10:03:18 +0000 |
commit | f726becf7caba94af09e1909a4e10e3e1bd6006f (patch) | |
tree | 2bbb55d53de4c87329766bb829f06cdaff53d531 | |
parent | f6cd582907a9cb4b791e111dfe1be5d9faa8791f (diff) |
[CodeGen] Move printing MO_Metadata operands to MachineOperand::print
Work towards the unification of MIR and debug output by refactoring the
interfaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320684 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/MIRPrinter.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/MachineOperand.cpp | 2 | ||||
-rw-r--r-- | unittests/CodeGen/MachineOperandTest.cpp | 25 |
3 files changed, 27 insertions, 6 deletions
diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index fcf59adb7b3..723e57b4444 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/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/lib/CodeGen/MachineOperand.cpp b/lib/CodeGen/MachineOperand.cpp index 009722b981a..a1ae5d396c2 100644 --- a/lib/CodeGen/MachineOperand.cpp +++ b/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/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index 5c13ddc4b8c..192229be065 100644 --- a/unittests/CodeGen/MachineOperandTest.cpp +++ b/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 |