diff options
author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2017-12-19 21:47:05 +0000 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2017-12-19 21:47:05 +0000 |
commit | 43c2ba74fca95ca61abf3717b10a8a3b7369f3b3 (patch) | |
tree | 563f30b86aa46014ca1ffcd141cd3959a916a9cd | |
parent | 30e8e017c8380c26e3a9fac1b9c2d4a4d1686bae (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321111 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | docs/MIRLangRef.rst | 11 | ||||
-rw-r--r-- | lib/CodeGen/MIRPrinter.cpp | 14 | ||||
-rw-r--r-- | lib/CodeGen/MachineOperand.cpp | 6 | ||||
-rw-r--r-- | unittests/CodeGen/MachineOperandTest.cpp | 29 |
4 files changed, 45 insertions, 15 deletions
diff --git a/docs/MIRLangRef.rst b/docs/MIRLangRef.rst index 541c024bdec..150e4e21375 100644 --- a/docs/MIRLangRef.rst +++ b/docs/MIRLangRef.rst @@ -713,6 +713,17 @@ which may be emitted later in the MC layer as: .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. diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index eb2157e64b1..9b38b893973 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -784,7 +784,8 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx, 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 &MI, unsigned OpIdx, 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(" diff --git a/lib/CodeGen/MachineOperand.cpp b/lib/CodeGen/MachineOperand.cpp index 9031bdebc8a..586e826be58 100644 --- a/lib/CodeGen/MachineOperand.cpp +++ b/lib/CodeGen/MachineOperand.cpp @@ -798,11 +798,11 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, 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: { diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index fb43e10742b..cce85cafb2a 100644 --- a/unittests/CodeGen/MachineOperandTest.cpp +++ b/unittests/CodeGen/MachineOperandTest.cpp @@ -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 |