[llvm] r320685 - [CodeGen] Print MCSymbol operands as <mcsymbol sym> in both MIR and debug output
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 14 02:03:23 PST 2017
Author: thegameg
Date: Thu Dec 14 02:03:23 2017
New Revision: 320685
URL: http://llvm.org/viewvc/llvm-project?rev=320685&view=rev
Log:
[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.
Modified:
llvm/trunk/docs/MIRLangRef.rst
llvm/trunk/lib/CodeGen/MIRPrinter.cpp
llvm/trunk/lib/CodeGen/MachineOperand.cpp
llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp
Modified: llvm/trunk/docs/MIRLangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/MIRLangRef.rst?rev=320685&r1=320684&r2=320685&view=diff
==============================================================================
--- llvm/trunk/docs/MIRLangRef.rst (original)
+++ llvm/trunk/docs/MIRLangRef.rst Thu Dec 14 02:03:23 2017
@@ -121,6 +121,8 @@ Tests are more accessible and future pro
contains dummy functions (see above). The .mir loader will create the
IR functions automatically in this case.
+.. _limitations:
+
Limitations
-----------
@@ -678,6 +680,17 @@ Example:
CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp
+MCSymbol Operands
+^^^^^^^^^^^^^^^^^
+
+A MCSymbol operand is holding a pointer to a ``MCSymbol``. For the limitations
+of this operand in MIR, see :ref:`limitations <limitations>`.
+
+The syntax is:
+
+.. code-block:: text
+
+ EH_LABEL <mcsymbol Ltmp1>
.. TODO: Describe the parsers default behaviour when optional YAML attributes
are missing.
Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=320685&r1=320684&r2=320685&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Thu Dec 14 02:03:23 2017
@@ -799,7 +799,8 @@ void MIPrinter::print(const MachineInstr
case MachineOperand::MO_ExternalSymbol:
case MachineOperand::MO_GlobalAddress:
case MachineOperand::MO_RegisterLiveOut:
- case MachineOperand::MO_Metadata: {
+ case MachineOperand::MO_Metadata:
+ case MachineOperand::MO_MCSymbol: {
unsigned TiedOperandIdx = 0;
if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -831,9 +832,6 @@ void MIPrinter::print(const MachineInstr
printCustomRegMask(Op.getRegMask(), OS, TRI);
break;
}
- case MachineOperand::MO_MCSymbol:
- OS << "<mcsymbol " << *Op.getMCSymbol() << ">";
- break;
case MachineOperand::MO_CFIIndex: {
const MachineFunction &MF = *Op.getParent()->getMF();
print(MF.getFrameInstructions()[Op.getCFIIndex()], TRI);
Modified: llvm/trunk/lib/CodeGen/MachineOperand.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOperand.cpp?rev=320685&r1=320684&r2=320685&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOperand.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOperand.cpp Thu Dec 14 02:03:23 2017
@@ -660,7 +660,7 @@ void MachineOperand::print(raw_ostream &
getMetadata()->printAsOperand(OS, MST);
break;
case MachineOperand::MO_MCSymbol:
- OS << "<MCSym=" << *getMCSymbol() << '>';
+ OS << "<mcsymbol " << *getMCSymbol() << ">";
break;
case MachineOperand::MO_CFIIndex:
OS << "<call frame instruction>";
Modified: llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp?rev=320685&r1=320684&r2=320685&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp Thu Dec 14 02:03:23 2017
@@ -13,6 +13,8 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
@@ -314,4 +316,24 @@ TEST(MachineOperandTest, PrintMetadata)
ASSERT_TRUE(OS.str() == "!0");
}
+TEST(MachineOperandTest, PrintMCSymbol) {
+ MCAsmInfo MAI;
+ MCContext Ctx(&MAI, /*MRI=*/nullptr, /*MOFI=*/nullptr);
+ MCSymbol *Sym = Ctx.getOrCreateSymbol("foo");
+
+ // Create a MachineOperand with a metadata and print it.
+ MachineOperand MO = MachineOperand::CreateMCSymbol(Sym);
+
+ // Checking some preconditions on the newly created
+ // MachineOperand.
+ ASSERT_TRUE(MO.isMCSymbol());
+ ASSERT_TRUE(MO.getMCSymbol() == Sym);
+
+ std::string str;
+ // Print a MachineOperand containing a metadata node.
+ raw_string_ostream OS(str);
+ MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+ ASSERT_TRUE(OS.str() == "<mcsymbol foo>");
+}
+
} // end namespace
More information about the llvm-commits
mailing list