新开一楼,记录下一些探索。
code_typed(tst, (Int,))
这里 f()已经被换成 233 了。
julia> code_typed(tst, (Int,))
1-element Array{Any,1}:
CodeInfo(
1 ─ %1 = (x === 1)::Bool
└── goto #3 if not %1
2 ─ nothing::Const(#f#9(), false)
│ invoke Main.println(1::Int64)::Any
└── goto #8
3 ─ %6 = (x === 0)::Bool
└── goto #5 if not %6
4 ─ invoke Main.println(0::Int64)::Any
└── goto #8
5 ─ %10 = (x === -1)::Bool
└── goto #7 if not %10
6 ─ invoke Main.println(1::Int64)::Any
└── goto #8
7 ─ invoke Main.println(233::Int64)::Any
8 ┄ %15 = φ (#2 => true, #4 => false, #6 => false, #7 => false)::Bool
│ nothing::MaybeUndef(Const(#f#9(), false))
│ $(Expr(:throw_undef_if_not, :f, :(%15)))::Any
│ %18 = invoke Main.println("x="::String, _2::Int64, "; f="::Vararg{Any,N} where N, 233)::Const(nothing, false)
└── return %18
) => Nothing
code_llvm(tst, (Int,))
生成的 llvm ir 钦定后两个分支报错了,还有不知道怎么多了一堆变量。
julia> code_llvm(tst, (Int,))
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:51 within `tst'
; Function Attrs: uwtable
define void @julia_tst_13011(i64) #0 {
top:
%1 = alloca %jl_value_t addrspace(10)*, i32 5
%gcframe = alloca %jl_value_t addrspace(10)*, i32 3
%2 = bitcast %jl_value_t addrspace(10)** %gcframe to i8*
call void @llvm.memset.p0i8.i32(i8* %2, i8 0, i32 24, i32 0, i1 false)
%3 = call %jl_value_t*** inttoptr (i64 1801331392 to %jl_value_t*** ()*)() #4
%4 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 0
%5 = bitcast %jl_value_t addrspace(10)** %4 to i64*
store i64 2, i64* %5
%6 = getelementptr %jl_value_t**, %jl_value_t*** %3, i32 0
%7 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 1
%8 = bitcast %jl_value_t addrspace(10)** %7 to %jl_value_t***
%9 = load %jl_value_t**, %jl_value_t*** %6
store %jl_value_t** %9, %jl_value_t*** %8
%10 = bitcast %jl_value_t*** %6 to %jl_value_t addrspace(10)***
store %jl_value_t addrspace(10)** %gcframe, %jl_value_t addrspace(10)*** %10
switch i64 %0, label %L14 [
i64 1, label %L3
i64 0, label %L8
i64 -1, label %L12
]
L3: ; preds = %top
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:53 within `tst'
call void @julia_println_13012(i64 1)
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:64 within `tst'
%11 = call %jl_value_t addrspace(10)* @jl_box_int64(i64 signext 1)
%12 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 2
store %jl_value_t addrspace(10)* %11, %jl_value_t addrspace(10)** %12
%13 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %1, i32 0
store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 128616240 to
%jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %13
%14 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %1, i32 1
store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 273937456 to
%jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %14
%15 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %1, i32 2
store %jl_value_t addrspace(10)* %11, %jl_value_t addrspace(10)** %15
%16 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %1, i32 3
store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 273937488 to
%jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %16
%17 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %1, i32 4
store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 252889136 to
%jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %17
%18 = call nonnull %jl_value_t addrspace(10)* @jl_invoke(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 274393232 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %1, i32 5)
%19 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 1
%20 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %19
%21 = getelementptr %jl_value_t**, %jl_value_t*** %3, i32 0
%22 = bitcast %jl_value_t*** %21 to %jl_value_t addrspace(10)**
store %jl_value_t addrspace(10)* %20, %jl_value_t addrspace(10)** %22
ret void
L8: ; preds = %top
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:56 within `tst'
call void @julia_println_13012(i64 0)
br label %err
L12: ; preds = %top
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:59 within `tst'
call void @julia_println_13012(i64 1)
br label %err
L14: ; preds = %top
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:62 within `tst'
call void @julia_println_13012(i64 233)
br label %err
err: ; preds = %L8, %L12, %L14
; @ C:\Users\woclass\Desktop\proj\Julia\JuliaCN\2087-funcINfunc.jl:64 within `tst'
call void @jl_undefined_var_error(%jl_value_t addrspace(12)* addrspacecast (%jl_value_t* inttoptr (i64 252929848 to %jl_value_t*) to %jl_value_t addrspace(12)*))
unreachable
}