llvm.org GIT mirror llvm / d347e97
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320566 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 1 year, 11 months ago
8 changed file(s) with 95 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
237237 The block's name should be identical to the name of the IR block that this
238238 machine block is based on.
239239
240 .. _block-references:
241
240242 Block References
241243 ^^^^^^^^^^^^^^^^
242244
628630 .. code-block:: text
629631
630632 %sgpr2 = S_ADD_U32 _, target-index(amdgpu-constdata-start) + 8, implicit-def _, implicit-def _
633
634 Jump-table Index Operands
635 ^^^^^^^^^^^^^^^^^^^^^^^^^
636
637 A jump-table index operand with the index 0 is printed as following:
638
639 .. code-block:: text
640
641 tBR_JTr killed %r0, %jump-table.0
642
643 A machine jump-table entry contains a list of ``MachineBasicBlocks``. When serializing all the function's jump-table entries, the following format is used:
644
645 .. code-block:: text
646
647 jumpTable:
648 kind:
649 entries:
650 - id:
651 blocks: [ , , ... ]
652
653 where ```` is describing how the jump table is represented and emitted (plain address, relocations, PIC, etc.), and each ```` is a 32-bit unsigned integer and ``blocks`` contains a list of :ref:`machine basic block references `.
654
655 Example:
656
657 .. code-block:: text
658
659 jumpTable:
660 kind: inline
661 entries:
662 - id: 0
663 blocks: [ '%bb.3', '%bb.9', '%bb.4.d3' ]
664 - id: 1
665 blocks: [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ]
631666
632667 .. TODO: Describe the parsers default behaviour when optional YAML attributes
633668 are missing.
639674 .. TODO: Describe the frame information YAML mapping.
640675 .. TODO: Describe the syntax of the stack object machine operands and their
641676 YAML definitions.
642 .. TODO: Describe the syntax of the jump table machine operands and their
643 YAML definitions.
644677 .. TODO: Describe the syntax of the block address machine operands.
645678 .. TODO: Describe the syntax of the CFI index machine operands.
646679 .. TODO: Describe the syntax of the metadata machine operands, and the
1919 #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
2020 #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
2121
22 #include "llvm/Support/Printable.h"
2223 #include
2324 #include
2425
124125 void dump() const;
125126 };
126127
128
129 /// Prints a jump table entry reference.
130 ///
131 /// The format is:
132 /// %jump-table.5 - a jump table entry with index == 5.
133 ///
134 /// Usage: OS << printJumpTableEntryReference(Idx) << '\n';
135 Printable printJumpTableEntryReference(unsigned Idx);
136
127137 } // End llvm namespace
128138
129139 #endif
851851 case MachineOperand::MO_CImmediate:
852852 case MachineOperand::MO_MachineBasicBlock:
853853 case MachineOperand::MO_ConstantPoolIndex:
854 case MachineOperand::MO_TargetIndex: {
854 case MachineOperand::MO_TargetIndex:
855 case MachineOperand::MO_JumpTableIndex: {
855856 unsigned TiedOperandIdx = 0;
856857 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
857858 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
865866 break;
866867 case MachineOperand::MO_FrameIndex:
867868 printStackObjectReference(Op.getIndex());
868 break;
869 case MachineOperand::MO_JumpTableIndex:
870 OS << "%jump-table." << Op.getIndex();
871869 break;
872870 case MachineOperand::MO_ExternalSymbol: {
873871 StringRef Name = Op.getSymbolName();
905905 OS << "Jump Tables:\n";
906906
907907 for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
908 OS << " jt#" << i << ": ";
908 OS << printJumpTableEntryReference(i) << ": ";
909909 for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
910910 OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
911911 }
916916 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
917917 LLVM_DUMP_METHOD void MachineJumpTableInfo::dump() const { print(dbgs()); }
918918 #endif
919
920 Printable llvm::printJumpTableEntryReference(unsigned Idx) {
921 return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
922 }
919923
920924 //===----------------------------------------------------------------------===//
921925 // MachineConstantPool implementation
1313 #include "llvm/CodeGen/MachineOperand.h"
1414 #include "llvm/Analysis/Loads.h"
1515 #include "llvm/CodeGen/MIRPrinter.h"
16 #include "llvm/CodeGen/MachineJumpTableInfo.h"
1617 #include "llvm/CodeGen/MachineRegisterInfo.h"
1718 #include "llvm/CodeGen/TargetInstrInfo.h"
1819 #include "llvm/CodeGen/TargetRegisterInfo.h"
522523 break;
523524 }
524525 case MachineOperand::MO_JumpTableIndex:
525 OS << "';
526 OS << printJumpTableEntryReference(getIndex());
526527 break;
527528 case MachineOperand::MO_GlobalAddress:
528529 OS << "
2727 ]
2828 ; CHECK-LABEL: function jt1:
2929 ; CHECK-NEXT: Jump Tables:
30 ; CHECK0-NEXT: jt#0:
31 ; CHECK0-NOT: jt#1:
32 ; CHECK4-NEXT: jt#0:
33 ; CHECK4-SAME: jt#1:
34 ; CHECK4-SAME: jt#2:
35 ; CHECK4-SAME: jt#3:
36 ; CHECK4-NOT: jt#4:
37 ; CHECK8-NEXT: jt#0:
38 ; CHECK8-SAME: jt#1:
39 ; CHECK8-NOT: jt#2:
40 ; CHECKM1-NEXT: jt#0:
41 ; CHECKM1-SAME: jt#1
42 ; CHECKM1-NOT: jt#2:
30 ; CHECK0-NEXT: %jump-table.0:
31 ; CHECK0-NOT: %jump-table.1:
32 ; CHECK4-NEXT: %jump-table.0:
33 ; CHECK4-SAME: %jump-table.1:
34 ; CHECK4-SAME: %jump-table.2:
35 ; CHECK4-SAME: %jump-table.3:
36 ; CHECK4-NOT: %jump-table.4:
37 ; CHECK8-NEXT: %jump-table.0:
38 ; CHECK8-SAME: %jump-table.1:
39 ; CHECK8-NOT: %jump-table.2:
40 ; CHECKM1-NEXT: %jump-table.0:
41 ; CHECKM1-SAME: %jump-table.1
42 ; CHECKM1-NOT: %jump-table.2:
4343 ; CHEC-NEXT: Function Live Ins:
4444
4545 bb1: tail call void @ext(i32 0) br label %return
7676 ]
7777 ; CHECK-LABEL: function jt2:
7878 ; CHECK-NEXT: Jump Tables:
79 ; 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{{$}}
80 ; CHECK4-NEXT: jt#0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
81 ; CHECK8-NEXT: jt#0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
82 ; CHECKM1-NEXT: jt#0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
79 ; 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{{$}}
80 ; CHECK4-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
81 ; CHECK8-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
82 ; CHECKM1-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
8383 ; CHEC-NEXT: Function Live Ins:
8484
8585 bb1: tail call void @ext(i32 1) br label %return
1111 ]
1212 ; CHECK-LABEL: function jt2:
1313 ; CHECK0-NEXT: Jump Tables:
14 ; CHECK0-NEXT: jt#0:
15 ; CHECK0-NOT: jt#1:
14 ; CHECK0-NEXT: %jump-table.0:
15 ; CHECK0-NOT: %jump-table.1:
1616 ; CHECK4-NOT: Jump Tables:
1717 ; CHECK8-NOT: Jump Tables:
1818
3232 ]
3333 ; CHECK-LABEL: function jt4:
3434 ; CHECK0-NEXT: Jump Tables:
35 ; CHECK0-NEXT: jt#0:
36 ; CHECK0-NOT: jt#1:
35 ; CHECK0-NEXT: %jump-table.0:
36 ; CHECK0-NOT: %jump-table.1:
3737 ; CHECK4-NEXT: Jump Tables:
38 ; CHECK4-NEXT: jt#0:
39 ; CHECK4-NOT: jt#1:
38 ; CHECK4-NEXT: %jump-table.0:
39 ; CHECK4-NOT: %jump-table.1:
4040 ; CHECK8-NOT: Jump Tables:
4141
4242 bb1: tail call void @ext(i32 0) br label %return
6161 ]
6262 ; CHECK-LABEL: function jt8:
6363 ; CHECK-NEXT: Jump Tables:
64 ; CHECK-NEXT: jt#0:
65 ; CHECK-NOT: jt#1:
64 ; CHECK-NEXT: %jump-table.0:
65 ; CHECK-NOT: %jump-table.1:
6666
6767 bb1: tail call void @ext(i32 0) br label %return
6868 bb2: tail call void @ext(i32 2) br label %return
180180 }
181181 }
182182
183 TEST(MachineOperandTest, PrintJumpTableIndex) {
184 // Create a MachineOperand with a jump-table index and print it.
185 MachineOperand MO = MachineOperand::CreateJTI(3);
186
187 // Checking some preconditions on the newly created
188 // MachineOperand.
189 ASSERT_TRUE(MO.isJTI());
190 ASSERT_TRUE(MO.getIndex() == 3);
191
192 // Print a MachineOperand containing a jump-table index.
193 std::string str;
194 raw_string_ostream OS(str);
195 MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
196 ASSERT_TRUE(OS.str() == "%jump-table.3");
197 }
198
183199 } // end namespace