Skip to content

Commit

Permalink
[CodeGen] Print jump-table index operands as %jump-table.0 in both MI…
Browse files Browse the repository at this point in the history
…R 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.

llvm-svn: 320566
  • Loading branch information
francisvm committed Dec 13, 2017
1 parent b3a0d51 commit b41dbbe
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 33 deletions.
37 changes: 35 additions & 2 deletions llvm/docs/MIRLangRef.rst
Expand Up @@ -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
^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
Expand Up @@ -20,6 +20,7 @@
#ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
#define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H

#include "llvm/Support/Printable.h"
#include <cassert>
#include <vector>

Expand Down Expand Up @@ -125,6 +126,15 @@ class MachineJumpTableInfo {
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
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/MIRPrinter.cpp
Expand Up @@ -852,7 +852,8 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
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);
Expand All @@ -867,9 +868,6 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
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 << '$';
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/MachineFunction.cpp
Expand Up @@ -906,7 +906,7 @@ void MachineJumpTableInfo::print(raw_ostream &OS) const {
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]);
}
Expand All @@ -918,6 +918,10 @@ void MachineJumpTableInfo::print(raw_ostream &OS) const {
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
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/MachineOperand.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -523,7 +524,7 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
break;
}
case MachineOperand::MO_JumpTableIndex:
OS << "<jt#" << getIndex() << '>';
OS << printJumpTableEntryReference(getIndex());
break;
case MachineOperand::MO_GlobalAddress:
OS << "<ga:";
Expand Down
34 changes: 17 additions & 17 deletions llvm/test/CodeGen/AArch64/max-jump-table.ll
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/CodeGen/AArch64/min-jump-table.ll
Expand Up @@ -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:

Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions llvm/unittests/CodeGen/MachineOperandTest.cpp
Expand Up @@ -181,4 +181,20 @@ TEST(MachineOperandTest, PrintTargetIndexName) {
}
}

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

0 comments on commit b41dbbe

Please sign in to comment.