Skip to content

Commit

Permalink
fix llvmpasses
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed May 11, 2021
1 parent 7d7f12b commit abeb8dc
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 9 deletions.
19 changes: 19 additions & 0 deletions test/llvmpasses/alloc-opt-gcframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
# CHECK: store atomic {} addrspace(10)* @tag, {} addrspace(10)* addrspace(10)* {{.*}} unordered, align 8, !tbaa !0
println("""
define {} addrspace(10)* @return_obj() {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand All @@ -33,6 +34,7 @@ define {} addrspace(10)* @return_obj() {
# CHECK-NOT: @llvm.lifetime.end
println("""
define i64 @return_load(i64 %i) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand All @@ -47,12 +49,14 @@ define i64 @return_load(i64 %i) {
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @ccall_obj
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: @julia.gc_alloc_obj
# CHECK: @jl_gc_pool_alloc
# CHECK: store atomic {} addrspace(10)* @tag, {} addrspace(10)* addrspace(10)* {{.*}} unordered, align 8, !tbaa !0
println("""
define void @ccall_obj(i8* %fptr) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand All @@ -65,6 +69,7 @@ define void @ccall_obj(i8* %fptr) {

# CHECK-LABEL: @ccall_ptr
# CHECK: alloca i64
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: @julia.gc_alloc_obj
# CHECK-NOT: @jl_gc_pool_alloc
Expand All @@ -75,6 +80,7 @@ define void @ccall_obj(i8* %fptr) {
# CHECK-NEXT: ret void
println("""
define void @ccall_ptr(i8* %fptr) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand All @@ -89,12 +95,14 @@ define void @ccall_ptr(i8* %fptr) {
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @ccall_unknown_bundle
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: @julia.gc_alloc_obj
# CHECK: @jl_gc_pool_alloc
# CHECK: store atomic {} addrspace(10)* @tag, {} addrspace(10)* addrspace(10)* {{.*}} unordered, align 8, !tbaa !0
println("""
define void @ccall_unknown_bundle(i8* %fptr) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand All @@ -110,6 +118,7 @@ define void @ccall_unknown_bundle(i8* %fptr) {

# CHECK-LABEL: @lifetime_branches
# CHECK: alloca i64
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK: L1:
# CHECK-NEXT: call void @llvm.lifetime.start{{.*}}(i64 8,
Expand All @@ -126,6 +135,7 @@ define void @ccall_unknown_bundle(i8* %fptr) {
# CHECK-NEXT: call void @llvm.lifetime.end{{.*}}(i64 8,
println("""
define void @lifetime_branches(i8* %fptr, i1 %b, i1 %b2) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
br i1 %b, label %L1, label %L3
Expand All @@ -151,12 +161,14 @@ L3:
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @object_field
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: @julia.gc_alloc_obj
# CHECK-NOT: @jl_gc_pool_alloc
# CHECK-NOT: store {} addrspace(10)* @tag, {} addrspace(10)* addrspace(10)* {{.*}}, align 8, !tbaa !0
println("""
define void @object_field({} addrspace(10)* %field) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand All @@ -170,13 +182,15 @@ define void @object_field({} addrspace(10)* %field) {

# CHECK-LABEL: @memcpy_opt
# CHECK: alloca [16 x i8], align 16
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: @julia.gc_alloc_obj
# CHECK-NOT: @jl_gc_pool_alloc
# CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
println("""
define void @memcpy_opt(i8* %v22) {
top:
%pgcstack = call {}*** @julia.get_pgcstack()
%v6 = call {}*** @julia.ptls_states()
%v18 = bitcast {}*** %v6 to i8*
%v19 = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %v18, $isz 16, {} addrspace(10)* @tag)
Expand All @@ -189,6 +203,7 @@ top:
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @preserve_opt
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: @julia.gc_alloc_obj
# CHECK-NOT: @jl_gc_pool_alloc
Expand All @@ -197,6 +212,7 @@ top:
println("""
define void @preserve_opt(i8* %v22) {
top:
%pgcstack = call {}*** @julia.get_pgcstack()
%v6 = call {}*** @julia.ptls_states()
%v18 = bitcast {}*** %v6 to i8*
%v19 = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %v18, $isz 16, {} addrspace(10)* @tag)
Expand All @@ -212,6 +228,7 @@ top:
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @preserve_branches
# CHECK: call {}*** @julia.get_pgcstack()
# CHECK: call {}*** @julia.ptls_states()
# CHECK: L1:
# CHECK-NEXT: @external_function()
Expand All @@ -224,6 +241,7 @@ top:
# CHECK: L3:
println("""
define void @preserve_branches(i8* %fptr, i1 %b, i1 %b2) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
br i1 %b, label %L1, label %L3
Expand All @@ -249,6 +267,7 @@ L3:
println("""
declare void @external_function()
declare {}*** @julia.ptls_states()
declare {}*** @julia.get_pgcstack()
declare noalias nonnull {} addrspace(10)* @julia.gc_alloc_obj(i8*, $isz, {} addrspace(10)*)
declare {}* @julia.pointer_from_objref({} addrspace(11)*)
declare void @llvm.memcpy.p11i8.p0i8.i64(i8 addrspace(11)* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
Expand Down
5 changes: 5 additions & 0 deletions test/llvmpasses/alloc-opt-pass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ println("""
# CHECK: L3:
println("""
define void @preserve_branches(i8* %fptr, i1 %b, i1 %b2) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
br i1 %b, label %L1, label %L3
Expand Down Expand Up @@ -58,6 +59,7 @@ L3:
# CHECK: L3:
println("""
define void @preserve_branches2(i8* %fptr, i1 %b, i1 %b2) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v2 = call {} addrspace(10)* @external_function2()
Expand Down Expand Up @@ -85,6 +87,7 @@ L3:
# CHECK: ret void
println("""
define void @legal_int_types() {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%var1 = call {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 12, {} addrspace(10)* @tag)
Expand All @@ -101,6 +104,7 @@ println("""
declare void @external_function()
declare {} addrspace(10)* @external_function2()
declare {}*** @julia.ptls_states()
declare {}*** @julia.get_pgcstack()
declare noalias {} addrspace(10)* @julia.gc_alloc_obj(i8*, $isz, {} addrspace(10)*)
declare {}* @julia.pointer_from_objref({} addrspace(11)*)
declare void @llvm.memcpy.p11i8.p0i8.i64(i8 addrspace(11)* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
Expand All @@ -119,6 +123,7 @@ declare void @llvm.julia.gc_preserve_end(token)
# CHECK: load i
println("""
define void @memref_collision($isz %x) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
Expand Down
10 changes: 5 additions & 5 deletions test/llvmpasses/final-lower-gc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
declare void @boxed_simple({} addrspace(10)*, {} addrspace(10)*)
declare {} addrspace(10)* @jl_box_int64(i64)
declare {}*** @julia.ptls_states()
declare {}*** @julia.get_pgcstack()
declare void @jl_safepoint()
declare {} addrspace(10)* @jl_apply_generic({} addrspace(10)*, {} addrspace(10)**, i32)

Expand All @@ -21,12 +22,11 @@ top:
; CHECK-LABEL: @gc_frame_lowering
; CHECK: %gcframe = alloca {} addrspace(10)*, i32 4
%gcframe = call {} addrspace(10)** @julia.new_gc_frame(i32 2)
; CHECK: %ptls = call {}*** @julia.ptls_states()
%ptls = call {}*** @julia.ptls_states()
; CHECK: [[GCFRAME_SLOT:%.*]] = call {}*** @julia.get_pgcstack()
%pgcstack = call {}*** @julia.get_pgcstack()
; CHECK-DAG: [[GCFRAME_SIZE_PTR:%.*]] = getelementptr inbounds {} addrspace(10)*, {} addrspace(10)** %gcframe, i32 0
; CHECK-DAG: [[GCFRAME_SIZE_PTR2:%.*]] = bitcast {} addrspace(10)** [[GCFRAME_SIZE_PTR]] to i64*
; CHECK-DAG: store i64 8, i64* [[GCFRAME_SIZE_PTR2]], align 8, !tbaa !0
; CHECK-DAG: [[GCFRAME_SLOT:%.*]] = getelementptr inbounds {}**, {}*** %ptls, i32 0
; CHECK-DAG: [[PREV_GCFRAME_PTR:%.*]] = getelementptr inbounds {} addrspace(10)*, {} addrspace(10)** %gcframe, i32 1
; CHECK-DAG: [[PREV_GCFRAME_PTR2:%.*]] = bitcast {} addrspace(10)** [[PREV_GCFRAME_PTR]] to {}***
; CHECK-DAG: [[PREV_GCFRAME:%.*]] = load {}**, {}*** [[GCFRAME_SLOT]], align 8
Expand All @@ -46,8 +46,7 @@ top:
call void @boxed_simple({} addrspace(10)* %aboxed, {} addrspace(10)* %bboxed)
; CHECK-NEXT: [[PREV_GCFRAME_PTR3:%.*]] = getelementptr inbounds {} addrspace(10)*, {} addrspace(10)** %gcframe, i32 1
; CHECK-NEXT: [[PREV_GCFRAME_PTR4:%.*]] = load {} addrspace(10)*, {} addrspace(10)** [[PREV_GCFRAME_PTR3]], align 8, !tbaa !0
; CHECK-NEXT: [[GCFRAME_SLOT3:%.*]] = getelementptr inbounds {}**, {}*** %ptls, i32 0
; CHECK-NEXT: [[GCFRAME_SLOT4:%.*]] = bitcast {}*** [[GCFRAME_SLOT3]] to {} addrspace(10)**
; CHECK-NEXT: [[GCFRAME_SLOT4:%.*]] = bitcast {}*** [[GCFRAME_SLOT]] to {} addrspace(10)**
; CHECK-NEXT: store {} addrspace(10)* [[PREV_GCFRAME_PTR4]], {} addrspace(10)** [[GCFRAME_SLOT4]], align 8, !tbaa !0
call void @julia.pop_gc_frame({} addrspace(10)** %gcframe)
; CHECK-NEXT: ret void
Expand All @@ -57,6 +56,7 @@ top:
define {} addrspace(10)* @gc_alloc_lowering() {
top:
; CHECK-LABEL: @gc_alloc_lowering
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
; CHECK: %v = call noalias nonnull {} addrspace(10)* @jl_gc_pool_alloc
Expand Down
Loading

0 comments on commit abeb8dc

Please sign in to comment.