diff options
-rw-r--r-- | docs/MIRLangRef.rst | 37 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineJumpTableInfo.h | 10 | ||||
-rw-r--r-- | lib/CodeGen/MIRPrinter.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/MachineFunction.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/MachineOperand.cpp | 3 | ||||
-rw-r--r-- | test/CodeGen/AArch64/max-jump-table.ll | 34 | ||||
-rw-r--r-- | test/CodeGen/AArch64/min-jump-table.ll | 16 | ||||
-rw-r--r-- | unittests/CodeGen/MachineOperandTest.cpp | 16 |
8 files changed, 95 insertions, 33 deletions
diff --git a/docs/MIRLangRef.rst b/docs/MIRLangRef.rst index b0e3984c338..ebc9d456703 100644 --- a/docs/MIRLangRef.rst +++ b/docs/MIRLangRef.rst @@ -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 diff --git a/include/llvm/CodeGen/MachineJumpTableInfo.h b/include/llvm/CodeGen/MachineJumpTableInfo.h index adcd1d0de63..25a3e6b556a 100644 --- a/include/llvm/CodeGen/MachineJumpTableInfo.h +++ b/include/llvm/CodeGen/MachineJumpTableInfo.h @@ -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 diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 5367216c20b..505b7c3b6c7 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -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); @@ -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 << '$'; diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index f0d5eec4dea..dba0dfbe886 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -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]); } @@ -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 //===----------------------------------------------------------------------===// diff --git a/lib/CodeGen/MachineOperand.cpp b/lib/CodeGen/MachineOperand.cpp index cd8c86e782a..82e635d9c62 100644 --- a/lib/CodeGen/MachineOperand.cpp +++ b/lib/CodeGen/MachineOperand.cpp @@ -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 &OS, ModuleSlotTracker &MST, break; } case MachineOperand::MO_JumpTableIndex: - OS << "<jt#" << getIndex() << '>'; + OS << printJumpTableEntryReference(getIndex()); break; case MachineOperand::MO_GlobalAddress: OS << "<ga:"; diff --git a/test/CodeGen/AArch64/max-jump-table.ll b/test/CodeGen/AArch64/max-jump-table.ll index 1a7a418b31f..9a0179ecc1b 100644 --- a/test/CodeGen/AArch64/max-jump-table.ll +++ b/test/CodeGen/AArch64/max-jump-table.ll @@ -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 diff --git a/test/CodeGen/AArch64/min-jump-table.ll b/test/CodeGen/AArch64/min-jump-table.ll index 80974debc48..b22e683ebfe 100644 --- a/test/CodeGen/AArch64/min-jump-table.ll +++ b/test/CodeGen/AArch64/min-jump-table.ll @@ -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 diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index 46f50ab0151..aed60c0a3d6 100644 --- a/unittests/CodeGen/MachineOperandTest.cpp +++ b/unittests/CodeGen/MachineOperandTest.cpp @@ -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 |