llvm.org GIT mirror llvm / ee30ab7
[CodeGen] Print MCSymbol operands as <mcsymbol sym> in both MIR and debug output Work towards the unification of MIR and debug output by printing `<mcsymbol sym>` instead of `<MCSym=sym>`. Only debug syntax is affected. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320685 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 2 years ago
4 changed file(s) with 38 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
119119 - It is possible to drop the whole IR section of the MIR file if it only
120120 contains dummy functions (see above). The .mir loader will create the
121121 IR functions automatically in this case.
122
123 .. _limitations:
122124
123125 Limitations
124126 -----------
677679
678680 CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp
679681
682 MCSymbol Operands
683 ^^^^^^^^^^^^^^^^^
684
685 A MCSymbol operand is holding a pointer to a ``MCSymbol``. For the limitations
686 of this operand in MIR, see :ref:`limitations `.
687
688 The syntax is:
689
690 .. code-block:: text
691
692 EH_LABEL
680693
681694 .. TODO: Describe the parsers default behaviour when optional YAML attributes
682695 are missing.
798798 case MachineOperand::MO_ExternalSymbol:
799799 case MachineOperand::MO_GlobalAddress:
800800 case MachineOperand::MO_RegisterLiveOut:
801 case MachineOperand::MO_Metadata: {
801 case MachineOperand::MO_Metadata:
802 case MachineOperand::MO_MCSymbol: {
802803 unsigned TiedOperandIdx = 0;
803804 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
804805 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
830831 printCustomRegMask(Op.getRegMask(), OS, TRI);
831832 break;
832833 }
833 case MachineOperand::MO_MCSymbol:
834 OS << "";
835 break;
836834 case MachineOperand::MO_CFIIndex: {
837835 const MachineFunction &MF = *Op.getParent()->getMF();
838836 print(MF.getFrameInstructions()[Op.getCFIIndex()], TRI);
659659 getMetadata()->printAsOperand(OS, MST);
660660 break;
661661 case MachineOperand::MO_MCSymbol:
662 OS << "<MCSym=" << *getMCSymbol() << '>';
662 OS << "<mcsymbol " << *getMCSymbol() << ">";
663663 break;
664664 case MachineOperand::MO_CFIIndex:
665665 OS << "";
1212 #include "llvm/IR/LLVMContext.h"
1313 #include "llvm/IR/Module.h"
1414 #include "llvm/IR/ModuleSlotTracker.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCAsmInfo.h"
1517 #include "llvm/Support/raw_ostream.h"
1618 #include "gtest/gtest.h"
1719
313315 ASSERT_TRUE(OS.str() == "!0");
314316 }
315317
318 TEST(MachineOperandTest, PrintMCSymbol) {
319 MCAsmInfo MAI;
320 MCContext Ctx(&MAI, /*MRI=*/nullptr, /*MOFI=*/nullptr);
321 MCSymbol *Sym = Ctx.getOrCreateSymbol("foo");
322
323 // Create a MachineOperand with a metadata and print it.
324 MachineOperand MO = MachineOperand::CreateMCSymbol(Sym);
325
326 // Checking some preconditions on the newly created
327 // MachineOperand.
328 ASSERT_TRUE(MO.isMCSymbol());
329 ASSERT_TRUE(MO.getMCSymbol() == Sym);
330
331 std::string str;
332 // Print a MachineOperand containing a metadata node.
333 raw_string_ostream OS(str);
334 MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
335 ASSERT_TRUE(OS.str() == "");
336 }
337
316338 } // end namespace