[llvm] r320566 - [CodeGen] Print jump-table index operands as %jump-table.0 in both MIR and debug output

Francis Visoiu Mistrih via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 02:30:59 PST 2017


Author: thegameg
Date: Wed Dec 13 02:30:59 2017
New Revision: 320566

URL: http://llvm.org/viewvc/llvm-project?rev=320566&view=rev
Log:
[CodeGen] Print jump-table index operands as %jump-table.0 in both MIR and debug output

Work towards the unification of MIR and debug output by printing `%jump-table.0` instead of `<jt#0>`.

Only debug syntax is affected.

Modified:
    llvm/trunk/docs/MIRLangRef.rst
    llvm/trunk/include/llvm/CodeGen/MachineJumpTableInfo.h
    llvm/trunk/lib/CodeGen/MIRPrinter.cpp
    llvm/trunk/lib/CodeGen/MachineFunction.cpp
    llvm/trunk/lib/CodeGen/MachineOperand.cpp
    llvm/trunk/test/CodeGen/AArch64/max-jump-table.ll
    llvm/trunk/test/CodeGen/AArch64/min-jump-table.ll
    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=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/docs/MIRLangRef.rst (original)
+++ llvm/trunk/docs/MIRLangRef.rst Wed Dec 13 02:30:59 2017
@@ -238,6 +238,8 @@ in the block's definition:
 The block's name should be identical to the name of the IR block that this
 machine block is based on.
 
+.. _block-references:
+
 Block References
 ^^^^^^^^^^^^^^^^
 
@@ -630,6 +632,39 @@ and the offset 8:
 
     %sgpr2 = S_ADD_U32 _, target-index(amdgpu-constdata-start) + 8, implicit-def _, implicit-def _
 
+Jump-table Index Operands
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+A jump-table index operand with the index 0 is printed as following:
+
+.. code-block:: text
+
+    tBR_JTr killed %r0, %jump-table.0
+
+A machine jump-table entry contains a list of ``MachineBasicBlocks``. When serializing all the function's jump-table entries, the following format is used:
+
+.. code-block:: text
+
+    jumpTable:
+      kind:             <kind>
+      entries:
+        - id:             <index>
+          blocks:         [ <bbreference>, <bbreference>, ... ]
+
+where ``<kind>`` is describing how the jump table is represented and emitted (plain address, relocations, PIC, etc.), and each ``<index>`` is a 32-bit unsigned integer and ``blocks`` contains a list of :ref:`machine basic block references <block-references>`.
+
+Example:
+
+.. code-block:: text
+
+    jumpTable:
+      kind:             inline
+      entries:
+        - id:             0
+          blocks:         [ '%bb.3', '%bb.9', '%bb.4.d3' ]
+        - id:             1
+          blocks:         [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ]
+
 .. TODO: Describe the parsers default behaviour when optional YAML attributes
    are missing.
 .. TODO: Describe the syntax for the bundled instructions.
@@ -640,8 +675,6 @@ and the offset 8:
 .. TODO: Describe the frame information YAML mapping.
 .. TODO: Describe the syntax of the stack object machine operands and their
    YAML definitions.
-.. TODO: Describe the syntax of the jump table machine operands and their
-   YAML definitions.
 .. TODO: Describe the syntax of the block address machine operands.
 .. TODO: Describe the syntax of the CFI index machine operands.
 .. TODO: Describe the syntax of the metadata machine operands, and the

Modified: llvm/trunk/include/llvm/CodeGen/MachineJumpTableInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineJumpTableInfo.h?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineJumpTableInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineJumpTableInfo.h Wed Dec 13 02:30:59 2017
@@ -20,6 +20,7 @@
 #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
 #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
 
+#include "llvm/Support/Printable.h"
 #include <cassert>
 #include <vector>
 
@@ -125,6 +126,15 @@ public:
   void dump() const;
 };
 
