[llvm] r321111 - [CodeGen] Move printing MO_IntrinsicID operands to MachineOperand::print
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 13:47:05 PST 2017
Author: thegameg
Date: Tue Dec 19 13:47:05 2017
New Revision: 321111
URL: http://llvm.org/viewvc/llvm-project?rev=321111&view=rev
Log:
[CodeGen] Move printing MO_IntrinsicID operands to MachineOperand::print
Work towards the unification of MIR and debug output by refactoring the
interfaces.
Also add support for printing with a null TargetIntrinsicInfo and no
MachineFunction.
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=321111&r1=321110&r2=321111&view=diff
==============================================================================
--- llvm/trunk/docs/MIRLangRef.rst (original)
+++ llvm/trunk/docs/MIRLangRef.rst Tue Dec 19 13:47:05 2017
@@ -713,6 +713,17 @@ which may be emitted later in the MC lay
.cfi_offset w30, -16
+IntrinsicID Operands
+^^^^^^^^^^^^^^^^^^^^
+
+An Intrinsic ID operand contains a generic intrinsic ID or a target-specific ID.
+
+The syntax for the ``returnaddress`` intrinsic is:
+
+.. code-block:: text
+
+ %x0 = COPY intrinsic(@llvm.returnaddress)
+
.. TODO: Describe the parsers default behaviour when optional YAML attributes
are missing.
.. TODO: Describe the syntax for the bundled instructions.
Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=321111&r1=321110&r2=321111&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Tue Dec 19 13:47:05 2017
@@ -784,7 +784,8 @@ void MIPrinter::print(const MachineInstr
case MachineOperand::MO_RegisterLiveOut:
case MachineOperand::MO_Metadata:
case MachineOperand::MO_MCSymbol:
- case MachineOperand::MO_CFIIndex: {
+ case MachineOperand::MO_CFIIndex:
+ case MachineOperand::MO_IntrinsicID: {
unsigned TiedOperandIdx = 0;
if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -813,17 +814,6 @@ void MIPrinter::print(const MachineInstr
printCustomRegMask(Op.getRegMask(), OS, TRI);
break;
}
- case MachineOperand::MO_IntrinsicID: {
- Intrinsic::ID ID = Op.getIntrinsicID();
- if (ID < Intrinsic::num_intrinsics)
- OS << "intrinsic(@" << Intrinsic::getName(ID, None) << ')';
- else {
- const MachineFunction &MF = *Op.getParent()->getMF();
- const TargetIntrinsicInfo *TII = MF.getTarget().getIntrinsicInfo();
- OS << "intrinsic(@" << TII->getName(ID) << ')';
- }
- break;
- }
case MachineOperand::MO_Predicate: {
auto Pred = static_cast<CmpInst::Predicate>(Op.getPredicate());
OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
Modified: llvm/trunk/lib/CodeGen/MachineOperand.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOperand.cpp?rev=321111&r1=321110&r2=321111&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOperand.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOperand.cpp Tue Dec 19 13:47:05 2017
@@ -798,11 +798,11 @@ void MachineOperand::print(raw_ostream &
case MachineOperand::MO_IntrinsicID: {
Intrinsic::ID ID = getIntrinsicID();
if (ID < Intrinsic::num_intrinsics)
- OS << "<intrinsic:@" << Intrinsic::getName(ID, None) << '>';
+ OS << "intrinsic(@" << Intrinsic::getName(ID, None) << ')';
else if (IntrinsicInfo)
- OS << "<intrinsic:@" << IntrinsicInfo->getName(ID) << '>';
+ OS << "intrinsic(@" << IntrinsicInfo->getName(ID) << ')';
else
- OS << "<intrinsic:" << ID << '>';
+ OS << "intrinsic(" << ID << ')';
break;
}
case MachineOperand::MO_Predicate: {
Modified: llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp?rev=321111&r1=321110&r2=321111&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp Tue Dec 19 13:47:05 2017
@@ -353,4 +353,33 @@ TEST(MachineOperandTest, PrintCFI) {
ASSERT_TRUE(OS.str() == "<cfi directive>");
}
+TEST(MachineOperandTest, PrintIntrinsicID) {
+ // Create a MachineOperand with a generic intrinsic ID.
+ MachineOperand MO = MachineOperand::CreateIntrinsicID(Intrinsic::bswap);
+
+ // Checking some preconditions on the newly created
+ // MachineOperand.
+ ASSERT_TRUE(MO.isIntrinsicID());
+ ASSERT_TRUE(MO.getIntrinsicID() == Intrinsic::bswap);
+
+ std::string str;
+ {
+ // Print a MachineOperand containing a generic intrinsic ID.
+ raw_string_ostream OS(str);
+ MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+ ASSERT_TRUE(OS.str() == "intrinsic(@llvm.bswap)");
+ }
+
+ str.clear();
+ // Set a target-specific intrinsic.
+ MO = MachineOperand::CreateIntrinsicID((Intrinsic::ID)-1);
+ {
+ // Print a MachineOperand containing a target-specific intrinsic ID but not
+ // IntrinsicInfo.
+ raw_string_ostream OS(str);
+ MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+ ASSERT_TRUE(OS.str() == "intrinsic(4294967295)");
+ }
+}
+
} // end namespace
More information about the llvm-commits
mailing list