mollusk 0e4acfb8f2 fix incorrect folder name for julia-0.6.x
Former-commit-id: ef2c7401e0876f22d2f7762d182cfbcd5a7d9c70
2018-06-11 03:28:36 -07:00

10 lines
15 KiB
HTML

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Working with LLVM · The Julia Language</title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
</script><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/><link href="../assets/julia-manual.css" rel="stylesheet" type="text/css"/></head><body><nav class="toc"><a href="../index.html"><img class="logo" src="../assets/logo.png" alt="The Julia Language logo"/></a><h1>The Julia Language</h1><select id="version-selector" onChange="window.location.href=this.value" style="visibility: hidden"></select><form class="search" id="search-form" action="../search.html"><input id="search-query" name="q" type="text" placeholder="Search docs"/></form><ul><li><a class="toctext" href="../index.html">Home</a></li><li><span class="toctext">Manual</span><ul><li><a class="toctext" href="../manual/introduction.html">Introduction</a></li><li><a class="toctext" href="../manual/getting-started.html">Getting Started</a></li><li><a class="toctext" href="../manual/variables.html">Variables</a></li><li><a class="toctext" href="../manual/integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a></li><li><a class="toctext" href="../manual/mathematical-operations.html">Mathematical Operations and Elementary Functions</a></li><li><a class="toctext" href="../manual/complex-and-rational-numbers.html">Complex and Rational Numbers</a></li><li><a class="toctext" href="../manual/strings.html">Strings</a></li><li><a class="toctext" href="../manual/functions.html">Functions</a></li><li><a class="toctext" href="../manual/control-flow.html">Control Flow</a></li><li><a class="toctext" href="../manual/variables-and-scoping.html">Scope of Variables</a></li><li><a class="toctext" href="../manual/types.html">Types</a></li><li><a class="toctext" href="../manual/methods.html">Methods</a></li><li><a class="toctext" href="../manual/constructors.html">Constructors</a></li><li><a class="toctext" href="../manual/conversion-and-promotion.html">Conversion and Promotion</a></li><li><a class="toctext" href="../manual/interfaces.html">Interfaces</a></li><li><a class="toctext" href="../manual/modules.html">Modules</a></li><li><a class="toctext" href="../manual/documentation.html">Documentation</a></li><li><a class="toctext" href="../manual/metaprogramming.html">Metaprogramming</a></li><li><a class="toctext" href="../manual/arrays.html">Multi-dimensional Arrays</a></li><li><a class="toctext" href="../manual/linear-algebra.html">Linear algebra</a></li><li><a class="toctext" href="../manual/networking-and-streams.html">Networking and Streams</a></li><li><a class="toctext" href="../manual/parallel-computing.html">Parallel Computing</a></li><li><a class="toctext" href="../manual/dates.html">Date and DateTime</a></li><li><a class="toctext" href="../manual/interacting-with-julia.html">Interacting With Julia</a></li><li><a class="toctext" href="../manual/running-external-programs.html">Running External Programs</a></li><li><a class="toctext" href="../manual/calling-c-and-fortran-code.html">Calling C and Fortran Code</a></li><li><a class="toctext" href="../manual/handling-operating-system-variation.html">Handling Operating System Variation</a></li><li><a class="toctext" href="../manual/environment-variables.html">Environment Variables</a></li><li><a class="toctext" href="../manual/embedding.html">Embedding Julia</a></li><li><a class="toctext" href="../manual/packages.html">Packages</a></li><li><a class="toctext" href="../manual/profile.html">Profiling</a></li><li><a class="toctext" href="../manual/stacktraces.html">Stack Traces</a></li><li><a class="toctext" href="../manual/performance-tips.html">Performance Tips</a></li><li><a class="toctext" href="../manual/workflow-tips.html">Workflow Tips</a></li><li><a class="toctext" href="../manual/style-guide.html">Style Guide</a></li><li><a class="toctext" href="../manual/faq.html">Frequently Asked Questions</a></li><li><a class="toctext" href="../manual/noteworthy-differences.html">Noteworthy Differences from other Languages</a></li><li><a class="toctext" href="../manual/unicode-input.html">Unicode Input</a></li></ul></li><li><span class="toctext">Standard Library</span><ul><li><a class="toctext" href="../stdlib/base.html">Essentials</a></li><li><a class="toctext" href="../stdlib/collections.html">Collections and Data Structures</a></li><li><a class="toctext" href="../stdlib/math.html">Mathematics</a></li><li><a class="toctext" href="../stdlib/numbers.html">Numbers</a></li><li><a class="toctext" href="../stdlib/strings.html">Strings</a></li><li><a class="toctext" href="../stdlib/arrays.html">Arrays</a></li><li><a class="toctext" href="../stdlib/parallel.html">Tasks and Parallel Computing</a></li><li><a class="toctext" href="../stdlib/linalg.html">Linear Algebra</a></li><li><a class="toctext" href="../stdlib/constants.html">Constants</a></li><li><a class="toctext" href="../stdlib/file.html">Filesystem</a></li><li><a class="toctext" href="../stdlib/io-network.html">I/O and Network</a></li><li><a class="toctext" href="../stdlib/punctuation.html">Punctuation</a></li><li><a class="toctext" href="../stdlib/sort.html">Sorting and Related Functions</a></li><li><a class="toctext" href="../stdlib/pkg.html">Package Manager Functions</a></li><li><a class="toctext" href="../stdlib/dates.html">Dates and Time</a></li><li><a class="toctext" href="../stdlib/iterators.html">Iteration utilities</a></li><li><a class="toctext" href="../stdlib/test.html">Unit Testing</a></li><li><a class="toctext" href="../stdlib/c.html">C Interface</a></li><li><a class="toctext" href="../stdlib/libc.html">C Standard Library</a></li><li><a class="toctext" href="../stdlib/libdl.html">Dynamic Linker</a></li><li><a class="toctext" href="../stdlib/profile.html">Profiling</a></li><li><a class="toctext" href="../stdlib/stacktraces.html">StackTraces</a></li><li><a class="toctext" href="../stdlib/simd-types.html">SIMD Support</a></li></ul></li><li><span class="toctext">Developer Documentation</span><ul><li><a class="toctext" href="reflection.html">Reflection and introspection</a></li><li><span class="toctext">Documentation of Julia&#39;s Internals</span><ul><li><a class="toctext" href="init.html">Initialization of the Julia runtime</a></li><li><a class="toctext" href="ast.html">Julia ASTs</a></li><li><a class="toctext" href="types.html">More about types</a></li><li><a class="toctext" href="object.html">Memory layout of Julia Objects</a></li><li><a class="toctext" href="eval.html">Eval of Julia code</a></li><li><a class="toctext" href="callconv.html">Calling Conventions</a></li><li><a class="toctext" href="compiler.html">High-level Overview of the Native-Code Generation Process</a></li><li><a class="toctext" href="functions.html">Julia Functions</a></li><li><a class="toctext" href="cartesian.html">Base.Cartesian</a></li><li><a class="toctext" href="meta.html">Talking to the compiler (the <code>:meta</code> mechanism)</a></li><li><a class="toctext" href="subarrays.html">SubArrays</a></li><li><a class="toctext" href="sysimg.html">System Image Building</a></li><li class="current"><a class="toctext" href="llvm.html">Working with LLVM</a><ul class="internal"><li><a class="toctext" href="#Overview-of-Julia-to-LLVM-Interface-1">Overview of Julia to LLVM Interface</a></li><li><a class="toctext" href="#Building-Julia-with-a-different-version-of-LLVM-1">Building Julia with a different version of LLVM</a></li><li><a class="toctext" href="#Passing-options-to-LLVM-1">Passing options to LLVM</a></li><li><a class="toctext" href="#Improving-LLVM-optimizations-for-Julia-1">Improving LLVM optimizations for Julia</a></li></ul></li><li><a class="toctext" href="stdio.html">printf() and stdio in the Julia runtime</a></li><li><a class="toctext" href="boundscheck.html">Bounds checking</a></li><li><a class="toctext" href="locks.html">Proper maintenance and care of multi-threading locks</a></li><li><a class="toctext" href="offset-arrays.html">Arrays with custom indices</a></li><li><a class="toctext" href="libgit2.html">Base.LibGit2</a></li><li><a class="toctext" href="require.html">Module loading</a></li></ul></li><li><span class="toctext">Developing/debugging Julia&#39;s C code</span><ul><li><a class="toctext" href="backtraces.html">Reporting and analyzing crashes (segfaults)</a></li><li><a class="toctext" href="debuggingtips.html">gdb debugging tips</a></li><li><a class="toctext" href="valgrind.html">Using Valgrind with Julia</a></li><li><a class="toctext" href="sanitizers.html">Sanitizer support</a></li></ul></li></ul></li></ul></nav><article id="docs"><header><nav><ul><li>Developer Documentation</li><li>Documentation of Julia&#39;s Internals</li><li><a href="llvm.html">Working with LLVM</a></li></ul><a class="edit-page" href="https://github.com/JuliaLang/julia/blob/master/doc/src/devdocs/llvm.md"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>Working with LLVM</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" id="Working-with-LLVM-1" href="#Working-with-LLVM-1">Working with LLVM</a></h1><p>This is not a replacement for the LLVM documentation, but a collection of tips for working on LLVM for Julia.</p><h2><a class="nav-anchor" id="Overview-of-Julia-to-LLVM-Interface-1" href="#Overview-of-Julia-to-LLVM-Interface-1">Overview of Julia to LLVM Interface</a></h2><p>Julia statically links in LLVM by default. Build with <code>USE_LLVM_SHLIB=1</code> to link dynamically.</p><p>The code for lowering Julia AST to LLVM IR or interpreting it directly is in directory <code>src/</code>.</p><table><tr><th>File</th><th>Description</th></tr><tr><td><code>builtins.c</code></td><td>Builtin functions</td></tr><tr><td><code>ccall.cpp</code></td><td>Lowering <code>ccall</code></td></tr><tr><td><code>cgutils.cpp</code></td><td>Lowering utilities, notably for array and tuple accesses</td></tr><tr><td><code>codegen.cpp</code></td><td>Top-level of code generation, pass list, lowering builtins</td></tr><tr><td><code>debuginfo.cpp</code></td><td>Tracks debug information for JIT code</td></tr><tr><td><code>disasm.cpp</code></td><td>Handles native object file and JIT code diassembly</td></tr><tr><td><code>gf.c</code></td><td>Generic functions</td></tr><tr><td><code>intrinsics.cpp</code></td><td>Lowering intrinsics</td></tr><tr><td><code>llvm-simdloop.cpp</code></td><td>Custom LLVM pass for <code>@simd</code></td></tr><tr><td><code>sys.c</code></td><td>I/O and operating system utility functions</td></tr></table><p>Some of the <code>.cpp</code> files form a group that compile to a single object.</p><p>The difference between an intrinsic and a builtin is that a builtin is a first class function that can be used like any other Julia function. An intrinsic can operate only on unboxed data, and therefore its arguments must be statically typed.</p><h3><a class="nav-anchor" id="Alias-Analysis-1" href="#Alias-Analysis-1">Alias Analysis</a></h3><p>Julia currently uses LLVM&#39;s <a href="http://llvm.org/docs/LangRef.html#tbaa-metadata">Type Based Alias Analysis</a>. To find the comments that document the inclusion relationships, look for <code>static MDNode*</code> in <code>src/codegen.cpp</code>.</p><p>The <code>-O</code> option enables LLVM&#39;s <a href="http://llvm.org/docs/AliasAnalysis.html#the-basicaa-pass">Basic Alias Analysis</a>.</p><h2><a class="nav-anchor" id="Building-Julia-with-a-different-version-of-LLVM-1" href="#Building-Julia-with-a-different-version-of-LLVM-1">Building Julia with a different version of LLVM</a></h2><p>The default version of LLVM is specified in <code>deps/Versions.make</code>. You can override it by creating a file called <code>Make.user</code> in the top-level directory and adding a line to it such as:</p><pre><code class="language-none">LLVM_VER = 3.5.0</code></pre><p>Besides the LLVM release numerals, you can also use <code>LLVM_VER = svn</code> to bulid against the latest development version of LLVM.</p><h2><a class="nav-anchor" id="Passing-options-to-LLVM-1" href="#Passing-options-to-LLVM-1">Passing options to LLVM</a></h2><p>You can pass options to LLVM using <em>debug</em> builds of Julia. To create a debug build, run <code>make debug</code>. The resulting executable is <code>usr/bin/julia-debug</code>. You can pass LLVM options to this executable via the environment variable <code>JULIA_LLVM_ARGS</code>. Here are example settings using <code>bash</code> syntax:</p><ul><li><p><code>export JULIA_LLVM_ARGS = -print-after-all</code> dumps IR after each pass.</p></li><li><p><code>export JULIA_LLVM_ARGS = -debug-only=loop-vectorize</code> dumps LLVM <code>DEBUG(...)</code> diagnostics for loop vectorizer <em>if</em> you built Julia with <code>LLVM_ASSERTIONS=1</code>. Otherwise you will get warnings about &quot;Unknown command line argument&quot;. Counter-intuitively, building Julia with <code>LLVM_DEBUG=1</code> is <em>not</em> enough to dump <code>DEBUG</code> diagnostics from a pass.</p></li></ul><h2><a class="nav-anchor" id="Improving-LLVM-optimizations-for-Julia-1" href="#Improving-LLVM-optimizations-for-Julia-1">Improving LLVM optimizations for Julia</a></h2><p>Improving LLVM code generation usually involves either changing Julia lowering to be more friendly to LLVM&#39;s passes, or improving a pass.</p><p>If you are planning to improve a pass, be sure to read the <a href="http://llvm.org/docs/DeveloperPolicy.html">LLVM developer policy</a>. The best strategy is to create a code example in a form where you can use LLVM&#39;s <code>opt</code> tool to study it and the pass of interest in isolation.</p><ol><li><p>Create an example Julia code of interest.</p></li><li><p>Use <code>JULIA_LLVM_ARGS = -print-after-all</code> to dump the IR.</p></li><li><p>Pick out the IR at the point just before the pass of interest runs.</p></li><li><p>Strip the debug metadata and fix up the TBAA metadata by hand.</p></li></ol><p>The last step is labor intensive. Suggestions on a better way would be appreciated.</p><footer><hr/><a class="previous" href="sysimg.html"><span class="direction">Previous</span><span class="title">System Image Building</span></a><a class="next" href="stdio.html"><span class="direction">Next</span><span class="title">printf() and stdio in the Julia runtime</span></a></footer></article></body></html>