+
+/// Prints a jump table entry reference.
+///
+/// The format is:
+///   %jump-table.5       - a jump table entry with index == 5.
+///
+/// Usage: OS << printJumpTableEntryReference(Idx) << '\n';
+Printable printJumpTableEntryReference(unsigned Idx);
+
 } // End llvm namespace
 
 #endif

Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Wed Dec 13 02:30:59 2017
@@ -852,7 +852,8 @@ void MIPrinter::print(const MachineInstr
   case MachineOperand::MO_CImmediate:
   case MachineOperand::MO_MachineBasicBlock:
   case MachineOperand::MO_ConstantPoolIndex:
-  case MachineOperand::MO_TargetIndex: {
+  case MachineOperand::MO_TargetIndex:
+  case MachineOperand::MO_JumpTableIndex: {
     unsigned TiedOperandIdx = 0;
     if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
       TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -867,9 +868,6 @@ void MIPrinter::print(const MachineInstr
   case MachineOperand::MO_FrameIndex:
     printStackObjectReference(Op.getIndex());
     break;
-  case MachineOperand::MO_JumpTableIndex:
-    OS << "%jump-table." << Op.getIndex();
-    break;
   case MachineOperand::MO_ExternalSymbol: {
     StringRef Name = Op.getSymbolName();
     OS << '$';

Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Wed Dec 13 02:30:59 2017
@@ -906,7 +906,7 @@ void MachineJumpTableInfo::print(raw_ost
   OS << "Jump Tables:\n";
 
   for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
-    OS << "  jt#" << i << ": ";
+    OS << printJumpTableEntryReference(i) << ": ";
     for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
       OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
   }
@@ -918,6 +918,10 @@ void MachineJumpTableInfo::print(raw_ost
 LLVM_DUMP_METHOD void MachineJumpTableInfo::dump() const { print(dbgs()); }
 #endif
 
+Printable llvm::printJumpTableEntryReference(unsigned Idx) {
+  return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
+}
+
 //===----------------------------------------------------------------------===//
 //  MachineConstantPool implementation
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/CodeGen/MachineOperand.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOperand.cpp?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOperand.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOperand.cpp Wed Dec 13 02:30:59 2017
@@ -14,6 +14,7 @@
 #include "llvm/CodeGen/MachineOperand.h"
 #include "llvm/Analysis/Loads.h"
 #include "llvm/CodeGen/MIRPrinter.h"
+#include "llvm/CodeGen/MachineJumpTableInfo.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetRegisterInfo.h"
@@ -523,7 +524,7 @@ void MachineOperand::print(raw_ostream &
     break;
   }
   case MachineOperand::MO_JumpTableIndex:
-    OS << "<jt#" << getIndex() << '>';
+    OS << printJumpTableEntryReference(getIndex());
     break;
   case MachineOperand::MO_GlobalAddress:
     OS << "<ga:";

Modified: llvm/trunk/test/CodeGen/AArch64/max-jump-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/max-jump-table.ll?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/max-jump-table.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/max-jump-table.ll Wed Dec 13 02:30:59 2017
@@ -28,19 +28,19 @@ entry:
   ]
 ; CHECK-LABEL: function jt1:
 ; CHECK-NEXT: Jump Tables:
-; CHECK0-NEXT: jt#0:
-; CHECK0-NOT: jt#1:
-; CHECK4-NEXT: jt#0:
-; CHECK4-SAME: jt#1:
-; CHECK4-SAME: jt#2:
-; CHECK4-SAME: jt#3:
-; CHECK4-NOT: jt#4:
-; CHECK8-NEXT: jt#0:
-; CHECK8-SAME: jt#1:
-; CHECK8-NOT: jt#2:
-; CHECKM1-NEXT: jt#0:
-; CHECKM1-SAME: jt#1
-; CHECKM1-NOT: jt#2:
+; CHECK0-NEXT: %jump-table.0:
+; CHECK0-NOT: %jump-table.1:
+; CHECK4-NEXT: %jump-table.0:
+; CHECK4-SAME: %jump-table.1:
+; CHECK4-SAME: %jump-table.2:
+; CHECK4-SAME: %jump-table.3:
+; CHECK4-NOT: %jump-table.4:
+; CHECK8-NEXT: %jump-table.0:
+; CHECK8-SAME: %jump-table.1:
+; CHECK8-NOT: %jump-table.2:
+; CHECKM1-NEXT: %jump-table.0:
+; CHECKM1-SAME: %jump-table.1
+; CHECKM1-NOT: %jump-table.2:
 ; CHEC-NEXT: Function Live Ins:
 
 bb1: tail call void @ext(i32 0) br label %return
@@ -77,10 +77,10 @@ entry:
   ]
 ; CHECK-LABEL: function jt2:
 ; CHECK-NEXT: Jump Tables:
-; CHECK0-NEXT: jt#0:  %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
-; CHECK4-NEXT: jt#0:  %bb.1 %bb.2 %bb.3 %bb.4{{$}}
-; CHECK8-NEXT: jt#0:  %bb.1 %bb.2 %bb.3 %bb.4{{$}}
-; CHECKM1-NEXT: jt#0:  %bb.1 %bb.2 %bb.3 %bb.4{{$}}
+; CHECK0-NEXT: %jump-table.0:  %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
+; CHECK4-NEXT: %jump-table.0:  %bb.1 %bb.2 %bb.3 %bb.4{{$}}
+; CHECK8-NEXT: %jump-table.0:  %bb.1 %bb.2 %bb.3 %bb.4{{$}}
+; CHECKM1-NEXT: %jump-table.0:  %bb.1 %bb.2 %bb.3 %bb.4{{$}}
 ; CHEC-NEXT: Function Live Ins:
 
 bb1: tail call void @ext(i32 1) br label %return

Modified: llvm/trunk/test/CodeGen/AArch64/min-jump-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/min-jump-table.ll?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/min-jump-table.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/min-jump-table.ll Wed Dec 13 02:30:59 2017
@@ -12,8 +12,8 @@ entry:
   ]
 ; CHECK-LABEL: function jt2:
 ; CHECK0-NEXT: Jump Tables:
-; CHECK0-NEXT: jt#0:
-; CHECK0-NOT: jt#1:
+; CHECK0-NEXT: %jump-table.0:
+; CHECK0-NOT: %jump-table.1:
 ; CHECK4-NOT: Jump Tables:
 ; CHECK8-NOT: Jump Tables:
 
@@ -33,11 +33,11 @@ entry:
   ]
 ; CHECK-LABEL: function jt4:
 ; CHECK0-NEXT: Jump Tables:
-; CHECK0-NEXT: jt#0:
-; CHECK0-NOT: jt#1:
+; CHECK0-NEXT: %jump-table.0:
+; CHECK0-NOT: %jump-table.1:
 ; CHECK4-NEXT: Jump Tables:
-; CHECK4-NEXT: jt#0:
-; CHECK4-NOT: jt#1:
+; CHECK4-NEXT: %jump-table.0:
+; CHECK4-NOT: %jump-table.1:
 ; CHECK8-NOT: Jump Tables:
 
 bb1: tail call void @ext(i32 0) br label %return
@@ -62,8 +62,8 @@ entry:
   ]
 ; CHECK-LABEL: function jt8:
 ; CHECK-NEXT: Jump Tables:
-; CHECK-NEXT: jt#0:
-; CHECK-NOT: jt#1:
+; CHECK-NEXT: %jump-table.0:
+; CHECK-NOT: %jump-table.1:
 
 bb1: tail call void @ext(i32 0) br label %return
 bb2: tail call void @ext(i32 2) br label %return

Modified: llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp?rev=320566&r1=320565&r2=320566&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/MachineOperandTest.cpp Wed Dec 13 02:30:59 2017
@@ -181,4 +181,20 @@ TEST(MachineOperandTest, PrintTargetInde
   }
 }
 
+TEST(MachineOperandTest, PrintJumpTableIndex) {
+  // Create a MachineOperand with a jump-table index and print it.
+  MachineOperand MO = MachineOperand::CreateJTI(3);
+
+  // Checking some preconditions on the newly created
+  // MachineOperand.
+  ASSERT_TRUE(MO.isJTI());
+  ASSERT_TRUE(MO.getIndex() == 3);
+
+  // Print a MachineOperand containing a jump-table index.
+  std::string str;
+  raw_string_ostream OS(str);
+  MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+  ASSERT_TRUE(OS.str() == "%jump-table.3");
+}
+
 } // end namespace




More information about the llvm-commits mailing list