Skip to content

Commit

Permalink
[DPWBS-1354] feat(Legalizer): add support for G_JUMP_TABLE and G_BRJT
Browse files Browse the repository at this point in the history
add legalizer tests
  • Loading branch information
gargaroff committed Mar 5, 2020
1 parent 54eb299 commit cb85092
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
11 changes: 11 additions & 0 deletions llvm/lib/Target/TriCore/TriCoreLegalizerInfo.cpp
Expand Up @@ -107,6 +107,11 @@ TriCoreLegalizerInfo::TriCoreLegalizerInfo(const TriCoreSubtarget &ST) {
.legalFor({s16, s32, s64})
.clampScalar(0, s16, s64);

// Jump table calculation

// G_JUMP_TABLE is only legal for pointers
getActionDefinitionsBuilder(G_JUMP_TABLE).legalFor({p0});

// Stack allocation

// G_DYN_STACKALLOC should be lowered to a stack pointer subtraction
Expand Down Expand Up @@ -433,6 +438,12 @@ TriCoreLegalizerInfo::TriCoreLegalizerInfo(const TriCoreSubtarget &ST) {
// G_BRINDIRECT is valid for p0 types.
getActionDefinitionsBuilder(G_BRINDIRECT).legalFor({p0});

// G_BRJT requires a pointer type destination, a jump table index immediate
// and a s32 entry
getActionDefinitionsBuilder(G_BRJT).legalIf([=](const LegalityQuery &Query) {
return Query.Types[0] == p0 && Query.Types[1] == s32;
});

// Variadic Arguments

// G_VASTART is legal for pointer type
Expand Down
89 changes: 89 additions & 0 deletions llvm/test/CodeGen/TriCore/GlobalIsel/legalize-jump-table-brjt.mir
@@ -0,0 +1,89 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=tricore -global-isel -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s

--- |
define i32 @jt_test(i32 %x) {
entry:
switch i32 %x, label %return [
i32 75, label %sw.bb
i32 34, label %sw.bb
i32 56, label %sw.bb
i32 35, label %sw.bb
i32 40, label %sw.bb
i32 4, label %sw.bb1
i32 5, label %sw.bb1
i32 6, label %sw.bb1
]

sw.bb: ; preds = %entry, %entry, %entry, %entry, %entry
%add = add nsw i32 %x, 42
br label %return

sw.bb1: ; preds = %entry, %entry, %entry
%mul = mul nsw i32 %x, 3
br label %return

return: ; preds = %sw.bb1, %sw.bb, %entry
%retval.0 = phi i32 [ %mul, %sw.bb1 ], [ %add, %sw.bb ], [ 0, %entry ]
ret i32 %retval.0
}

...
---
name: jt_test
tracksRegLiveness: true
jumpTable:
kind: inline
entries:
- id: 0
blocks: [ '%bb.3', '%bb.3', '%bb.3', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.2', '%bb.2', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.2', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.2', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4',
'%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.4', '%bb.2' ]
body: |
; CHECK-LABEL: name: jt_test
; CHECK: bb.0.entry:
; CHECK: successors: %bb.1(0x80000000)
; CHECK: liveins: $d4
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[JUMP_TABLE:%[0-9]+]]:_(p0) = G_JUMP_TABLE %jump-table.0
; CHECK: G_BRJT [[JUMP_TABLE]](p0), %jump-table.0, [[COPY]](s32)
; CHECK: bb.1.entry:
; CHECK: successors: %bb.3(0x2aaaaaab), %bb.4(0x2aaaaaab), %bb.2(0x2aaaaaab)
; CHECK: G_BR %bb.4
; CHECK: bb.2.sw.bb:
; CHECK: successors: %bb.4(0x80000000)
; CHECK: G_BR %bb.4
; CHECK: bb.3.sw.bb1:
; CHECK: successors: %bb.4(0x80000000)
; CHECK: bb.4.return:
; CHECK: RET implicit $a11
bb.0.entry:
liveins: $d4
%0:_(s32) = COPY $d4
%1:_(p0) = G_JUMP_TABLE %jump-table.0
G_BRJT %1:_(p0), %jump-table.0, %0:_(s32)
bb.1.entry:
successors: %bb.3(0x2aaaaaab), %bb.4(0x2aaaaaab), %bb.2(0x2aaaaaab)
G_BR %bb.4
bb.2.sw.bb:
G_BR %bb.4
bb.3.sw.bb1:
bb.4.return:
RET implicit $a11
...

0 comments on commit cb85092

Please sign in to comment.