Last active
December 6, 2021 00:52
-
-
Save tkf/1b63dd12897ff6f4d3912514863fdd37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "IRDumps.Internal.FunctionCollection with 11 entries:\n \"jfptr_ref_alloca_demo_9\" => [IRDump(597, \"jfptr_ref_alloca_demo_9\", \"Propaga…\n \"japi1_include_string_6\" => [IRDump(399, \"japi1_include_string_6\", \"Merge Du…\n \"julia_ConsoleLogger_2\" => [IRDump(172, \"julia_ConsoleLogger_2\", \"Merge Dup…\n \"jfptr_TextDisplay_1\" => [IRDump(6, \"jfptr_TextDisplay_1\", \"Propagate (no…\n \"jfptr_TTYTerminal_5\" => [IRDump(349, \"jfptr_TTYTerminal_5\", \"Simplify th…\n \"julia_ref_alloca_demo_8\" => [IRDump(592, \"julia_ref_alloca_demo_8\", \"Merge D…\n \"japi1_preserve_7\" => [IRDump(489, \"japi1_preserve_7\", \"Merge Duplicat…\n nothing => [IRDump(10, nothing, \"Inliner for always_inline …\n \"julia_TTYTerminal_4\" => [IRDump(343, \"julia_TTYTerminal_4\", \"Merge Dupli…\n \"jfptr_ConsoleLogger_3\" => [IRDump(177, \"jfptr_ConsoleLogger_3\", \"Propagate…\n \"julia_TextDisplay_0\" => [IRDump(1, \"julia_TextDisplay_0\", \"Merge Duplica…" | |
}, | |
"metadata": {}, | |
"execution_count": 1 | |
} | |
], | |
"cell_type": "code", | |
"source": [ | |
"using IRDumps\n", | |
"using InteractiveUtils\n", | |
"\n", | |
"begin\n", | |
" # Julia code to be executed in an external process\n", | |
" code = \"\"\"\n", | |
" function ref_alloca_demo()\n", | |
" ref = Ref(0)\n", | |
" ptr = Ptr{Int}(pointer_from_objref(ref))\n", | |
" GC.@preserve ref begin\n", | |
" yield()\n", | |
" unsafe_store!(ptr, 123)\n", | |
" end\n", | |
" ref[]\n", | |
" end\n", | |
"\n", | |
" ref_alloca_demo()\n", | |
" \"\"\"\n", | |
"\n", | |
" # Dump LLVM IR with JULIA_LLVM_ARGS=-print-after-all\n", | |
" irs = IRDumps.dump(code)\n", | |
" passes = only(values(irs[r\"julia_ref_alloca_demo\"]))\n", | |
" irs\n", | |
"end" | |
], | |
"metadata": {}, | |
"execution_count": 1 | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Unoptimized LLVM IR" | |
], | |
"metadata": {} | |
}, | |
{ | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "*** IR Dump of \u001b[34m\u001b[1mjulia_ref_alloca_demo_8\u001b[22m\u001b[39m After \u001b[34m\u001b[1mMerge Duplicate Global Constants\u001b[22m\u001b[39m ***\n\u001b[95mdefine\u001b[39m \u001b[36mi64\u001b[39m \u001b[93m@julia_ref_alloca_demo_8\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m \u001b[0m!dbg \u001b[0m!5 \u001b[33m{\u001b[39m\n\u001b[91mtop:\u001b[39m\n \u001b[0m%0 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*** \u001b[[email protected]_states\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m\n \u001b[0m%1 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*** \u001b[0m%0 \u001b[95mto\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m**\n \u001b[0m%2 \u001b[0m= \u001b[96m\u001b[1mgetelementptr\u001b[22m\u001b[39m \u001b[95minbounds\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*\u001b[0m, \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m** \u001b[0m%1\u001b[0m, \u001b[36mi64\u001b[39m \u001b[33m4\u001b[39m\n \u001b[0m%3 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m** \u001b[0m%2 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m**\n \u001b[0m%4 \u001b[0m= \u001b[96m\u001b[1mload\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m** \u001b[0m%3\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[0m!tbaa \u001b[0m!7\u001b[0m, \u001b[0m!invariant.load \u001b[0m!4\n \u001b[0m%5 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*** \u001b[0m%0 \u001b[95mto\u001b[39m \u001b[36mi8\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!11\n \u001b[0m%6 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[95mnoalias\u001b[39m \u001b[95mnonnull\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[[email protected]_alloc_obj\u001b[39m\u001b[33m(\u001b[39m\u001b[36mi8\u001b[39m\u001b[0m* \u001b[0m%5\u001b[0m, \u001b[36mi64\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[95maddrspacecast\u001b[39m \u001b[33m(\u001b[39m\u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[95minttoptr\u001b[39m \u001b[33m(\u001b[39m\u001b[36mi64\u001b[39m \u001b[33m140386211816368\u001b[39m \u001b[95mto\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*\u001b[33m)\u001b[39m \u001b[95mto\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*\u001b[33m)\u001b[39m\u001b[33m)\u001b[39m \u001b[0m#1\u001b[0m, \u001b[0m!dbg \u001b[0m!11\n \u001b[0m%7 \u001b[0m= \u001b[0m%6 \u001b[90m; %7 = addrspacecast {} addrspace(10)* %6 to {} addrspace(11)*, !dbg !11\u001b[39m\n \u001b[0m%8 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%6 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!11\n \u001b[96m\u001b[1mstore\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[33m0\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%8\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!11\u001b[0m, \u001b[0m!tbaa \u001b[0m!19\n \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[36mvoid\u001b[39m \u001b[33m(\u001b[39m\u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m...\u001b[33m)\u001b[39m \u001b[[email protected]_barrier\u001b[39m\u001b[33m(\u001b[39m\u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%6\u001b[33m)\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!11\n \u001b[0m%9 \u001b[0m= \u001b[0m%6 \u001b[90m; %9 = addrspacecast {} addrspace(10)* %6 to {} addrspace(11)*, !dbg !23\u001b[39m\n \u001b[0m%10 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[95mnonnull\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[[email protected]_from_objref\u001b[39m\u001b[33m(\u001b[39m\u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%9\u001b[33m)\u001b[39m \u001b[0m#3\u001b[0m, \u001b[0m!dbg \u001b[0m!23\n \u001b[0m%11 \u001b[0m= \u001b[96m\u001b[1mptrtoint\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%10 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!23\n \u001b[0m%12 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[36mtoken\u001b[39m \u001b[33m(\u001b[39m\u001b[0m...\u001b[33m)\u001b[39m \u001b[[email protected]_preserve_begin\u001b[39m\u001b[33m(\u001b[39m\u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%6\u001b[33m)\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!27\n \u001b[0m%13 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[95mnonnull\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[93m@jlsys_yield_2\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!28\n \u001b[0m%14 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%10 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!29\n \u001b[0m%15 \u001b[0m= \u001b[96m\u001b[1mgetelementptr\u001b[22m\u001b[39m \u001b[95minbounds\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%14\u001b[0m, \u001b[36mi64\u001b[39m \u001b[33m0\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!29\n \u001b[96m\u001b[1mstore\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[33m123\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%15\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m1\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!29\u001b[0m, \u001b[0m!tbaa \u001b[0m!33\n \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[36mvoid\u001b[39m \u001b[[email protected]_preserve_end\u001b[39m\u001b[33m(\u001b[39m\u001b[36mtoken\u001b[39m \u001b[0m%12\u001b[33m)\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!32\n \u001b[0m%16 \u001b[0m= \u001b[0m%6 \u001b[90m; %16 = addrspacecast {} addrspace(10)* %6 to {} addrspace(11)*, !dbg !34\u001b[39m\n \u001b[0m%17 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%16 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!34\n \u001b[0m%18 \u001b[0m= \u001b[96m\u001b[1mload\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%17\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!34\u001b[0m, \u001b[0m!tbaa \u001b[0m!19\n \u001b[96m\u001b[1mret\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[0m%18\u001b[0m, \u001b[0m!dbg \u001b[0m!39\n\u001b[33m}\u001b[39m\n" | |
}, | |
"metadata": {}, | |
"execution_count": 2 | |
} | |
], | |
"cell_type": "code", | |
"source": [ | |
"first(passes)" | |
], | |
"metadata": {}, | |
"execution_count": 2 | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Just after the first llvm-alloc-opt" | |
], | |
"metadata": {} | |
}, | |
{ | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "*** IR Dump of \u001b[34m\u001b[1mjulia_ref_alloca_demo_8\u001b[22m\u001b[39m After \u001b[34m\u001b[1mPromote heap allocation to stack\u001b[22m\u001b[39m ***\n\u001b[95mdefine\u001b[39m \u001b[36mi64\u001b[39m \u001b[93m@julia_ref_alloca_demo_8\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m \u001b[0m!dbg \u001b[0m!5 \u001b[33m{\u001b[39m\n\u001b[91mtop:\u001b[39m\n \u001b[0m%0 \u001b[0m= \u001b[96m\u001b[1malloca\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m16\u001b[39m\n \u001b[0m%1 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%0 \u001b[95mto\u001b[39m \u001b[36mi8\u001b[39m\u001b[0m*\n \u001b[0m%2 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[36mi8\u001b[39m\u001b[0m* \u001b[0m%1 \u001b[95mto\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*\n \u001b[0m%3 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*** \u001b[[email protected]_states\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m\n \u001b[0m%4 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m*** \u001b[0m%3 \u001b[95mto\u001b[39m \u001b[36mi8\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!7\n \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[36mvoid\u001b[39m \u001b[[email protected]\u001b[39m\u001b[33m(\u001b[39m\u001b[36mi64\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[36mi8\u001b[39m\u001b[0m* \u001b[0m%1\u001b[33m)\u001b[39m\n \u001b[0m%5 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%2 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!7\n \u001b[96m\u001b[1mstore\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[33m0\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%5\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!7\u001b[0m, \u001b[0m!tbaa \u001b[0m!15\n \u001b[0m%6 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[95mnonnull\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[93m@jlsys_yield_2\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!21\n \u001b[0m%7 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%2 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!22\n \u001b[0m%8 \u001b[0m= \u001b[96m\u001b[1mgetelementptr\u001b[22m\u001b[39m \u001b[95minbounds\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%7\u001b[0m, \u001b[36mi64\u001b[39m \u001b[33m0\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!22\n \u001b[96m\u001b[1mstore\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[33m123\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%8\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m1\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!22\u001b[0m, \u001b[0m!tbaa \u001b[0m!27\n \u001b[0m%9 \u001b[0m= \u001b[96m\u001b[1mbitcast\u001b[22m\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[0m%2 \u001b[95mto\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m*\u001b[0m, \u001b[0m!dbg \u001b[0m!28\n \u001b[0m%10 \u001b[0m= \u001b[96m\u001b[1mload\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m\u001b[0m, \u001b[36mi64\u001b[39m\u001b[0m* \u001b[0m%9\u001b[0m, \u001b[95malign\u001b[39m \u001b[33m8\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!28\u001b[0m, \u001b[0m!tbaa \u001b[0m!15\n \u001b[96m\u001b[1mret\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[0m%10\u001b[0m, \u001b[0m!dbg \u001b[0m!33\n\u001b[33m}\u001b[39m\n" | |
}, | |
"metadata": {}, | |
"execution_count": 3 | |
} | |
], | |
"cell_type": "code", | |
"source": [ | |
"allocopt = first(ir for ir in passes if ir.pass == \"Promote heap allocation to stack\")" | |
], | |
"metadata": {}, | |
"execution_count": 3 | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Fully optimized LLVM IR" | |
], | |
"metadata": {} | |
}, | |
{ | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "*** IR Dump of \u001b[34m\u001b[1mjulia_ref_alloca_demo_8\u001b[22m\u001b[39m After \u001b[34m\u001b[1mSafe Stack instrumentation pass\u001b[22m\u001b[39m ***\n\u001b[95mdefine\u001b[39m \u001b[36mi64\u001b[39m \u001b[93m@julia_ref_alloca_demo_8\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m \u001b[0m!dbg \u001b[0m!5 \u001b[33m{\u001b[39m\n\u001b[91mtop:\u001b[39m\n \u001b[0m%0 \u001b[0m= \u001b[96m\u001b[1mcall\u001b[22m\u001b[39m \u001b[95mnonnull\u001b[39m \u001b[33m{\u001b[39m\u001b[33m}\u001b[39m\u001b[0m* \u001b[93m@jlsys_yield_2\u001b[39m\u001b[33m(\u001b[39m\u001b[33m)\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!7\n \u001b[96m\u001b[1mret\u001b[22m\u001b[39m \u001b[36mi64\u001b[39m \u001b[33m123\u001b[39m\u001b[0m, \u001b[0m!dbg \u001b[0m!8\n\u001b[33m}\u001b[39m\n" | |
}, | |
"metadata": {}, | |
"execution_count": 4 | |
} | |
], | |
"cell_type": "code", | |
"source": [ | |
"last(passes)" | |
], | |
"metadata": {}, | |
"execution_count": 4 | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Appendix" | |
], | |
"metadata": {} | |
}, | |
{ | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Julia Version 1.6.0\n", | |
"Commit f9720dc2eb (2021-03-24 12:55 UTC)\n", | |
"Platform Info:\n", | |
" OS: Linux (x86_64-pc-linux-gnu)\n", | |
" CPU: AMD EPYC 7502 32-Core Processor\n", | |
" WORD_SIZE: 64\n", | |
" LIBM: libopenlibm\n", | |
" LLVM: libLLVM-11.0.1 (ORCJIT, znver2)\n", | |
"Environment:\n", | |
" JULIA_PROJECT = /home/arakaki/repos/scratch/2021/julia/ref-alloca\n", | |
" JULIA_LOAD_PATH = @\n" | |
] | |
} | |
], | |
"cell_type": "code", | |
"source": [ | |
"versioninfo()" | |
], | |
"metadata": {}, | |
"execution_count": 5 | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"---\n", | |
"\n", | |
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" | |
], | |
"metadata": {} | |
} | |
], | |
"nbformat_minor": 3, | |
"metadata": { | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "1.6.0" | |
}, | |
"kernelspec": { | |
"name": "julia-1.6", | |
"display_name": "Julia 1.6.0", | |
"language": "julia" | |
} | |
}, | |
"nbformat": 4 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is machine-generated - editing it directly is not advised | |
[[ArgCheck]] | |
git-tree-sha1 = "dedbbb2ddb876f899585c4ec4433265e3017215a" | |
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" | |
version = "2.1.0" | |
[[Base64]] | |
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | |
[[Dates]] | |
deps = ["Printf"] | |
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" | |
[[GitDataManager]] | |
deps = ["Sockets"] | |
git-tree-sha1 = "e8f03ade9a3a427803ae01303d48553c49ba1fa8" | |
repo-rev = "master" | |
repo-url = "https://github.com/tkf/GitDataManager.jl.git" | |
uuid = "e46aa908-4c54-40d5-94de-678bb20abb10" | |
version = "0.1.0-DEV" | |
[[IOCapture]] | |
deps = ["Logging", "Random"] | |
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a" | |
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" | |
version = "0.2.2" | |
[[IRDumps]] | |
deps = ["ArgCheck", "InteractiveUtils"] | |
git-tree-sha1 = "7247ecb24e1679361f5115600a4ee5b6029d86e4" | |
repo-rev = "main" | |
repo-url = "https://github.com/tkf/IRDumps.jl.git" | |
uuid = "c8e92293-cae1-4b79-88ed-f0aaeba70b74" | |
version = "0.1.0-DEV" | |
[[InteractiveUtils]] | |
deps = ["Markdown"] | |
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | |
[[JSON]] | |
deps = ["Dates", "Mmap", "Parsers", "Unicode"] | |
git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37" | |
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" | |
version = "0.21.2" | |
[[Literate]] | |
deps = ["Base64", "IOCapture", "JSON", "REPL"] | |
git-tree-sha1 = "d3493acfb9e6aa0cff46b09773fc2342327b0feb" | |
uuid = "98b081ad-f1c9-55d3-8b20-4c87d4299306" | |
version = "2.9.4" | |
[[Logging]] | |
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" | |
[[Markdown]] | |
deps = ["Base64"] | |
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" | |
[[Mmap]] | |
uuid = "a63ad114-7e13-5084-954f-fe012c677804" | |
[[Parsers]] | |
deps = ["Dates"] | |
git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc" | |
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" | |
version = "2.1.2" | |
[[Printf]] | |
deps = ["Unicode"] | |
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" | |
[[REPL]] | |
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] | |
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" | |
[[Random]] | |
deps = ["Serialization"] | |
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | |
[[Serialization]] | |
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" | |
[[Sockets]] | |
uuid = "6462fe0b-24de-5631-8697-dd941f90decc" | |
[[Unicode]] | |
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[deps] | |
GitDataManager = "e46aa908-4c54-40d5-94de-678bb20abb10" | |
IRDumps = "c8e92293-cae1-4b79-88ed-f0aaeba70b74" | |
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | |
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using IRDumps | |
using InteractiveUtils | |
begin | |
# Julia code to be executed in an external process | |
code = """ | |
function ref_alloca_demo() | |
ref = Ref(0) | |
ptr = Ptr{Int}(pointer_from_objref(ref)) | |
GC.@preserve ref begin | |
yield() | |
unsafe_store!(ptr, 123) | |
end | |
ref[] | |
end | |
ref_alloca_demo() | |
""" | |
# Dump LLVM IR with JULIA_LLVM_ARGS=-print-after-all | |
irs = IRDumps.dump(code) | |
passes = only(values(irs[r"julia_ref_alloca_demo"])) | |
irs | |
end | |
#- | |
# ### Unoptimized LLVM IR | |
first(passes) | |
#- | |
# ### Just after the first llvm-alloc-opt | |
allocopt = first(ir for ir in passes if ir.pass == "Promote heap allocation to stack") | |
#- | |
# ### Fully optimized LLVM IR | |
last(passes) | |
#- | |
# ## Appendix | |
versioninfo() | |
#- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment