Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit dae5d38

Browse files
committed
[GlobalISel] Add a G_JUMP_TABLE opcode.
This opcode generates a pointer to the address of the jump table specified by the source operand, which is a jump table index. It will be used in conjunction with an upcoming G_BRJT opcode to support jump table codegen with GlobalISel. Differential Revision: https://reviews.llvm.org/D63111 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363096 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 68e99ab commit dae5d38

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,14 @@ class MachineIRBuilder {
13591359
return buildInstr(TargetOpcode::G_UMAX, {Dst}, {Src0, Src1});
13601360
}
13611361

1362+
/// Build and insert \p Res = G_JUMP_TABLE \p JTI
1363+
///
1364+
/// G_JUMP_TABLE sets \p Res to the address of the jump table specified by
1365+
/// the jump table index \p JTI.
1366+
///
1367+
/// \return a MachineInstrBuilder for the newly created instruction.
1368+
MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI);
1369+
13621370
virtual MachineInstrBuilder buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps,
13631371
ArrayRef<SrcOp> SrcOps,
13641372
Optional<unsigned> Flags = None);

include/llvm/Support/TargetOpcodes.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,15 @@ HANDLE_TARGET_OPCODE(G_ADDRSPACE_CAST)
566566
/// Generic block address
567567
HANDLE_TARGET_OPCODE(G_BLOCK_ADDR)
568568

569+
/// Generic jump table address
570+
HANDLE_TARGET_OPCODE(G_JUMP_TABLE)
571+
569572
// TODO: Add more generic opcodes as we move along.
570573

571574
/// Marker for the end of the generic opcode.
572575
/// This is used to check if an opcode is in the range of the
573576
/// generic opcodes.
574-
HANDLE_TARGET_OPCODE_MARKER(PRE_ISEL_GENERIC_OPCODE_END, G_BLOCK_ADDR)
577+
HANDLE_TARGET_OPCODE_MARKER(PRE_ISEL_GENERIC_OPCODE_END, G_JUMP_TABLE)
575578

576579
/// BUILTIN_OP_END - This must be the last enum value in this list.
577580
/// The target-specific post-isel opcode values start here.

include/llvm/Target/GenericOpcodes.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ def G_BLOCK_ADDR : GenericInstruction {
169169
let hasSideEffects = 0;
170170
}
171171

172+
def G_JUMP_TABLE : GenericInstruction {
173+
let OutOperandList = (outs type0:$dst);
174+
let InOperandList = (ins unknown:$jti);
175+
let hasSideEffects = 0;
176+
}
177+
172178
//------------------------------------------------------------------------------
173179
// Binary ops.
174180
//------------------------------------------------------------------------------

lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ MachineInstrBuilder MachineIRBuilder::buildGlobalValue(unsigned Res,
179179
.addGlobalAddress(GV);
180180
}
181181

182+
MachineInstrBuilder MachineIRBuilder::buildJumpTable(const LLT PtrTy,
183+
unsigned JTI) {
184+
return buildInstr(TargetOpcode::G_JUMP_TABLE, {PtrTy}, {})
185+
.addJumpTableIndex(JTI);
186+
}
187+
182188
void MachineIRBuilder::validateBinaryOp(const LLT &Res, const LLT &Op0,
183189
const LLT &Op1) {
184190
assert((Res.isScalar() || Res.isVector()) && "invalid operand type");

lib/CodeGen/MachineVerifier.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,14 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
13121312

13131313
break;
13141314
}
1315+
case TargetOpcode::G_JUMP_TABLE: {
1316+
if (!MI->getOperand(1).isJTI())
1317+
report("G_JUMP_TABLE source operand must be a jump table index", MI);
1318+
LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
1319+
if (!DstTy.isPointer())
1320+
report("G_JUMP_TABLE dest operand must have a pointer type", MI);
1321+
break;
1322+
}
13151323
default:
13161324
break;
13171325
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# RUN: not llc -march=aarch64 -o /dev/null -run-pass=none -verify-machineinstrs %s 2>&1 | FileCheck %s
2+
# REQUIRES: global-isel, aarch64-registered-target
3+
4+
---
5+
name: test_jump_table
6+
legalized: true
7+
tracksRegLiveness: true
8+
jumpTable:
9+
kind: block-address
10+
entries:
11+
- id: 0
12+
blocks: [ '%bb.0' ]
13+
liveins:
14+
body: |
15+
bb.0:
16+
17+
; CHECK: Bad machine code: Too few operands
18+
%0:_(s32) = G_JUMP_TABLE
19+
20+
; CHECK: G_JUMP_TABLE source operand must be a jump table index
21+
%2:_(s32) = G_JUMP_TABLE %0
22+
23+
; CHECK: G_JUMP_TABLE dest operand must have a pointer type
24+
%3:_(s32) = G_JUMP_TABLE %jump-table.0
25+
26+
...

0 commit comments

Comments
 (0)