Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach InteractiveUtils how to read ncat AST #45399

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

BioTurboNick
Copy link
Contributor

Will resolve #43294

@BioTurboNick
Copy link
Contributor Author

BioTurboNick commented May 21, 2022

Well, that was a lot of work for an underwhelming result 😆

They all have the same entry point, so they all look like this:

julia> @code_lowered [3 4 ;;; 5 4]
CodeInfo(
1 ─ %1 = Core.tuple(dimsshape, row_first)
│   %2 = Core._apply_iterate(Base.iterate, Base._hvncat, %1, xs)
└──      return %2
)

The LLVM and assembly are more interesting

julia> @code_llvm [3 4 ;;; 5 4]
;  @ abstractarray.jl:2129 within `hvncat`
; Function Attrs: uwtable
define nonnull {}* @julia_hvncat_827([3 x i64]* nocapture nonnull readonly align 8 dereferenceable(24) %0, i8 zeroext %1, i64 signext %2, i64 signext %3, i64 signext %4, i64 signext %5) #0 {
top:
  %6 = alloca [7 x {}*], align 8
  %gcframe10 = alloca [7 x {}*], align 16
  %gcframe10.sub = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 0
  %.sub = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 0
  %7 = bitcast [7 x {}*]* %gcframe10 to i8*
  call void @llvm.memset.p0i8.i32(i8* nonnull align 16 dereferenceable(56) %7, i8 0, i32 56, i1 false)
  %8 = call {}*** inttoptr (i64 43440368 to {}*** ()*)() #4
; ┌ @ abstractarray.jl:2134 within `_hvncat`
   %9 = bitcast [7 x {}*]* %gcframe10 to i64*
   store i64 20, i64* %9, align 16
   %10 = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 1
   %11 = bitcast {}** %10 to {}***
   %12 = load {}**, {}*** %8, align 8
   store {}** %12, {}*** %11, align 8
   %13 = bitcast {}*** %8 to {}***
   store {}** %gcframe10.sub, {}*** %13, align 8
   %ptls_field6 = getelementptr inbounds {}**, {}*** %8, i64 2305843009213693954
   %14 = bitcast {}*** %ptls_field6 to i8**
   %ptls_load78 = load i8*, i8** %14, align 8
   %15 = call noalias nonnull {}* @jl_gc_pool_alloc(i8* %ptls_load78, i32 1416, i32 32) #5
   %16 = bitcast {}* %15 to i64*
   %17 = getelementptr inbounds i64, i64* %16, i64 -1
   store atomic i64 289240400, i64* %17 unordered, align 8
   %18 = bitcast {}* %15 to i8*
   %19 = bitcast [3 x i64]* %0 to i8*
   call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(24) %18, i8* nonnull align 8 dereferenceable(24) %19, i64 24, i1 false)
   %20 = and i8 %1, 1
   %.not = icmp eq i8 %20, 0
   %21 = select i1 %.not, {}* inttoptr (i64 286603920 to {}*), {}* inttoptr (i64 286531536 to {}*)
   %22 = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 6
   store {}* %15, {}** %22, align 16
   %23 = call nonnull {}* @jl_box_int64(i64 signext %2)
   %24 = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 5
   store {}* %23, {}** %24, align 8
   %25 = call nonnull {}* @jl_box_int64(i64 signext %3)
   %26 = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 4
   store {}* %25, {}** %26, align 16
   %27 = call nonnull {}* @jl_box_int64(i64 signext %4)
   %28 = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 3
   store {}* %27, {}** %28, align 8
   %29 = call nonnull {}* @jl_box_int64(i64 signext %5)
   %30 = getelementptr inbounds [7 x {}*], [7 x {}*]* %gcframe10, i64 0, i64 2
   store {}* %29, {}** %30, align 16
   store {}* inttoptr (i64 284363968 to {}*), {}** %.sub, align 8
   %31 = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 1
   store {}* %15, {}** %31, align 8
   %32 = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 2
   store {}* %21, {}** %32, align 8
   %33 = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 3
   store {}* %23, {}** %33, align 8
   %34 = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 4
   store {}* %25, {}** %34, align 8
   %35 = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 5
   store {}* %27, {}** %35, align 8
   %36 = getelementptr inbounds [7 x {}*], [7 x {}*]* %6, i64 0, i64 6
   store {}* %29, {}** %36, align 8
   %37 = call nonnull {}* @jl_invoke({}* inttoptr (i64 352304192 to {}*), {}** nonnull %.sub, i32 7, {}* inttoptr (i64 206632560 to {}*))
   %38 = load {}*, {}** %10, align 8
   %39 = bitcast {}*** %8 to {}**
   store {}* %38, {}** %39, align 8
; └
  ret {}* %37
}

julia> @code_native [3 4 ;;; 5 4]
        .text
; ┌ @ abstractarray.jl:2129 within `hvncat`
        pushq   %rbp
        movq    %rsp, %rbp
        pushq   %r15
        pushq   %r14
        pushq   %r13
        pushq   %r12
        pushq   %rsi
        pushq   %rdi
        pushq   %rbx
        andq    $-32, %rsp
        subq    $192, %rsp
        movq    %r9, 56(%rsp)
        movq    %r8, %rsi
        movl    %edx, %ebx
        movq    %rcx, %r14
        vxorps  %xmm0, %xmm0, %xmm0
        vmovups %ymm0, 88(%rsp)
        vmovaps %ymm0, 64(%rsp)
        movl    $jl_get_pgcstack, %eax
        vzeroupper
        callq   *%rax
        movq    %rax, %r15
; │┌ @ abstractarray.jl:2134 within `_hvncat`
        movq    $20, 64(%rsp)
        movq    (%r15), %rax
        movq    %rax, 72(%rsp)
        leaq    64(%rsp), %rax
        movq    %rax, (%r15)
        movq    16(%r15), %rcx
        movabsq $jl_gc_pool_alloc, %rax
        movl    $1416, %edx                     # imm = 0x588
        movl    $32, %r8d
        callq   *%rax
        movq    %rax, %rdi
        movq    $289240400, -8(%rdi)            # imm = 0x113D7550
        movq    16(%r14), %rax
        movq    %rax, 16(%rdi)
        vmovups (%r14), %xmm0
        vmovups %xmm0, (%rdi)
        testb   $1, %bl
        movl    $286603920, %eax                # imm = 0x11153A90
        movl    $286531536, %r12d               # imm = 0x11141FD0
        cmoveq  %rax, %r12
        movq    %rdi, 112(%rsp)
        movabsq $jl_box_int64, %r13
        movq    %rsi, %rcx
        callq   *%r13
        movq    %rax, %r14
        movq    %r14, 104(%rsp)
        movq    56(%rsp), %rcx
        callq   *%r13
        movq    %rax, %rsi
        movq    %rsi, 96(%rsp)
        movq    48(%rbp), %rcx
        callq   *%r13
        movq    %rax, %rbx
        movq    %rbx, 88(%rsp)
        movq    56(%rbp), %rcx
        callq   *%r13
        movq    %rax, 80(%rsp)
        movq    $284363968, 128(%rsp)           # imm = 0x10F30CC0
        movq    %rdi, 136(%rsp)
        movq    %r12, 144(%rsp)
        movq    %r14, 152(%rsp)
        movq    %rsi, 160(%rsp)
        movq    %rbx, 168(%rsp)
        movq    %rax, 176(%rsp)
        movabsq $jl_invoke, %rax
        leaq    128(%rsp), %rdx
        movl    $352304192, %ecx                # imm = 0x14FFBC40
        movl    $206632560, %r9d                # imm = 0xC50F670
        movl    $7, %r8d
        callq   *%rax
        movq    72(%rsp), %rcx
        movq    %rcx, (%r15)
; │└
        leaq    -56(%rbp), %rsp
        popq    %rbx
        popq    %rdi
        popq    %rsi
        popq    %r12
        popq    %r13
        popq    %r14
        popq    %r15
        popq    %rbp
        retq
        nopl    (%rax,%rax)
; └

@BioTurboNick BioTurboNick marked this pull request as ready for review May 22, 2022 01:29
@BioTurboNick BioTurboNick changed the title Draft: Teach InteractiveUtils how to read ncat AST Teach InteractiveUtils how to read ncat AST May 22, 2022
@BioTurboNick
Copy link
Contributor Author

Might be good to get this out of the way and into 1.11, if there are no objections. @KristofferC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InteractiveUtils needs to be made aware of hvncat syntax
1 participant