llvm.org GIT mirror llvm / f726bec
[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 Francis Visoiu Mistrih 2 years ago
3 changed file(s) with 27 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
797797 case MachineOperand::MO_JumpTableIndex:
798798 case MachineOperand::MO_ExternalSymbol:
799799 case MachineOperand::MO_GlobalAddress:
800 case MachineOperand::MO_RegisterLiveOut: {
800 case MachineOperand::MO_RegisterLiveOut:
801 case MachineOperand::MO_Metadata: {
801802 unsigned TiedOperandIdx = 0;
802803 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
803804 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
829830 printCustomRegMask(Op.getRegMask(), OS, TRI);
830831 break;
831832 }
832 case MachineOperand::MO_Metadata:
833 Op.getMetadata()->printAsOperand(OS, MST);
834 break;
835833 case MachineOperand::MO_MCSymbol:
836834 OS << "";
837835 break;
656656 break;
657657 }
658658 case MachineOperand::MO_Metadata:
659 OS << '<';
660659 getMetadata()->printAsOperand(OS, MST);
661 OS << '>';
662660 break;
663661 case MachineOperand::MO_MCSymbol:
664662 OS << "';
288288 ASSERT_TRUE(OS.str() == "liveout()");
289289 }
290290
291 TEST(MachineOperandTest, PrintMetadata) {
292 LLVMContext Ctx;
293 Module M("MachineOperandMDNodeTest", Ctx);
294 NamedMDNode *MD = M.getOrInsertNamedMetadata("namedmd");
295 ModuleSlotTracker DummyMST(&M);
296 Metadata *MDS = MDString::get(Ctx, "foo");
297 MDNode *Node = MDNode::get(Ctx, MDS);
298 MD->addOperand(Node);
299
300 // Create a MachineOperand with a metadata and print it.
301 MachineOperand MO = MachineOperand::CreateMetadata(Node);
302
303 // Checking some preconditions on the newly created
304 // MachineOperand.
305 ASSERT_TRUE(MO.isMetadata());
306 ASSERT_TRUE(MO.getMetadata() == Node);
307
308 std::string str;
309 // Print a MachineOperand containing a metadata node.
310 raw_string_ostream OS(str);
311 MO.print(OS, DummyMST, LLT{}, false, false, 0, /*TRI=*/nullptr,
312 /*IntrinsicInfo=*/nullptr);
313 ASSERT_TRUE(OS.str() == "!0");
314 }
315
291316 } // end namespace