Skip to content

Commit

Permalink
[DPWBS-1210] feat(Legalizer): lower G_DYN_STACKALLOC
Browse files Browse the repository at this point in the history
Lowering G_DYN_STACKALLOC generates a stack-pointer subtraction
  • Loading branch information
gargaroff committed Feb 10, 2020
1 parent dece823 commit 9d07a5f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/TriCore/TriCoreLegalizerInfo.cpp
Expand Up @@ -102,6 +102,11 @@ TriCoreLegalizerInfo::TriCoreLegalizerInfo(const TriCoreSubtarget &ST) {
.clampScalar(0, s32, s64)
.widenScalarToNextPow2(0);

// Stack allocation

// G_DYN_STACKALLOC should be lowered to a stack pointer subtraction
getActionDefinitionsBuilder(G_DYN_STACKALLOC).lowerFor({{p0, s32}});

// Binary Ops

// Simple binary operators are only legal for s32 types.
Expand Down
61 changes: 61 additions & 0 deletions llvm/test/CodeGen/TriCore/GlobalIsel/legalize-dyn-stackalloc.mir
@@ -0,0 +1,61 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -O0 -mtriple=tricore -global-isel -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s

--- |
define i8* @test_dyn_stackalloc(i32 %numelts) {
%addr = alloca i8, i32 %numelts
ret i8* %addr
}

define i8* @test_aligned_dyn_stackalloc(i32 %numelts) {
%addr = alloca i8, i32 %numelts, align 32
ret i8* %addr
}
...

---
name: test_dyn_stackalloc
stack:
- { id: 0, name: addr, type: variable-sized, alignment: 1 }
body: |
bb.1:
liveins: $d4
; CHECK-LABEL: name: test_dyn_stackalloc
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[COPY1:%[0-9]+]]:_(p0) = COPY $a10
; CHECK: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY1]](p0)
; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[PTRTOINT]], [[COPY]]
; CHECK: [[INTTOPTR:%[0-9]+]]:_(p0) = G_INTTOPTR [[SUB]](s32)
; CHECK: $a10 = COPY [[INTTOPTR]](p0)
; CHECK: [[COPY2:%[0-9]+]]:_(p0) = COPY [[INTTOPTR]](p0)
; CHECK: $a2 = COPY [[COPY2]](p0)
%0:_(s32) = COPY $d4
%1:_(p0) = G_DYN_STACKALLOC %0(s32), 0
$a2 = COPY %1(p0)
...

---
name: test_aligned_dyn_stackalloc
stack:
- { id: 0, name: addr, type: variable-sized, alignment: 32 }
body: |
bb.1:
liveins: $d4
; CHECK-LABEL: name: test_aligned_dyn_stackalloc
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $d4
; CHECK: [[COPY1:%[0-9]+]]:_(p0) = COPY $a10
; CHECK: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY1]](p0)
; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[PTRTOINT]], [[COPY]]
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 -32
; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[SUB]], [[C]]
; CHECK: [[INTTOPTR:%[0-9]+]]:_(p0) = G_INTTOPTR [[AND]](s32)
; CHECK: $a10 = COPY [[INTTOPTR]](p0)
; CHECK: [[COPY2:%[0-9]+]]:_(p0) = COPY [[INTTOPTR]](p0)
; CHECK: $a2 = COPY [[COPY2]](p0)
%0:_(s32) = COPY $d4
%1:_(p0) = G_DYN_STACKALLOC %0(s32), 32
$a2 = COPY %1(p0)
...

0 comments on commit 9d07a5f

Please sign in to comment.