The LLVM Project Bloghttps://blog.llvm.org/Recent content on The LLVM Project BlogHugo -- gohugo.ioenllvm.orgMon, 04 Nov 2024 00:00:00 +0000- GSoC 2024: Out-Of-Process Execution For Clang-Replhttps://blog.llvm.org/posts/2024-10-23-out-of-process-execution-for-clang-repl/Mon, 04 Nov 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-10-23-out-of-process-execution-for-clang-repl/<p>Hello! I’m Sahil Patidar, and this summer I had the exciting opportunity toparticipate in Google Summer of Code (GSoC) 2024. My project revolved aroundenhancing Clang-Repl by introducing Out-Of-Process Execution.</p><p>Mentors: Vassil Vassilev and Matheus Izvekov</p><h2 id="project-background">Project Background</h2><p>Clang-Repl, part of the LLVM project, is a powerful interactive C++ interpreter using Just-In-Time (JIT) compilation. However, it faced two major issues: high resource consumption and instability. Running both Clang-Repl and JIT in the same process consumed excessive system resources, and any crash in user code would shut down the entire session.</p><p>To address these problems, <strong>Out-Of-Process Execution</strong> was introduced. By executing user code in a separate process, resource usage is reduced and crashes no longer affect the main session. This solution significantly enhances both the efficiency and stability of Clang-Repl, making it more reliable and suitable for a broader range of use cases, especially on resource-constrained systems.</p><h2 id="what-we-accomplished">What We Accomplished</h2><p>As part of my GSoC project, I’ve been focused on implementing out-of-process execution in Clang-Repl and enhancing the ORC JIT infrastructure to support this feature. Here is a breakdown of the key tasks and improvements I worked on:</p><h3 id="out-of-process-execution-support-for-clang-repl">Out-Of-Process Execution Support for Clang-Repl</h3><p><strong>PR</strong>: <a href="https://github.com/llvm/llvm-project/pull/110418">#110418</a></p><p>One of the primary objectives of my project was to implement <strong>out-of-process (OOP) execution</strong> capabilities within Clang-Repl, enabling it to execute code in a separate, isolated process. This feature leverages <strong>ORC JIT’s remote execution capabilities</strong> to enhance code execution flexibility by isolating runtime environments.</p><p>To enable OOP execution in Clang-Repl, I utilized the <code>llvm-jitlink-executor</code>, allowing Clang-Repl to offload code execution to a dedicated executor process. This setup introduces a layer of isolation between Clang-Replâs main process and the code execution environment.</p><ul><li><p><strong>New Command-Line Flags</strong>:</p><p>To facilitate the out-of-process execution, I added two key command-line flags:</p><ul><li><p><strong><code>--oop-executor</code></strong>This flag starts a separate JIT executor process. The executor handles the actual code execution independently of the main Clang-Repl process.</p></li><li><p><strong><code>--oop-executor-connect</code></strong>This flag establishes a communication link between Clang-Repl and the out-of-process executor. It allows Clang-Repl to transmit code to the executor and retrieve the results from the execution.</p></li></ul></li></ul><p>With these flags in place, Clang-Repl can utilize <code>llvm-jitlink-executor</code> to execute code in an isolated environment. This approach significantly enhances separation between the compilation and execution stages, increasing flexibility and ensuring a more secure and manageable execution process.</p><h3 id="issues-encountered">Issues Encountered</h3><ul><li><p><strong>Block Dependence Calculation in ObjectLinkingLayer</strong><a href="https://github.com/llvm/llvm-project/commit/896dd322afcc1cf5dc4fa7375dedd55b59001eb4">Commit Link</a></p><p><strong>Code Example</strong></p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>clang<span style="color:#f92672">-</span>repl<span style="color:#f92672">></span> <span style="color:#66d9ef">int</span> f() {<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">1</span>;}</span></span><span style="display:flex;"><span>clang<span style="color:#f92672">-</span>repl<span style="color:#f92672">></span> <span style="color:#66d9ef">int</span> f1() {<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">f</span>();}</span></span><span style="display:flex;"><span>clang<span style="color:#f92672">-</span>repl<span style="color:#f92672">></span> f1();</span></span><span style="display:flex;"><span>error: disconnecting</span></span><span style="display:flex;"><span>clang<span style="color:#f92672">-</span>repl<span style="color:#f92672">></span> JIT session error: FD<span style="color:#f92672">-</span>transport disconnected</span></span><span style="display:flex;"><span>JIT session error: disconnecting</span></span><span style="display:flex;"><span>JIT session error: FD<span style="color:#f92672">-</span>transport disconnected</span></span><span style="display:flex;"><span>JIT session error: Failed to materialize symbols: { (main, { __Z2fv }) }</span></span><span style="display:flex;"><span>disconnecting</span></span></code></pre></div><p>During my work on <code>clang-repl</code>, I encountered an issue where the JIT session would crash during incremental compilation. The root cause was a bug in <code>ObjectLinkingLayer::computeBlockNonLocalDeps</code>. The problem arose from the way the worklist was built: it was being populated within the same loop that records immediate dependencies and dependants, which caused some blocks to be missed from the worklist. This bug was fixed by <strong>Lang Hames</strong>.</p></li></ul><h3 id="orc-jit-enhancements">ORC JIT Enhancements</h3><p>As part of the OOP execution work, several improvements were made to ORC JIT, the underlying framework responsible for dynamic compilation and execution of code in Clang-Repl. These improvements target better handling of incremental execution, especially for Mach-O and ELF platforms, and ensuring that initializers are properly managed across different execution environments.</p><ol><li><p><strong>Incremental Initializer Execution for Mach-O and ELF</strong><strong>PRs</strong>: <a href="https://github.com/llvm/llvm-project/pull/97441">#97441</a>, <a href="https://github.com/llvm/llvm-project/pull/110406">#110406</a></p><p>In a typical JIT execution environment, the <code>dlopen</code> function is used to handle code mapping, reference counting, and initializer execution for dynamically loaded libraries. However, this approach is often too broad for interactive environments like Clang-Repl, where we only need to execute newly introduced initializers rather than reinitializing everything. To address this, I introduced the <strong><code>dlupdate</code></strong> function in the ORC runtime.</p><p>The <code>dlupdate</code> function is a targeted solution that focuses solely on running new initializers added during a REPL session. Unlike <code>dlopen</code>, which handles a variety of tasks and can lead to unnecessary overhead, <code>dlupdate</code> only triggers the execution of newly registered initializers, avoiding redundant operations. This improvement is particularly beneficial in interactive settings like Clang-Repl, where code is frequently updated in small increments.</p><p>By streamlining the execution of initializers, this change significantly improves the efficiency of Clang-Repl.</p></li><li><p><strong>Push-Request Model for ELF Initializers</strong><strong>PR</strong>: <a href="https://github.com/llvm/llvm-project/pull/102846">#102846</a></p><p>A push-request model has been introduced to manage ELF initializers within the runtime state for each <code>JITDylib</code>, similar to how initializers are handled for Mach-O and COFF. Previously, ELF required a fresh request for initializers with each invocation of <code>dlopen</code>, but lacked mechanisms to register, deregister, or retain these initializers. This created issues during subsequent <code>dlopen</code> calls, as initializers were erased after the <code>rt_getInitializers</code> function was invoked, making further executions impossible.</p><p>To resolve these issues, the following functions were introduced:</p><ul><li><strong><code>__orc_rt_elfnix_register_init_sections</code></strong>: Registers ELF initializers for the <code>JITDylib</code>.</li><li><strong><code>__orc_rt_elfnix_register_jitdylib</code></strong>: Registers the <code>JITDylib</code> with the ELF runtime state.</li></ul><p>With the new push-request model, the management and tracking of initializers for each <code>JITDylib</code> state are now more efficient. By leveraging Mach-Oâs <code>RecordSectionsTracker</code>, only newly registered initializers are executed, greatly improving efficiency and reliability when working with ELF targets in <code>clang-repl</code>.</p><p>This update is crucial for enabling out-of-process execution in <code>clang-repl</code> on ELF platforms, offering a more effective approach to managing incremental execution.</p></li></ol><h3 id="additional-improvements">Additional Improvements</h3><p>Beyond the main enhancements to Clang-Repl and ORC JIT, I also worked on several other improvements:</p><ol><li><p><strong>Auto-loading Dynamic Libraries in ORC JIT.</strong></p><p><strong>PR</strong>: <a href="https://github.com/llvm/llvm-project/pull/109913">#109913</a> (On-going)</p><p>With this update, weâve introduced a new feature to the ORC executor and controller: <strong>automatic loading of dynamic libraries in the ORC JIT</strong>. This enhancement enables efficient resolution of symbols from both loaded and unloaded libraries.</p><ul><li><p>How It Works:</p><ul><li><strong>Symbol Lookup:</strong>When a lookup request is made, the system first attempts to resolve the symbol from already loaded libraries.</li><li><strong>Unloaded Libraries Scan:</strong>If the symbol is not found in any loaded library, the system then scans the unloaded dynamic libraries to locate it.</li></ul></li><li><p>Key Addition: <strong>Global Bloom Filter</strong>A significant improvement in this update is the introduction of a <strong>Global Bloom Filter</strong>. When a symbol cannot be resolved in the loaded libraries, the symbol tables from the scanned libraries are incorporated into this filter. If the symbol is still not found, the bloom filterâs result is returned to the controller, allowing it to skip checking for symbols that do not exist in the global table during future lookups.</p></li></ul><p>Additionally, the system tracks symbols that were previously thought to be present but are actually absent in both loaded and unloaded libraries. With these enhancements, symbol resolution is significantly faster, as the bloom filter helps prevent unnecessary lookups, thereby improving efficiency for both loaded and unloaded dynamic libraries.</p></li><li><p><strong>Refactor of <code>dlupdate</code> Function</strong><strong>PR</strong>: <a href="https://github.com/llvm/llvm-project/pull/110491">#110491</a></p><p>This update simplifies the <code>dlupdate</code> function by removing the <code>mode</code> argument, streamlining the function’s interface. The change enhances the clarity and usability of <code>dlupdate</code> by reducing unnecessary parameters, improving the overall maintainability of the code.</p></li></ol><h2 id="benchmarks-in-process-vs-out-of-process-execution">Benchmarks: In-Process vs Out-of-Process Execution</h2><ul><li><a href="https://gist.github.com/SahilPatidar/4870bf9968b1b0cb3dabcff7281e6135">Prime Finder</a></li><li><a href="https://gist.github.com/SahilPatidar/2191963e59feb7dfa1314509340f95a1">Fibonacci Sequence</a></li><li><a href="https://gist.github.com/SahilPatidar/1df9e219d0f8348bd126f1e01658b3fa">Matrix Multiplication</a></li><li><a href="https://gist.github.com/SahilPatidar/c814634b2f863fc167b8d16b573f88ec">Sorting Algorithms</a></li></ul><h2 id="result">Result</h2><p>With these changes, <code>clang-repl</code> now supports out-of-process execution. We can run it using the following command:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>clang-repl --oop-executor<span style="color:#f92672">=</span>path/to/llvm-jitlink-executor --orc-runtime<span style="color:#f92672">=</span>path/to/liborc_rt.a</span></span></code></pre></div><h2 id="future-work">Future Work</h2><ul><li><p><strong>Crash Recovery and Session Continuation :</strong>Investigate and develop ways to enhance crash recovery so that if something goes wrong, the session can seamlessly resume without losing progress. This involves exploring options for an automatic process to restart the executor in the event of a crash.</p></li><li><p><strong>Finalize Auto Library Loading in ORC JIT :</strong>Wrap up the feature that automatically loads libraries in ORC JIT. This will streamline symbol resolution for both loaded and unloaded dynamic libraries by ensuring that any required dylibs containing symbol definitions are loaded as needed.</p></li></ul><h2 id="conclusion">Conclusion</h2><p>With this project, <strong>Clang-Repl</strong> now supports <strong>out-of-process execution</strong> for both <code>ELF</code> and <code>Mach-O</code>, making it much more efficient and stable, especially on devices with limited resources.</p><p>In the future, I plan to work on automating library loading and improving ORC-JIT to make Clang-Repl’s out-of-process execution even better.</p><h2 id="acknowledgements">Acknowledgements</h2><p>I would like to thank <strong>Google Summer of Code (GSoC)</strong> and the LLVM community for providing me with this amazing opportunity. Special thanks to my mentors, <strong>Vassil Vassilev</strong> and <strong>Matheus Izvekov</strong>, for their continuous support and guidance. I am also deeply grateful to <strong>Lang Hames</strong> for sharing their expertise on ORC-JIT and helping improve <code>clang-repl</code>. This experience has been a major step in my development, and I look forward to continuing my contributions to open source.</p><h2 id="related-links">Related Links</h2><ul><li><a href="https://github.com/llvm/llvm-project">LLVM Repository</a></li><li><a href="https://discourse.llvm.org/t/clang-out-of-process-execution-for-clang-repl/68225">Project Description</a></li><li><a href="https://github.com/SahilPatidar">My GitHub Profile</a></li></ul>
- GSoC 2024: The 1001 thresholds in LLVMhttps://blog.llvm.org/posts/2024-08-31-the-1001-thresholds-in-llvm/Mon, 21 Oct 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-08-31-the-1001-thresholds-in-llvm/<p>Hey everyone! My name is Shourya and I worked on LLVM this summer through GSoC. My project is called <a href="https://summerofcode.withgoogle.com/programs/2024/projects/MnheN07A">The 1001 thresholds in LLVM</a>. The main objective of this project was to study how varying different thresholds in llvm affect performance parameters like compile-time, bitcode-size, execution-time and llvm stats.</p><h1 id="background">Background</h1><p>LLVM has lots of thresholds and flags to avoid “costly cases”. However, it is unclear if these thresholds are useful, their value is reasonable, and what impact they really have. Since there are a lot, one cannot do a simple exhaustive search. An example of work in this direction includes the introduction of a C++ class that can replace hardcoded values which offers control over the threshold, e.g., one can increase the recursion limit via a command line flag from the hardcoded “6” to a different number. As such there is a need to explore different thresholds in llvm, understand what it means for a threshold to be hit, profile different thresholds and select optimal values for different thresholds.</p><h1 id="what-we-did">What We Did</h1><p>This work provides a tool that can efficiently explore these knobs and understand how modifying them affects metrics like compile time, size of the generated program, or any statistic that LLVM emits like âNumber of loops vectorizedâ. (Note that execution-time is currently not evaluated because input-gen does not work on optimized IR and is thus part of future work.)</p><p>We first built a clang matcher for which we looked for the following patterns :</p><ol><li>Const knob_name = knob_val</li><li>Cl::init</li><li>Enum {knob_name = knob_val}</li></ol><p>to first identify the <a href="https://docs.google.com/spreadsheets/d/1J8G06FVoI6dyoz36_zCz1Z1udcLLg5If5gdSpcII-S8/edit?usp=sharing">knobs</a> in the codebase and then used a custom python tool (optimised to deal with I/O and cache bottlenecks) to collect the different stat values in parallel and stored them in a json file. After manual selection of interesting knobs, we have so far conducted three studies in which we measure compile-time and bitcode-size along with various other statistics, and present them in the form of interactive graphs. Two of them (on 10,000 and 100 bitcode files) look at average statistics for each knob value while the third one (on 10,000 bitcode files) studies how each file is affected individually by changing knob values. We see some very interesting patterns in these graphs, for instance in the following two graphs, representing the jump-threading-threshold, we can observe improved statistics (top graph) and decreased average compile time (bottom graph) if the knob value is increased.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/the-1001-thresholds-in-llvm-2024-08-31-figure1.png"><br /></div><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/the-1001-thresholds-in-llvm-2024-08-31-figure2.png"><br /></div><h1 id="results">Results</h1><p>The per file study proves that there is no one single magic knob value and the optimum, with regards to compile time or code size, depends on the file that is currently being compiled. For instance here we can see that different knob values (for the knob licm-mssa-optimization-cap) give good cumulative compile time improvements for different files. In detail, most files benefit from a knob value of 300 while 60 is the best knob value for the second most files.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/the-1001-thresholds-in-llvm-2024-08-31-figure3.png"><br /></div><p>We further show that the presence of an oracle that can tell the best knob value for each file can significantly improve the cumulative compile time.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/the-1001-thresholds-in-llvm-2024-08-31-figure4.png"><br /></div><p>In this project, we explored various thresholds in LLVMâspecifically, 93 thresholds (a 100 file study for each can be found <a href="https://sh0g0-1758.github.io/GSOC-X-LLVM/100.html">here</a>) using the Clang matcherâand observed that these thresholds are largely file-specific. This indicates that there is no universally optimal value, or even a set of values, that can be applied across different scenarios. Instead, what is needed is an adaptive mechanism within LLVM, an oracle, that can dynamically determine the appropriate threshold values during compilation.</p><p>We also experimented with varying thresholds cumulatively by leveraging file-specific information through an LLVM pass. However, after discussions with the mentors, this approach was set aside due to the significant changes it would necessitate across other parts of the LLVM codebase.</p><p>As a result, we have not yet categorized different thresholds, such as identifying optimal threshold values for specific file types (e.g., I/O-intensive files). Nonetheless, we provide a tool that can efficiently collect this data (LLVM statistics, bitcode-size and compile-time) and help visualize it with the help of interactive graphs as well as histograms that examine these variations on a per-file basis. Additionally, a correlation table between knob values and performance metrics further illustrates the significant impact this study could have on improving LLVM’s overall performance.</p><h1 id="future-work">Future Work</h1><p>The early results show that we need a better understanding of knob values to maximise various objectives. Our results will provide the community with the first step in developing a guided compilation model attune to the file that is being compiled. We further intend to show how these knobs interact with each other and whether modifying multiple knobs together compounds the benefits or not. One more area of work could be on <a href="https://llvm.org/devmtg/2024-04/slides/LightningTalks/Ivanov-AutomaticProxyAppGeneration.pdf">input-gen</a> that would enable us to collect and study execution-time in our performance parameters.</p><h1 id="acknowledgements">Acknowledgements</h1><p>This project would not have been possible without my amazing mentors, Jan Hückelheim, Johannes Doerfert, the LLVM Foundation admins, and the GSoC admins.</p><h1 id="links">Links</h1><p><a href="https://github.com/Sh0g0-1758/GSOC-X-LLVM/tree/oracle">Code</a></p><p><a href="https://sh0g0-1758.github.io/GSOC-X-LLVM/">Studies</a></p><p><a href="https://summerofcode.withgoogle.com/programs/2024/projects/MnheN07A">GSoC Project Page</a></p>
- GSoC 2024: 3-way comparison intrinsicshttps://blog.llvm.org/posts/2024-08-29-gsoc-three-way-comparison/Mon, 07 Oct 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-08-29-gsoc-three-way-comparison/<p>Hello everyone! My name is Volodymyr, and in this post I would like to talk about the project I have been working on for the past couple of months as part of Google Summer of Code 2024. The aim of the project was to introduce 3-way comparison intrinsics to LLVM IR and add a decent level of optimizations for them.</p><h1 id="background">Background</h1><p>Three-way comparison is an operation present in many high-level languages, such as C++ and its spaceship operator or Rust and the <code>Ord</code> trait. It operates on two values for which there is a defined comparison operation and returns <code>-1</code> if the first operand is less than the second, <code>0</code> if they are equal, and <code>1</code> otherwise. At the moment, compilers that use LLVM express this operation using different sequences of instructions which are optimized and lowered individually rather than as a single operation. Adding an intrinsic for this operation would therefore help us generate better machine code on some targets, as well as potentially optimize patterns in the middle-end that we didn’t optimize before.</p><h1 id="what-was-done">What was done</h1><p>Over the course of the project I have added two new intrinsics to the LLVM IR: <code>llvm.ucmp</code> for an unsigned 3-way comparison and <code>llvm.scmp</code> for a signed comparison. They both take two arguments that must be integers or vectors of integers and return an integer or a vector of integers with the same number of elements. The arguments and the result do not need to have the same type.</p><p>In the middle-end the following passes received some support for these intrinsics:</p><ul><li>InstSimplify (<a href="https://github.com/llvm/llvm-project/pull/93730">#1</a>, <a href="https://github.com/llvm/llvm-project/pull/95601">#2</a>)</li><li>InstCombine (<a href="https://github.com/llvm/llvm-project/pull/96118">#1</a>, <a href="https://github.com/llvm/llvm-project/pull/98360">#2</a>, <a href="https://github.com/llvm/llvm-project/pull/101049">#3</a>, <a href="https://github.com/llvm/llvm-project/pull/105272">#4</a>, <a href="https://github.com/llvm/llvm-project/pull/105583">#5</a>)</li><li><a href="https://github.com/llvm/llvm-project/pull/97235">CorrelatedValuePropagation</a></li><li><a href="https://github.com/llvm/llvm-project/pull/97974">ConstraintElimination</a></li></ul><p>I have also added folds of idiomatic ways that a 3-way comparison can be expressed to a call to the corresponding intrinsic.</p><p>In the backend there are two different ways of expanding the intrinsics: <a href="https://github.com/llvm/llvm-project/pull/91871">as a nested select</a> (i.e. <code>(x < y) ? -1 : (x > y ? 1 : 0)</code>) or <a href="https://github.com/llvm/llvm-project/pull/98774">as a subtraction of zero-extended comparisons</a> (<code>zext(x > y) - zext(x < y)</code>). The second option is the default one, but targets can choose to use the first one through a TLI hook.</p><h1 id="results">Results</h1><p>I think that overall the project was successful and brought a small positive change to LLVM. To demonstrate its impact in a small test case, the following function in C++ that uses the spaceship operator was compiled twice, first with Clang 18.1 and then with Clang built from the main branch of LLVM repository:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-C++" data-lang="C++"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><compare></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>strong_ordering cmp(<span style="color:#66d9ef">unsigned</span> <span style="color:#66d9ef">int</span> a, <span style="color:#66d9ef">unsigned</span> <span style="color:#66d9ef">int</span> b)</span></span><span style="display:flex;"><span>{</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> a <span style="color:#f92672"><=></span> b;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>With Clang 18.1:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>; ====== LLVM IR ======</span></span><span style="display:flex;"><span>define i8 @cmp(i32 %a, i32 %b) {</span></span><span style="display:flex;"><span>entry:</span></span><span style="display:flex;"><span> %cmp.lt = icmp ult i32 %a, %b</span></span><span style="display:flex;"><span> %sel.lt = select i1 %cmp.lt, i8 -1, i8 1</span></span><span style="display:flex;"><span> %cmp.eq = icmp eq i32 %a, %b</span></span><span style="display:flex;"><span> %sel.eq = select i1 %cmp.eq, i8 0, i8 %sel.lt</span></span><span style="display:flex;"><span> ret i8 %sel.eq</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>; ====== x86_64 assembly ======</span></span><span style="display:flex;"><span>cmp:</span></span><span style="display:flex;"><span> xor ecx, ecx</span></span><span style="display:flex;"><span> cmp edi, esi</span></span><span style="display:flex;"><span> mov eax, 0</span></span><span style="display:flex;"><span> sbb eax, eax</span></span><span style="display:flex;"><span> or al, 1</span></span><span style="display:flex;"><span> cmp edi, esi</span></span><span style="display:flex;"><span> movzx eax, al</span></span><span style="display:flex;"><span> cmove eax, ecx</span></span><span style="display:flex;"><span> ret</span></span></code></pre></div><p>With freshly built Clang:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-plain" data-lang="plain"><span style="display:flex;"><span>; ====== LLVM IR ======</span></span><span style="display:flex;"><span>define i8 @cmp(i32 %a, i32 %b) {</span></span><span style="display:flex;"><span>entry:</span></span><span style="display:flex;"><span> %sel.eq = tail call i8 @llvm.ucmp.i8.i32(i32 %a, i32 %b)</span></span><span style="display:flex;"><span> ret i8 %sel.eq</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>; ====== x86_64 assembly ======</span></span><span style="display:flex;"><span>cmp:</span></span><span style="display:flex;"><span> cmp edi, esi</span></span><span style="display:flex;"><span> seta al</span></span><span style="display:flex;"><span> sbb al, 0</span></span><span style="display:flex;"><span> ret</span></span></code></pre></div><p>As you can see, the number of instructions in the generated code had gone down considerably (from 8 to 3 excluding <code>ret</code>). Although this isn’t much and is a small synthetic test, it can still make a noticeable impact if code like this is found in a hot path somewhere.</p><p>The impact of these changes on real-world code is much harder to quantify. Looking at llvm-opt-benchmark, there are quite a few places where the intrinsics are being used, which suggests that some improvement must have taken place, although it is unlikely to be significant in all but very few cases.</p><h1 id="future-work">Future Work</h1><p>There are still many opportunities for optimization in the middle-end, some of which are already known and being worked on at the time of writing this, others are yet to be discovered. I would also like to allow pointers and vectors of pointers to be valid operands for the intrinsics, although that would be quite a minor change. In the backend I would also like to work on better handling of intrinsics in GlobalISel, which is something that I didn’t have enough time for and other members of LLVM community had helped me with.</p><h1 id="acknowledgements">Acknowledgements</h1><p>None of this would have been possible without my two amazing mentors, Nikita Popov and Dhruv Chawla, and the LLVM community as a whole. Thank you for helping me on this journey and I am looking forward to working with you in the future.</p>
- GSoC 2024: ABI Lowering in ClangIRhttps://blog.llvm.org/posts/2024-09-07-abi-lowering-in-clangir/Mon, 30 Sep 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-09-07-abi-lowering-in-clangir/<p>ClangIR is an ongoing effort to build a high-level intermediate representation(IR) for C/C++ within the LLVM ecosystem. Its key advantage lies in its abilityto retain more source code information. While ClangIR is making progress, itstill lacks certain features, notably ABI handling. Currently, ClangIR lowersmost functions without accounting for ABI-specific calling convention details.</p><h2 id="goals">Goals</h2><p>The “Build & Run SingleSource Benchmarks with ClangIR - Part 2” Google Summer ofCode 2024 builds on my contributions from GSoC 2023 by addressing one of themain issues I encountered: target-specific lowering. It focuses on extendingClangIRâs code generation capabilities, particularly in ABI-lowering for X86-64.Several tests rely on operations and types (e.g., <code>va_arg</code> calls and complexdata types) that require target-specific information to compile correctly.</p><p>The concrete steps to achieve this were:</p><ol><li><strong>Implement foundational infrastructure</strong> that can scale to multiplearchitectures while adhering to ClangIR design principles such as CodeGenparity, feature guarding, and AST backreferences.</li><li><strong>Handle basic calling convention scenarios</strong> as a proof of concept tovalidate the foundational infrastructure.</li><li><strong>Add lowering for a second architecture</strong> to further validate theinfrastructure’s extensibility to multiple architectures.</li><li><strong>Unify target-specific ClangIR lowering into the library</strong>, as there are afew isolated methods handling target-specific code lowering like<code>cir.va_arg</code>.</li><li><strong>Integrate calling convention lowering into the main pipeline</strong> to ensurefuture contributions and continued development of this infrastructure.</li></ol><h2 id="contributions">Contributions</h2><p>The list of contribution (PRs) can be found<a href="https://github.com/llvm/clangir/pulls?q=is%3Apr+is%3Aclosed+author%3Asitio-couto+closed%3A%3E2024-05-01">here</a>.</p><h3 id="target-lowering-library">Target Lowering Library</h3><p>The most significant contribution of this project was the development of amodular <a href="https://github.com/llvm/clangir/pull/643"><code>TargetLowering</code> library</a>.This ensures that target-specific MLIR lowering passes can leverage this sharedlibrary for lowering logic. The library also follows ClangIR’s feature guardingprinciples, ensuring that any contributor can refer to the original CodeGen forcontributions, and any unimplemented feature is asserted at specific codepoints, making it easy to track missing functionality.</p><h3 id="calling-convention-lowering-pass">Calling Convention Lowering Pass</h3><p>As a proof of concept, the initial development of the <code>TargetLowering</code> libraryfocused on implementing a <a href="https://github.com/llvm/clangir/pull/642">calling convention loweringpass</a> that targets multiplearchitectures. Currently, ClangIR ignores the target ABI during CodeGen toretain high-level information. For example, structs are not unraveled to improveargument-passing efficiency. ABI-specific LLVM attributes are also ignored. Thispass addresses these issues by properly tagging LLVM attributes and rewritingfunction definitions and calls to handle unraveled structs. This was implementedfor both X86-64 and <a href="https://github.com/llvm/clangir/pull/679">AArch64</a>,demonstrating the library’s multi-architecture support.</p><h2 id="shortcomings">Shortcomings</h2><h3 id="target-specific-lowering-unification">Target-Specific Lowering Unification</h3><p>While some target-specific lowering code was moved into the library, it wascopied and pasted rather than properly integrated. This is not ideal forleveraging the libraryâs multi-architecture features.</p><h3 id="inclusion-in-the-main-pipeline">Inclusion in the Main Pipeline</h3><p>This is still a work in progress, as the library is not yet mature enough tohandle most pre-existing ClangIR tests. There are also feature guards withunreachable statements for many unimplemented features.</p><h2 id="future-work">Future Work</h2><p>Now that there is a base infrastructure for handling target-agnostic totarget-specific CIR code, there is a large amount of future work to be done,including:</p><ul><li>Improving DataLayout-related queries using MLIR’s built-in tools.</li><li>Implementing calling convention lowering for additional types, such aspointers.</li><li>Extending the TargetLowering library to support more architectures.</li><li>Unifying remaining target-specific lowering code from other parts of ClangIR.</li></ul><h2 id="acknowledgements">Acknowledgements</h2><p>I would like to thank my Google Summer of Code mentors, Bruno Cardoso Lopes andNathan Lanza, for another great GSoC experience. I also want to thank the LLVMcommunity and Google for organizing the program.</p>
- GSoC 2024: Statistical Analysis of LLVM-IR Compilationhttps://blog.llvm.org/posts/2024-08-29-gsoc-2024-statistical_analysis_of_llvm-ir_compilation/Mon, 23 Sep 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-08-29-gsoc-2024-statistical_analysis_of_llvm-ir_compilation/<p>Welcome! My name is Andrew and I contributed to LLVM through the 2024 Google Summer of Code Program. My project is called <a href="https://summerofcode.withgoogle.com/programs/2024/projects/hquDyVBK">Statistical Analysis of LLVM-IR Compilation</a>. The objective of this project is to provide an analysis of how time is spent in the optimization pipeline. Generally, drastic differences in the percentage of time spent by a pass in the pipeline is considered abnormal.</p><h1 id="background">Background</h1><p>In principle, an LLVM IR bitcode file, or module, contains IR features that determine the behavior of the compiler optimization pipeline. By varying these features, the optimization pipeline, opt, can add significantly to the compilation time or marginally. More specifically, optimizations succeed in less or more time; the user can wait for a microsecond or a few minutes. LLVM compiler developers constantly edit the pipeline, so the performance of these optimizations can vary by compiler version (sometimes significantly).</p><p>Having a large IR dataset such as <a href="https://huggingface.co/datasets/llvm-ml/ComPile">ComPile</a> allows for testing the LLVM compilation pipeline on a varied sample of IR. The size of this sample is sufficient to determine outlying IR modules. By identifying and examining such files using utilities which are being added to the <a href="https://github.com/llvm-ml/llvm-ir-dataset-utils">LLVM IR Dataset Utils Repo</a>, the causes of unexpected compilation times can be determined. Developers can then modify and improve the compilation pipeline accordingly.</p><h1 id="summary-of-work">Summary of Work</h1><p>The utilities added in <a href="https://github.com/llvm-ml/llvm-ir-dataset-utils/pull/37">PR37</a> are intended to write each IR module to a tar file corresponding to a programming language. Each file written to the tar files is indexed by its location in the HF dataset. This allows easy identification of files for tools which can be used for data extraction and analysis in the shell, notably clang. Tar file creation allows for potentially using less storage space then downloading the HF dataset to disk, and it allows code to be written which does not depend on the Python interpreter to load the dataset for access.</p><p>The Makefile from <a href="https://github.com/llvm-ml/llvm-ir-dataset-utils/pull/36">PR36</a> is responsible for carrying out the data collection. This data includes text segment size, user CPU instruction counts during compile time (analogous to time), IR feature counts sourced from the LLVM pass <code>print<func-properties></code>, and maximum relative time pass names and percentage counts. The data can be extracted in parallel or serially and is stored in a CSV file.</p><p>An important data collection command in the Makefile is <code>clang -w -c -ftime-report $(lang)/bc_files/[email protected] -o /dev/null</code>. The output from the command is large, but the part of interest is the first <code>Pass execution timing report</code>:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>===-------------------------------------------------------------------------===</span></span><span style="display:flex;"><span> Pass execution timing report</span></span><span style="display:flex;"><span>===-------------------------------------------------------------------------===</span></span><span style="display:flex;"><span> Total Execution Time: 2.2547 seconds (2.2552 wall clock)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> ---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---</span></span><span style="display:flex;"><span> 2.1722 ( 96.5%) 0.0019 ( 47.5%) 2.1741 ( 96.4%) 2.1745 ( 96.4%) VerifierPass</span></span><span style="display:flex;"><span> 0.0726 ( 3.2%) 0.0000 ( 0.0%) 0.0726 ( 3.2%) 0.0726 ( 3.2%) AlwaysInlinerPass</span></span><span style="display:flex;"><span> 0.0042 ( 0.2%) 0.0015 ( 39.2%) 0.0058 ( 0.3%) 0.0058 ( 0.3%) AnnotationRemarksPass</span></span><span style="display:flex;"><span> 0.0014 ( 0.1%) 0.0005 ( 13.3%) 0.0019 ( 0.1%) 0.0020 ( 0.1%) EntryExitInstrumenterPass</span></span><span style="display:flex;"><span> 0.0003 ( 0.0%) 0.0000 ( 0.0%) 0.0003 ( 0.0%) 0.0003 ( 0.0%) CoroConditionalWrapper</span></span><span style="display:flex;"><span> 2.2507 (100.0%) 0.0039 (100.0%) 2.2547 (100.0%) 2.2552 (100.0%) Total</span></span></code></pre></div><p>A user can visually see the distribution of these passes by using a profiling tool for .json files. The .json file for a given bitcode file is obtained by <code>clang -c -ftime-trace <file></code>.</p><p>The visualization of this output can be filtered to the passes of interest as in the following image:</p><figure><img src="https://blog.llvm.org/img/file4504_pass_trace.png" alt="ftime-trace of C IR Outlier"></figure><p>The CoroConditionalWrapper pass is accounted by the “Total CoroConditionalWrapper” block. Clearly, that pass takes a far smaller amount of time than the others, as accounted for by the pass execution timing report. However, instead of seeing the pass as an insignificant percentage of time, the visualization allows for additional comparisons of the relative timings of each pass. The example image has the optimization passes of interest selected, but the .json file provides information on the entire compilation pipeline as well. Thus, the entire pipeline execution flow can be visualized.</p><h1 id="current-status">Current Status</h1><p>Currently, there are three PRs that require approval to be merged. There has been ongoing discussion on their contents, so few steps should be left to merge them.In the current state, users of the utilities in <a href="https://github.com/llvm-ml/llvm-ir-dataset-utils/pull/38">PR38</a> should be able to readily reproduce the quantitative results I had obtained for my GSoC midterm presentation graphs. Users can easily perform outlier analysis as well on the IR files (excluding Julia IR). Some of the results include the following:</p><p>Scatter Plot of C IR Files:</p><figure><img src="https://blog.llvm.org/img/c_instvtext.png" alt="C IR Compiler Instruction Counts versus Text Segment Size"></figure><p>Table of outliers for C IR files:</p><figure><img src="https://blog.llvm.org/img/c_outliers.png" alt="C IR Outlier Files"></figure><h1 id="future-work">Future Work</h1><p>It was discussed in PR 37 to consolidate the tar file creation into the dataset file writer Python script. This is a feature I wish to implement in order to speed up the tar file creation process by having the bitcode files written from memory to the tar instead of from memory, to disk, to tar.</p><p>As mentioned, Julia IR was not analyzed. Modifying the scripts to include Julia IR results is desirable to make complete use of the dataset.Adding additional documentation for demonstration-of-use purposes could help clarify ways to use the tools.</p><p>Additionally, outlier analysis can be expanded upon by using more advanced outlier detection methods. Not all the data collected in the CSV files was used, so using those extra features–in particular the <code>print<func-properties></code> pass–can allow for improved accuracy in outlier detection.</p><h1 id="acknowledgements">Acknowledgements</h1><p>I would like to thank my mentors Johannes Doerfert and Aiden Grossman for their constant support during and prior to the GSoC program. Additionally, I would like to acknowledge the work of the LLVM Foundation admins and the GSoC admins.</p><h1 id="links">Links</h1><ul><li><p><a href="https://github.com/llvm-ml/llvm-ir-dataset-utils/pull/38">PR 38</a></p></li><li><p><a href="https://github.com/llvm-ml/llvm-ir-dataset-utils/pull/37">PR 37</a></p></li><li><p><a href="https://github.com/llvm-ml/llvm-ir-dataset-utils/pull/36">PR 36</a></p></li><li><p><a href="https://github.com/llvm-ml/llvm-ir-dataset-utils">LLVM IR Dataset Utils Repo</a></p></li><li><p><a href="https://huggingface.co/datasets/llvm-ml/ComPile">Compile Dataset</a></p></li></ul>
- GSoC 2024: Reviving NewGVNhttps://blog.llvm.org/posts/2024-09-01-reviving-newgvn/Mon, 16 Sep 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-09-01-reviving-newgvn/<p>This summer I participated in GSoC under the LLVM Compiler Infrastructure. The goal of the project was to improve the NewGVN pass so that it can replace GVN as the main value numbering pass in LLVM.</p><h1 id="background">Background</h1><p>Global Value Numbering (GVN) consists of assigning value numbers such that instructions with the same value number are equivalent. NewGVN was introduced in 2016 to replace GVN. We now highlight a few aspects in which NewGVN is better than GVN.</p><p>A key advantage of NewGVN over GVN is that it is complete for loops, while GVN is only complete for acyclical code. NewGVN is complete for loops because when it first processes loops, it assumes that only the first iteration will be executed, later corroborating these assumptionsâthis is known as the optimistic assumption. In practice, the optimistic assumption boils down to assuming that backedges are unreachable and, consequently, that when evaluating phi instructions, the values carried by them can be ignored. For instance, in the example below, <code>%a</code> is optimistically evaluated to <code>0</code>. This leads to evaluating <code>%c</code> to <code>%x</code>, which in turn leads to evaluating <code>%a.i</code> to <code>0</code>. At this point, there are two possibilities: either the assumption was correct and the loop actually only executes once, and the value numbers computed so far are correct, or the instructions in the loop need to be reevaluated. Assume, for this example, that NewGVN could not prove that only one iteration is executed. Then <code>%a</code> once again evaluates to <code>0</code>, and all other registers also evaluate to the same. Thanks to the optimistic assumption, we were able to discover that <code>%a</code> is loop-invariant and, moreover, that it is equal to <code>0</code>.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#66d9ef">define</span> <span style="color:#66d9ef">i32</span> @optimistic(<span style="color:#66d9ef">i32</span> %x, <span style="color:#66d9ef">i32</span> %y){</span></span><span style="display:flex;"><span>entry:</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">br</span> <span style="color:#66d9ef">label</span> %loop</span></span><span style="display:flex;"><span>loop:</span></span><span style="display:flex;"><span> %a = <span style="color:#66d9ef">phi</span> <span style="color:#66d9ef">i32</span> [<span style="color:#ae81ff">0</span>, %entry], [%a.i, %loop]</span></span><span style="display:flex;"><span> ...</span></span><span style="display:flex;"><span> %c = <span style="color:#66d9ef">xor</span> <span style="color:#66d9ef">i32</span> %x, %a</span></span><span style="display:flex;"><span> %a.i = <span style="color:#66d9ef">sub</span> <span style="color:#66d9ef">i32</span> %x, %c</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">br</span> <span style="color:#66d9ef">i1</span> ..., <span style="color:#66d9ef">label</span> %loop,<span style="color:#66d9ef">label</span> %exit</span></span><span style="display:flex;"><span>exit:</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">ret</span> <span style="color:#66d9ef">i32</span> %a</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>On the other hand, GVN fails to detect this equivalence because it would pessimistically evaluate <code>%a</code> to itself, and the previously described evaluation steps would never take place.</p><p>Another advantage of NewGVN is the value numbering of memory operations using <a href="https://releases.llvm.org/14.0.0/docs/MemorySSA.html">MemorySSA</a>. It provides a functional view of memory where instructions that can modify memory produce a new memory version, which is then used by other memory operations. This greatly simplifies the detection of redundancies among memory operations. For example, two loads of the same type from equivalent pointers and memory versions are trivially equivalent.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#66d9ef">define</span> <span style="color:#66d9ef">i32</span> @foo(<span style="color:#66d9ef">i32</span> %v, <span style="color:#960050;background-color:#1e0010">ptr</span> %p) {</span></span><span style="display:flex;"><span>entry:</span></span><span style="display:flex;"><span><span style="color:#75715e">; 1 = MemoryDef(liveOnEntry)</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">store</span> <span style="color:#66d9ef">i32</span> %v, <span style="color:#960050;background-color:#1e0010">ptr</span> %p, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span><span style="color:#75715e">; MemoryUse(1)</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> %a = <span style="color:#66d9ef">load</span> <span style="color:#66d9ef">i32</span>, <span style="color:#960050;background-color:#1e0010">ptr</span> %p, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span><span style="color:#75715e">; MemoryUse(1)</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> %b = <span style="color:#66d9ef">load</span> <span style="color:#66d9ef">i32</span>, <span style="color:#960050;background-color:#1e0010">ptr</span> %p, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span><span style="color:#75715e">; 2 = MemoryDef(1)</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">call</span> <span style="color:#66d9ef">void</span> @f(<span style="color:#66d9ef">i32</span> %a)</span></span><span style="display:flex;"><span><span style="color:#75715e">; MemoryUse(2)</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> %c = <span style="color:#66d9ef">load</span> <span style="color:#66d9ef">i32</span>, <span style="color:#960050;background-color:#1e0010">ptr</span> %p, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> %d = <span style="color:#66d9ef">sub</span> <span style="color:#66d9ef">i32</span> %b, %c</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">ret</span> <span style="color:#66d9ef">i32</span> %d</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>In the example above (annotated with MemorySSA), <code>%a</code> and <code>%b</code> are equivalent, while <code>%c</code> is not. All three loads are of the same type from the same pointer, but they don’t all load from the same memory state. Loads <code>%a</code> and <code>%b</code> load from the memory defined by the store (Memory <code>1</code>), while <code>%c</code> loads from the memory defined by the function call (Memory <code>2</code>). GVN can also detect these redundancies, but it relies on the more expensive and less general MemoryDependenceAnalysis.</p><p>Despite these and other improvements NewGVN is still not widely used, mainly because it lacks partial redundancy elimination (PRE) and because it is bug-ridden.</p><h1 id="implementing-pre">Implementing PRE</h1><p>Our main contribution was the development of a PRE stage for NewGVN (<a href="https://github.com/ManuelJBrito/llvm-project/tree/Benchmarks">found here</a>). Our solution relied on generalizing Phi-of-Ops. It performs a special case of PRE where the instruction depends on a phi instruction, and an equivalent value is available on every reaching path. This is achieved in two steps: phi-translation and phi-insertion.</p><p>Phi-translation consists of evaluating the original instruction in the context of each of its block’s predecessors. Phi operands are replaced by the value incoming from the predecessor. The value is available in the predecessor if the translated instruction is equivalent to a constant, function argument, or another instruction that dominates the predecessor.</p><p>Phi-insertion occurs after phi-translation if the value is available in every predecessor. At that point, a phi of the equivalent values is constructed and used to replace the original instruction. The full process is illustrated in the following example.</p><div style="margin:0 auto;"> <img src="https://blog.llvm.org/img/reviving-newgvn-phiofops.png"><br/></div><p>Our generalization eliminated the need for a dependent phi and introduced the ability to insert the missing values in cases where the instruction is partially redundant. To prevent increases in code size (ignoring the inserted phi instructions), the insertion is only made if itâs the only one required. The full process is illustrated in the following example.</p><div style="margin:0 auto;"> <img src="https://blog.llvm.org/img/reviving-newgvn-pre.png"><br/></div><p>Integrating PRE into the existing framework also allowed us to gain loop-invariant code motion (LICM) for free. The optimistic assumption, combined with PRE, allows NewGVN to speculatively hoist instructions out of loops. On the other hand, LICM in GVN relies on using LoopInfo and can only handle very specific cases.</p><h1 id="missing-features">Missing Features</h1><p>The two main features our PRE implementation lacks are critical edge splitting and load coercion. Critical edge splitting is required to ensure that we do not insert instructions into paths where they won’t be used. Currently, our implementation simply bails in such cases. Load coercion allows us to detect equivalences of loaded values with different types, such as loads of <code>i32</code> and <code>float</code>, and then coerce the loaded type using conversion operations.</p><p>The difficulty in implementing these features is that NewGVN is designed to perform analysis and transformation in separate steps, while these features involve modifying the function during the analysis phase.</p><h1 id="results">Results</h1><p>We evaluated our implementation using the automated benchmarking tool <a href="https://www.phoronix-test-suite.com/">Phoronix Test Suite</a> from which we selected a set of 20 C/C++ applications (listed below).</p><table><thead><tr><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td>aircrack-ng</td><td>encode-flac</td><td>luajit</td><td>scimark2</td></tr><tr><td>botan</td><td>espeak</td><td>mafft</td><td>simdjson</td></tr><tr><td>zstd</td><td>fftw</td><td>ngspice</td><td>sqlite-speedtest</td></tr><tr><td>crafty</td><td>john-the-ripper</td><td>quantlib</td><td>tjbench</td></tr><tr><td>draco</td><td>jpegxl</td><td>rnnoise</td><td>graphics-magick</td></tr></tbody></table><p>The default <code>-O2</code> pipeline was used. The only change betweeen compilations was the value numbering pass used.</p><p>Despite the missing features, we observed that our implementation, on average, performs 0.4% better than GVN. However, it is important to mention that our solution hasn’t been fine-tuned to consider the rest of the optimization pipeline, which resulted in some cases where our implementation regressed compared to both GVN and the existing NewGVN. The most severe case was with jpegxl, where our implementation, on average, performed 10% worse than GVN. It’s important to note that this was an outlier; excluding jpegxl, most regressions were at most 2%. Unfortunately, due to time constraints, we were unable to study these cases in more detail.</p><h1 id="future-work">Future Work</h1><p>In the future, we plan to implement the aforementioned missing features and fine-tune the heuristics for when to perform PRE to prevent the regressions discussed in the results section. Once these issues are addressed, we’ll upstream our implementation, bringing us a step closer to reviving NewGVN.</p>
- GSoC 2024: Compile GPU kernels using ClangIRhttps://blog.llvm.org/posts/2024-08-29-gsoc-opencl-c-support-for-clangir/Mon, 09 Sep 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-08-29-gsoc-opencl-c-support-for-clangir/<p>Hello everyone! I’m 7mile. My GSoC project this summer is <a href="https://discourse.llvm.org/t/clangir-compile-gpu-kernels-using-clangir/76984">Compile GPU kernels using ClangIR</a>. It’s been an exciting journey in compiler development, and I’m thrilled to share the progress and insights gained along the way here.</p><h1 id="background">Background</h1><p><a href="https://github.com/llvm/clangir">The ClangIR project</a> aims to establish a new IR for Clang, built on top of MLIR. As part of the ongoing effort to support heterogeneous programming models, this project focuses on integrating OpenCL C language support into ClangIR. The ultimate goal is to enable the compilation of GPU kernels written in OpenCL C into LLVM IR targeting the SPIR-V architecture, laying the groundwork for future enhancements in SYCL and CUDA support.</p><h1 id="what-we-did">What We Did</h1><p>Our work involved several key areas:</p><ol><li><p><strong>Address Space Support</strong>: One of the fundamental tasks was teaching ClangIR to handle address spaces, a vital feature for languages like OpenCL. Initially, we considered mimicking LLVM’s approach, but this proved inadequate for ClangIR’s goals. After thorough discussion and an <a href="https://discourse.llvm.org/t/rfc-clangir-unified-address-space-design-in-clangir/79728">RFC</a>, we implemented a unified address space design that aligns with ClangIR’s objectives, ensuring a clean and maintainable code structure.</p></li><li><p><strong>OpenCL Language and SPIR-V Target Integration</strong>: We extended ClangIR to support the OpenCL language and the SPIR-V target. This involved enhancing the pipeline to accommodate the latest OpenCL 3.0 specification and implementing hooks for language-specific and target-specific customizations.</p></li><li><p><strong>Vector Type Support</strong>: OpenCL vector types, a critical feature for GPU programming, were integrated into ClangIR. We leveraged ClangIR’s existing cir.vector type to generate the necessary code, ensuring consistent compilation results.</p></li><li><p><strong>Kernel and Module Metadata Emission</strong>: We added support for emitting OpenCL kernel and module metadata in ClangIR, a necessary step for proper integration with the SPIR-V target. This included the creation of structured attributes to represent metadata, following MLIR’s preferences for well-defined structures.</p></li><li><p><strong>Global and Static Variables with Qualifiers</strong>: We implemented support for global and static variables with qualifiers like <code>global</code>, <code>constant</code>, and <code>local</code>, ensuring that these constructs are correctly represented and lowered in the ClangIR pipeline.</p></li><li><p><strong>Calling Conventions</strong>: We adjusted the calling conventions in ClangIR to align with SPIR-V requirements, migrating from the default <code>cdecl</code> to SPIR-V-specific conventions like <code>SpirKernel</code> and <code>SpirFunction</code>. This also enables most OpenCL built-in functions like <code>barrier</code> and <code>get_global_id</code>.</p></li><li><p><strong>User Experience Enhancements</strong>: Finally, we ensured that the end-to-end kernel compilation experience using ClangIR was smooth and intuitive, with minimal manual intervention required.</p></li></ol><h1 id="results">Results</h1><p>The project successfully met its primary goals. OpenCL kernels from the Polybench-GPU benchmark suite can now be compiled using ClangIR into LLVM IR for SPIR-V. All patches have been merged into the main ClangIR repository, and the projectâs progress has been well-documented in the <a href="https://github.com/llvm/clangir/issues/689">overview issue</a>. I believe the work not only advanced OpenCL support but also laid a solid foundation for future enhancements, such as SYCL and CUDA support in ClangIR.</p><p>We have successfully compiled and executed all 20 OpenCL C benchmarks from the <a href="https://github.com/sgrauerg/polybenchGpu">polybenchGpu</a> repository, passing the built-in result validation. Please refer to our <a href="https://github.com/seven-mile/clangir-ocl-ae">artifact evaluation repository</a> for detailed instructions on how to experiment with our work.</p><h1 id="future-works">Future Works</h1><p>As we look forward, there are two key areas that require further development:</p><ol><li><p><strong>Function Attribute Consistency</strong>: For example, the <code>convergent</code> function attribute is crucial for preventing misoptimizations in SIMT languages like OpenCL. ClangIR currently lacks this attribute, which could lead to issues in parallel computing contexts. Addressing this is a priority to ensure correct optimization behavior.</p></li><li><p><strong>Support for OpenCL Built-in Types</strong>: Another critical area for future work is the support for OpenCL built-in types, such as <code>pipe</code> and <code>image</code>. These types are essential for handling data streams and image processing tasks in various specialized OpenCL applications. Supporting these types will significantly enhance ClangIR’s adherence to the OpenCL standard, broadening its applicability and ensuring better compatibility with a wide range of OpenCL programs.</p></li></ol><h1 id="acknowledgements">Acknowledgements</h1><p>This project would not have been possible without the guidance and support of the LLVM community. I extend my deepest gratitude to my mentors, Julian Oppermann, Victor Lomüller, and Bruno Cardoso Lopes, whose expertise and encouragement were instrumental throughout this journey. Additionally, I would like to thank Vinicius Couto Espindola for his collaboration on ABI-related work. This experience has been immensely rewarding, both technically and in terms of community engagement.</p><h1 id="appendix">Appendix</h1><ul><li><a href="https://github.com/llvm/clangir/issues/689">Overview issue of OpenCL C support</a></li><li><a href="https://github.com/seven-mile/clangir-ocl-ae">Artifact Evaluation Instructions</a></li></ul>
- GSoC 2024: Half-precision in LLVM libchttps://blog.llvm.org/posts/2024-08-31-half-precision-in-llvm-libc/Sat, 31 Aug 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-08-31-half-precision-in-llvm-libc/<p>C23 defines new floating-point types, such as <code>_Float16</code>, which corresponds tothe binary16 format from IEEE Std 754, also known as “half-precision,” or FP16.C23 also defines new variants of the C standard library’s math functionsaccordingly, such as <code>fabsf16</code> to get the absolute value of a <code>_Float16</code>.</p><p>The “Half-precision in LLVM libc” Google Summer of Code 2024 project aimed toimplement these new <code>_Float16</code> math functions in LLVM libc, making it the firstknown C standard library implementation to implement these C23 functions.</p><p>We split math functions into two categories: basic operations and higher mathfunctions. The current implementation status of math functions in LLVM libc canbe viewed at <a href="https://libc.llvm.org/math/index.html#implementation-status">https://libc.llvm.org/math/index.html#implementation-status</a>.</p><p>The exact goals of this project were to:</p><ol><li>Setup generated headers properly so that the <code>_Float16</code> type and <code>_Float16</code>functions can be used with various compilers and architectures.</li><li>Add generic implementations of <code>_Float16</code> basic operations for supportedarchitectures.</li><li>Add optimized implementations of <code>_Float16</code> basic operations for specificarchitectures using special hardware instructions and compiler builtinswhenever possible.</li><li>Add generic implementations of as many <code>_Float16</code> higher math functions aspossible. We knew we would not have enough time to implement all of them.</li></ol><h2 id="work-done">Work done</h2><ol><li>The <code>_Float16</code> type can now be used in generated headers, and declarations of<code>_Float16</code> math functions are generated with <code>#ifdef</code> guards to enable themwhen they are supported.<ul><li><a href="https://github.com/llvm/llvm-project/pull/93567">https://github.com/llvm/llvm-project/pull/93567</a></li></ul></li><li>All 70 planned <code>_Float16</code> basic operations have been merged.<ul><li><a href="https://github.com/llvm/llvm-project/issues/93566">https://github.com/llvm/llvm-project/issues/93566</a></li></ul></li><li>The <code>_Float16</code>, <code>float</code> and <code>double</code> variants of various basic operationshave been optimized on certain architectures.<ul><li><a href="https://github.com/llvm/llvm-project/pull/98376">https://github.com/llvm/llvm-project/pull/98376</a></li><li><a href="https://github.com/llvm/llvm-project/pull/99037">https://github.com/llvm/llvm-project/pull/99037</a></li><li><a href="https://github.com/llvm/llvm-project/pull/100002">https://github.com/llvm/llvm-project/pull/100002</a></li></ul></li><li>Out of the 54 planned <code>_Float16</code> higher math functions, 8 have been mergedand 9 have an open pull request.<ul><li><a href="https://github.com/llvm/llvm-project/issues/95250">https://github.com/llvm/llvm-project/issues/95250</a></li></ul></li></ol><p>We ran into unexpected issues, such as:</p><ul><li>Bugs in Clang 11, which is currently still supported by LLVM libc and used inpost-commit CI.</li><li>Some post-commit CI workers having old versions of compiler runtimes that aremissing some floating-point conversion functions on certain architectures.</li><li>Inconsistent behavior of floating-point conversion functions across compilerruntime vendors (GCC’s libgcc and LLVM’s compiler-rt) and CPU architectures.</li></ul><p>Due to these issues, LLVM libc currently only enables all <code>_Float16</code> functionson x86-64 Linux. Some were disabled on AArch64 due to Clang 11 bugs, and allwere disabled on 32-bit Arm and on RISC-V due to issues with compiler runtimes.Some are not available on GPUs because they take <code>_Float128</code> arguments, and the<code>_Float128</code> type is not available on GPUs.</p><p>There is work in progress to work around issues with compiler runtimes by usingour own floating-point conversion functions.</p><h2 id="work-left-to-do">Work left to do</h2><ul><li>Implement the remaining <code>_Float16</code> higher math functions.</li><li>Enable the <code>_Float16</code> math functions that are disabled on AArch64 once LLVMlibc bumps its minimum supported Clang version.</li><li>Enable <code>_Float16</code> math functions on 32-bit Arm and on RISC-V once issues withcompiler runtimes are resolved.</li></ul><h2 id="acknowledgements">Acknowledgements</h2><p>I would like to thank my Google Summer of Code mentors, Tue Ly and Joseph Huber,as well as other LLVM maintainers I interacted with, for their help. I wouldalso like to thank Google for organizing this program.</p>
- GSoC 2024: GPU Libc Benchmarkinghttps://blog.llvm.org/posts/2024-08-09-libc-gpu-benchmarking/Fri, 09 Aug 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-08-09-libc-gpu-benchmarking/<p>Hey everyone! My name is James and I worked on LLVM this summer through GSoC. My project is called <a href="https://summerofcode.withgoogle.com/programs/2024/projects/HkRoz49I">GPU Libc Benchmarking</a>. The main objective of this project was to develop microbenchmarking infrastructure for libc on the GPU.</p><h1 id="background">Background</h1><p>The LLVM libc project was designed as an alternative to glibc that aims to be modular, configurable, and sanitizer-friendly. Currently, LLVM libc is being ported to Nvidia and AMD GPUs to give libc functionality (e.g. printf(), malloc(), and math functions) on the GPU. As of March 2024, programs can use GPU libc in offloading languages (CUDA, OpenMP) or through direct compilation and linking with the libc library.</p><h1 id="what-we-did">What We Did</h1><p>During this project, we developed a microbenchmarking framework that is directly compiled for and run on the GPU, using libc functions to display output to the user. As this was a short project (90 hours), we mostly focused on developing the infrastructure and writing a few example usages (isalnum(), isalpha(), and sin()).</p><p>Our benchmarking infrastructure is based on Google Benchmark and measures the average cycles, minimum, maximum, and standard deviation of each benchmark. Each benchmark is run for multiple iterations to stabilize the results. Benchmark writers can measure against vendor implementations of libc functions by passing specific linking flags to the benchmarkâs CMake portion and registering the corresponding vendor function from the benchmark itself.</p><p>Below is an example of our benchmarking infrastructure’s output for <code>sinf()</code></p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>Benchmark <span style="color:#f92672">|</span> Cycles <span style="color:#f92672">|</span> Min <span style="color:#f92672">|</span> Max <span style="color:#f92672">|</span> Iterations <span style="color:#f92672">|</span> Time <span style="color:#f92672">/</span> Iteration <span style="color:#f92672">|</span> Stddev <span style="color:#f92672">|</span> Threads <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span><span style="color:#f92672">----------------------------------------------------------------------------------------------------------</span></span></span><span style="display:flex;"><span>Sinf_1 <span style="color:#f92672">|</span> <span style="color:#ae81ff">764</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">369</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">2101</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">273</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">323</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>Sinf_128 <span style="color:#f92672">|</span> <span style="color:#ae81ff">721</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">699</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">744</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">913</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">16</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>Sinf_1024 <span style="color:#f92672">|</span> <span style="color:#ae81ff">661</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">650</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">689</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">9</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">31</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>Sinf_4096 <span style="color:#f92672">|</span> <span style="color:#ae81ff">666</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">663</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">669</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">28</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">28</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPi_1 <span style="color:#f92672">|</span> <span style="color:#ae81ff">372</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">369</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">632</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">70</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">39</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPi_128 <span style="color:#f92672">|</span> <span style="color:#ae81ff">379</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">379</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">379</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">4</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">895</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPi_1024 <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">338</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">20</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPi_4096 <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">4</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">28</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPow30_1 <span style="color:#f92672">|</span> <span style="color:#ae81ff">371</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">369</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">510</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">70</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">17</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPow30_128 <span style="color:#f92672">|</span> <span style="color:#ae81ff">379</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">379</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">379</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">4</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">894</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPow30_1024 <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">338</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">20</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfTwoPow30_4096 <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">335</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">4</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">28</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfVeryLarge_1 <span style="color:#f92672">|</span> <span style="color:#ae81ff">477</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">369</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">632</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">70</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">58</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfVeryLarge_128 <span style="color:#f92672">|</span> <span style="color:#ae81ff">487</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">480</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">493</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">900</span> us <span style="color:#f92672">|</span> <span style="color:#ae81ff">14</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfVeryLarge_1024 <span style="color:#f92672">|</span> <span style="color:#ae81ff">442</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">440</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">447</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">7</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">18</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span><span style="display:flex;"><span>SinfVeryLarge_4096 <span style="color:#f92672">|</span> <span style="color:#ae81ff">441</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">441</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">442</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">4</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">28</span> ms <span style="color:#f92672">|</span> <span style="color:#ae81ff">14</span> <span style="color:#f92672">|</span> <span style="color:#ae81ff">32</span> <span style="color:#f92672">|</span></span></span></code></pre></div><p>Users can register benchmarks similar to Google Benchmark, using a macro:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#66d9ef">uint64_t</span> <span style="color:#a6e22e">BM_IsAlnumCapital</span>() {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">char</span> x <span style="color:#f92672">=</span> <span style="color:#e6db74">'A'</span>;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> LIBC_NAMESPACE<span style="color:#f92672">::</span><span style="color:#a6e22e">latency</span>(LIBC_NAMESPACE<span style="color:#f92672">::</span>isalnum, x);</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span><span style="color:#a6e22e">BENCHMARK</span>(LlvmLibcIsAlNumGpuBenchmark, IsAlnumCapital, BM_IsAlnumCapital);</span></span></code></pre></div><h1 id="results">Results</h1><p>This project met its major goal of creating microbenchmarking infrastructure for the GPU. However, the original scope of this proposal included a CPU component that would use vendor tools to measure GPU kernel properties. However, this was removed after discussion with the mentors due to technical obstacles in offloading specific kernels to the GPU that would require major changes to other parts of the code.</p><h1 id="future-work">Future Work</h1><p>As this was a short project (90 hours), we only focused on implementing the microbenchmarking infrastructure. Future contributors can use the benchmarking infrastructure to add additional benchmarks. In addition, there are improvements to microbenchmarking infrastructure that could be added, such as more options for user input ranges, better random distributions for math functions, and a CPU element that can launch multiple kernels and compare results against functions running on the CPU.</p><p>The existing code can be found in the <a href="https://github.com/llvm/llvm-project/tree/main/libc/benchmarks/gpu">LLVM repo</a>.</p><h1 id="acknowledgements">Acknowledgements</h1><p>This project would not have been possible without my amazing mentor, Joseph Huber, the LLVM Foundation admins, and the GSoC admins.</p><h1 id="links">Links</h1><p><a href="https://github.com/llvm/llvm-project/commits?author=jameshu15869">Landed PRs</a></p><p><a href="https://github.com/llvm/llvm-project">LLVM GitHub</a></p><p><a href="https://llvm.org/">LLVM Homepage</a></p><p><a href="https://summerofcode.withgoogle.com/programs/2024/projects/HkRoz49I">GSoC Project Page</a></p>
- LLVM Google Summer of Code 2024 & 2023https://blog.llvm.org/posts/2024-02-26-gsoc/Thu, 14 Mar 2024 00:00:00 +0000https://blog.llvm.org/posts/2024-02-26-gsoc/<p>The LLVM organization was accepted to participate in Google Summer of Code in 2024. Soon, prospective participants will begin submitting their project proposals, and mentors will review them to select those who will spend a significant amount of time this year contributing to various parts of LLVM.</p><p>But first, let’s look back and see what we had in 2023. The Google Summer of Code 2023 was very successful for the LLVM project. Overall, we received 54 proposals for 24 open projects. Out of this set of proposals, 20 projects were successfully completed and covered many different aspects of LLVM and its subprojects.</p><ul><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/lAxUTgOM">ExtractAPI while building</a> by Ankur Saini, mentored by Daniel Grumberg</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/X0cFgJkY">WebAssembly Support for clang-repl</a> by Anubhab Ghosh, mentored by Vassil Vassilev and Alexander Penev</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/XvbLGMbT">Modules Build Daemon: Build System Agnostic Support for Explicitly Built Modules</a> by Connor Sughrue, mentored by Jan Svoboda, Michael Spencer</li><li>[Interactive MLIR query tool to make exploring the IR easier] (<a href="https://summerofcode.withgoogle.com/archive/2023/projects/bdePp9VD">https://summerofcode.withgoogle.com/archive/2023/projects/bdePp9VD</a>) by Devajith Valaparambil Sreeramaswamy, mentored by Jacques Pienaar</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/JdqGUwNq">Improving Compile Times</a> by Dhruv Chawla, mentored by Nikita Popov</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/uBg3dUrw">Adding C++ Support to Clang’s ExtractAPI</a> by Erick Velez, mentored by Daniel Grumberg</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/AtKA6GoV">Optimizing MLIRâs Presburger library</a> by gilsaia, mentored by Kunwar Grover</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/sc4OauXM">Adapting IR Load Semantics to Freeze All or Freeze Only Uninitialized Data</a> by John McIver, mentored by Nuno Lopes</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/a16FfPnb">Addressing Rust optimization failures in LLVM</a> by Kohei Asano, mentored by Nikita Popov</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/qxuEqL8W">Tutorial development with clang-repl</a> by Krishna Narayanan, mentored by Vassil Vassilev</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/oQUfcx89">Fix Handling of Undefined Behavior in NewGVN</a> by Manuel Brito, mentored by Nuno Lopes</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/JToY28Mf">Map LLVM values to corresponding source-level expressions</a> by phyBrackets, mentored by Satish Guggilla and Karthik Senthil</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/T8rB84Sr">Machine Learning Guided Ordering of Compiler Optimization Passes</a> by Puneeth A R, mentored by Tarindu Jayatilaka, Johannes Doerfert, and Mircea Trofin</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/TMnF4MqC">Patch based test coverage for quick test feedback</a> by ShivamGupta123, mentored by Henrik Olsson</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/4vqXC8Ez">Re-optimization using JITLink</a> by Sunho Kim, mentored by Vassil Vassilev, Stefan Gränitz, and Lang Hames</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/wxRFR261">Improvements in Clang Diagnostics</a> by Takuya Shimizu, mentored by Timm Bäder</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/Yofn8VfG">Build & Run SingleSource Benchmarks with ClangIR</a> by Vinicius Espindola, mentored by Bruno Cardoso Lopes and Nathan Lanza</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/wiTzRdnV">Better Performance Models for MLGO Training</a> by Viraj Shah, mentored by Mircea Trofin, Aiden Grossman, and Ondrej Sykora</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/ghJRTsUJ">Enhancing llvm-cov to Generate Hierarchical Coverage Reports</a> by Yuhao Gu, mentored by Petr Hosek and Gulfem Savrun Yeniceri</li><li><a href="https://summerofcode.withgoogle.com/archive/2023/projects/Gxg82Pvd">Autocompletion in Clang-REPL</a> by Yuquan Fu, mentored by Vassil Vassilev</li></ul><p>Some projects also provided detailed end-of-project reports or project diaries that are outstanding on their own:</p><ul><li><a href="https://blog.llvm.org/posts/2023-10-5-tutorial-development-with-clang-repl/">Tutorial Development with Clang-Repl</a></li><li><a href="ttps://blog.llvm.org/posts/2023-09-19-diagnostic-improvements-in-clang-17/">Diagnostic Improvements in Clang 17</a></li><li><a href="https://dc03.github.io/">Improving Compile Times</a></li><li><a href="https://khei4.github.io/gsoc2023/">Addressing Rust optimization failures in LLVM</a></li><li><a href="https://blog.llvm.org/posts/2023-09-19-gsoc-2023-blog-post/">Map LLVM Values to corresponding source level expression</a></li><li><a href="https://blog.llvm.org/posts/2023-12-31-compiler-research-internships-2023/">Another step forward towards interactive programming</a> - covers <em>Autocompletion in Clang-REPL</em>, <em>WebAssembly Support for Clang-Repl</em>, <em>Re-optimization using JITLink</em> and <em>Tutorial development with clang-repl</em> projects.</li></ul><h2 id="gsoc-2024">GSoC 2024</h2><p>With a successful end to 2023, the LLVM Project is excited to participate in GSOC 2024. If you are interested in participating, here are some guidelines:</p><h3 id="1-project-ideas">1. Project ideas</h3><p>Please take a look on list of projects at <a href="https://llvm.org/OpenProjects.html#gsoc24">Open Projects</a> page. Projects also have topics below on <a href="https://discourse.llvm.org/tag/gsoc2024">LLVM Discourse</a> having #gsoc24 tag, so you can ask mentors about details of the project, skills required, etc.</p><h3 id="2-way-to-submitting-a-proposal">2. Way to submitting a proposal</h3><p>We encourage you to discuss your proposal before submitting to GSoC system. Having your proposal discussed ensures that your proposal will be well aligned with the project. Please do not hijack other threads (e.g. with mentor Q&A) and create a separate new thread to discuss your proposal. The ideal proposal will contain:</p><ul><li>A descriptive title</li><li>Information about you, including contact information. Please do not forget to include:<ul><li>Your prior compiler and compiler-related experience, if any (e.g. studies at the University, prior contributions)</li><li>Whether you have any prior contributions to LLVM. If yes, please provide links to these contributions.</li><li>Your past open source participation and contributions, if any</li><li>Your knowledge of programming languages (e.g. C, C++, Python, Rust, etc.) and your estimate of your level of experience</li></ul></li><li>Information about your proposed project. This should be fairly detailed and include a timeline.</li><li>Information about other commitments that might affect your ability to work during the GSoC period (exams, classes, holidays, other jobs, weddings, etc.). Also, if the project allows both medium- and large-size participation, indicate the intended size of the project and the timeframe of your participation.</li></ul><h3 id="3-useful-links">3. Useful links</h3><p><a href="https://llvm.org/docs/Contributing.html">LLVM Contribution Guidelines</a><a href="https://llvm.org/docs/DeveloperPolicy.html">LLVM Developer Policy</a><a href="https://discord.gg/ezbevd7tJC">GSoC channel on LLVM Discord</a><a href="https://llvm.org/docs/GettingInvolved.html">Other documents</a><a href="https://llvm.org/docs/CodeOfConduct.html">LLVM Community Code of Conduct</a><a href="https://google.github.io/gsocguides/student/">GSoC Contributor Guide</a><a href="https://developers.google.com/open-source/gsoc/help/%5Bstudent-advice">Advice for People Applying for GSoC</a><a href="https://summerofcode.withgoogle.com/">GSoC Program Website</a><a href="https://llvm.org/docs/GettingInvolved.html#office-hours">LLVM Office Hours</a></p><h3 id="4-deadlines">4. Deadlines</h3><ul><li>Submission to GSoC system opens on March 18th at 18:00 UTC.</li><li>Submission to GSoC system ends on April 2nd at 18:00 UTC.</li><li>Results to be announced on May 1st at 18:00 UTC.</li></ul><p>Welcome to the 20th Google Summer of Code!</p>
- Another step forward towards interactive programminghttps://blog.llvm.org/posts/2023-12-31-compiler-research-internships-2023/Sun, 31 Dec 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-12-31-compiler-research-internships-2023/<p>The <a href="https://compiler-research.org">Compiler Research</a> team is pleased to announce the successful completionof another round of internships focused on enhancements in interactiveprogramming, specifically in relation to the <a href="https://clang.llvm.org/docs/ClangRepl.html">Clang-REPL</a> component in LLVM.</p><p>The Compiler Research team includes researchers located at Princeton Universityand CERN. Our primary goal is best described as follows:</p><blockquote><p>To establish a proficient workflow in LLVM, where <a href="https://compiler-research.org/interactive_cpp">interactive development</a> inC++ is possible, and exploratory C++ becomes an accessible experience to awider audience.</p></blockquote><p>Following are some notable contributions by our interns this year.</p><h2 id="yuquan-fu---autocompletion-in-clang-repl">Yuquan Fu - Autocompletion in Clang-REPL</h2><p>Clang-Repl allows developers to program in C++ interactively with a REPLenvironment. However, it was missing the ability to suggest code completion orauto-complete options for user input, which can be time-consuming and prone totyping errors.</p><p>With this code completion system, users can either complete their input quicklyor see a list of valid completion candidates. The code completion is alsocontext-aware, providing semantically relevant results based on the currentposition and input on the current line.</p><p>Mentors: Vassil Vassilev (<a href="https://www.princeton.edu/">Princeton.edu</a>) & David Lange (<a href="https://www.princeton.edu/">Princeton.edu</a>)</p><p>Project Details: <a href="https://www.syntaxforge.net/clang-repl-cc/">Autocompletion in Clang-REPL</a></p><p>Funding: Google Summer of Code 2023</p><h3 id="example--avoiding-tedious-typing">Example â avoiding tedious typing</h3><pre tabindex="0"><code>clang-repl> struct WhateverMeaningfulLoooooooooongName{ int field;};clang-repl> Wh<tab></code></pre><p>With code completion, hitting tab completes the entity name:</p><pre tabindex="0"><code>clang-repl> WhateverMeaningfulLoooooooooongName</code></pre><blockquote><p>For implementation details, please see the respective <a href="https://compiler-research.org/assets/presentations/CaaS_Weekly_30_08_2023_Fred-Code_Completion_in_ClangRepl_GSoC.pdf">slides</a> and the<a href="https://compiler-research.org/blogs/gsoc23_ffu_experience_blog/">blog</a>.</p></blockquote><h2 id="anubhab-ghosh---webassembly-support-for-clang-repl">Anubhab Ghosh - WebAssembly Support for Clang-Repl</h2><p>The Xeus Framework enables accessing Clang-REPL (an interpreter that JITcompiles C++ code into native code) in a web browser, using Jupyter. However,this shifts the computational load to the server.</p><p>A more scalable approach is to use WebAssembly. It allows sandboxed executionof native (e.g. C/C++/Rust) programs compiled to an intermediate bytecode atcloser to native speeds. The idea is to run clang-repl within WebAssembly andgenerate JIT-compiled WebAssembly code and execute it on the client side.</p><p>However, this comes with some challenges (e.g., code in WebAssembly isimmutable, which is unacceptable for JIT).</p><p>Solution: To address the code immutability issue, a new WebAssembly module iscreated at each iteration of the REPL loop. Initially, a precompiled modulecontaining the Standard C/C++ libraries, LLVM, Clang, and wasm-ld is sent tothe browser, which runs the interpreter and compiles the user code.</p><p>Since we cannot call Interpreter::Execute() to execute the module (due toJITLink reliance), the LLVM WebAssembly backend is used manually to produce anobject file. This file is then passed to the WebAssembly version of LLD(wasm-ld) to turn it into a shared library which is written to the virtual filesystem of Emscripten. The dynamic linking facilities of Emscripten can be usedto load this library.</p><p>Mentors: Vassil Vassilev (<a href="https://www.princeton.edu/">Princeton.edu</a>) & Alexander Penev (<a href="https://uni-plovdiv.bg/en/">Uni-Plovdiv.bg</a>)</p><p>Project Details: <a href="https://gist.github.com/argentite/c0852d3e178c4770a429f14291e83475">WebAssembly Support for Clang-Repl</a></p><p>Funding: Google Summer of Code 2023</p><h3 id="example">Example:</h3><pre tabindex="0"><code>SDL_Init(SDL_INIT_VIDEO);SDL_Window *window;SDL_Rendered *renderer;SDL_CreateWindowAndRenderer (300, 300, 0, &window, &renderer);</code></pre><p>This should connect to a simple black canvas. Next, we can draw things into it.</p><pre tabindex="0"><code>SDL_SetRenderDrawColor(renderer, 0x80, 0x00, 0x00, 0xFF);SDL_Rect rect3 = {.x = 20, .y = 20, .w = 150, .h = 100};SDL_RenderFillRect(rendered, &rect3); SDL_SetRenderDrawColor(renderer, 0x00, 0x80, 0x00, 0xFF);SDL_Rect rect4 = {.x = 40, .y = 40, .w = 150, .h = 100};SDL_RenderFillRect(rendered, &rect4); SDL_RenderPresent(renderer);</code></pre><p>The output should look something like this:</p><figure><img src="https://blog.llvm.org/img/WebAssemblyExample.png" alt="Web Assembly Example"></figure><h2 id="sunho-kim----re-optimization-using-jitlink">Sunho Kim - Re-optimization using JITLink</h2><p>In order to support re-optimization, the JITLink API was extended by adding thecross-architecture stub creation API. This API works in all platforms andarchitectures that JITLink supports and through this we can create theredirectable stubs by using JITLink.</p><p>Once the re-optimization API was developed, it was time to actually implementre-optimization. A new layer was introduced to support re-optimization of IRmodules. There were many abstraction levels where redirection could beimplemented, but we ended up doing it at IR level since that brings a lot ofre-optimization techniques to be implemented easily by transforming IRdirectly. From an API perspective, the most flexible abstraction level to dothis may be at the FrontEnd AST level.</p><p>Clang-Repl relies on LLJIT to do JIT-related tasks. Enabling re-optimizationfor LLJIT also helped enable it in Clang-Repl. However, there were minorchallenges (e.g., mismatch in what clang-repl expects from how the runtimeexecutes the static initializers and how ELF orc runtime runs it). Possiblesolutions for these are in discussion (e.g., adding a new dl function).Nevertheless, we now have a real-world experimental environment where we cantest new re-optimization techniques and perform benchmarks to see if they areuseful.</p><p>Finally, based on the above infrastructure, profile guided optimization is nowpossible (by transforming the IR module). There are still some enhancementspending before the code is fully upstreamed, but the current code achievesinstrumentation on the orc-runtime side, which simplifies implementation by alot.</p><p>Mentors: Vassil Vassilev (<a href="https://www.princeton.edu/">Princeton.edu</a>) & Lang Hames/ lhames (<a href="https://www.apple.com">Apple</a>)</p><p>Project Details: <a href="https://gist.github.com/sunho/bbbf7c415ea4e16d37bec5cea8adce5a">Re-optimization using JITLink</a></p><p>Funding: Google Summer of Code 2023</p><h3 id="example-doing-the--o2-optimization-if-function-was-called-more-than-10-times">Example: Doing the -O2 optimization if function was called more than 10 times</h3><p>The following example builds a PassManager using the LLVM library and then runsthe optimization pipeline.</p><pre tabindex="0"><code>static Error reoptimizeTo02(ReOptimizeLayer &Parent, ReOptMaterializationUnitID MUID, unsigned Curverison, ResourceTrackerSP OldRT, ThreadSafeModule &TSM) { TSM.withModuleDo([&]{llvm::Module &M) { auto PassManager = buildPassManager(); PassManager.run(M); }); return Error::success();}ReOptLayer ->setReoptimizeFunc(reoptimizeTo02);ReOptLayer ->setAddProfileFunc(reoptimizeIfCallFrequent);</code></pre><p>For more examples, please see the <a href="https://github.com/sunho/LLVM-JITLink-COFF-Example">LLVM-JITLink-COFF-Example</a> repo.</p><h2 id="krishna-narayanan---tutorial-development-with-clang-repl">Krishna Narayanan - Tutorial development with clang-repl</h2><p>Open Source documentation is often a neglected area in the software lifecycle.Specifically, this project targeted helping contributors by documenting howthey can set up respective environments on their local machines to contributeto the code and documentation of the respective project. These environmentswere set up locally, tested and then the setup methodology was updated in therelevant documentation.</p><p>Besides other compiler research technologies, write-ups were also added to LLVM(specifically the Clang-Repl documentation) as part of this project. Usageexamples were also added.</p><p>Mentors: Vassil Vassilev (<a href="https://www.princeton.edu/">Princeton.edu</a>) & David Lange (<a href="https://www.princeton.edu/">Princeton.edu</a>)</p><p>Project Details: <a href="https://github.com/Krishna-13-cyber/GSoC23-LLVM/blob/main/README.md">Tutorial development with clang-repl</a></p><p>Funding: Google Summer of Code 2023</p><h3 id="example-1">Example</h3><pre tabindex="0"><code>// Classes and Structuresclang-repl> #include <iostream>clang-repl> class Rectangle {int width, height; public: void set_values (int,int);\clang-repl... int area() {return width*height;}};clang-repl> void Rectangle::set_values (int x, int y) { width = x;height = y;}clang-repl> int main () { Rectangle rect;rect.set_values (3,4);\clang-repl... std::cout << "area: " << rect.area() << std::endl;\clang-repl... return 0;}clang-repl> main();area: 12</code></pre>
- Tools for Learning LLVM TableGenhttps://blog.llvm.org/posts/2023-12-07-tools-for-learning-llvm-tablegen/Thu, 07 Dec 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-12-07-tools-for-learning-llvm-tablegen/<p><a href="https://github.com/llvm/llvm-project/tree/main/llvm/utils/TableGen">TableGen</a>is a language used within the LLVM project for generating a variety of files,when manual maintenance would be very difficult.</p><p>For example, it is used to define all of the instructions that can be used on aparticular architecture. The information is defined in TableGen and we canproduce many things based on that single source file. C++ code, documentation,command line options, and so on.</p><p>TableGen has been in existence since<a href="https://github.com/llvm/llvm-project/commit/a6240f6b1a34f9238cbe8bc8c9b6376257236b0a">before</a>the first official release of LLVM, over 20 years ago.</p><p>Today in the <a href="https://github.com/llvm/llvm-project">LLVM project repository</a> there areover a thousand TableGen source files totalling over 500,000 lines of code.Making it the 5th most popular language in the repository.</p><table><thead><tr><th>Language</th><th>files</th><th>blank</th><th>comment</th><th>code</th></tr></thead><tbody><tr><td>C++</td><td>29642</td><td>958542</td><td>1870101</td><td>5544445</td></tr><tr><td>C/C++ Header</td><td>11844</td><td>316806</td><td>499845</td><td>1486165</td></tr><tr><td>C</td><td>10535</td><td>259900</td><td>1603594</td><td>1011269</td></tr><tr><td>Assembly</td><td>10694</td><td>478035</td><td>1222315</td><td>820236</td></tr><tr><td>TableGen</td><td>1312</td><td>94112</td><td>83616</td><td>580289</td></tr></tbody></table><p>(Counted from<a href="https://github.com/llvm/llvm-project/commit/ba24b814f2a20a136f0a7a0b492b6ad8a62114c6">this commit</a>,rest of table omitted)</p><p>With projects such as MLIR<a href="https://mlir.llvm.org/docs/DefiningDialects/Operations/">embracing TableGen</a>,it is only going to grow. So if you are contributing to LLVM, you will encounterit at some point.</p><p>Which might be a problem as TableGen only exists within LLVM. Unlike a languagesuch as C++, TableGen does not have a large array of resources.</p><p>So, as well as joining a new project, you also need to learn a newDomain Specific Language (DSL). You did not come to LLVM to learn a DSL, youprobably came here to write a compiler.</p><p>I cannot say when this problem might be solved, but the situation is not asbleak as it appears. There have been big improvements in TableGen toolsrecently, which means you can put more of your energy into the goals thatbrought you to LLVM in the first place.</p><h1 id="a-brief-introduction-to-tablegen">A Brief Introduction to TableGen</h1><p>Imagine you wanted to represent the registers of an architecture. I am going touse Arm’s AArch64 in particular here.</p><p>You could describe them in TableGen as:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cat register.td</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>class Register<int _size, string _alias<span style="color:#f92672">=</span><span style="color:#e6db74">""</span>> <span style="color:#f92672">{</span></span></span><span style="display:flex;"><span> int size <span style="color:#f92672">=</span> _size;</span></span><span style="display:flex;"><span> string alias <span style="color:#f92672">=</span> _alias;</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>// <span style="color:#ae81ff">64</span> bit general purpose registers are X<N>.</span></span><span style="display:flex;"><span>def X0: Register<8> <span style="color:#f92672">{}</span></span></span><span style="display:flex;"><span>// Some have special alternate names.</span></span><span style="display:flex;"><span>def X29: Register<8, <span style="color:#e6db74">"frame pointer"</span>> <span style="color:#f92672">{}</span></span></span><span style="display:flex;"><span>// Some registers omitted...</span></span></code></pre></div><p>By default, the TableGen compiler <code>llvm-tblgen</code> creates ârecordsâ - which areshown below.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ./bin/llvm-tblgen register.td</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>------------- Classes -----------------</span></span><span style="display:flex;"><span>class Register<int Register:_size <span style="color:#f92672">=</span> ?, string Register:_alias <span style="color:#f92672">=</span> <span style="color:#e6db74">""</span>> <span style="color:#f92672">{</span></span></span><span style="display:flex;"><span> int size <span style="color:#f92672">=</span> Register:_size;</span></span><span style="display:flex;"><span> string alias <span style="color:#f92672">=</span> Register:_alias;</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span></span></span><span style="display:flex;"><span>------------- Defs -----------------</span></span><span style="display:flex;"><span>def X0 <span style="color:#f92672">{</span> // Register</span></span><span style="display:flex;"><span> int size <span style="color:#f92672">=</span> 8;</span></span><span style="display:flex;"><span> string alias <span style="color:#f92672">=</span> <span style="color:#e6db74">""</span>;</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span></span></span><span style="display:flex;"><span>def X29 <span style="color:#f92672">{</span> // Register</span></span><span style="display:flex;"><span> int size <span style="color:#f92672">=</span> 8;</span></span><span style="display:flex;"><span> string alias <span style="color:#f92672">=</span> <span style="color:#e6db74">"frame pointer"</span>;</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span></span></span></code></pre></div><p>This is the intermediate representation (IR) of the TableGen compiler, similarto LLVM’s “LLVM IR”.</p><p>When using LLVM you would select a “target” which is the processor architectureyou want to generate instructions for. TableGen’s equivalent is a “backend”.These backends do not generate instructions, but instead output a format forthat backend’s specific use case.</p><p>For example, there is a backend that generates C++ code for<a href="https://godbolt.org/z/5c696j1f9">searching</a> data tables. Other examples areC header files and <a href="https://docutils.sourceforge.io/rst.html">reStructuredText</a>documentation.</p><pre tabindex="0"><code> TableGen source | +--llvm-tblgen----------------|------------------------+ | v | | +----- Expanded records ----+ | | | | | | v v | | +-------------------------+ +-------------------+ | | | --gen-searchable-tables | | Other backends... | | | +-------------------------+ +-------------------+ | | | | | +--------------|---------------------------|-----------+ v v .inc file with C++ code Other output formats... for table searching.</code></pre><p>The main compiler is <code>llvm-tblgen</code>, but there are others specific tosub-projects of LLVM. For example <code>clang-tblgen</code> and <code>lldb-tblgen</code>. The onlydifference is the backends included in each one, the language is the same.</p><p>You might take your register definitions and produce C++ code to initialise themin some kind of bootloader. Perhaps you also document it and produce a diagramof the process. With enough backends, you could do all that from the sameTableGen source code.</p><p>You would write these backends either in C++ within the TableGen compiler,or as an external backend using the compiler’s<a href="https://godbolt.org/z/vre845e77">JSON output</a> (<code>--dump-json</code>). So you can useany language with a JSON parser (such as<a href="https://github.com/llvm/llvm-project/blob/main/llvm/utils/TableGen/jupyter/sql_query_backend.ipynb">Python</a>).</p><h1 id="there-is-tablegen-and-there-are-things-built-with-tablegen">There is TableGen and There Are Things Built With TableGen</h1><p>This is more a mindset than a tool. It is summed up best by a quote from the<a href="https://llvm.org/docs/TableGen/index.html#tablegen-deficiencies">documentation</a>:</p><blockquote><p>Despite being very generic, TableGen has some deficiencies that have beenpointed out numerous times. The common theme is that, while TableGen allowsyou to build domain specific languages, the final languages that you createlack the power of other DSLs, which in turn increase considerably the size andcomplexity of TableGen files.</p><p>At the same time, TableGen allows you to create virtually any meaning of thebasic concepts via custom-made backends, which can pervert the original designand make it very hard for newcomers to understand the evil TableGen file.â</p></blockquote><p>This means that you will be tackling TableGen, and things built with TableGen.Which are often more complicated than the language.</p><p>It is like learning C++ and struggling to use <a href="https://www.boost.org/">Boost</a>.Someone might say to you, âBoost is not required, why not remove it and saveyourself the hassle?â. As someone new to C++, you might not be aware of theboundary between the two of them.</p><p>Of course this does not help you too much if the project you want to contributeto uses Boost. You are stuck dealing with both. In LLVM terms, the TableGenlanguage and the backends that consume it are a package deal.</p><p>I mention this so that you can draw a distinction between not understandingone or the other. Knowing which one is confusing you is a big advantageto finding help.</p><p>For any task there are probably one or two “things built with TableGen” that youneed to understand and even then, not entirely.</p><p>Do not think that your TableGen journey must end with understanding all the waysit is used. That is possible, but it is not required, and hardly anyone learnseverything. Instead put your energy into the things that really interest you.</p><h1 id="compiler-explorer">Compiler Explorer</h1><p>Of course we have TableGen in Compiler Explorer! Is a language even real if it isnot in Compiler Explorer?</p><p>(Of course it is, but if your favourite language is not there, Compiler Explorerhas <a href="https://github.com/compiler-explorer/compiler-explorer/blob/main/docs/AddingALanguage.md">excellent documentation</a>and friendly maintainers)</p><p>Compiler Explorer is a whole bunch of different versions of compilers fordifferent languages and different architectures that you can access with just abrowser tab.</p><p>It is an incredible tool for learning, teaching, triaging, optimising and<a href="https://www.youtube.com/watch?v=O5sEug_iaf4">many more</a> things. I will not go intodetail about it here, just a few things about TableGen’s inclusion.</p><p>The obvious thing is that <code>llvm-tblgen</code> does not emit instructions (though ahypothetical backend could) so there is no option to compile to binary orexecute code.</p><p>By default, records are printed as plain text. You can choose a backend by adding acompiler option, or by opening the “Overrides” menu and selecting an “Action”.</p><p>It is important to note that TableGen backends have very specific expectations ofwhat will be in the source code. As if you had a C++ compiler thatwould not compile for Arm unless it saw <code>arm_is_cool</code> somewhere in thesource code.</p><p>In the LLVM repository all the required classes are set up for you, but inCompiler Explorer they are not. So, if you would like to experiment with anexisting backend, I suggest you provide stub implementations of the classes, orcopy some from the LLVM project repository. You can also use standard includesfrom <code>include/llvm/*.td</code>.</p><p>It is not possible at this time to develop a backend within Compiler Explorer,but you can select the JSON backend and copy that JSON to give to local scripts.</p><p>Multi-file projects (âIDE modeâ) also work as expected, so, if you would like,you can have your own <a href="https://godbolt.org/z/4qhdoaMjE">include files</a>.</p><p>Finally, remember that you can share Compiler Explorer examples. If you areasking or answering questions about TableGen, always include a Compiler Explorerlink if you can!</p><h1 id="jupyter-notebooks">Jupyter Notebooks</h1><p><a href="https://jupyter.org/">Jupyter</a> creates interactive notebooks. A notebook is asingle document which contains text, code and the results of running that code.This enables you to edit the code and rerun it to update the results in thenotebook.</p><p>This is great for taking notes or building up large examples from small chunksof code. You can export the document as a notebook that anyone can edit, orin noninteractive formats such as PDF or Markdown.</p><p>TableGen can be used in notebooks by using the TableGen Jupyter Kernel.Installation instructions are available <a href="https://github.com/llvm/llvm-project/tree/main/llvm/utils/TableGen/jupyter">here</a> and you can watch me talk more about it<a href="https://www.youtube.com/watch?v=Gf0FUiY2TRo">here</a>.</p><p><strong>Note:</strong> There is also an<a href="https://github.com/llvm/llvm-project/tree/main/mlir/utils/jupyter">MLIR kernel</a>for Jupyter, along with many others.</p><p>We have aimed to give the same experience as other languages, so I will focusnot on how to use a notebook, but instead on what we have been able to make withthem.</p><h2 id="tablegen-tutorial-notebook">TableGen Tutorial Notebook</h2><p>This notebook is an introduction to TableGen. You can read it on<a href="https://github.com/llvm/llvm-project/blob/main/llvm/utils/TableGen/jupyter/tablegen_tutorial_part_1.ipynb">GitHub</a>,or <a href="https://raw.githubusercontent.com/llvm/llvm-project/main/llvm/utils/TableGen/jupyter/tablegen_tutorial_part_1.ipynb">download</a>it and read it in Jupyter.</p><p>When using Jupyter, you can edit the document to add your own examples or expandthe ones that you find interesting.</p><h2 id="how-to-write-a-tablegen-backend-notebook">“How to Write a TableGen Backend” Notebook</h2><p>This notebook uses Python instead of TableGen, and it shows you how to write abackend.</p><p>The 2021 EU LLVM Developer’s Meeting talk<a href="https://www.youtube.com/watch?v=UP-LBRbvI_U">âHow to write a TableGen backendâ</a>by Min-Yih Hsu is the basis for this. The<a href="https://github.com/llvm/llvm-project/blob/main/llvm/utils/TableGen/jupyter/sql_query_backend.ipynb">notebook</a>is in fact a Python port of Min’s own<a href="https://github.com/mshockwave/SQLGen">C++</a> implementation.</p><p>It shows you how to take the JSON output of <code>llvm-tblgen</code> and process it withPython to create SQL queries.</p><p>What is unique here is we now have the same content in multiple media forms andmultiple programming languages. Choose the ones that suit you best.</p><p>Referring back to âThere is TableGen and There are Things Built With TableGenâ, the tutorial notebook is TableGen. The writing a backend notebook is âThingsBuilt With TableGenâ.</p><h2 id="limitations">Limitations</h2><p>The major limitation of the notebooks is that we have no output filtering. Thismeans if you do <code>include âllvm/Target/Target.td"</code> you will get about 320,000lines of output (before you have added any of your own code). This is more thana default notebook accepts from a kernel and when I removed that limit, thebrowser tab crashed.</p><p>This is not a problem in most cases and the possible solutions have bigtrade-offs, so we are not going to rush a fix. If it does affect you, please add yourfeedback to the<a href="https://github.com/llvm/llvm-project/issues/72856">tracking issue</a>.</p><h1 id="tablegen-language-server">TableGen Language Server</h1><p>The MLIR project has implemented a server for the<a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a>(LSP). Which supports TableGen and<a href="https://mlir.llvm.org/docs/Tools/MLIRLSP/">2 other languages</a> used within MLIR.</p><p>The language server protocol provides information to compatible editors aboutthe structure of a language and project. For example, where are the includedfiles? Where is the definition of a particular type?</p><p>If you have used a LSP compatible editor (such as Visual Studio Code), you haveprobably used a language server without knowing. âGo To Definitionâ is themost common feature they provide.</p><p>The Language Server Protocol allows you to open a project, go to the code youwant to change and jump from there directly to the other relevant parts of therepository. With 500,000+ lines of TableGen in the LLVM project, that is a lot ofcode you get to ignore!</p><h1 id="setup">Setup</h1><p>You will need a copy of the server binary <code>tblgen-lsp-server</code>. Which you can getfrom the<a href="https://github.com/llvm/llvm-project/releases">release package</a> for yourplatform, or you can build it yourself.</p><p>This is how to build it yourself:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cmake -G Ninja <path-to>/llvm-project/llvm -DCMAKE_BUILD_TYPE<span style="color:#f92672">=</span>Release -DLLVM_ENABLE_PROJECTS<span style="color:#f92672">=</span><span style="color:#e6db74">"mlir"</span></span></span><span style="display:flex;"><span>$ ninja tblgen-lsp-server</span></span></code></pre></div><p>Having run those commands, <code>tblgen-lsp-server</code> is found in <code><build-dir>/bin/</code>.</p><p>The server reads a compilation database file <code>tablegen_compile_commands.yml</code>,which is made for you when you configure LLVM using CMake.</p><p>This serves a similar purpose to the <code>compile_commands.json</code> file generated when using<code>CMAKE_EXPORT_COMPILE_COMMANDS</code>, but the two files are not related.</p><p>As long as your checkout of llvm-project includes<a href="https://github.com/llvm/llvm-project/commit/c4afeccdd235a282d200c450e06a730504a66a08">this commit</a>the compilation database includes TableGen files from all enabledprojects (prior to that commit it was MLIR only).</p><p>For example this configure command includes information about TableGen files from theLLVM, Clang, MLIR and LLDB subprojects:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cmake -G Ninja <path-to>/llvm-project/llvm -DCMAKE_BUILD_TYPE<span style="color:#f92672">=</span>Release -DLLVM_ENABLE_PROJECTS<span style="color:#f92672">=</span><span style="color:#e6db74">"clang;llvm;lldb;mlir"</span></span></span></code></pre></div><p>This also applies to <code>-DLLVM_TARGETS_TO_BUILD=</code>. Enabling only one target meansthat the compilation database only has files relevant to that target.</p><p><strong>Note:</strong> You do not need to build a project to include its TableGen files inthe compilation database. Configuring is all that is needed.</p><p>Next, configure the LSP client for your editor.</p><p>If you are using Visual Studio Code, install the MLIR<a href="https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-mlir">extension</a>. Then follow the setup instructions<a href="https://mlir.llvm.org/docs/Tools/MLIRLSP/#td---tablegen-files">here</a> to tellthe extension where the server and compilation database are.</p><p>If you are using a different editor, refer to its documentation to learn how toset up a language server. Setting the path to the compilation database may requirethe use of the server’s command line options. Run <code>tblgen-lsp-server --help</code> tosee all available options.</p><h2 id="example">Example</h2><p>This example assumes you have configured LLVM with the <code>AArch64</code> target enabled.(It is enabled by default)</p><ul><li>Open the file <code>llvm/lib/Target/AArch64/AArch64.td</code>.</li><li>Put your cursor on a use of the <code>SubtargetFeature</code> type.</li><li>In the menu bar, select “Go” then “Go to Definition”.</li><li>This takes you to <code>llvm/include/llvm/Target/Target.td</code>, where<code>SubtargetFeature</code> is defined.</li></ul><h2 id="limitations-1">Limitations</h2><p>The language server highlights an anti-pattern in the way some LLVM targetssuch as AArch64 use TableGen.</p><p>You may find yourself in a file that uses a class but does not define it orinclude any files which define it. This is because this file is intended to beincluded in another file, which does include a definition of that class.</p><pre tabindex="0"><code>example.td: class Example {}uses_example.td: def example: Example {}main.td: include "example.td" include "uses_example.td"</code></pre><p>The example above shows this anti-pattern:</p><ul><li>The file <code>example.td</code> defines the class <code>Example</code>.</li><li><code>uses_example.td</code> uses the class <code>Example</code>, but does not include <code>example.td</code>.</li><li><code>main.td</code> includes both <code>example.td</code> and <code>uses_example.td</code>.</li><li><code>main.td</code> is the file that is compiled.</li><li>When you are in <code>uses_example.td</code>, the language server does not know where<code>Example</code> is defined,</li><li>When you are in <code>main.td</code>, the language server does know where <code>Example</code> isdefined.</li></ul><p>Perhaps we can address this by improving the language server, or reorganisingthe includes so we do not have files that appear to be isolated.</p><h1 id="dump">Dump</h1><p>What about <code>printf</code>? The best debugging tool of them all.</p><p>TableGen’s equivalent is<a href="https://llvm.org/docs/TableGen/ProgRef.html#dump-print-messages-to-stderr">dump</a>,and its companion <code>repr</code>.</p><pre tabindex="0"><code>def op;class A { string A = "some text"; dag X =(op op);}def a : A;dump "The Value of a is: \n" # !repr(a);</code></pre><p><code>dump</code> prints to <code>stderr</code>:</p><pre tabindex="0"><code><source>:8:1: note: The Value of a is:a {// A string A = "some text"; dag X = (op op);}dump "The Value of a is: \n" # !repr(a);^</code></pre><p>This was added<a href="https://github.com/llvm/llvm-project/commit/411c4edeef076bd2e01b104fe095ba381600a3d3">recently</a>.So you will need a recent build, or a released version 18.0 or newer (which is unreleasedat time of writing).</p><p>Of course you can try this<a href="https://godbolt.org/z/Ta6jb19hr">on Compiler Explorer</a> right now!</p><h1 id="assertions">Assertions</h1><p>An assertion checks that a condition is true at a specific point in yourprogram. An assertion consists of:</p><ul><li>The keyword <code>assert</code>.</li><li>A condition (usually a call to one of the<a href="https://llvm.org/docs/TableGen/ProgRef.html#bang-operators">bang operators</a>).</li><li>A message.</li></ul><p>If the condition is false, a compiler error is generated with the message youprovided.</p><p>For example, the code below checks that you have not tried to make a registerwith a size that is less than 0.</p><pre tabindex="0"><code>class Register<int _size> { assert !gt(_size, 0), "Register size must be > 0, not " # _size # "." ; int size = _size;}def X0: Register<8> {}def X1: Register<-8> {}</code></pre><p>(<a href="https://godbolt.org/z/e4GzvhEeh">Try this on Compiler Explorer</a>)</p><p>The register <code>X0</code> has <code>_size=8</code>, so the condition <code>!gt(_size, 0)</code> (which wouldbe <code>_size > 0</code> in C syntax) is true and therefore no error is generated.</p><p>The register <code>X1</code> has <code>_size=-8</code>, so the condition is false and an error isgenerated. The compiler output is shown below:</p><pre tabindex="0"><code><source>:2:11: error: assertion failed assert !gt(_size, 0), ^note: Register size must be > 0, not -8.</code></pre><p>While learning new code it is helpful to add your own assertions to check yourassumptions. In addition, adding assertions to code written to be used by otherpeople is a good way to stop them using it incorrectly. Unlike documentation,you cannot miss an assertion error.</p><h1 id="find-in-files">Find In Files</h1><p>This is last because in an ideal world it would be the last option, but it isoften not the least of the options. Grep, ack, Find In Files, whatever you call it,searching text is unreasonably effective if you have a little knowledge of thelanguage syntax.</p><p>Why should I mention such an obvious idea? Well, obvious is subjective, andthere is a special situation that makes it more effective than usual.</p><p>In the LLVM project repository we have the vast majority of TableGen code in use today.Would you like to know how to use a particular feature? It is all there,somewhere in 500,000+ lines of source code. You would be surprised by what asimple query can find despite that.</p><p>Think about the thing you are trying to find. What do you think its sourcecode would look like? If it is a class would it have template arguments or notand so would there be a <code><</code> after the name? If it is an error message, what partswould be constant and what parts would be inserted into a template message?</p><p><code>Expected end of line</code> is likely to be a static string so you can search for themessage itself. In contrast, <code>class Foo has no attribute Bar</code> is more likely tobe created by substituting in the name of the class and attribute. So a goodsearch term for this would be <code>has no attribute</code>.</p><p>There are also tests for the compiler, most of which are in<a href="https://github.com/llvm/llvm-project/tree/main/llvm/test/TableGen">this folder</a>.This folder contains minimal examples for the language features. Try narrowingyour search to this location.</p><h1 id="conclusion">Conclusion</h1><p>Learning TableGen does not have to be scary. Do not think that because it is anisolated DSL that it does not have what you have come to expect from yourfavourite languages.</p><p>Keep in mind that TableGen is also a tool, not a goal in itself. If you canachieve your goals with a limited but accurate understanding of TableGen and itsbackends, that is great. Learn as much as you want or need.</p><p>In addition to the tools, there is an active community ready to answer yourquestions on <a href="https://discord.com/invite/xS7Z362">Discord</a> or the<a href="https://discourse.llvm.org/">forums</a>.</p><p>If you find problems or want to contribute improvements please do so. Open aGitHub <a href="https://github.com/llvm/llvm-project/issues">Issue</a> or<a href="https://llvm.org/docs/Contributing.html">Pull Request</a>.</p><p>Look at the other languages you use. Do they have these tools? Should they? Theymight be the difference between frustration and your new favourite language.</p><h1 id="acknowledgements">Acknowledgements</h1><p>Thank you to Andrzej WarzyÅski, Francesco Petrogalli, Min-Yih Hsu and Sally Neale (Arm) for reviewing this article.</p>
- Tutorial Development with Clang-Replhttps://blog.llvm.org/posts/2023-10-5-tutorial-development-with-clang-repl/Thu, 05 Oct 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-10-5-tutorial-development-with-clang-repl/<h2 id="introduction">Introduction</h2><p>I’m Krishna Narayanan, a final undergraduate at Veermata Jijabai TechnologicalInstitute, Mumbai and I am talking about my GSoC project in this blog postwhich mentions the goals, tasks we have accomplished during this summer tenure.My GSoC project aims to develop tutorials demonstrating the current capabilities ofClang-repl. The need for Clang-repl is that it presents opportunities for rigorousopen-source development. However, even though it is inspired by cling, not all ofClang-repl and Cling are the same, i.e., they are similar, but work needs to be done toadd Xeus protocol support for Clang-repl.In a similar convention, tutorials were demonstrated for CppInterOp (clang-based C++),Xeus-cpp (interactive programming environment for C++) and Xeus-clang-repl.</p><h2 id="contributions">Contributions:</h2><p>This is the list of contributions according to the pull requests I have sent:</p><h3 id="1-update-clang-repl-documentation">1. Update Clang-Repl Documentation</h3><ul><li><a href="https://reviews.llvm.org/D152109">https://reviews.llvm.org/D152109</a></li><li><a href="https://reviews.llvm.org/D156858">https://reviews.llvm.org/D156858</a></li><li><a href="https://github.com/llvm/llvm-project/pull/65650">https://github.com/llvm/llvm-project/pull/65650</a></li></ul><p>This patch adds support for Clang-Repl documentation, basically, it provides alldetails regarding the usage of Clang-Repl. It emphasises the features of Clang-Replthat it offers to the user. The REPL nature enables users to prototype,experiment and gives a user-friendly experience. Similarly, the second patchadds Clang-Repl Execution Handling Results by Saqib in which we enabled thegraphviz extension for the llvm/clang documents to support the graphviz conventionfor pictorial representation (under review).</p><h3 id="2-add-c-interop-documentation-setup">2. Add C++ InterOp Documentation Setup</h3><ul><li><a href="https://github.com/compiler-research/CppInterOp/pull/87">https://github.com/compiler-research/CppInterOp/pull/87</a></li><li><a href="https://github.com/compiler-research/CppInterOp/pull/99">https://github.com/compiler-research/CppInterOp/pull/99</a></li><li><a href="https://github.com/compiler-research/CppInterOp/pull/105">https://github.com/compiler-research/CppInterOp/pull/105</a></li><li><a href="https://github.com/compiler-research/CppInterOp/pull/121">https://github.com/compiler-research/CppInterOp/pull/121</a></li><li><a href="https://github.com/compiler-research/CppInterOp/pull/134">https://github.com/compiler-research/CppInterOp/pull/134</a></li></ul><p><strong>CppInterOp</strong> is a clang-based C++ Interoperability library, which enables interoperabilitywith C++ code to more interactive languages like Python. The above patch addsdocumentation setup for CppInterOp consisting of both sphinx and doxygendocumentations. The above patches have covered all topics, points catering to thedevelopment and usage of CppInterOp which include building from source(installation), usage, FAQs, developerâs documentation, tutorials and references. The tutorials inthe docs give a detailed understanding of C++ InterOp usage, which includes C-C++interoperability and C++-python interoperability.</p><h3 id="3-add-xeus-clang-repl-documentation-setup">3. Add xeus-clang-repl Documentation Setup</h3><ul><li><a href="https://github.com/compiler-research/xeus-clang-repl/pull/33">https://github.com/compiler-research/xeus-clang-repl/pull/33</a></li><li><a href="https://github.com/compiler-research/xeus-clang-repl/pull/34">https://github.com/compiler-research/xeus-clang-repl/pull/34</a></li><li><a href="https://github.com/compiler-research/xeus-clang-repl/pull/35">https://github.com/compiler-research/xeus-clang-repl/pull/35</a></li></ul><p><strong>Xeus-clang-repl</strong> integrates clang-repl with the xeus protocol and is a platformfor C++ usage in Jupyter Notebooks. The above patch adds a documentation setupfor xeus-clang-repl consisting of both sphinx and doxygen documentations. Thedocumentation covers all information regarding installation, usage, importanceand references for xeus-clang-repl. It includes tutorials portraying the differentfeatures that can be used in xeus-clang-repl, especially the C++-python integrationexecuting simultaneously in the Jupyter cell with the help of magic commands( %%python).</p><h3 id="4-add-xeus-cpp-documentation-setup">4. Add xeus-cpp Documentation Setup</h3><ul><li><a href="https://github.com/compiler-research/xeus-cpp/pull/13">https://github.com/compiler-research/xeus-cpp/pull/13</a></li></ul><p><strong>Xeus-cpp</strong> is an interactive programming environment that allows you toexecute C++ code in a Jupyter Notebook. The above patch adds a documentation setupfor xeus-cpp consisting of both sphinx and doxygen documentations.The documentationcovers all information regarding installation, usage, importance and referencesfor xeus-cpp.It includes tutorials portraying the different features that can be used in xeus-cpp,especially the C++-python integration executing simultaneously in the Jupyter cellwith the help of magic commands(%%python).</p><h3 id="5-others">5. Others</h3><ul><li><a href="https://github.com/compiler-research/xeus-cpp/pull/12">https://github.com/compiler-research/xeus-cpp/pull/12</a></li><li><a href="https://github.com/vgvassilev/clad/pull/610">https://github.com/vgvassilev/clad/pull/610</a></li></ul><p>These are miscellaneous patches contributing to the development of currentdocumentation setup and content. It includes migration from the v1 to the v2 configurationfor readthedocs setup.</p><h2 id="acknowledgements">Acknowledgements</h2><p>All the goals that were originally proposed have been completed to the best of myabilities (the xeus-cpp setup has not been merged yet). I will be working on improvingthese things after suggestions in the upcoming weeks to make tutorials and documentationmore understandable for users. I will keep working with the compiler research groupeven after the GSoC period, contributing to tutorials and landing other developmentpatches.</p><p>I am extremely grateful to my mentors, Vassil and David, for their constanthelp and support in the last two months. Many thanks to Vassil for providing helpand reviewing the code promptly and guiding me towards the final goal, specialthanks to Parth and Baidyanath for guiding me during the initial phase of GSoC.The journey has been quite full of learning, experiencing new techstack and realisingthe importance of documentation and tutorials for a better user experience. I thankVassil and all LLVM community members for giving me this great opportunity to workwith such an evergreen and interesting community.</p><p>Finally, thanking everyone at the compiler research group for assisting throughoutthe GSoC period with many new concepts and help I needed. I am also thankful toGoogle for providing me the opportunity to work on this project during the summer,which helped me learn a lot and will also surely help in my career in the future.</p>
- Diagnostic Improvements in Clang 17https://blog.llvm.org/posts/2023-09-19-diagnostic-improvements-in-clang-17/Tue, 19 Sep 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-09-19-diagnostic-improvements-in-clang-17/<h2 id="introduction">Introduction</h2><p>In the last few months, I have been a part of an ongoing effort to improve Clang’s diagnostic capabilities.The newly released Clang 17 brings several of these improvements to the forefront.This blog post aims to provide a comprehensive overview of these diagnostic enhancements.We will employ simplified code examples and compare diagnostic outputs from Clang 16 and Clang 17 to illustrate how the latest updates can enhance the development experience for Clang users.</p><h3 id="multi-line-printing-of-code-snippets">Multi-line printing of code snippets</h3><p>One of the most anticipated diagnostic features of Clang 17 is its support for multi-line printing of code snippets.This marks a departure from the old single-line limit, which used to make it difficult to fully understand the context around a code issue.This new feature improves the readability and comprehensibility of diagnostic messages by displaying a more complete view of the code in question.Moreover, line numbers are now attached to the left of each line, allowing for quicker navigation and issue resolution.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">func</span>(</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> a, <span style="color:#66d9ef">int</span> b, <span style="color:#66d9ef">int</span><span style="color:#f92672">&</span> r);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">test</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>ptr) {</span></span><span style="display:flex;"><span> func(<span style="color:#ae81ff">3</span>, <span style="color:#ae81ff">4</span>, <span style="color:#ae81ff">5</span>);</span></span><span style="display:flex;"><span> func(<span style="color:#ae81ff">3</span>, <span style="color:#ae81ff">4</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:5:3: error: no matching function for call to 'func'</span></span><span style="display:flex;"><span> func(3, 4, 5);</span></span><span style="display:flex;"><span> ^~~~</span></span><span style="display:flex;"><span><source>:1:5: note: candidate function not viable: expects an lvalue for 3rd argument</span></span><span style="display:flex;"><span>int func(</span></span><span style="display:flex;"><span> ^</span></span><span style="display:flex;"><span><source>:6:3: error: no matching function for call to 'func'</span></span><span style="display:flex;"><span> func(3, 4);</span></span><span style="display:flex;"><span> ^~~~</span></span><span style="display:flex;"><span><source>:1:5: note: candidate function not viable: requires 3 arguments, but 2 were provided</span></span><span style="display:flex;"><span>int func(</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:5:3: error: no matching function for call to 'func'</span></span><span style="display:flex;"><span> 5 | func(3, 4, 5);</span></span><span style="display:flex;"><span> | ^~~~</span></span><span style="display:flex;"><span><source>:1:5: note: candidate function not viable: expects an lvalue for 3rd argument</span></span><span style="display:flex;"><span> 1 | int func(</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span> 2 | int a, int b, int& r);</span></span><span style="display:flex;"><span> | ~~~~~~</span></span><span style="display:flex;"><span><source>:6:3: error: no matching function for call to 'func'</span></span><span style="display:flex;"><span> 6 | func(3, 4);</span></span><span style="display:flex;"><span> | ^~~~</span></span><span style="display:flex;"><span><source>:1:5: note: candidate function not viable: requires 3 arguments, but 2 were provided</span></span><span style="display:flex;"><span> 1 | int func(</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span> 2 | int a, int b, int& r);</span></span><span style="display:flex;"><span> | ~~~~~~~~~~~~~~~~~~~~</span></span></code></pre></div><p>In this example, the newly covered source ranges make it easier to understand why the overload candidate is invalid.</p><p>Commit: <a href="https://reviews.llvm.org/D147875">https://reviews.llvm.org/D147875</a> (Timm Bäder)</p><h3 id="preprocessor-related-diagnostics">Preprocessor-related diagnostics</h3><ul><li>Clang warns on macro redefinitions. When the redefinition happens in assembly files, and the previous definition of the macro comes from the command line, the last definition is now diagnosed as coming from <code><command line></code> instead of <code><built-in></code>.</li></ul><p>Assembly file:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-asm" data-lang="asm"><span style="display:flex;"><span><span style="color:#75715e">#define MACRO 3</span></span></span></code></pre></div><p>Clang invocation command:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>clang -DMACRO=1 file.S</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>warning: 'MACRO' macro redefined [-Wmacro-redefined]</span></span><span style="display:flex;"><span>#define MACRO <span style="color:#ae81ff">3</span></span></span><span style="display:flex;"><span> ^</span></span><span style="display:flex;"><span><built-in>:362:9: note: previous definition is here</span></span><span style="display:flex;"><span>#define MACRO <span style="color:#ae81ff">1</span></span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>warning: 'MACRO' macro redefined [-Wmacro-redefined]</span></span><span style="display:flex;"><span> 1 | #define MACRO 3</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span><command line>:1:9: note: previous definition is here</span></span><span style="display:flex;"><span> 1 | #define MACRO 1</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D145397">https://reviews.llvm.org/D145397</a> (John Brawn)</p><br><ul><li>Clang 17 emits a warning on any language-defined builtin macro being undefined or redefined, some of which were just ignored in Clang 16.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">#undef __cplusplus</span></span></span></code></pre></div><p>Before: <em>No Warning</em></p><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:1:8: warning: undefining builtin macro [-Wbuiltin-macro-redefined]</span></span><span style="display:flex;"><span> 1 | #undef __cplusplus</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Redefinition of compiler builtin macros usually leads to unintended results because library headers often rely on these macros, and they do notexpect these macros to be modified by users.</p><p>Commit: <a href="https://reviews.llvm.org/D144654">https://reviews.llvm.org/D144654</a> (John Brawn)</p><br><ul><li>Clang 17 diagnoses unexpected tokens after a <code>#pragma clang|GCC diagnostic push|pop</code> directive.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">#pragma clang diagnostic push ignore</span></span></span></code></pre></div><p>Before: <em>No Warning</em></p><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:1:31: warning: unexpected token in pragma diagnostic [-Wunknown-pragmas]</span></span><span style="display:flex;"><span> 1 | #pragma clang diagnostic push ignored</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://github.com/llvm/llvm-project/commit/7ff507f1448bfdfcaa91d177d1f655dcb17557e7">https://github.com/llvm/llvm-project/commit/7ff507f1448bfdfcaa91d177d1f655dcb17557e7</a> (Aaron Ballman)</p><h3 id="attribute-related-diagnostics">Attribute related diagnostics</h3><ul><li>Clang 17 generates notes and fix-its for <code>ifunc</code>/<code>alias</code> attributes which point to unmangled function names.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span>__attribute__((used)) <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">void</span> <span style="color:#f92672">*</span>resolve_foo() { <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>; }</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>__attribute__((ifunc(<span style="color:#e6db74">"resolve_foo"</span>))) <span style="color:#66d9ef">void</span> foo();</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:3:16: error: ifunc must point to a defined function</span></span><span style="display:flex;"><span>__attribute__((ifunc("resolve_foo"))) void foo();</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:3:16: error: ifunc must point to a defined function</span></span><span style="display:flex;"><span> 3 | __attribute__((ifunc("resolve_foo"))) void foo();</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span><source>:3:16: note: the function specified in an ifunc must refer to its mangled name</span></span><span style="display:flex;"><span><source>:3:16: note: function by that name is mangled as "_ZL11resolve_foov"</span></span><span style="display:flex;"><span> 3 | __attribute__((ifunc("resolve_foo"))) void foo();</span></span><span style="display:flex;"><span> | ^~~~~~~~~~~~~~~~~~~~</span></span><span style="display:flex;"><span> | ifunc("_ZL11resolve_foov")</span></span></code></pre></div><p>One needs to be aware of the C++ name mangling when using <code>ifunc</code> or <code>alias</code> attributes, but knowing the mangled name from a function signature isn’tan easy task for many people.This change makes the error message highly understandable by suggesting that the <code>ifunc</code> needs to refer to the mangled name,and it also makes this error more actionable by representing the mangled name.</p><p>Commit: <a href="https://reviews.llvm.org/D143803">https://reviews.llvm.org/D143803</a> (Dhruv Chawla)</p><br><ul><li>Clang 17 avoids duplicate warnings on unreachable <code>[[fallthrough]];</code> statements previously issued from <code>-Wunreachable-code</code> and <code>-Wunreachable-code-fallthrough</code> by prioritizing <code>-Wunreachable-code-fallthrough</code>.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">f</span>(<span style="color:#66d9ef">int</span> n) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">switch</span> (n) {</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">[[fallthrough]]</span>;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">case</span> <span style="color:#ae81ff">1</span><span style="color:#f92672">:</span>;</span></span><span style="display:flex;"><span> }</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Clang invocation command:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>clang++ -Wunreachable file.cpp</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:3:5: warning: code will never be executed [-Wunreachable-code]</span></span><span style="display:flex;"><span> [[fallthrough]];</span></span><span style="display:flex;"><span> ^~~~~~~~~~~~~~~~</span></span><span style="display:flex;"><span><source>:3:5: warning: fallthrough annotation in unreachable code [-Wunreachable-code-fallthrough]</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:3:5: warning: fallthrough annotation in unreachable code [-Wunreachable-code-fallthrough]</span></span><span style="display:flex;"><span> 3 | [[fallthrough]];</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D145842">https://reviews.llvm.org/D145842</a> (Takuya Shimizu)</p><br><ul><li>Clang 17 correctly emits diagnostics for <code>unavailable</code> attributes that were ignored in Clang 16.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">template</span> <span style="color:#f92672"><</span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">_ValueType</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">int</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">__attribute__</span>((unavailable)) polymorphic_allocator {};</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">f</span>() { polymorphic_allocator<span style="color:#f92672"><</span><span style="color:#66d9ef">void</span><span style="color:#f92672">></span> a; }</span></span></code></pre></div><p>Before:No diagnostics</p><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:4:12: error: 'polymorphic_allocator<void>' is unavailable</span></span><span style="display:flex;"><span> 4 | void f() { polymorphic_allocator<void> a; }</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span><source>:2:36: note: 'polymorphic_allocator<void>' has been explicitly marked unavailable here</span></span><span style="display:flex;"><span> 2 | class __attribute__((unavailable)) polymorphic_allocator {};</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D147495">https://reviews.llvm.org/D147495</a> (Shafik Yaghmour)</p><br><ul><li>Clang no longer emits <code>-Wunused-variable</code> warnings for variables declared with <code>__attribute__((cleanup(...)))</code> to match GCC’s behavior.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">c</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>);</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">f</span>(<span style="color:#66d9ef">void</span>) { <span style="color:#66d9ef">int</span> __attribute__((cleanup(c))) X1 <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>; }</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:2:48: warning: unused variable 'X1' [-Wunused-variable]</span></span><span style="display:flex;"><span>void f(void) { int __attribute__((cleanup(c))) X1 = 4; }</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After: <em>No Warning</em></p><p><code>cleanup</code> attribute is used to write RAII in C.Objects declared with this attribute are actually <em>used</em> as arguments to the function specified in <code>cleanup</code> attribute after its declaration,and thus, it’s considered better not to diagnose them as unused.</p><p>Commit: <a href="https://reviews.llvm.org/D152180">https://reviews.llvm.org/D152180</a> (Nathan Chancellor)</p><h3 id="alignas-specifier"><code>alignas</code> specifier</h3><ul><li>Clang 16 modeled <code>alignas(type-id)</code> as <code>alignas(alignof(type-id))</code>.Clang 17 fixes this modeling and thus fixes the wrong mention of <code>alignof</code> in diagnostics about <code>alignas</code> and <code>_Alignas</code>.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">alignas</span>(<span style="color:#66d9ef">void</span>) A {};</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:1:16: error: invalid application of 'alignof' to an incomplete type 'void'</span></span><span style="display:flex;"><span>struct alignas(void) A {};</span></span><span style="display:flex;"><span> ~^~~~~</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:1:16: error: invalid application of 'alignas' to an incomplete type 'void'</span></span><span style="display:flex;"><span> 1 | struct alignas(void) A {};</span></span><span style="display:flex;"><span> | ~^~~~~</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D150528">https://reviews.llvm.org/D150528</a> (yronglin)</p><h3 id="shadowings">Shadowings</h3><ul><li>Clang 17 emits an error when lambda’s captured variable shadows a template parameter.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">auto</span> h <span style="color:#f92672">=</span> [y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>]<span style="color:#f92672"><</span><span style="color:#66d9ef">typename</span> y<span style="color:#f92672">></span>(y) { <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>; }</span></span></code></pre></div><p>Before: <em>No Error</em></p><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:1:11: error: declaration of 'y' shadows template parameter</span></span><span style="display:flex;"><span> 1 | auto h = [y = 0]<typename y>(y) { return 0; };</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span><source>:1:27: note: template parameter is declared here</span></span><span style="display:flex;"><span> 1 | auto h = [y = 0]<typename y>(y) { return 0; };</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D148712">https://reviews.llvm.org/D148712</a> (Mariya Podchishchaeva)</p><br><ul><li>Clang 17’s <code>-Wshadow</code> diagnoses shadowings by static local variables.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> var;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">f</span>() { <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">int</span> var <span style="color:#f92672">=</span> <span style="color:#ae81ff">42</span>; }</span></span></code></pre></div><p>Before: <em>No Warning</em></p><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:2:23: warning: declaration shadows a variable in the global namespace [-Wshadow]</span></span><span style="display:flex;"><span> 2 | void f() { static int var = 42; }</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span><source>:1:5: note: previous declaration is here</span></span><span style="display:flex;"><span> 1 | int var;</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D151214">https://reviews.llvm.org/D151214</a> (Takuya Shimizu)</p><h3 id="-wformat"><code>-Wformat</code></h3><ul><li>Clang 17 diagnoses invalid use of scoped enumeration types in format strings, which is an Undefined Behavior.Now it also emits a fix-it hint to suggest the use of <code>static_cast</code> to its underlying type to avoid the UB.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><limits.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><stdio.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">enum</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Foo</span> <span style="color:#f92672">:</span> <span style="color:#66d9ef">long</span> {</span></span><span style="display:flex;"><span> Bar <span style="color:#f92672">=</span> LONG_MAX,</span></span><span style="display:flex;"><span>};</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() { printf(<span style="color:#e6db74">"%ld"</span>, Foo<span style="color:#f92672">::</span>Bar); }</span></span></code></pre></div><p>Before: <em>No Warning</em></p><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:8:28: warning: format specifies type 'long' but the argument has type 'Foo' [-Wformat]</span></span><span style="display:flex;"><span> 8 | int main() { printf("%ld", Foo::Bar); }</span></span><span style="display:flex;"><span> | ~~~ ^~~~~~~~</span></span><span style="display:flex;"><span> | static_cast<long>( )</span></span></code></pre></div><p>Commit: <a href="https://github.com/llvm/llvm-project/commit/3632e2f5179a420ea8ab84e6ca33747ff6130fa2">https://github.com/llvm/llvm-project/commit/3632e2f5179a420ea8ab84e6ca33747ff6130fa2</a> (Aaron Ballman)</p><p>Commit: <a href="https://reviews.llvm.org/D153622">https://reviews.llvm.org/D153622</a> (Alex Brachet)</p><br><ul><li>Clang 17’s <code>-Wformat</code> recognizes <code>%lb</code> and <code>%lB</code> as format specifiers.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><cstdio></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() { <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">"%lb %lB"</span>, <span style="color:#ae81ff">10L</span>, <span style="color:#ae81ff">10L</span>); }</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:2:23: warning: length modifier 'l' results in undefined behavior or no effect with 'b' conversion specifier [-Wformat]</span></span><span style="display:flex;"><span>int main() { printf("%lb %lB", 10L, 10L); }</span></span><span style="display:flex;"><span> ~^~</span></span><span style="display:flex;"><span><source>:2:27: warning: length modifier 'l' results in undefined behavior or no effect with 'B' conversion specifier [-Wformat]</span></span><span style="display:flex;"><span>int main() { printf("%lb %lB", 10L, 10L); }</span></span><span style="display:flex;"><span> ~^~</span></span></code></pre></div><p>After: <em>No Warning</em></p><p><code>%b</code> and <code>%B</code> are new formats for printing binary representations of integers specified in the ISO C23 draft.There are already several libc implementations available that support this format. (glibc >= 2.35, for example)</p><p>Clang 16 already recognizes <code>%b</code> and <code>%llb</code> as valid format specifiers but handles <code>%lb</code> as invalid.Clang 17 recognizes <code>%lb</code> and <code>%lB</code> to avoid false positive warnings and to emit correct fix-it hints.</p><p>Commit: <a href="https://reviews.llvm.org/D148779">https://reviews.llvm.org/D148779</a> (Fangrui Song)</p><h3 id="constexpr-related-diagnostics">Constexpr-related diagnostics</h3><ul><li><p>Clang often prints the subexpression values of binary operators such as <code>==</code>, <code>||</code>, and <code>&&</code> in static assertion failures to help usersunderstand the cause of the failure.Clang 17 stops printing subexpression values if the binary operator is <code>||</code> because it is evident that both subexpressions evaluate to <code>false</code> in that case.</p></li><li><p>The error message for the failure of static assertion now points to the asserted expression instead of the <code>static_assert</code> token.</p></li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> a <span style="color:#f92672">=</span> false;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">bool</span> b <span style="color:#f92672">=</span> false;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">static_assert</span>(a <span style="color:#f92672">||</span> b);</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:3:1: error: static assertion failed due to requirement 'a || b'</span></span><span style="display:flex;"><span>static_assert(a || b);</span></span><span style="display:flex;"><span>^ ~~~~~~</span></span><span style="display:flex;"><span><source>:3:17: note: expression evaluates to 'false || false'</span></span><span style="display:flex;"><span>static_assert(a || b);</span></span><span style="display:flex;"><span> ~~^~~~</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:3:15: error: static assertion failed due to requirement 'a || b'</span></span><span style="display:flex;"><span> 3 | static_assert(a || b);</span></span><span style="display:flex;"><span> | ^~~~~~</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D147745">https://reviews.llvm.org/D147745</a> (Jorge Pinto Sousa)</p><p>Commit: <a href="https://reviews.llvm.org/D146376">https://reviews.llvm.org/D146376</a> (Krishna Narayanan)</p><br><ul><li>Clang 17 diagnoses calls to a null function pointer in constexpr evaluation as such instead of just saying it is invalid.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">int</span> <span style="color:#a6e22e">call</span>(<span style="color:#66d9ef">int</span> (<span style="color:#f92672">*</span>F)()) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> F();</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span><span style="color:#66d9ef">static_assert</span>(call(<span style="color:#66d9ef">nullptr</span>));</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:4:15: error: static assertion expression is not an integral constant expression</span></span><span style="display:flex;"><span>static_assert(call(nullptr));</span></span><span style="display:flex;"><span> ^~~~~~~~~~~~~</span></span><span style="display:flex;"><span><source>:2:12: note: subexpression not valid in a constant expression</span></span><span style="display:flex;"><span> return F();</span></span><span style="display:flex;"><span> ^</span></span><span style="display:flex;"><span><source>:4:15: note: in call to 'call(nullptr)'</span></span><span style="display:flex;"><span>static_assert(call(nullptr));</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:4:15: error: static assertion expression is not an integral constant expression</span></span><span style="display:flex;"><span> 4 | static_assert(call(nullptr));</span></span><span style="display:flex;"><span> | ^~~~~~~~~~~~~</span></span><span style="display:flex;"><span><source>:2:12: note: 'F' evaluates to a null function pointer</span></span><span style="display:flex;"><span> 2 | return F();</span></span><span style="display:flex;"><span> | ^</span></span><span style="display:flex;"><span><source>:4:15: note: in call to 'call(nullptr)'</span></span><span style="display:flex;"><span> 4 | static_assert(call(nullptr));</span></span><span style="display:flex;"><span> | ^~~~~~~~~~~~~</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D145793">https://reviews.llvm.org/D145793</a> (Takuya Shimizu)</p><br><ul><li>Member function calls are displayed more true to the user-written code.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">Foo</span> {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">int</span> <span style="color:#a6e22e">div</span>(<span style="color:#66d9ef">int</span> i) <span style="color:#66d9ef">const</span> { <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">1</span> <span style="color:#f92672">/</span> i; }</span></span><span style="display:flex;"><span>};</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> Foo obj;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">const</span> Foo <span style="color:#f92672">&</span>ref <span style="color:#f92672">=</span> obj;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">static_assert</span>(ref.div(<span style="color:#ae81ff">0</span>));</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:7:15: error: static assertion expression is not an integral constant expression</span></span><span style="display:flex;"><span>static_assert(ref.div(0));</span></span><span style="display:flex;"><span> ^~~~~~~~~~</span></span><span style="display:flex;"><span><source>:2:45: note: division by zero</span></span><span style="display:flex;"><span> constexpr int div(int i) const { return 1 / i; }</span></span><span style="display:flex;"><span> ^</span></span><span style="display:flex;"><span><source>:7:19: note: in call to '&obj->div(0)'</span></span><span style="display:flex;"><span>static_assert(ref.div(0));</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:7:15: error: static assertion expression is not an integral constant expression</span></span><span style="display:flex;"><span> 7 | static_assert(ref.div(0));</span></span><span style="display:flex;"><span> | ^~~~~~~~~~</span></span><span style="display:flex;"><span><source>:2:45: note: division by zero</span></span><span style="display:flex;"><span> 2 | constexpr int div(int i) const { return 1 / i; }</span></span><span style="display:flex;"><span> | ^ ~</span></span><span style="display:flex;"><span><source>:7:15: note: in call to 'ref.div(0)'</span></span><span style="display:flex;"><span> 7 | static_assert(ref.div(0));</span></span><span style="display:flex;"><span> | ^~~~~~~~~~</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D151720">https://reviews.llvm.org/D151720</a> (Takuya Shimizu)</p><br><ul><li>When a constexpr variable’s constructor call leaves its subobject uninitialized, Clang 17 prints the uninitialized subobject’s name instead of its type.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">Foo</span> {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">constexpr</span> <span style="color:#a6e22e">Foo</span>() {}</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> val;</span></span><span style="display:flex;"><span>};</span></span><span style="display:flex;"><span><span style="color:#66d9ef">constexpr</span> Foo ff;</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:5:15: error: constexpr variable 'ff' must be initialized by a constant expression</span></span><span style="display:flex;"><span>constexpr Foo ff;</span></span><span style="display:flex;"><span> ^~</span></span><span style="display:flex;"><span><source>:5:15: note: subobject of type 'int' is not initialized</span></span><span style="display:flex;"><span><source>:3:7: note: subobject declared here</span></span><span style="display:flex;"><span> int val;</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:5:15: error: constexpr variable 'ff' must be initialized by a constant expression</span></span><span style="display:flex;"><span> 5 | constexpr Foo ff;</span></span><span style="display:flex;"><span> | ^~</span></span><span style="display:flex;"><span><source>:5:15: note: subobject 'val' is not initialized</span></span><span style="display:flex;"><span><source>:3:7: note: subobject declared here</span></span><span style="display:flex;"><span> 3 | int val;</span></span><span style="display:flex;"><span> | ^</span></span></code></pre></div><p>Commit: <a href="https://reviews.llvm.org/D146358">https://reviews.llvm.org/D146358</a> (Takuya Shimizu)</p><br><ul><li>Clang 17 diagnoses unused const variable template as “unused variable template” instead of “unused variable”.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">namespace</span> {</span></span><span style="display:flex;"><span><span style="color:#66d9ef">template</span> <span style="color:#f92672"><</span><span style="color:#66d9ef">typename</span> T<span style="color:#f92672">></span> <span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">double</span> var_t <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Before:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:2:40: warning: unused variable 'var_t' [-Wunused-const-variable]</span></span><span style="display:flex;"><span>template <typename T> constexpr double var_t = 0;</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>After:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-console" data-lang="console"><span style="display:flex;"><span><source>:2:40: warning: unused variable template 'var_t' [-Wunused-template]</span></span><span style="display:flex;"><span> 2 | template <typename T> constexpr double var_t = 0;</span></span><span style="display:flex;"><span> | ^~~~~</span></span></code></pre></div><p>Uninstantiated templates do not generate symbols, and thus, the meaning of <em>unused</em> is broader than the usualunused variables or functions.</p><p>For this reason, <code>-Wunused</code> omits <code>-Wunused-template</code>.This change follows the rationale and leads to fewer unwanted <code>-Wunused-const-variable</code> warnings.</p><p>Commit: <a href="https://reviews.llvm.org/D152796">https://reviews.llvm.org/D152796</a> (Takuya Shimizu)</p><h2 id="acknowledgements">Acknowledgements</h2><p>Special thanks are in order for Timm Bäder, my Google Summer of Code mentor, for his invaluable guidance and support throughout the project.</p><p>Further gratitude is extended to my regular reviewers: Aaron Ballman, Christopher Di Bella, and Shafik Yaghmour, for their insightful and constructive feedbackthat greatly improved my codes.</p>
- Map LLVM Values to corresponding source level expression, GSoC'23 Projecthttps://blog.llvm.org/posts/2023-09-19-gsoc-2023-blog-post/Tue, 19 Sep 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-09-19-gsoc-2023-blog-post/<p>Hi, My name is Shivam, I involved with the LLVM Foundation in 2023 GSoC edition and worked on an interesting project <a href="https://discourse.llvm.org/t/map-llvm-values-to-corresponding-source-level-expressions/68450">Map LLVM Values to corresponding source level expression</a>.</p><h1 id="project-scope">Project Scope</h1><p>Programmers frequently rely on compiler-generated remarks and analysis reports to enhance the efficiency of their code. While compilers excel at including source code positions (such as line and column numbers) in these generated messages, it would be advantageous if these reports also contained the corresponding source-level expressions. The LLVM implementation presently employs a limited set of intrinsic functions to establish a connection between LLVM program elements and source-level expressions. This project’s objective is to leverage the data embedded in these intrinsic functions to either generate source expressions that correspond to LLVM values. The optimization of memory accesses within a program is crucial for achieving optimal application performance. Specifically, our goal is to utilize compiler analysis messages that detail source-level memory accesses associated with LLVM load/store pointer values, which can impede compiler optimizations. As an illustration, this information can be used to identify memory access dependencies that hinder vectorization.</p><p>Expected result was to provide an interface which takes an LLVM value at any point in the LLVM transformations pipeline and returns a string corresponding to the equivalent source-level expression. We are especially interested in using this interface to map addresses used in load/store instructions to equivalent source-level memory references.</p><h1 id="what-we-did">What we did</h1><p>The core achievement of the project is the development of an analysis pass that operates on LLVM intermediate representation (IR). This analysis pass identifies load and store instructions, and then conducts a recursive traversal to construct source expressions that represent equivalent source-level memory references. This is achieved by utilizing the metadata and debug intrinsics available in the LLVM IR. This pass was integrated into the loop vectorizer framework, which is a significant step towards practical application. Accompanying the implementation, a comprehensive suite of tests was developed to ensure the accuracy and expected behavior of the analysis pass.Analysis pass exist at <code>llvm/lib/Analysis/SourceExpressionAnalysis.cpp</code></p><h1 id="implementation-overview">Implementation Overview</h1><h2 id="debug-metadata-handling">Debug Metadata Handling:</h2><p>The implementation effectively processes debug metadata associated with instructions. It leverages debug value and declare instructions to retrieve variable names, which are then used to construct source expressions. This enables accurate mapping of LLVM values to their corresponding source-level expressions.</p><h2 id="instruction-types-handling">Instruction Types Handling:</h2><p>The implementation covers a range of instruction types, including binary operators, GetElementPtr, sign extension instructions, LoadInst, and StoreInst. This comprehensive coverage ensures that a wide array of LLVM instructions can be translated into meaningful source-level expressions.</p><h2 id="type-and-tag-handling">Type and Tag Handling:</h2><p>The implementation utilizes type information from DIType to determine the type tag, which aids in constructing accurate source-level expressions. Different types are handled appropriately, enhancing the fidelity of the generated expressions.</p><h2 id="expression-construction">Expression Construction:</h2><p>The implementation constructs source-level expressions using the provided LLVM instructions. It combines operand names, operator symbols, and other relevant components to create expressions that closely resemble the original source code.</p><h2 id="loadinst-and-storeinst-processing">LoadInst and StoreInst Processing:</h2><p>The implementation effectively processes LoadInst and StoreInst instructions. It generates source expressions for the loaded and stored values, considering both instruction operands and their associated debug metadata.</p><h2 id="mapping-storage">Mapping Storage:</h2><p>The SourceExpressionsMap efficiently stores generated source expressions for various LLVM values. This storage mechanism helps in avoiding redundant calculations and ensures consistent results throughout the analysis.</p><p>However, Itâs important to note that the generated source expressions are in C/C++ Style. Accounting for different source languages and their peculiarities has been beyond the scope of this initial attempt.In addition to developing a separate analysis pass for translating LLVM values into source-level expressions, the implementation was further enhanced by integrating this pass with the Loop Vectorizer. This integration allows for the reporting of source expressions for dependence source and destination pointers in the context of the loop vectorization process. This feature provides valuable insights to developers, aiding in their understanding of memory access patterns and facilitating optimizations.</p><h1 id="the-current-state">The Current State</h1><p>The project has successfully delivered the core functionality of generating source expressions for load and store instructions, covering array and pointer memory references. While initial attempts were made to handle complex structures like structs, this aspect is currently outside the project’s scope.</p><p>Structs pose a unique challenge due to their intricate representation within the LLVM Intermediate Representation (IR). While the project did make initial attempts to incorporate basic support for handling structs, the complexity of nested structures presented significant difficulties. As a result, we encountered obstacles in accurately extracting source expressions for structs and their complex compositions.</p><p>The code still didnât get merge, we still need review on the patch from other community members, the pull request is trackable on Github now <a href="https://github.com/llvm/llvm-project/pull/66591">Map LLVM Values to source level expression</a></p><p>Letâs look at how the analysis pass able to provide useful source level expression for the memory dependencies in the loop.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#75715e">//test.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">test_backward_dep</span>(<span style="color:#66d9ef">int</span> n, <span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>A) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>; i <span style="color:#f92672"><=</span> n<span style="color:#f92672">-</span><span style="color:#ae81ff">3</span>; i <span style="color:#f92672">+=</span> <span style="color:#ae81ff">3</span>) {</span></span><span style="display:flex;"><span> A[i] <span style="color:#f92672">=</span> A[i<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>];</span></span><span style="display:flex;"><span> A[i<span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>] <span style="color:#f92672">=</span> A[i<span style="color:#f92672">+</span><span style="color:#ae81ff">3</span>];</span></span><span style="display:flex;"><span> }</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Generate LLVM file (*.ll) using</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>clang <span style="color:#f92672">-</span>O3 <span style="color:#f92672">-</span>S <span style="color:#f92672">-</span>g emitllvm test.c</span></span></code></pre></div><p>(Assuming <code>test.ll</code> file gets generated)</p><p>Using below clang command to compile and emit remarks related to loop vectorization along with source expression</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>opt <span style="color:#f92672">-</span>report<span style="color:#f92672">-</span>source<span style="color:#f92672">-</span>expr<span style="color:#f92672">=</span>true <span style="color:#f92672">-</span>passes<span style="color:#f92672">=</span><span style="color:#960050;background-color:#1e0010">'</span><span style="color:#a6e22e">function</span>(loop<span style="color:#f92672">-</span>vectorize,require<span style="color:#f92672"><</span>access<span style="color:#f92672">-</span>info<span style="color:#f92672">></span>)<span style="color:#960050;background-color:#1e0010">'</span> <span style="color:#f92672">-</span>disable<span style="color:#f92672">-</span>output <span style="color:#f92672">-</span>pass<span style="color:#f92672">-</span>remarks<span style="color:#f92672">-</span>analysis<span style="color:#f92672">=</span>loop<span style="color:#f92672">-</span>vectorize test.ll</span></span></code></pre></div><p><strong>Note</strong> : A command-line option, ReportSourceExpr, was introduced to control the reporting of source expressions. This option allows users to toggle the reporting of source expressions for Load/Store pointers. By setting this option to true (<code>-report-source-expr=true</code>), developers can receive additional information about the source expressions associated with dependence source and destination pointers, enhancing the quality and depth of the optimization reports.</p><h2 id="output-remarks">Output remarks</h2><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>remark: test.c:<span style="color:#ae81ff">3</span><span style="color:#f92672">:</span><span style="color:#ae81ff">12</span><span style="color:#f92672">:</span> loop not vectorized: unsafe dependent memory operations in the loop. Use <span style="color:#960050;background-color:#1e0010">#</span>pragma loop <span style="color:#a6e22e">distribute</span>(enable) to allow loop distribution to attempt to isolate the offending operation into a separate loop </span></span><span style="display:flex;"><span>Dependence source: <span style="color:#f92672">&</span>A[(i <span style="color:#f92672">+</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">3</span>)] Dependence destination: <span style="color:#f92672">&</span>A[(i <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>)]</span></span></code></pre></div><p>This output includes the information about the loop that wasnât vectorized due to unsafe dependent memory operations. And the interesting part for us is the <code>Dependence Source</code> and <code>Destination</code> source expressions.</p><p>This quick demonstration shows how the analysis can be integrated into the compilation process to provide valuable insights into the memory access patterns and their implications for Loop Vectorization.</p><h1 id="challenges-and-learnings">Challenges and learnings</h1><p>One of the challenges faced during the project was integrating support for complex structures like structs. These structures require specialized handling due to their intricacies in the LLVM IR. However, this aspect revealed the depth of understanding needed for successful interaction with LLVM’s IR and debug metadata. The project was an interesting journey, allowing for deep exploration of LLVM IR and a practical understanding of optimization remarks and metadata. Additionally, working with the loop vectorizer provided insights into its functionality and integration with custom analyses.Overall, the project served as a stepping stone for me to becoming an active contributor to the LLVM community. It provided invaluable learning opportunities and practical insights into compiler optimizations and LLVM’s architecture.</p><h1 id="future-work">Future Work</h1><pre><code>⢠Handling Structs and Complex Data Types⢠Support for Other LLVM Instructions⢠Accurately build the source expression when the Optimizations alters the source level data in the IR rigorously. ⢠Possible integration with LLVM debugger.⢠Support multiple source languages, we would need to define mappings from LLVM constructs to constructs in each target language. </code></pre><h1 id="final-words">Final Words</h1><p>I really wanted to thanks LLVM Foundation and my mentors Karthik Senthil and Satish Guggila for guiding over the project. It was amazing experience for me to working on this project. I am hoping that I’ll keep myself active in LLVM and Compilers. More details of this project can be found in this <a href="https://docs.google.com/document/d/1t1K6vzCYDnFBTH8d1NIJInhxRe5mc1FxkMaX_2WVcmc/edit?usp=sharing">final report</a>. Feel free to reach out to me at <a href="mailto:[email protected]">[email protected]</a> for discussing this patch or anything else.</p>
- Adding a new target/object backend to LLVM JITLinkhttps://blog.llvm.org/posts/2023-03-16-adding-new-llvm-jitlink-target-object-backend/Tue, 28 Mar 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-03-16-adding-new-llvm-jitlink-target-object-backend/<h2 id="motivation">Motivation</h2><p>For the last year, I have been contributing to <a href="https://llvm.org/docs/JITLink.html">LLVM JITLink</a>. This post aims todoubly serve as a summary of my work and documentation for future contributors looking to add a new target/objectbackend to LLVM JITLink.</p><p>We will start by establishing some background and definitions of relevant concepts. Then, we will talk about whatthe project actually entailed. Finally, we will go over the execution details of the project.</p><blockquote><p>The end goal of the project was to make LLVM JITLink capable of linking a 32-bit ELF object file, with i386specific relocations, into a 32-bit process on the i386 hardware architecture.</p><p>If the goal of the project already makes sense to you and you are looking to get started with adding a newtarget/object backend to LLVM JITLink yourself, you can skip to the â<a href="#recap-and-conveniences">Recap and conveniences</a>âsection.</p></blockquote><h2 id="background">Background</h2><h3 id="linking">Linking</h3><p>Our code often relies on external dependencies. For example, even a simple hello-world program written in C dependson the C stdlib for the printf function. These external dependencies are expressed as symbolic references, which Iwill henceforth refer to as just symbols. Symbols are names of data or functions that have unknown addresses andare resolved or fixed up during the linking process.</p><p>In chronological order -</p><ol><li>The compiler converts source code to machine code.</li><li>The assembler converts machine code to object files (ELF, MachO, COFF etc.)</li><li>The linker links one or more object files (fixing up symbolic references along the way) and produces anexecutable or a shared library (also called shared object or dylib).</li></ol><blockquote><p>For the purposes of this discussion we will focus on executables, but the points that will be made hold for sharedobjects as well.</p></blockquote><h3 id="jit-linking">JIT linking</h3><p>Unlike static linking, JIT (Just-in-time) linking is performed at runtime. While a static linker producesexecutables that are stored on disk, a JIT linker produces an in-memory image of the executable – essentiallyready to execute bytes in memory. JIT linking a C program may feel very much like running a shell script. Underthe hood though, the C program is linked into the memory of the invoking process, also commonly referredto as the executor process. The JIT linker patches up the executor process’ memory to account for the addresses ofsymbols at runtime, and executes necessary initializers.</p><p>If you are familiar with dynamic loading then JIT linking may sound familiar, and the two have a lot in common,however they are not the same. JIT linking operates on relocatable objects (vs shared objects/dylibs for dynamicloading), and performs both the static linkerâs and the dynamic loaderâs jobs. Doing so allows the JITlinker to dead-strip redundant symbols, which dynamic loading cannot do, and this allows JIT linking to supportfiner grained compilation of languages that tend to produce a lot of redundant symbol definitions(e.g. C++).</p><h3 id="need-for-jit-linking">Need for JIT linking</h3><p>JIT linking is primarily useful in the context of pre-compiled languages, such as C, C++, Rust etc. Why? At run time,these languages have no way<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> to bring new symbol definitions into a running processâ memory and resolvereferences to them. Although dynamic loading partially solves this issue, it has its drawbacks (discussed above)and lags far behind the static linking experience.</p><p>With JIT linking, at run time, symbolic references can be resolved to existing symbols (from the newly JITâd code), orto newly JIT’d symbols (from the pre-compiled code). The below toy example shows what this looks like in code.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#75715e">// Let's assume we have the following, rather contrived,</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// C++ program that wants to add 2 numbers, but wants to use</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// an `add` function from a relocatable object file supplied by</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the user.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Let's also assume that the add function in the user-supplied</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// relocatable object will reference a symbol named `MAGIC` in its</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// definition.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#66d9ef">int</span> MAGIC <span style="color:#f92672">=</span> <span style="color:#ae81ff">42</span>;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>(<span style="color:#66d9ef">int</span> argc, <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> argv[]) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> a <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> b <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>;</span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span> <span style="color:#75715e">// Read the path of the user supplied relocatable object.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> string userSuppliedObjectPath <span style="color:#f92672">=</span> ...;</span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span> <span style="color:#75715e">// Initialize your JIT class that uses JIT linking under the hood.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> JIT J;</span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span> <span style="color:#75715e">// Add the relocatable object to your JIT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> J.<span style="color:#a6e22e">addObject</span>(userSuppliedObjectPath);</span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span> <span style="color:#75715e">// Lookup the `add` function in the newly added JIT object.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// Once all symbolic references within the user supplied object</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// are resolved, the content is fixed up and emitted to memory.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// And we can then get a pointer to the `add` function.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">auto</span> <span style="color:#f92672">*</span>add <span style="color:#f92672">=</span> (<span style="color:#66d9ef">int</span>(<span style="color:#f92672">*</span>)(<span style="color:#66d9ef">int</span>, <span style="color:#66d9ef">int</span>))J.<span style="color:#a6e22e">lookup</span>(<span style="color:#e6db74">"add"</span>).<span style="color:#a6e22e">getAddress</span>();</span></span><span style="display:flex;"><span> </span></span><span style="display:flex;"><span> <span style="color:#75715e">// At this point the symbolic reference to `MAGIC` in add's</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// definition must have been resolved to the memory address</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// of the constant `MAGIC` that we defined in this program.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span> <span style="color:#75715e">// Run the add function found in the JIT module.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">int</span> result <span style="color:#f92672">=</span> <span style="color:#a6e22e">add</span>(a, b);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>That said, JIT linking by itself is not something that is very useful for an end user. JIT linking is an enablerfor certain use-cases with pre-compiled languages (some use-cases exist for JIT-compiled languages as well<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>).</p><ol><li><strong>JIT compilers</strong> (think of something like the JIT compilation component of the <a href="https://en.wikipedia.org/wiki/HotSpot_(virtual_machine)">Java Hotspot VM</a>, but for astatically compiled language)</li><li><strong>Debugger expression evaluators</strong> (such as the LLDB expression evaluator)</li><li><strong>REPLs</strong> (such as <a href="https://root.cern/cling/">Cling</a> and the currently experimental<sup id="fnref:3"><a href="#fn:3" class="footnote-ref" role="doc-noteref">3</a></sup> <a href="https://clang.llvm.org/docs/ClangRepl.html">Clang-REPL</a>)</li><li><strong>Standalone scripts</strong> (such as the <a href="https://jblevins.org/log/swift">Swift scripts</a>, where the JIT linking isused to add an <a href="https://github.com/apple/swift/blob/main/lib/Immediate/Immediate.cpp#L228">immediate</a> mode tothe compiler, which runs your code in-place via a JIT, rather than compiling it)</li><li><strong>Scriptable extensions</strong> (think about running JITâd code in the context of some existing app, allowing the appto be extended by JITâd code rather than precompiled plugins)</li></ol><p>While the above use cases may seem different, they are really the same â <strong>JIT linking enables linking code intoexisting processes (that may or may not already contain state/context), in an ABI-compatible way.</strong></p><h3 id="llvm-jitlink">LLVM JITLink</h3><p>LLVM JITLink is a JIT linking implementation, in the form of a low-level library within the LLVM infrastructure.It powers <a href="https://llvm.org/docs/ORCv2.html">LLVM’s ORC JIT APIs</a>, which is what end-users would usually use forbuilding runtime linking environments. It provides primitives for:</p><ol><li>Re-using existing compilers to generate relocatable objects at runtime.</li><li>Allocating memory within a target executor process.</li><li>Linking code into a target executor process in an ABI-compatible way.</li></ol><p>In simple words, a program Y, running in a process X, can hand JITLink a relocatable object file and JITLink willlink the object fileâs code into Xâs memory and run it under Xâs existing context (globals, functions etc.), as ifit were part of a dynamic library loaded into process X<sup id="fnref:4"><a href="#fn:4" class="footnote-ref" role="doc-noteref">4</a></sup>.</p><h2 id="the-project">The project</h2><p>Having set up all that background, letâs understand the main task and the end goal of the project.</p><h3 id="the-task---adding-the-i386targetelfobjectbackend-to-jitlink">The task - Adding the i386(target)/ELF(object)backend to JITLink</h3><ol><li><strong>What is a target?</strong><ol><li>Target here, refers to a hardware architecture. <strong>i386 is a 32 bit x86 architecture</strong>.</li></ol></li><li><strong>What is an object?</strong><ol><li>Object here, refers to an object file format. <a href="https://en.wikipedia.org/wiki/Executable_and_Linkable_Format">ELF</a>is the object format commonly used on Linux systems.</li></ol></li><li><strong>Why do different target/object combinations matter and need additional work?</strong><ol><li>Different target/object combinations matter, because each combination may use distinct methods for connectingsymbolic references to symbol definitions. These methods are commonly referred to as<a href="https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html#scrolltoc">relocations</a>.</li></ol></li></ol><h3 id="the-end-goal">The end goal</h3><p>The end goal of the project was to make LLVM JITLink capable of linking a 32-bit ELF object file, with i386 specificrelocations, into a 32-bit process on the i386 hardware architecture.</p><h2 id="execution">Execution</h2><h3 id="understanding-high-level-constructs">Understanding high level constructs</h3><h4 id="linkgraphhttpsgithubcomllvmllvm-projectblob110c1b64a7b9984a604aa2809e0fb8c01278609dllvmincludellvmexecutionenginejitlinkjitlinkhl845"><a href="https://github.com/llvm/llvm-project/blob/110c1b64a7b9984a604aa2809e0fb8c01278609d/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L845">LinkGraph</a></h4><blockquote><p>The LLVM JITLink <a href="https://llvm.org/docs/JITLink.html#linkgraph">documentation</a> has an excellent description of LinkGraph.I recommend reading it after the below, high-level description of LinkGraph.</p></blockquote><p>LinkGraph is an internal representation of an object file within LLVM JITLink. While object formats may havedifferent schemas and terminology for similar concepts, they all aim to represent machine code that can be relocatedin virtual memory. The purpose of a LinkGraph is to provide a generic representation of these concepts and nuancesacross different object file formats.</p><p>To draw conceptual analogies between the LinkGraph and an object format, let’s use ELF as an example. An ELF objectcontains:</p><ol><li><strong>Sections</strong> - Any chunk of bytes that must be moved into memory as a unit.</li><li><strong>Symbols</strong> - A named chunk of bytes that could represent either data or executable instructions. Symbols occur aschildren of sections.</li><li><strong>Relocations</strong> - A description of how to fix up bytes within a section once the address of the relocation’starget symbol is resolved.</li></ol><p>A LinkGraph is capable of representing all of the above concepts. It first defines some building blocks.</p><ol><li><a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L105">Addressable</a> - Anything that can be assigned an address in the executor processâ virtual address space.</li><li><a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L152">Block</a> - A chunk of bytes that is addressable and occurs as part of a section.</li></ol><p>On top of these building blocks, it defines the higher level object format concepts.</p><ol><li><a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L410">Symbol</a> - Equivalent of a symbol in the ELF format. Represented using an offset from the base (address) of aBlock and a size in bytes.</li><li><a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L688">Section</a> - Equivalent of a section in the ELF format. Represented using a collection of symbols and blocks.</li><li><a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L61">Edge</a> - Equivalent of a relocation in the ELF format. Represented using an offset from the start of thecontaining block (indicating the storage location that needs to be fixed up), a pointer to the target whose address needs to be used for the fix-up and a kind to specify the patching formula.</li></ol><h4 id="jitlinkcontexthttpsgithubcomllvmllvm-projectblob4cb0b7ce3b4987446264312d582dac9c9a98a488llvmincludellvmexecutionenginejitlinkjitlinkhl1765"><a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L1765">JITLinkContext</a></h4><p>JITLinkContext represents the target process that you’re linking into, and it provides the JIT linker with theability to ask questions about and take actions within the process. This includes the ability to look up symbols andallocate memory, in the target process, as well as to publish the results of the linking process to the broaderenvironment. Specifically, the JITLinkContext informs others of the addresses it has assigned to symbols and when thosesymbols become available in memory.</p><h3 id="understanding-the-jit-linking-algorithm">Understanding the JIT linking algorithm</h3><p>The LLVM JITLink linking algorithm happens in multiple phases, with each phase consisting of passes over theLinkGraph and a call to the next phase at the end. In each phase the algorithm modifies the LinkGraph as needed, bythe end, producing a ready to execute in-memory image of the relocatable object that we started out with.</p><blockquote><p>Something that did not click for me initially, but simplified things significantly once it did, was the fact thatthe LinkGraph was just that, a graph! Re-reading LLVM JITLinkâs high-level description of the <a href="https://llvm.org/docs/JITLink.html#generic-link-algorithm">generic JIT linkingalgorithm</a> with this simple view of the LinkGraph madeit much easier and intuitive to make sense of what was going on in the JIT linking process.</p></blockquote><p>The algorithm also provides, implementers and users of JITLink, hooks to tap into the linking process. These hooks canbe used to achieve a number of things, including but not limited to, link-time optimizations, testing, validation etc.</p><h3 id="the-tangibles">The tangibles</h3><p>First, I set up a test loop to validate whether LLVM JITLink is able to link 32-bit i386 ELF objects, containingvalid i386/ELF relocations, into a 32 bit process. The existing llvm-jitlink tool, which is built and put into the binfolder by default when you build the LLVM project, came in handy. llvm-jitlink is a command line wrapper for theJITLink library. It takes relocatable objects as input and links them into the executor process using JITLink.</p><p>The tricky part here, at least for me, was to get a 32-bit llvm-jitlink ELF executable. By default, Clang producesexecutables for the host architecture because of which I had to understand cross-compilation<sup id="fnref:5"><a href="#fn:5" class="footnote-ref" role="doc-noteref">5</a></sup> (compiling for atarget different from the host architecture) since I was developing on x86-64 hardware. In order to obtain a 32-bitllvm-jitlink ELF executable, on an x86-64 system, I needed the following -</p><ol><li><p><strong>Cross-compiler</strong> - A cross-compiler that could generate 32 bit x86 code. Clang generates 32-bit x86 code if thefollowing flags are specified in the build configuration:</p><ol><li><code>CMAKE_CXX_FLAGS="-m32"</code> or <code>CMAKE_C_FLAGS="-m32"</code> - instructs Clang to generate 32-bit code instead of thedefault 64-bit code.</li><li><code>LLVM_DEFAULT_TARGET_TRIPLE=X86</code> - instructs Clang to generate machine code for the x86 target by default.</li></ol></li><li><p><strong>Target shared libraries</strong> - 32 bit x86 shared libraries, that might be checked against during compilation. In mycase installing <code>libstdc++.i686</code> and <code>glibc-devel.i686</code> sufficed since that is all I needed to generate programscontaining all possible i386/ELF relocations.</p></li></ol><blockquote><p>The full command that I used to generate my build configuration was -</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>cmake <span style="color:#f92672">-</span>DCMAKE_CXX_FLAGS<span style="color:#f92672">=</span><span style="color:#e6db74">"-m32"</span> <span style="color:#f92672">-</span>DCMAKE_C_FLAGS<span style="color:#f92672">=</span><span style="color:#e6db74">"-m32"</span> <span style="color:#960050;background-color:#1e0010">\</span> </span></span><span style="display:flex;"><span><span style="color:#f92672">-</span>DCMAKE_CXX_COMPILER<span style="color:#f92672">=<</span>PATH_PREFIX<span style="color:#f92672">>/</span>bin<span style="color:#f92672">/</span>clang<span style="color:#f92672">++</span> \</span></span><span style="display:flex;"><span><span style="color:#f92672">-</span>DCMAKE_BUILD_TYPE<span style="color:#f92672">=</span>Debug <span style="color:#960050;background-color:#1e0010">\</span> </span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// It is important that the `llvm-tblgen`executable is for the host architecture</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#f92672">-</span>DLLVM_TABLEGEN<span style="color:#f92672">=<</span>LLVM_BUILD_DIR_FOR_HOST_ARCH<span style="color:#f92672">>/</span>bin<span style="color:#f92672">/</span>llvm<span style="color:#f92672">-</span>tblgen \</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#f92672">-</span>DLLVM_DEFAULT_TARGET_TRIPLE<span style="color:#f92672">=</span>i386<span style="color:#f92672">-</span>unknown<span style="color:#f92672">-</span>linux<span style="color:#f92672">-</span>gnu \</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Set of targets that the compiler must be able to generate code for. </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Can save compilation time by omitting redundant target backends.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#f92672">-</span>DLLVM_TARGETS_TO_BUILD<span style="color:#f92672">=</span>X86 \</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#f92672">-</span>G <span style="color:#e6db74">"Ninja"</span> ..<span style="color:#f92672">/</span>llvm</span></span></code></pre></div></blockquote><p>The last piece of my test loop was the plumbing in LLVM JITLink, on top of which I could start adding i386/ELFrelocations. I added this plumbing as part of my first <a href="https://github.com/llvm/llvm-project/commit/29fe204b4e87dcd78bebd40df512e8017dffea8f">commit</a> to LLVM JITLink.At a high level, there were 2 things that I implemented in that commit -</p><ol><li><strong>ELFLinkGraphBuilder_i386</strong> - contained specialized logic for parsing i386/ELF relocations from an object file.</li><li><strong>ELFJITLinker_i386</strong> - contained specialized logic for fixing up i386/ELF relocations in the executable imagesupposed to be emitted to memory.</li></ol><p>Having set up a test loop, I incrementally added support for the following i386/ELF relocations to LLVM JITLink.</p><blockquote><p>Quick aside, before we talk about the individual relocations! Letâs recall what relocations are.</p><p>The compiler generates code which contains symbolic references to actual symbols (everything other than localvariables in a function and functions themselves). The compiler just refers to symbols by the names used by theprogrammer and leaves a set of TODOs for the linker to complete during linking.</p><p>In ELF objects, these TODOs are found in the <a href="https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html#scrolltoc">relocation</a>section. They tell the linker where and how a symbolic reference needs to be fixed. The linker then, for the mostpart, follows the compilerâs instructions and resolves all the relocations in the program. The linker can resolverelocations because it has a view of the entire compiled program.</p></blockquote><ol><li>R_386_32<ol><li><strong>What</strong> - Tells the linker to replace the symbolic reference with the symbolâs absolute memory address.</li><li><strong>When</strong> - Used to reference global and static variables in non position-independent code (PIC). PIC allows codeto be loaded at any address in memory, rather than at a fixed address.</li><li><strong>Code</strong> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">// Compile with => clang -m32 -c -o obj.o obj.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// declare a global variable x</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">int</span> x;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Compiler should generate a R_386_32 relocation here. </span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> x <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">50</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">4</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c7</span> <span style="color:#ae81ff">45</span> <span style="color:#a6e22e">fc</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">movl</span> <span style="color:#a6e22e">$0x0</span><span style="color:#f92672">,-</span><span style="color:#ae81ff">0x4</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span>)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Compiler wants to move the value of x into</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the eax register but doesn't know the address</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// of x. So it leaves a TODO for the linker and</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// temporarily uses 0 as x's address.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">b</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">a1</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">mov</span> <span style="color:#ae81ff">0x0</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">c</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_32</span> <span style="color:#a6e22e">x</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">10</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">c0</span> <span style="color:#ae81ff">01</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x1</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Same thing here</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#ae81ff">13</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">a3</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span><span style="color:#f92672">,</span><span style="color:#ae81ff">0x0</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">14</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_32</span> <span style="color:#a6e22e">x</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">18</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">31</span> <span style="color:#a6e22e">c0</span> <span style="color:#a6e22e">xor</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#a6e22e">a</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">c4</span> <span style="color:#ae81ff">04</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x4</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">esp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#a6e22e">d</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">d</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#a6e22e">e</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c3</span> <span style="color:#a6e22e">ret</span></span></span></code></pre></div></li></ol></li><li>R_386_PC32<ol><li><strong>What</strong> - Tells the linker to resolve the symbolic reference using the symbolâs relative offset to the currentprogram counter (PC). The linker finds the offset of the referenced symbol, relative to the PC and hard-codesit in the corresponding assembly instruction. At run time, the processor looks at the <a href="https://c9x.me/x86/html/file_module_x86_id_26.html">call instructionâsencoding</a> and knows that the operand to the instruction represents the symbolâs offset to the PC.</li><li><strong>When</strong> - Used to call functions in PIC.</li><li><strong>Code</strong> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">// Compile with => clang -m32 -ffunction-sections -c -o obj.o obj.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span> <span style="color:#75715e">// declare a global function x</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">void</span> x {}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Compiler should generate a R_386_PC32 relocation here. </span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> x();</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;</span></span><span style="display:flex;"><span> }</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">x</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">d</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">4</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c3</span> <span style="color:#a6e22e">ret</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">ec</span> <span style="color:#ae81ff">08</span> <span style="color:#a6e22e">sub</span> <span style="color:#a6e22e">$0x8</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">esp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">6</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c7</span> <span style="color:#ae81ff">45</span> <span style="color:#a6e22e">fc</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">movl</span> <span style="color:#a6e22e">$0x0</span><span style="color:#f92672">,-</span><span style="color:#ae81ff">0x4</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span>)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Compiler wants to call function x</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// but doesn't know its address. So it leaves</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// a TODO for the linker and temporarily uses garbage</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// bytes as x's address.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The linker will replace the garbage bytes 0xfffffffc</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// with `offset => PC - address of x`.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `e8` here tells the i386 processor that the operand</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// is a PC relative offset and that the address of x needs</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// to be computed using `PC + offset`</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">d</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">e8</span> <span style="color:#a6e22e">fc</span> <span style="color:#a6e22e">ff</span> <span style="color:#a6e22e">ff</span> <span style="color:#a6e22e">ff</span> <span style="color:#a6e22e">call</span> <span style="color:#a6e22e">e</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">+</span><span style="color:#ae81ff">0xe</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">e</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_PC32</span> <span style="color:#a6e22e">x</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">12</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">31</span> <span style="color:#a6e22e">c0</span> <span style="color:#a6e22e">xor</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">14</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">c4</span> <span style="color:#ae81ff">08</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x8</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">esp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">17</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">d</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">18</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c3</span> <span style="color:#a6e22e">ret</span></span></span></code></pre></div></li></ol></li></ol><blockquote><p>Another short detour to talk about dynamic linking because the remaining relocations are what enable dynamic linking.</p><p>In static linking, if your program accesses even a single symbol from a given library, then that entire library islinked with your program, which among other issues, increases the size of the generated executable. For instance, letâstalk about that simple C program that just prints hello world again. With static linking, the executable thatâsgenerated from your program is going to pull in the entire C standard library, because your program accessed theprintf function.</p><p>In dynamic linking, referenced libraries are accessed at build time but they are not brought into the linkedexecutable. Instead, the referenced global variables from these libraries are linked at load time (when the program isloaded into memory, to be run) and referenced functions from these libraries are linked at invocation time.</p><p>Thereâs pros and cons to both approaches, whose details I will not go into, but will cursorily mention below.</p><ol><li><p>With static linking the only thing the user of your executable needs is the executable itself. They wonât runinto issues of missing libraries.</p></li><li><p>With dynamic linking you donât need to update your executable, if the shared library is updated. This isespecially useful if you are distributing your executable.</p></li><li><p>Dynamic linking is just harder to implement than static linking.</p></li></ol></blockquote><blockquote><p>If youâre not already familiar with the concepts of GOT and PLT, I also recommend you take yet another quick detourfor some <a href="#what-are-got-and-plt">visual explanations</a>!</p></blockquote><ol start="3"><li>R_386_GOTPC -<ol><li><strong>What</strong> - Tells the linker to replace the symbolic reference with the delta between the storage location, wherethe relocation has to be applied (or the fixup location) and the address of the GLOBAL_OFFSET_TABLE (GOT) symbol.</li><li><strong>When</strong> - This relocation isnât used in isolation. Rather it is an enabler for R_386_GOTOFF, R_386_GOT32 andR_386_PLT32, which need to use the memory address of the GOT.</li><li><strong>Code</strong> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">// Compile with => clang -m32 -fPIC -c -o obj.o obj.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Declare a global static</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">static</span> <span style="color:#66d9ef">int</span> a <span style="color:#f92672">=</span> <span style="color:#ae81ff">42</span>;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Since we passed the `PIC` flag to Clang to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// indicate that we want position independent code</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// Clang will generate code to access `a` using</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// the GOT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">return</span> a;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">50</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// This `call` instr is just telling the processor to</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// push the next instr's address on the stack and jump to</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// address 9. But 9 is the address of the next line. That's</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// weird...</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#ae81ff">4</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">e8</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">call</span> <span style="color:#ae81ff">9</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">+</span><span style="color:#ae81ff">0x9</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// And now that we did jump to 9, all we did was pop </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the value that was on the stack and store it in ebx.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Wasn't the value on the stack just 9's address? Even </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// weirder...</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#ae81ff">9</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">58</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Wait a minute. The compiler left a TODO here for the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// linker, to find the delta between the fixup location </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// and the address of the GOT. </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Ok, so if the address of the GOT was let's say 20, </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// then the linker will try to hardcode the value </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `0x20-0xc => 0x14` and add it to the value in eax (0x9),</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// which will give us `0x14 + 0x9 => 0x1d`. </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Ah, that's not the address of the GOT. Yes, but </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `0x1d + 0x3 => 0x20` is. Well, where is the 3 coming from?</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The compiler helps us here, a bit. The address in eax isn't</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the address of the fixup location it's off by 0x3. So along</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// with leaving us a TODO, the compiler also leaves us a reminder</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// to add 0x3 to our delta calculation, in order to arrive at </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the correct address of the GOT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">a</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">81</span> <span style="color:#a6e22e">c0</span> <span style="color:#ae81ff">03</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x3</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">c</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_GOTPC</span> <span style="color:#a6e22e">_GLOBAL_OFFSET_TABLE_</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Not super important what happens after the R_386_GOTPC</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// relocation is resolved for now...</span></span></span></code></pre></div></li></ol></li><li>R_386_GOTOFF -<ol><li><strong>What</strong> - Tells the linker to resolve the symbolic reference with the offset between the symbolâs address andthe address of the GOTâs base (computed and stored in a register when the R_386_GOTPC relocation is handled).</li><li><strong>When</strong> - Used by shared libraries and executables to access internal symbols in a position independent way.</li><li><strong>Code</strong> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">// Compile with => clang -m32 -fPIC -c -o obj.o obj.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Declare a global static</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">static</span> <span style="color:#66d9ef">int</span> a <span style="color:#f92672">=</span> <span style="color:#ae81ff">42</span>;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Since we passed the `PIC` flag to Clang to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// indicate that we want position independent code</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// Clang will generate code to access `a` using</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// the GOT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">return</span> a;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">50</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">4</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">e8</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">call</span> <span style="color:#ae81ff">9</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">+</span><span style="color:#ae81ff">0x9</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">9</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">58</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// We saw above how the R_386_GOTPC relocation gets resolved</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// and that the ebx register contains the address of the </span></span></span><span style="display:flex;"><span><span style="color:#75715e">// GOT after the relocation is resolved.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">a</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">81</span> <span style="color:#a6e22e">c0</span> <span style="color:#ae81ff">03</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x3</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">c</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_GOTPC</span> <span style="color:#a6e22e">_GLOBAL_OFFSET_TABLE_</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">10</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c7</span> <span style="color:#ae81ff">45</span> <span style="color:#a6e22e">fc</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">movl</span> <span style="color:#a6e22e">$0x0</span><span style="color:#f92672">,-</span><span style="color:#ae81ff">0x4</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span>)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Compiler wants to access `a`, but since we told it</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// to generate position-independent code, it generates access</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// to `a` using the GOT and leaves a TODO for the linker to find</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the offset of `a` from the base of the GOT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The linker already knows the address of the base of the GOT</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// at this point - it's stored in ebx. It computes the address of</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `a` and fixes up the 4 bytes after `0x8b 0x80`, to store the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// offset between `a` and the GOT's base.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#ae81ff">17</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">8</span><span style="color:#a6e22e">b</span> <span style="color:#ae81ff">80</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">mov</span> <span style="color:#ae81ff">0x0</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebx</span>)<span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">19</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_GOTOFF</span> <span style="color:#a6e22e">a</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#a6e22e">d</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">c4</span> <span style="color:#ae81ff">04</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x4</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">esp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">20</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">d</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">21</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c3</span> <span style="color:#a6e22e">ret</span></span></span></code></pre></div></li></ol></li><li>R_386_GOT32<ol><li><strong>What</strong> - Tells the linker to resolve the symbolic reference with the offset between the address of the GOTâsbase and the symbolâs entry in the GOT (essentially computing an index into the GOT).</li><li><strong>When</strong> - Used by shared libraries and executable to access external data symbols in a position independent way.</li><li><strong>Code</strong> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">// Compile with => clang -m32 -fPIC -c -o obj.o obj.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Declaring that `a` is defined externally.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">extern</span> <span style="color:#66d9ef">int</span> a;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Since we passed the `PIC` flag to Clang to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// indicate that we want position independent code</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// Clang will generate code to access `a` using</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// the GOT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">return</span> a;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">50</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">4</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">e8</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">call</span> <span style="color:#ae81ff">9</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">+</span><span style="color:#ae81ff">0x9</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">9</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">59</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ecx</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// We saw above how the R_386_GOTPC relocation gets resolved</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// and that the ebx register contains the address of the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// GOT after the relocation is resolved.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">a</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">81</span> <span style="color:#a6e22e">c1</span> <span style="color:#ae81ff">03</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x3</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">c</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_GOTPC</span> <span style="color:#a6e22e">_GLOBAL_OFFSET_TABLE_</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">10</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c7</span> <span style="color:#ae81ff">45</span> <span style="color:#a6e22e">fc</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">movl</span> <span style="color:#a6e22e">$0x0</span><span style="color:#f92672">,-</span><span style="color:#ae81ff">0x4</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span>)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Compiler wants to access `a`, but since we told it to</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// generate position-independent code, it generates access to</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `a` using the GOT and leaves a TODO for the linker to find</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// the offset of `a`'s GOT entry from the base of the GOT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `a` got a GOT entry because we did not define it internally</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// and the compiler thinks that it will either come from another</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// source file or a shared library.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The linker already knows the address of the base of the GOT</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// at this point - it's stored in ebx. It finds the address of</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `a`'s GOT entry and fixes up the 4 bytes after `0x8b 0x81`,</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// to store the offset between `a`'s GOT entry and the GOT's base.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#ae81ff">17</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">8</span><span style="color:#a6e22e">b</span> <span style="color:#ae81ff">81</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">mov</span> <span style="color:#ae81ff">0x0</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebx</span>)<span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">19</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_GOT32</span> <span style="color:#a6e22e">a</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// eax, at this point contains `a`'s address, which is dereferenced</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// in this mov instruction and stored into eax itself.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#ae81ff">1</span><span style="color:#a6e22e">d</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">8</span><span style="color:#a6e22e">b</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">mov</span> (<span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span>)<span style="color:#f92672">,%</span><span style="color:#a6e22e">eax</span> </span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span><span style="color:#a6e22e">f</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">c4</span> <span style="color:#ae81ff">04</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x4</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">esp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">22</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">d</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff">23</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c3</span> <span style="color:#a6e22e">ret</span></span></span></code></pre></div></li></ol></li><li>R_386_PLT32<ol><li><strong>What</strong> - Tells the linker to resolve the symbolic reference with the symbolâs PLT entry.</li><li><strong>When</strong> - Used by shared libraries and executables to access external function symbols in aposition-independent way.</li><li><strong>Code</strong> -</li></ol><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#75715e">// Compile with => clang -m32 -fPIC -c -o obj.o obj.c</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Declaring that `foo` is a function defined externally.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">extern</span> <span style="color:#66d9ef">int</span> <span style="color:#a6e22e">foo</span>(<span style="color:#66d9ef">void</span>);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>(<span style="color:#66d9ef">void</span>) {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Since we passed the `PIC` flag to Clang to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// indicate that we want position independent code</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// Clang will generate code to access `foo` using</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// the PLT.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#66d9ef">return</span> foo();</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span> <span style="color:#ae81ff">00000000</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">>:</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">0</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">55</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">1</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">89</span> <span style="color:#a6e22e">e5</span> <span style="color:#a6e22e">mov</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">esp</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">3</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">53</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">4</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">50</span> <span style="color:#a6e22e">push</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">5</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">e8</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">call</span> <span style="color:#a6e22e">a</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">+</span><span style="color:#ae81ff">0xa</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">a</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">b</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#75715e">// We saw above how the R_386_GOTPC relocation gets resolved</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// and that the ebx register contains the address of the </span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// GOT after the relocation is resolved.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#a6e22e">b</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">81</span> <span style="color:#a6e22e">c3</span> <span style="color:#ae81ff">03</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x3</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">d</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_GOTPC</span> <span style="color:#a6e22e">_GLOBAL_OFFSET_TABLE_</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">11</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c7</span> <span style="color:#ae81ff">45</span> <span style="color:#a6e22e">f8</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#ae81ff">00</span> <span style="color:#a6e22e">movl</span> <span style="color:#a6e22e">$0x0</span><span style="color:#f92672">,-</span><span style="color:#ae81ff">0x8</span>(<span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span>)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#75715e">// Compiler wants to access `foo`, but since we told it to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// generate position-independent code, it generates access to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// `foo` using its PLT entry and leaves a TODO for the linker to</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// find `foo`'s PLT entry address.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// The PLT machinery was explained here!</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#ae81ff">18</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">e8</span> <span style="color:#a6e22e">fc</span> <span style="color:#a6e22e">ff</span> <span style="color:#a6e22e">ff</span> <span style="color:#a6e22e">ff</span> <span style="color:#a6e22e">call</span> <span style="color:#ae81ff">19</span> <span style="color:#f92672"><</span><span style="color:#a6e22e">main</span><span style="color:#f92672">+</span><span style="color:#ae81ff">0x19</span><span style="color:#f92672">></span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">19</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">R_386_PLT32</span> <span style="color:#a6e22e">foo</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">1</span><span style="color:#a6e22e">d</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">83</span> <span style="color:#a6e22e">c4</span> <span style="color:#ae81ff">04</span> <span style="color:#a6e22e">add</span> <span style="color:#a6e22e">$0x4</span><span style="color:#f92672">,%</span><span style="color:#a6e22e">esp</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">20</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">b</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebx</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">21</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">5</span><span style="color:#a6e22e">d</span> <span style="color:#a6e22e">pop</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">ebp</span></span></span><span style="display:flex;"><span> <span style="color:#ae81ff">22</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">c3</span> <span style="color:#a6e22e">ret</span></span></span></code></pre></div></li></ol><h2 id="testing">Testing</h2><p>While I did talk about setting up a âtest loopâ earlier, here I want to briefly touch upon the topic of regressiontests – not so much upon the âwhyâ and the âwhatâ, but the âhowâ. Thereâs some excellent testing utilities alreadyavailable in the LLVM project, but I found related documentation to be lagging. Specifically, I want to focus on theutilities that one might interact with for writing a regression test for one of LLVM JITLinkâs target-object backend.</p><p>Before we go ahead, I want to mention this high level <a href="https://llvm.org/docs/TestingGuide.html#writing-new-regression-tests">testing guide</a>for LLVM. The guide should get you to the point where you know where/how to create a test file, how to make your testsdiscoverable by the test runner (LLVM Integration Tester - lit) and how to run the tests using the test runner.</p><p>That said, letâs use the sample test file below, to talk about the utilities that you might use for writing a regressiontest for one of LLVM JITLinkâs target-object backend.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#75715e">// Regression test files are assembly files (".s" extension).</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The files must begin with what are known as "RUN" lines.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Each "RUNâ line tells lit how to run the test file.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// RUN lines look and feel like you were running shell commands.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Each regression test will likely begin with the following</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// two RUN lines, although the exact RUN command may need to be</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// modified, based on the test cases need.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">RUN</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">llvm</span><span style="color:#f92672">-</span><span style="color:#a6e22e">mc</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">triple</span><span style="color:#f92672">=</span><span style="color:#a6e22e">i386</span><span style="color:#f92672">-</span><span style="color:#a6e22e">unknown</span><span style="color:#f92672">-</span><span style="color:#a6e22e">linux</span><span style="color:#f92672">-</span><span style="color:#a6e22e">gnu</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">position</span><span style="color:#f92672">-</span><span style="color:#a6e22e">independent</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">filetype</span><span style="color:#f92672">=</span><span style="color:#a6e22e">obj</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">o</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">t</span>.<span style="color:#a6e22e">o</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">s</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Notice how llvm-jitlink is run with the "-noexec" option.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The option tells llvm-jitlink to not run the code loaded</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// to memory. This is important because JITLink may be linking</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// and loading code for an architecture different from the one</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// where the regression test is running in LLVM's build/release</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// pipeline.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">RUN</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">llvm</span><span style="color:#f92672">-</span><span style="color:#a6e22e">jitlink</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">noexec</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">t</span>.<span style="color:#a6e22e">o</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// llvm-jitlink also requires each file to have a "main" function.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Your test code can go here, but it doesn't have to.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>.<span style="color:#a6e22e">text</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">globl</span> <span style="color:#a6e22e">main</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">p2align</span> <span style="color:#ae81ff">4</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">0x90</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">type</span> <span style="color:#a6e22e">main</span><span style="color:#f92672">,</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#66d9ef">function</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">main</span><span style="color:#f92672">:</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">ret</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">size</span> <span style="color:#a6e22e">main</span><span style="color:#f92672">,</span> .<span style="color:#f92672">-</span><span style="color:#a6e22e">main</span></span></span></code></pre></div><p>The main thing that we want to determine in these target-object backend regression tests is whether the relocations inthe code emitted to memory were fixed up correctly. Meaning, we have to literally check whether certain bytes in certainmemory locations are what we expect them to be. Letâs look at some more intricate test cases that will show thedifferent kinds of checks we might need to perform and how we can perform them.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-as" data-lang="as"><span style="display:flex;"><span><span style="color:#75715e">// llvm-jitlink allows you to specify jitlink-check expressions.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// jit-link check expressions are checks against working memory.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// jit-link check expressions can be used with the `decode_operand` function.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `decode_operand` decodes the instruction at the given label</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// and then accesses the operand number that you have specified.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// For the expression below, decode operand decodes the operand at the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// label `foo`, accesses its 0th operand `external_data` and checks whether</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// its value is equal to the bytes represented by `0xDEADBEEF`.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Note - The operand number does not always have a one-to-one mapping</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// with what you see and while in this case `external_data` was indeed the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 0th operand of the instruction, for another instruction its operand</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// number may have been different.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">jitlink</span><span style="color:#f92672">-</span><span style="color:#a6e22e">check</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">decode_operand</span>(<span style="color:#a6e22e">foo</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">0</span>) <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span><span style="color:#a6e22e">xDEADBEEF</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">globl</span> <span style="color:#a6e22e">foo</span> </span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">p2align</span> <span style="color:#ae81ff">4</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">0x90</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">type</span> <span style="color:#a6e22e">foo</span><span style="color:#f92672">,</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#66d9ef">function</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">foo</span><span style="color:#f92672">:</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">movl</span> <span style="color:#a6e22e">external_data</span><span style="color:#f92672">,</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">size</span> <span style="color:#a6e22e">foo</span><span style="color:#f92672">,</span> .<span style="color:#f92672">-</span><span style="color:#a6e22e">foo</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The RHS of jitlink-check expressions doesn't have to be literal</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// bytes. It can be an expression of labels and other functions over</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// labels.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// In the below jitlink-check expression, the RHS</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// is calculating the difference between the address of the label</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `foo` and the address of the program counter when the instruction at label</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// `bar` is executed.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">jitlink</span><span style="color:#f92672">-</span><span style="color:#a6e22e">check</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">decode_operand</span>(<span style="color:#a6e22e">bar</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">0</span>) <span style="color:#f92672">=</span> <span style="color:#a6e22e">foo</span> <span style="color:#f92672">-</span> <span style="color:#a6e22e">next_pc</span>(<span style="color:#a6e22e">bar</span>)</span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">globl</span> <span style="color:#a6e22e">bar</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">p2align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">type</span> <span style="color:#a6e22e">bar</span><span style="color:#f92672">,</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#66d9ef">function</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">bar</span><span style="color:#f92672">:</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">calll</span> <span style="color:#a6e22e">foo</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">size</span> <span style="color:#a6e22e">bar</span><span style="color:#f92672">,</span> .<span style="color:#f92672">-</span><span style="color:#a6e22e">bar</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The `got_addr`function can also be used on the RHS, to access the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// address of the GOT entry of a symbol.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// In the below jitlink-check expression, the RHS is calculating the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// offset between the GOT entry for the symbol `named_data` and the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// GOT symbol itself.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">jitlink</span><span style="color:#f92672">-</span><span style="color:#a6e22e">check</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">decode_operand</span>(<span style="color:#a6e22e">test_got</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">4</span>) <span style="color:#f92672">=</span> <span style="color:#a6e22e">got_addr</span>(<span style="color:#a6e22e">test_file_name</span>.<span style="color:#a6e22e">o</span><span style="color:#f92672">,</span> <span style="color:#a6e22e">named_data</span>) <span style="color:#f92672">-</span> <span style="color:#a6e22e">_GLOBAL_OFFSET_TABLE_</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">globl</span> <span style="color:#a6e22e">test_got</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">p2align</span> <span style="color:#ae81ff">4</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">0x90</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">type</span> <span style="color:#a6e22e">test_got</span><span style="color:#f92672">,</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#66d9ef">function</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">test_got</span><span style="color:#f92672">:</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">leal</span> <span style="color:#a6e22e">named_data</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">GOT</span><span style="color:#f92672">,</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">size</span> <span style="color:#a6e22e">test_got</span><span style="color:#f92672">,</span> .<span style="color:#f92672">-</span><span style="color:#a6e22e">test_got</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// The LHS of a jitlink-check expression, can also be constructed manually</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// by "casting" a symbol, label or a function over a label to a machine register</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// size pointer.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">//</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// In the below jitlink-check expression the LHS is constructed by casting the</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// address of the GOT entry for `named_data` to a 32-bit pointer. The constructed</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// pointer is then dereferenced and compared against the `named_data` label.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">jitlink</span><span style="color:#f92672">-</span><span style="color:#a6e22e">check</span><span style="color:#f92672">:</span> <span style="color:#f92672">*</span>{<span style="color:#ae81ff">4</span>}(<span style="color:#a6e22e">got_addr</span>(<span style="color:#a6e22e">test_file_name</span>.<span style="color:#a6e22e">o</span><span style="color:#f92672">,</span> <span style="color:#a6e22e">named_data</span>)) <span style="color:#f92672">=</span> <span style="color:#a6e22e">named_data</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">globl</span> <span style="color:#a6e22e">test_got</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">p2align</span> <span style="color:#ae81ff">4</span><span style="color:#f92672">,</span> <span style="color:#ae81ff">0x90</span></span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">type</span> <span style="color:#a6e22e">test_got</span><span style="color:#f92672">,</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#66d9ef">function</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">test_got</span><span style="color:#f92672">:</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">leal</span> <span style="color:#a6e22e">named_data</span><span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">GOT</span><span style="color:#f92672">,</span> <span style="color:#f92672">%</span><span style="color:#a6e22e">eax</span></span></span><span style="display:flex;"><span>.<span style="color:#a6e22e">size</span> <span style="color:#a6e22e">test_got</span><span style="color:#f92672">,</span> .<span style="color:#f92672">-</span><span style="color:#a6e22e">test_got</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// NOTE - The above presented flavors of jitlink-check expressions is not an</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// exhaustive list of what's available. Rather it's just a summarization of some</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// of the ways in which I used jitlink-check expressions.</span></span></span></code></pre></div><h2 id="recap-and-conveniences">Recap and conveniences</h2><p>We covered a lot of ground there. Letâs quickly recap the things we talked about.</p><ol><li>We established the context required to understand the project. We defined basic concepts - linking and JITlinking, and talked about the need for JIT linking and LLVM JITLink.</li><li>We established an understanding of what the project was.</li><li>We went over the execution details of the project. We talked about important high level constructs, the high level JIT linking algorithm used by LLVM JITLink, setting up a testing loop for constant feedback and the details of each relocation that was added as part of the i386/ELF backend.</li><li>Finally, we talked about the tools and utilities that can be used to write regression tests for the project.</li></ol><h3 id="resources">Resources</h3><p>Below is an index of resources that I found useful (I may have mentioned them elsewhere in the post as well).</p><ol><li><a href="https://www.youtube.com/playlist?list=PLhy9gU5W1fvUND_5mdpbNVHC1WCIaABbP">Chris Kanichâs videos</a> for the systems programming course at University of Illinois, Chicago</li><li>Lang Hames’ videos (<a href="https://www.youtube.com/watch?v=hILdR8XRvdQ&t=2577s">1</a>, <a href="https://www.youtube.com/watch?v=MOQG5vkh9J8">2</a>, and <a href="https://www.youtube.com/watch?v=i-inxFudrgI&t=2243s">3</a>) on LLVM ORC APIs and JITLink. Thesevideos were extremely valuable in understanding JITLink’s raison d’être and the context in which it is used.</li><li>Linkers and Loaders by John R. Levine</li><li><a href="https://docs.oracle.com/cd/E23824_01/html/819-0690/toc.html">Oracleâs Linker and Libraries guide</a></li><li><a href="https://llvm.org/docs/JITLink.html">LLVM JITLink documentation</a></li><li><a href="https://llvm.org/docs/TestingGuide.html">LLVM testing infrastructure guide</a></li><li>Articles by Eli Bendersky on <a href="https://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/#id14">position-independent code</a> and <a href="https://eli.thegreenplace.net/2011/08/25/load-time-relocation-of-shared-libraries">load time relocation of sharedlibraries</a>.</li></ol><h3 id="development-conveniences">Development conveniences</h3><ol><li><strong>Dev setup</strong><ol><li>Thereâs detailed information about that on the <a href="https://llvm.org/docs/GettingStarted.html">getting started with LLVM page</a>.</li><li>If youâre okay using AWS EC2 for development you can create an instance using my public machine image.<ol><li>The image id is ami-00f1c534fe06c05a0. You can use the instructions <a href="https://aws.amazon.com/premiumsupport/knowledge-center/launch-instance-custom-ami/">here</a> to boot your instance usingthis image.</li><li>The instance comes with all the basic tools and softwares that you need to start contributing to LLVM - Clang, CMake, Python, zlib, ninja, git, php, arc.</li></ol></li></ol></li><li><strong>Build system</strong><ol><li>Use <code>ninja</code>! It is way faster than <code>make</code>.</li><li>If you want to build a <code>llvm-jitlink</code> binary, which you likely will for testing, just run <code>ninja llvm-jitlink</code>from your build folderâs root. This will avoid building other targets that you do not need and will complete much faster.</li><li>Other than that Iâm going to refrain from saying too much here because oneâs build system configuration rarely works on anotherâs machine.</li></ol></li><li><strong>Files you will be dealing with</strong><ol><li>Youâll likely be dealing with files under <a href="https://github.com/llvm/llvm-project/tree/main/llvm/lib/ExecutionEngine/JITLink">llvm/lib/ExecutionEngine/JITLink</a>.</li><li>The introductory commit for the <a href="https://github.com/llvm/llvm-project/commit/29fe204b4e87dcd78bebd40df512e8017dffea8f">i386/ELF</a> and <a href="https://github.com/llvm/llvm-project/commit/2ed91da0f1f312aedcfa01786fe991e33c6cf1fe">AArch64/ELF</a> backends will giveyou a very good idea of what aminimal backend implementation looks like. Keep in mind that these first commits are for backends for an existing object format (ELF in this case). If you are adding support for a backend without an existing object format, you might need to ask for help (more on that in a bit).</li></ol></li><li><strong>Code reviews</strong><ol><li>Install <a href="https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/">arcanist</a> - the tool for creating code reviews when contributing to LLVM.</li><li>Once installed the main commands you will be using are (assuming you are using git as your version control) -<ol><li>arc diff - To create code reviews and new revisions.</li><li>arc land - To close code reviews once they are approved and push changes to remote.</li></ol></li></ol></li><li><strong>Asking for help</strong><ol><li><a href="https://discord.gg/9v3CBuKpbx">#jit</a> channel of the LLVM discord server.</li></ol></li></ol><h2 id="closing-thoughts">Closing thoughts</h2><p>And thatâs about it! I donât have too much more to say on top of whatâs already been said. It was a great learningexperience contributing to LLVM JITLink. Iâd recommend it to anyone who wants to understand the story after compilationand up until a program is run - come say hi on the #jit channel of the LLVM discord server!</p><p>Iâd also like to give a big shout out to the folks on the #jit channel for helping me understand things and answering myquestions. And a special thanks to <a href="https://github.com/lhames">Lang Hames</a> for his help throughout the project andreviewing this post (thanks to <a href="https://github.com/weliveindetail">Stefan Gränitz</a> and <a href="https://github.com/vgvassilev">Vassil Vassilev</a>for reviewing as well)!</p><p>I plan on continuing my involvement with LLVM and JITLink, and am excited to see what I pick up next!</p><h2 id="appendix">Appendix</h2><h3 id="what-are-got-and-plt">What are GOT and PLT?</h3><p>The GLOBAL_OFFSET_TABLE (GOT) and PROCEDURE_LINKAGE_TABLE (PLT) are 2 tables used during the linking process thatmake dynamic linking work. Dynamically linked code needs to be position-independent<sup id="fnref:6"><a href="#fn:6" class="footnote-ref" role="doc-noteref">6</a></sup>, meaning that it should beable to be loaded at any address in memory and continue to work - all symbols that it references and all referencedsymbols that it contains, must be resolvable. Dynamically linked shared libraries can fulfill this position independencerequirement for internal symbols using pc-relative addressing, as the code of the shared libraries stays together inmemory. However, these libraries may also refer to external symbols or contain symbols, referenced by other sharedlibraries or the main executable. And since the load address of shared libraries, in memory, is not fixed, they requireanother layer of abstraction for the resolution of external symbols, for both data and functions. GOT and PLT are thoseabstractions.</p><p>Below are some simple visual examples to understand the GOT and PLT.</p><ol><li>Data symbol access through GOT</li></ol><div style="max-width:2000px; margin:0 auto;"> <img src="https://blog.llvm.org/img/jitlink-new-backend-GOT-2023-03-16.jpg"><br/></div><ol start="2"><li><p>Function symbol access through PLT</p><ol><li><p><strong>At load time</strong></p><ol><li>Call to x is generated via the PLT.</li><li>There is also an entry for x in the GOT, whose purpose will become clear in a minute.</li></ol></li></ol> <div style="max-width:2000px; margin:0 auto;"> <img src="https://blog.llvm.org/img/jitlink-new-backend-PLT-2023-03-16.png"><br/> </div><br><ol start="2"><li><p><strong>At first invocation time</strong></p><ol><li>Control jumps to PLT[1]</li><li>First instr of PLT[1] transfers control to *GOT[3] (the address stored in GOT[3]).<ol><li>Remember the address stored in GOT[3] is that of the 2nd instr of PLT[1].</li><li>Wait, so we go all the way to the PLT, to then go all the way to the GOT only to come back to the next instr in PLT[1]. We would have come there anyways as the processor processed instructions sequentially. Why did we take this roundabout route?</li><li>Weâll see in a second!</li></ol></li><li>Once weâre on the 2nd instr of PLT we push a value on the stack (what this value means is not super important here).</li><li>Then control jumps to PLT[0], from where you can see it eventually jumps to the address stored in GOT[2].<ol><li>And whose address is stored in GOT[2]? The dynamic linkerâs!</li></ol></li><li>The dynamic linker then goes ahead and links x (the external lib function we called) into the process and fixes the address in GOT[3] (which was initially the address of the 2nd instr of PLT[1]) to the new address of x in the process.</li><li>The dynamic linker then invokes x, which is what the user wanted to do in the first place.</li></ol></li></ol> <div style="max-width:2000px; margin:0 auto;"> <img src="https://blog.llvm.org/img/jitlink-new-backend-PLT2-2023-03-16.png"><br/> </div><br><ol start="3"><li><strong>Subsequent invocations</strong><ol><li>The first invocation of x looked like this -<ol><li>PLT[1] â *GOT[3] â PLT[1] â PLT[0] â *GOT[2] â x()</li></ol></li><li>However, since the dynamic linker now fixed the entry in GOT[3] to reflect xâs address, subsequent invocations of x look as below -<ol><li>PLT[1] â *GOT[3] (which is essentially calling x, since that is what GOT[3] stores now)</li></ol></li></ol></li></ol></li></ol><p>With the above process dynamic linking enables us to call a functions in position-independent code. Additionally, itmakes the common case (every invocation of x other than the first) faster!</p><h2 id="footnotes">Footnotes</h2><div class="footnotes" role="doc-endnotes"><hr><ol><li id="fn:1"><p>AOT, statically compiled languages - C, C++, Rust, unlike interpreted languages, such as Java, do not have aruntime that can be extended to bring in new symbols at runtime and perform symbol resolution for them. Java, forinstance, has the Java Virtual Machine (JVM) whose <a href="https://www.artima.com/insidejvm/ed2/lifetype.html">loading and linking</a> behavior can be customized to achievethe aforementioned task. <a href="#fnref:1" class="footnote-backref" role="doc-backlink">↩︎</a></p></li><li id="fn:2"><p>JIT-linking is primarily useful in the context of linking in pre-compiled languages (that’s certainly whatinspired it), but it’s not only useful in that context. In LLVM JITLink, through the <a href="https://github.com/llvm/llvm-project/blob/4cb0b7ce3b4987446264312d582dac9c9a98a488/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h#L1765">JITLinkContext</a> you canlink against other (non-statically compiled) code, so it’s useful for anyone who wants to interoperate with C/C++ that’s linked at runtime. You could also theoretically bring up a purely JIT’d language with it (and I think Julia does this). The advantages are interoperability with existing languages, compilers, tools, and the disadvantage is that it’s heavyweight compared to a custom JIT that manages its own linking directly. <a href="#fnref:2" class="footnote-backref" role="doc-backlink">↩︎</a></p></li><li id="fn:3"><p>Clang-REPL is an effort to move Cling, which is a standalone tool, into the LLVM infrastructure. <a href="#fnref:3" class="footnote-backref" role="doc-backlink">↩︎</a></p></li><li id="fn:4"><p>In fact, given a suitable JITLinkContext, JITLink can even link objects into a different process. LLDB uses thiscapability (via LLVMâs older MCJIT APIs) to JIT-link expressions in the debugger, but run them in the process being debugged, which may be on a different machine. <a href="#fnref:4" class="footnote-backref" role="doc-backlink">↩︎</a></p></li><li id="fn:5"><p>I found the following 2 resources very useful for understanding cross-compilation.</p><ol><li>âCross-platform Compilationâ chapter of the <a href="https://www.oreilly.com/library/view/getting-started-with/9781782166924/?_gl=1*142ghif*_ga*MTU5OTExNzkyNS4xNjc1MTc2MTkw*_ga_092EL089CH*MTY3Njc3NzE5MC4zLjEuMTY3Njc3NzMxMS42MC4wLjA.">Getting Started with LLVM Core Libraries</a> book.</li><li>Clang <a href="https://clang.llvm.org/docs/CrossCompilation.html">documentation</a> for cross-compiling.</li></ol> <a href="#fnref:5" class="footnote-backref" role="doc-backlink">↩︎</a></li><li id="fn:6"><p>Dynamically linked code can actually use the “static” relocation model, but the position-independent model isgenerally preferred. In position-independent code you only need to fix up the GOT, whereas in static code you need to fix up every external reference, which can hurt launch times. <a href="#fnref:6" class="footnote-backref" role="doc-backlink">↩︎</a></p></li></ol></div>
- The 2023 EuroLLVM Developers' Meeting Programhttps://blog.llvm.org/posts/2023-03-27-eurollvm2023-program/Mon, 27 Mar 2023 00:00:00 +0000https://blog.llvm.org/posts/2023-03-27-eurollvm2023-program/<p><img src="https://blog.llvm.org/img/EuroLLVM2023-horizontal.jpg" alt="2023 EuroLLVM Developers’ Meeting"></p><p>The LLVM Foundation is excited to announce the <a href="https://llvm.swoogo.com/2023eurollvm/">2023 EuroLLVM Developers’ Meeting</a> program! <strong>Early bird <a href="https://llvm.swoogo.com/2023eurollvm/begin">registration</a> ends April 10th.</strong></p><p><strong>Keynotes:</strong></p><ul><li>Order out of Chaos, The LLVM Release Process. - <em>Tobias Hieta</em></li><li>â-fbounds-safetyâ: Enforcing bounds safety for production C code - <em>Yeoul Na</em></li></ul><p><strong>Technical Talks:</strong></p><ul><li>An example of data flow analysis in MLIR - <em>Tom Eccles</em></li><li>MLIR-based offline memory planning and other graph-level optimizations for xcore.ai - <em>Deepak Panickal</em></li><li>A Rusty CHERI: The path to hardware capabilities in Rust - <em>Lewis Revill</em></li><li>Extending the AArch32 JITLink backend - <em>Stefan Gränitz</em></li><li>Using MLIR to Optimize Basic Linear Algebraic Subprograms - <em>Steven Varoumas</em></li><li>Buddy Compiler: An MLIR-based Compilation Framework for Deep Learning Co-design - <em>Hongbin Zhang</em></li><li>MachineScheduler - fine grain resource allocation using resource intervals. - <em>Francesco Petrogalli</em></li><li>Inliner in MLIR - <em>Javed Absar</em></li><li>How to use llvm-debuginfo-analyzer tool. - <em>Carlos Alberto Enciso</em></li><li>Practical Global Merge Function with ThinLTO - <em>Kyungwoo Lee</em></li><li>Prototyping MLIR in Python - <em>Sasha Lopoukhine, Mathieu Fehr</em></li><li>Extensible and Composable Dataflow Analysis in MLIR - <em>Jeff Niu</em></li><li>What would it take to remove debug intrinsics? - <em>Jeremy Morse</em></li><li>Compiling Ruby (with MLIR) - <em>Alex Denisov</em></li><li>Whatâs new in MLIR? - <em>Mehdi Amini</em></li><li>Structured Bindings and How to Analyze Them - <em>Domján Dániel</em></li><li>MLIR Dialect Design and Composition for Front-End Compilers - <em>Jeff Niu</em></li><li>ML-LLVM-Tools: Towards Seamless Integration of Machine Learning in Compiler Optimizations - <em>S. VenkataKeerthy, Siddharth Jain, Umesh Kalvakuntla</em></li><li>Optimizing the Linux Kernel with LLVM BOLT - <em>Maksim Panchenko</em></li><li>mlir-meminfo : A Memory Model for MLIR - <em>Kunwar Grover,Arjun Pitchanathan</em></li></ul><p><strong>Tutorials:</strong></p><ul><li>Developing BOLT pass - <em>Amir Ayupov</em></li><li>A whirlwind tour of the LLVM optimizer - <em>Nikita Popov</em></li><li>Tutorial: Controllable Transformations in MLIR - <em>Alex Zinenko</em></li><li>GlobalISel by example - <em>Alex Bradbury</em></li></ul><p><strong>Quick Talks:</strong></p><ul><li>Iterative Compilation - Give the compiler a second chance - <em>Ziv Ben Zion</em></li><li>Another level of indirection - Compiler Fallback of load/store into gather/scatter enhance compiler robustness by overcoming analysis and hardware limitations - <em>Omer Aviram</em></li><li>Switch per function in LLVM - <em>Tomer Nissim Schneider</em></li><li>Tensor Evolution - An ML Graph Optimization Technique - <em>Javed Absar,Muthu Baskaran</em></li><li>ML-on-CPU: should vectorization happen in the LLVM backend or higher up the stack? - <em>Elen Kalda</em></li><li>CORE-V LLVM: Adding eight vendor extensions to standard RISC-V LLVM - <em>Charlie Keaney,Chunyu Liao (å»æ¥ç),Lewis Revill</em></li><li>Advanced Bug Reports: Choose Your Own Adventure - <em>Arseniy Zaostrovnykh</em></li><li>Multiple-Entry, Multiple-Exit MLIR Regions - <em>Jeff Niu</em></li><li>Target-Independent Integer Arithmetic - <em>Jeff Niu</em></li><li>Improving Vectorization for Loops with Control Flow - <em>Ashutosh Nema</em></li><li>How to run the LLVM-Test Suite on GPUs and what youâll find - <em>Johannes Doerfert</em></li><li>OpenMP as GPU Kernel Language - <em>Johannes Doerfert</em></li></ul><p><strong>Lightning Talks:</strong></p><ul><li>LLVM IR as an Embedded Domain-Specific Language - <em>Nikita Baksalyar</em></li><li>Using MLIR for Dalvik Bytecode Analysis - <em>Eduardo Blázquez</em></li><li>High school studentâs experience with Clang - <em>Yubo Hui</em></li><li>Spot the Difference with LLVM-FLOW: an open-source interactive visualization tool for comparing IR CFGs - <em>Jinmyoung Lee</em></li><li>Leveraging MLIR for Better SYCL Compilation - <em>Victor Lomüller</em></li><li>Arm/AArch64 Embedded Development with LLD : Whatâs New - <em>Amilendra Kodithuwakku</em></li><li>Using automated tests to tune the -Og pipeline - <em>Stephen Livermore-Tozer</em></li><li>Buddy-CAAS: Compiler As A Service for MLIR - <em>Hongbin Zhang</em></li><li>llvm-buildmark - observations, tips, and tricks on reducing LLVM build times - <em>Alex Bradbury</em></li><li>Lock Coarsening optimizations for loops in Java - <em>Anna Thomas</em></li></ul><p><strong>Student Technical Talks</strong></p><ul><li>Cost Modelling for Register Allocation and Beyond - <em>Aiden Grossman</em></li><li>A Template-Based Code Generation Approach for MLIR - <em>Florian Drescher</em></li><li>MLIR Query Tool for easier exploration of the IR - <em>Devajith Valaparambil Sreeramaswamy</em></li><li>mlirSynth: Synthesis of Domain-Specific Programs in MLIR - <em>Alexander Brauckmann</em></li><li>Image Processing Ops as first class citizens in MLIR: write once, vectorise everywhere! - <em>Prathamesh Tagore,Hongbin Zhang</em></li><li>Using the Clang data-flow framework for null-pointer analysis - <em>Viktor Cseh</em></li><li>Fast and Vectorized Pivot Function for MLIR Presburger Library - <em>Qi</em></li><li>RISC-V Vector Extension Support in MLIR: Motivation, Abstraction, and Application - <em>Hongbin Zhang</em></li></ul><p><strong>Posters:</strong></p><ul><li>Automatic Translation of C++ to Rust - <em>Henrique Preto</em></li><li>A sustainable approach to have vector predication in the Loop Vectorizer - <em>Lorenzo Albano</em></li><li>Performance Analysis of Undefined Behavior Optimizations - <em>Lucian Popescu</em></li><li>Static Analysis for C++ Rust-Like Lifetime Annotations - <em>Susana Monteiro</em></li><li>Leveraging MLIR for Better SYCL Compilation - <em>Victor Lomüller</em></li><li>Forcefully Embedding MLIR into Python - <em>George Mitenkov</em></li></ul><p>We would also like to thank the program committee:</p><p>Kristof Beyls (<strong>Chair</strong>), Alex Bradbury, Alex Denisov, Anupama Chandrasekhar, David Spickett, Florian Hahn, Gabor Horvath,Hans Wennborg, Jakub Kuderski, Jonathan Springer, Jubi Taneja, Mehdi Amini, Michal Paczkowski, Min-Yih Hsu, Nadav Rotem, Paul Kirth, Petr Hosek, Quentin Colombet, Renato Golin, Stephen Neuendorffer, Timothy Harvey,and Tobias Grosser.</p><p>Register today to attend the <a href="https://llvm.swoogo.com/2023eurollvm/">2023 EuroLLVM Developers’ Meeting</a> in Glasgow, Scotland.</p>
- Interactive programming in C++ internships â LLVM Blog Posthttps://blog.llvm.org/posts/2022-12-21-compiler-research-internships/Wed, 21 Dec 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-12-21-compiler-research-internships/<hr><p>Another program year is ending and our <a href="https://compiler-research.org/">Compiler Research</a>team is extremely happy to share the hard work and the results of our internscontributors!</p><p>The Compiler Research team includes researchers located at Princeton Universityand CERN.Our primary goal is research into foundational software tools helping scientiststo program for speed, interoperability, interactivity, flexibility, andreproducibility. We work in various fields of science such as high energyphysics, where research is fundamentally connected to software at exabyte scale.We develop computational methods and research software for scientificexploration and discovery. Our current research focuses on three main topics:<a href="https://compiler-research.org/interactive_cpp">interpretative C/C++/CUDA</a>, automatic differentiation tools, and C++ language interoperability with Pythonand D.</p><p>This year, we had six participants who worked on seven projects, covering a widerange of topics, from LLVMâs new JIT linker(<a href="https://llvm.org/docs/JITLink.html#jit-linking">JITLink</a>) to<a href="https://clang.llvm.org/docs/ClangRepl.html">Clang-Repl</a>,an interactive C++ interpreter for incremental compilation integratedin <a href="https://clang.llvm.org/">Clang</a>. All projects rise toward acommon, ambitious goal: <strong>to establish a proficient workflow in LLVM,where <a href="https://compiler-research.org/interactive_cpp">interactivedevelopment in C++</a> is possible, and exploratory C++ becomes an accessibleexperience to a wider audience.</strong></p><p>Below you can find the list of projects from our interns, an overview of theobjectives and results. We invite you to follow the links to access a moredetailed description of each project.</p><h2 id="a-hrefhttpscompiler-researchorgassetsdocssunho_kim_gsoc22_reportpdfjitlink-support-for-a-new-formatarchitecture-elfaarch64a"><a href="https://compiler-research.org/assets/docs/Sunho_Kim_GSoC22_Report.pdf">JITLink support for a new format/architecture (ELF/AARCH64)</a></h2><p>Developer: <strong><a href="https://github.com/sunho">Sunho Kim</a></strong>(<em>Computer Science, De Anza College, Cupertino, California</em>)</p><p>Mentors: <strong>Stefan Gränitz</strong> (<em>Freelance Compiler Developer, Berlin,Deutschland</em>),<strong>Lang Hames</strong> (<em>Apple</em>), <strong>Vassil Vassilev</strong> (<em>Princeton University/CERN</em>)</p><p>Funding: <strong>Google Summer of Code 2022</strong></p><p>Suhno developed a <a href="https://llvm.org/docs/JITLink.html#jit-linking">JITLink</a>specialization that extends JITLinkâs generic linker algorithm, allowingJITLink to support ELF/aarch64 target and provides full support of all advancedPE/COFF object file features. By supporting the ELF/aarch64 target, JITLink cannow be used in Julia, while COFF/X86_64 enables Microsoft Visual C++ (MSCV)target in <a href="https://clang.llvm.org/docs/ClangRepl.html">Clang-Repl</a>.Here you can find Sunhoâs GSoC<a href="https://compiler-research.org/assets/docs/Sunho_Kim_GSoC22_Report.pdf">final report</a>.</p><p><strong>Hurray!</strong> This project has been accepted as a Tutorial at the<a href="https://llvm.swoogo.com/2022devmtg/speakers">2022 LLVM Developersâ Meeting</a>!The conference took place in San Jose, California, from 7th to 10th November2022.Here you can find the<a href="https://www.youtube.com/watch?v=UwHgCqQ2DDA&list=PL_R5A0lGi1ACZDCQw533fo2dBljmOqIYx&index=42">video</a>and the <a href="https://llvm.org/devmtg/2022-11/slides/Tutorial2-JITLink.pdf">slides</a>of Sunhoâs presentation.</p><p>The project was also presented at the Compiler As a Service (CaaS) monthlymeeting. Here you can find the <a href="https://www.youtube.com/watch?v=_5_gm58sQIg">video</a>and the <a href="https://compiler-research.org/assets/presentations/S_Kim-Jitlink_Coff.pdf">slides</a>of Sunhoâs presentation.</p><h2 id="a-hrefhttpscompiler-researchorgblogsgsoc22_izvekov_experience_blogextend-clang-to-resugar-template-specialization-accessesa"><a href="https://compiler-research.org/blogs/gsoc22_izvekov_experience_blog/">Extend Clang to resugar template specialization accesses</a></h2><p>Developer: <strong><a href="https://github.com/mizvekov">Matheus Izvekov</a></strong></p><p>Mentors: <strong>Richard Smith</strong> (<em>Google</em>), <strong>Vassil Vassilev</strong> (<em>PrincetonUniversity/CERN</em>)</p><p>Funding: <strong>Google Summer of Code 2022</strong></p><p><a href="https://clang.llvm.org/">Clang</a>âs type system was optimized bypushing type-syntactic-sugar on the arguments of a template specialization intothose member accesses. This was achieved by: 1. creating a new type node intothe Abstract Syntax Tree (AST) that represents the sugar of a member access ina template specialization; and 2. implementing single step desugaring logicwhich will perform the substitution of template parameter sugar into thecorresponding specialization argument sugar. As a result, we improved Clangâsdiagnostic system by enabling other constructs to preserve type sugar, allowingboth for their representation when present in the specialization argument.Here you can find Matheus’ GSoC<a href="https://compiler-research.org/assets/docs/Matheus_Izvekov_GSoC22_Report.pdf">final report</a>.</p><p><strong>Hurray!</strong> This project has been accepted as a Lightning Talk at the<a href="https://llvm.swoogo.com/2022devmtg/speakers">2022 LLVM Developersâ Meeting</a>!The conference took place in San Jose, California, from 7th to 10th November2022.Here you can find the <a href="https://www.youtube.com/watch?v=bZ2HPrSkTZI">video</a>and the<a href="https://llvm.org/devmtg/2022-11/slides/Lightning9-TypeResugaringInClang%20.pdf">slides</a>of Matheusâ presentation.</p><h2 id="a-hrefhttpscompiler-researchorgblogsgsoc22_zhang_chaudhari_experience_blogrecovering-from-errors-in-clang-repl-and-code-undoa"><a href="https://compiler-research.org/blogs/gsoc22_zhang_chaudhari_experience_blog/">Recovering from Errors in Clang-Repl and Code Undo</a></h2><p>Developers: <strong><a href="https://github.com/junaire">Jun Zhang</a></strong>(<em>Software Engineering, Anhui Normal University, WuHu, China</em>) and<strong><a href="https://github.com/Purva-Chaudhari">Purva Chaudhari</a></strong>(<em>California State University Northridge, Northridge CA, USA</em>)</p><p>Mentors: <strong>Vassil Vassilev</strong> (<em>Princeton University/CERN</em>)</p><p><a href="https://clang.llvm.org/docs/ClangRepl.html">Clang-Repl</a> is aninteractive C++ interpreter integrated in Clang, which enables incrementalcompilation. It supports interactive programming for C++ in aRead-Eval_Print Loop(<a href="https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a>)style, compiling the code just-in-time with a JIT approach that reduces thecompile-run cycles. We added the âundoâ functionality to Clang-REPL, and weimproved error-recovery by adding the possibility to recover the low-levelexecution infrastructure. As a result, Clang-REPL now supports reversalexecution and recovery actions on behalf of a user in an automatic andconvenient way.</p><p><strong>Hurray!</strong> This project has been accepted as a Lightning Talk at the<a href="https://llvm.swoogo.com/2022devmtg/speakers">2022 LLVM Developersâ Meeting</a>!The conference took place in San Jose, California, from 7th to 10th November2022.Here you can find the <a href="https://www.youtube.com/watch?v=LSPBPC2av54">video</a>and the<a href="https://llvm.org/devmtg/2022-11/slides/Lightning6-RecoveringFromErrorsInClang-ReplAndCodeUndo.pdf">slides</a>of Purva and Junâs presentation.</p><h2 id="a-hrefhttpscompiler-researchorgblogsgsoc22_ghosh_experience_blogshared-memory-based-jitlink-memory-managera"><a href="https://compiler-research.org/blogs/gsoc22_ghosh_experience_blog/">Shared Memory Based JITLink Memory Manager</a></h2><p>Developer: <strong><a href="https://github.com/argentite">Anubhab Ghosh</a></strong>(<em>Computer Science and Engineering, Indian Institute of Information Technology, Kalyani, India</em>)</p><p>Mentors: <strong>Stefan Gränitz</strong> (<em>Freelance Compiler Developer, Berlin, Deutschland</em>),<strong>Lang Hames</strong> (<em>Apple</em>), <strong>Vassil Vassilev</strong> (<em>Princeton University/CERN</em>)</p><p>Funding: <strong>Google Summer of Code 2022</strong></p><p>Anubhab introduced a new <a href="https://llvm.org/docs/JITLink.html">JITLinkMemoryManager</a>based on a MemoryMapper abstraction that is capable of allocating JIT code(and data) using shared memory. The following advantages should arise from theimplemented strategy: 1. a faster transport (and access) for code and data whenrunning JITâd code in a separate process on the same machine, and 2. theguarantee that all allocations are close together in memory and meet theconstraints of the default code model allowing the use of outputs from regularcompilers.Here you can find Anubhabâs GSoC<a href="https://compiler-research.org/assets/docs/Anubhab_Ghosh_GSoC2022_Report.pdf">final report</a>.</p><p><strong>Hurray!</strong> This project has been accepted as a Lightning Talk at the<a href="https://llvm.swoogo.com/2022devmtg/speakers">2022 LLVM Developersâ Meeting</a>!The conference took place in San Jose, California, from 7th to 10th November2022.Here you can find the <a href="https://www.youtube.com/watch?v=dosXtBAFWiE">video</a>and the<a href="https://llvm.org/devmtg/2022-11/slides/Lightning4-EfficientJIT-basedRemoteExecution.pdf">slides</a>of Anubhabâs presentation.</p><h2 id="a-hrefhttpshepsoftwarefoundationorggsocblogs2022blog_root_junzhanghtmloptimize-root-use-of-modules-for-large-codebasesa"><a href="https://hepsoftwarefoundation.org/gsoc/blogs/2022/blog_ROOT_JunZhang.html">Optimize ROOT use of modules for large codebases</a></h2><p>Developer: <strong><a href="https://github.com/junaire">Jun Zhang</a></strong>(<em>Software Engineering, Anhui Normal University, WuHu, China</em>)</p><p>Mentors: <strong>David Lange</strong> (<em>Princeton University</em>), <strong>Alexander Penev</strong>(<em>University of Plovdiv Paisii Hilendarski, Bulgaria</em>), <strong>Vassil Vassilev</strong>(<em>Princeton University/CERN</em>)</p><p>Funding: <strong>Google Summer of Code 2022</strong></p><p>The current performance of the modules usage in <a href="https://root.cern/">ROOT</a>was evaluated, and a strategy for optimizing the memory footprint was developed.This strategy includes reducing unnecessary symbol-lookups and module-loading,and is especially useful for very large codebases like <a href="https://cms-sw.github.io/">CMSSW</a>,where Jun reduced the amount of memory by half (from 1.1GB to 600MB) for simpleworkflows like hsimple.C, and the number of loaded from 180 to 52.Here you can find Junâs GSoC<a href="https://compiler-research.org/assets/docs/Jun_Zhang_GSoC22_Report.pdf">final report</a>.</p><h2 id="a-hrefhttpshepsoftwarefoundationorggsocblogs2022blog_compilerresearch-manishkausikhtmladd-initial-integration-of-clad-with-enzymea"><a href="https://hepsoftwarefoundation.org/gsoc/blogs/2022/blog_CompilerResearch-ManishKausik.html">Add Initial Integration of Clad with Enzyme</a></h2><p>Developer: <strong><a href="https://github.com/Nirhar">Manish Kausik H</a></strong>(<em>.Tech and M.Tech in Computer Science and Engineering(Dual Degree),Indian Institute of Technology Bhubaneswar</em>)</p><p>Mentors: <strong>David Lange</strong> (<em>Princeton University</em>), <strong>William Moses</strong>(<em>Massachusetts Institute of Technology</em>), <strong>Vassil Vassilev</strong> (<em>Princeton University/CERN</em>)</p><p>Funding: <strong>Google Summer of Code 2022</strong></p><p><a href="https://clad.readthedocs.io/en/latest/index.html">Clad</a> is an opensource plugin to the Clang compiler that enables <a href="https://en.wikipedia.org/wiki/Automatic_differentiation">Automatic Differentiation</a>for C++. Clad receives an Abstract Syntax Tree (AST) from the underlying<br>compiler platform (Clang), decides whether a derivative is requested andproduces it, and modifies the AST to insert the generated code.<a href="https://enzyme.mit.edu/">Enzyme AD</a> is an LLVM based AD plugin.It works by taking existing code as LLVM IR and computing the derivative(and gradient) of that function.In this project, Manish integrated Enzyme within Clad, giving a Clad user theoption of selecting Enzyme for Automatic Differentiation on demand. Theintegration of Clad and Enzyme t results in a new tool that offers an optimizedand flexible implementation of automatic differentiation.Here you can find Manishâs GSoC<a href="https://compiler-research.org/assets/docs/Manish_Kausik_H_GSoC22_Report.pdf">final report</a>.</p><h2 id="thank-you-developers">Thank you, developers!</h2><p>We hope our interns contributors enjoyed our community. Our best reward is toknow that we supported your early steps into the world of open-source softwaredevelopment and compiler construction. We hope that this experience motivatedyou to continue to be involved with the broad LLVM ecosystem.We express our gratitude to the <a href="https://summerofcode.withgoogle.com/">Google Summer of Code</a>Program and to the Institute for Research and Innovation in Software for HighEnergy Physics (<a href="https://iris-hep.org/">IRIS-HEP</a>) for supporting ourresearch and providing six young developers this wonderful opportunity.A special thanks goes to the LLVM community for being supportive and for sharingtheir knowledge and introducing our community to the new contributors. Thank youso much!Thanks for choosing Compiler-Research for your internship! We were lucky tohave you!</p>
- Office hours and the LLVM community calendar.https://blog.llvm.org/posts/2022-10-27-office-hours/Thu, 27 Oct 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-10-27-office-hours/<p>About a thousand people contribute code to LLVM each year. There are probablymany thousands who work on the LLVM code base in downstream projects. And evenmore people use the LLVM libraries to build other cool projects on top of.</p><p>The many LLVM users and contributors have long been communicating with eachother using mailing lists, bugzilla, and more recently,<a href="https://discourse.llvm.org/latest">Discourse</a> and <a href="https://github.com/llvm/llvm-project/issues">githubissues</a>. Next to theseasynchronous communication channels, the LLVM community has also long had moresynchronous communication channels, such as<a href="https://llvm.org/docs/GettingInvolved.html#irc">IRC</a> and<a href="https://discord.gg/xS7Z362">Discord</a>. Twice per year, there is the opportunityto communicate synchronously face-to-face with other LLVM-ers from around theworld: at the <a href="https://llvm.org/devmtg/">LLVM developer meetings</a>. The <a href="https://www.meetup.com/pro/llvm/">LLVMsocials</a> that happen in various places aroundthe world also provide the opportunity to meet face-to-face with LLVMers inyour area.</p><p>In recent years, we’ve added a number of online “face-to-face” synchronouscommunication channels. They often are the best way to make progress quickly.I think many don’t know of their existence yet, or just need a littleencouragement to make more use of them. Therefore, I thought it was worthwhileto highlight them in this post:</p><ul><li><a href="https://llvm.org/docs/GettingInvolved.html#online-sync-ups">Online sync-ups</a>are regular calls on specific topics. A few of them have been running foryears, but most started only in the last 2 years. A full list of currentonline sync-ups is documented at<a href="https://llvm.org/docs/GettingInvolved.html#online-sync-ups">https://llvm.org/docs/GettingInvolved.html#online-sync-ups</a></li><li>More recently, <a href="https://llvm.org/docs/GettingInvolved.html#office-hours">“officehours”</a> havestarted. In these, specific experienced people in the community makethemselves available for a chat and to answer questions on anything in theirarea of expertise. They are documented at<a href="https://llvm.org/docs/GettingInvolved.html#office-hours">https://llvm.org/docs/GettingInvolved.html#office-hours</a>. Whether you’reexperienced or not in LLVM, both online sync-ups and office hours can be agreat way to get advice and help on any issues you might be facing when usingor contributing to LLVM.</li></ul><p>One last way to find LLVM events that may be interesting to you, is to look atour <a href="https://calendar.google.com/calendar/u/0/[email protected]">LLVM communitycalendar</a>.It shows the schedule for most office hours, online sync-ups and socials. Ifyou’re an organizer of any of these events, please do not forget to <a href="https://llvm.org/docs/GettingInvolved.html#llvm-community-calendar">add yourevent to the community calendar by [email protected]</a>.</p>
- Announcing the LLVM Foundation Board of Directors for the 2022-2024 termhttps://blog.llvm.org/posts/2022-10-03-llvmfoundationboardannouncement/Mon, 03 Oct 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-10-03-llvmfoundationboardannouncement/<p>The <a href="https://foundation.llvm.org">LLVM Foundation</a> would like to announce our Board of Directors for the 2022-2024 term:</p><ul><li><a href="#kit">Kit Barton</a> (Secretary)</li><li><a href="#kristof">Kristof Beyls</a></li><li><a href="#beanz">Chris Bieneman</a></li><li><a href="#mike">Mike Edwards</a> (Treasurer)</li><li><a href="#reid">Reid Kleckner</a></li><li><a href="#anton">Anton Korobeynikov</a></li><li><a href="#chris">Chris Lattner</a></li><li><a href="#tanya">Tanya Lattner</a> (President)</li><li><a href="#wei">Wei Wu</a></li></ul><p>Three new members and six continuing members were elected to the nine person board.</p><p>Thank you to retiring board members Tom Stellard, Cyndy Ishida, and Hal Finkelfor all of their contributions to the board!</p><p>About the board of directors (listed alphabetically by last name):</p><h3 id="a-namekitkit-bartona"><a name="kit">Kit Barton</a></h3><p><img src="https://blog.llvm.org/img/board-22/Kit.png" alt="Kit Barton"></p><p>Kit Barton has been contributing to LLVM since 2015. His contributions haveprimarily been to the PowerPC backend and loop optimizations including the loopfusion pass. He has presented multiple technical talks, and tutorials at theLLVM Dev conferences over the last several years.</p><p>In addition to the contributions to LLVM, over the last several years Kit hasdriven the effort within IBM to migrate their proprietary C/C++ and Fortrancompilers to leverage LLVM technology. He is currently the technical lead forC/C++ and Fortran compilers on Power and z/OS at IBM.</p><p><a href="mailto:[email protected]">[Email]</a></p><h3 id="a-namekristofkristof-beylsa"><a name="kristof">Kristof Beyls</a></h3><p><img src="https://blog.llvm.org/img/board-22/Kristof.jpg" alt="Kristof Beyls"></p><p>Kristof Beyls has worked on LLVM since about 2010, initially as part of tech leading the migration of Armâs C/C++ toolchain to be based on LLVM technology. Since then, Kristof has worked on a variety of code generation projects using LLVM. He has contributed to LLVM in the areas of security mitigations, performance tuning, Arm backends, test-suite, LNT, etc.He has been helping with the organization of EuroLLVM meetings since the start; has been organizing the FOSDEM LLVM dev rooms for the past couple of years and has organized a few socials in Belgium. He has also been on the program committee for a few of the dev meetings. More recently, he works on progressing LLVM relicensing, getting LLVM office hours going and having an LLVM community calendar.Kristof is Senior Principal Engineer at Arm.</p><p><a href="https://twitter.com/kbeyls"> [Twitter]</a> <a href="https://github.com/kbeyls">[GitHub]</a> <a href="https://www.linkedin.com/in/kristof-beyls-b6371a1/">[LinkedIn]</a> <a href="mailto:[email protected]">[Email]</a></p><h3 id="a-namebeanzchris-bienemana"><a name="beanz">Chris Bieneman</a></h3><p><img src="https://blog.llvm.org/img/board-22/beanz.jpg" alt="Chris Bieneman"></p><p>Chris has been an LLVM contributor since 2013 with contributions up and down the monorepo. His work has ranged from the frontend to the backend, to debuggers, linkers, and JITs.</p><p>Chris has presented at several LLVM events and is passionate about community building. The LLVM project and community have been enormous influences in his life, and he is looking forward to the opportunity to work with the Foundation and community to bring that experience to more people around the world.</p><p>Chris is currently an engineer on the HLSL compiler team at Microsoft working on advancing graphics programming for Xboxand DirectX and bringing HLSL support into Clang.</p><p><a href="https://twitter.com/thegreatbeanz">[Twitter]</a> <a href="https://github.com/llvm-beanz">[GitHub]</a> [<a href="mailto:[email protected]">Email</a></p><p>beanz on LLVM’s Discourse, Discord, and IRC.</p><h3 id="a-namemikemike-edwardsa"><a name="mike">Mike Edwards</a></h3><p><img src="https://blog.llvm.org/img/board-22/Mike.jpg" alt="Mike Edwards"></p><p>Mike got involved with the LLVM project back in 2014 by contributing to the infrastructure projects. He has helped with everything from CI to the transition to GitHub.</p><p>Mike has served as the LLVM Foundations Treasurer since 2018. Mike cares very much about the mission of the LLVM Foundation and credits many of his career opportunities as a direct result of being involved with the LLVM community. He is looking forward to helping to build opportunities for many others to benefit from programs the Foundation has to offer.<a href="mailto:[email protected]">[Email]</a></p><h3 id="a-namereidreid-klecknera"><a name="reid">Reid Kleckner</a></h3><p><img src="https://blog.llvm.org/img/board-22/Reid.jpg" alt="Reid Kleckner"></p><p>Reid Kleckner began contributing to LLVM in 2009 while working on Unladen Swallow, a JIT for Python. That project inspired him to go deeper in compilers. After a long detour involving the DynamoRIO and DrMemory projects, in 2013, Reid joined a team at Google working on Clang and MSVC compatibility. This project required making wide-ranging changes across the compiler: frontend parser changes, Microsoft C++ ABI features, fixes for Windows calling conventions, new IR features such as musttail, parts of the Windows exception handling representation, and parts of the CodeView/PDB debug info format support.</p><p>Aside from direct code contributions, Reid has given two talks at US LLVM developer meetings and served on the program committee once. He looks forward to improving the community experience for the next generation of LLVM contributors.Reid currently manages a team supporting C++ and LLVM at Google.</p><p><a href="https://twitter.com/reidkleckner">[Twitter]</a> <a href="https://github.com/rnk">[GitHub]</a> <a href="[email protected]">[Email]</a></p><h3 id="a-nameantonanton-korobeynikova"><a name="anton">Anton Korobeynikov</a></h3><p><img src="https://blog.llvm.org/img/board-22/Anton.jpg" alt="Anton Korobeynikov"></p><p>Anton Korobeynikov began contributing to the LLVM project in 2006.Over the years, he has numerous technical contributions to differentareas including Windows support, ELF features, debug info, exceptionhandling, and backends such as ARM and x86.He was the original author of the MSP430 and original System Z backend.</p><p>In addition to his technical contributions, Anton has maintainedLLVMâs participation in Google Summer of Code by managingapplications, deadlines, and overall organization. He also supportsthe LLVM infrastructure, drove the Bugzilla to GtiHub migration andhas been on several program committees for the LLVM DevelopersâMeetings (both US and EuroLLVM).</p><p>Anton is currently an associate professor at the Saint PetersburgState University and has served on the LLVM Foundation board ofdirectors for the last 8 years.</p><p><a href="https://twitter.com/akorobeynikov">[Twitter]</a> <a href="https://github.com/asl">[GitHub]</a> <a href="https://www.linkedin.com/in/antonkorobeynikov/">[Linkedin]</a> <a href="mailto:[email protected]">[Email]</a> <a href="http://anton.korobeynikov.info">[Website]</a></p><h3 id="a-namechrischris-lattnera"><a name="chris">Chris Lattner</a></h3><p><img src="https://blog.llvm.org/img/board-22/ChrisL.jpg" alt="Chris Lattner"></p><p>Chris Lattner cofounded the LLVM Compiler infrastructure project, the Clang compiler, the Swift programming language, the MLIR compiler infrastructure, the CIRCT project, and has contributed to many other commercial and open source projects at Apple, Tesla, Google and SiFive. He is currently Cofounder and CEO of Modular, which is building an innovating new developer platform for AI Software.</p><p><a href="https://twitter.com/clattner_llvm">[Twitter]</a> <a href="https://github.com/lattner">[GitHub]</a> <a href="https://www.linkedin.com/in/chris-lattner-5664498a/"> [LinkedIn]</a> <a href="https://nondot.org/sabre/">[Website]</a> <a href="mailto:[email protected]">[Email]</a></p><h3 id="a-nametanyatanya-lattnera"><a name="tanya">Tanya Lattner</a></h3><p><img src="https://blog.llvm.org/img/board-22/Tanya.jpg" alt="Tanya Lattner"></p><p>Tanya Lattner has been involved in the LLVM project for over 20 years. She began as a graduate student who wrote her master’s thesis using LLVM, and continued on using and extending LLVM technologies at various jobs during her career as a compiler engineer.</p><p>Tanya is also a long time volunteer with the LLVM Project. She has organized LLVM Developersâ Meetings, workshops, was the release manager for several years, and adminstrates LLVM infrastructure.</p><p>With the support of the initial board of directors, Tanya created the LLVM Foundation, defined its charitable and education mission, and worked to get 501(c)(3) status. She is passionate about the LLVM Community and wants to help see it thrive and grow for years to come.</p><p>Tanya is the COO and President of the LLVM Foundation.</p><p><a href="https://twitter.com/tonic888"> [Twitter] </a> <a href="https://github.com//tlattner"> [GitHub]</a> <a href="https://www.linkedin.com/in/tanyalattner/"> [LinkedIn]</a> <a href="mailto:[email protected]"> [Email]</a></p><h3 id="a-nameweiwei-wua"><a name="wei">Wei Wu</a></h3><p><img src="https://blog.llvm.org/img/board-22/Wei.png" alt="Wei Wu"></p><p>Wei Wu is the co-founder and director of the PLCT lab, ISCAS. Heformed an LLVM development team in the PLCT lab which is activelycontributing code to LLVM upstream (currently mainly RISC-V backendand MLIR framework). He is also serving the LLVM IWG as a volunteer,trying to improve the LLVM’s infrastructure.</p><p>He is the chairman of OSDT (including HelloGCC and HelloLLVM)community which was founded in 2007. OSDT is an open community aimingto promote the development of toolchains, language VMs,emulators/simulators and other tools for software developers. Heestablished the HelloLLVM community in China a few years ago,dedicated to attracting and cultivating new LLVM developers. HelloLLVMis now a sub-community of OSDT.</p><p>He is very passionate about teaching compiler techniques to Chineseengineers and amateurs. He often gives talks and lectures amongamateurs and college students in OSDT meetups. He also collaborateswith college teachers, providing LLVM related seminars and experimentcourses.</p><p><a href="mailto:[email protected]"> [Email] </a></p>
- Announcing the 2022 LLVM Developers' Meeting Programhttps://blog.llvm.org/posts/2022-09-30-llvmdevmtgprogram/Fri, 30 Sep 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-09-30-llvmdevmtgprogram/<p><img src="https://blog.llvm.org/img/2022-LLVMDevMtgLogo.jpg" alt="2022 LLVM Dev Mtg Logo"></p><p>We had an amazing group of talk proposals submitted for the <a href="https://llvm.swoogo.com/2022devmtg/2359289">2022 LLVM Developers’ Meeting</a>. Thank you to all that submitted a talk proposal this year!</p><p>Here is the 2022 LLVM Developers’ Meeting program:</p><p><strong>Keynotes:</strong></p><ul><li>Paths towards unifying LLVM and MLIR - Nicolai Hähnle</li><li>Implementing Language Support for ABI-Stable Software Evolution in Swift and LLVM - Doug Gregor</li></ul><p><strong>Technical Talks:</strong></p><ul><li>Implementing the Unimplementable: Bringing HLSL’s Standard Library into Clang - Chris Bieneman</li><li>Heterogeneous Debug Metadata in LLVM - Scott Linder</li><li>Clang, Clang: Who’s there? WebAssembly!- Paulo Matos</li><li>MC/DC: Enabling easy-to-use safety-critical code coverage analysis with LLVM - Alan Phipps</li><li>What does it take to run LLVM Buildbots? - David Spickett</li><li>llvm-gitbom: Building Software Artifact Dependency Graphs for Vulnerability Detection - Bharathi Seshadri, Yongkui Han</li><li>CuPBoP: CUDA for Parallelized and Broad-range Processors - Ruobing Han</li><li>Uniformity Analysis for Irreducible CFGs - Sameer Sahasrabuddhe</li><li>Using Content-Addressable Storage in Clang for Caching Computations and Eliminating Redundancy - Steven Wu, Ben Langmuir</li><li>Direct GPU Compilation and Execution for Host Applications with OpenMP Parallelism - Shilei Tian, Joseph Huber</li><li>Linker Code Size Optimization for Native Mobile Applications - Gai Liu</li><li>Minotaur: A SIMD Oriented Superoptimizer - Zhengyang Liu</li><li>ML-based Hardware Cost Model for High-Level MLIR - Dibyendu Das, Sandya Mannarswamy</li><li>VAST: MLIR for program analysis of C/C++ - Henrich Lauko</li><li>MLIR for Functional Programming - Siddharth Bhat</li><li>SPIR-V Backend in LLVM: Upstream and Beyond - Michal Paszkowski, Alex Bezzubikov</li><li>IRDL: A Dialect for dialects - Mathieu Fehr, Théo Degioanni</li><li>Automated translation validation for an LLVM backend - Nader Boushehrinejad Moradi</li><li>llvm-dialects: bringing dialects to the LLVM IR substrate - Nicolai Hähnle</li><li>YARPGen: A Compiler Fuzzer for Loop Optimizations and Data-Parallel Languages - Vsevolod Livinskii</li><li>RISC-V Sign Extension Optimizations - Craig Topper</li><li>Execution Domain Transition: Binary and LLVM IR can run in conjunction - Jaeyong Ko</li></ul><p><strong>Tutorials:</strong></p><ul><li>Using LLVM’s libc - Sivachandra Reddy, Michael Jones, Tue Ly</li><li>How to implement a new JITLink backend in a week - Sunho Kim</li></ul><p><strong>Panels (some speakers still to be announced):</strong></p><ul><li>Machine Learning Guided Optimizations (MLGO) in LLVM</li><li>Static Analysis in Clang - Gabor Horvath, Artem Dergachev, Bruno Cardoso Lopes</li><li>High-level IRs for a C/C++ Optimizing Compiler - Bruno Lopes, Ivan Baev, Johannes Doerfert, Mehdi Amini</li><li>Panel discussion on âBest practices with toolchain release and maintenanceâ - Aditya Kumar</li></ul><p><strong>Student Technical Talks:</strong></p><ul><li>Merging Similar Control-Flow Regions in LLVM for Performance and Code Size Benefits - Charitha Saumya</li><li>Alive-mutate: a fuzzer that cooperates with Alive2 to find LLVM bugs - Yuyou Fan</li><li>Enabling Transformers to Understand Low-Level Programs - Zifan Guo, William S. Moses</li><li>LAGrad: Leveraging the MLIR Ecosystem for Efficient Differentiable Programming - Mai Jacob Peng</li><li>Scalable Loop Analysis - Vir Narula</li></ul><p><strong>Quick Talks:</strong></p><ul><li>LLVM Education Initiativei - Chris Bieneman, Kit Barton, Mike Edwards</li><li>Enabling AArch64 Instrumentation Support In BOLT - Elvina Yakubova</li><li>Approximating at Scale: How strtofloat in LLVMâs libc is faster - Michael Jones</li><li>MIR support in llvm-reduce - Matthew Arsenault</li><li>Interactive Crashlogs in LLDB - Med Ismail Bennani</li><li>clang-extract-api: Clang support for API information generation in JSON - Zixu Wang</li><li>Using modern CPU instructions to improve LLVM’s libc math library. - Tue Ly</li><li>Challenges Of Enabling Golang Binaries Optimization By BOLT - Vasily Leonenko, Vladislav Khmelevskyi</li><li>Inlining for Size - Kyungwoo Lee, Ellis Hoag, Nathan Lanza</li><li>Automatic indirect memory access instructions generation for pointer chasing patterns - PrzemysÅaw Ossowski</li><li>Link-Time Attributes for LTO: Incorporating linker knowledge into the LTO recompile - Todd Snider</li><li>Expecting the expected: Honoring user branch hints for code placement optimizations - Stan Kvasov, Vince Del Vecchio</li><li>CUDA-OMP â Or, Breaking the Vendor Lock - Johannes Doerfert, Joseph Huber</li><li>Thoughts on GPUs as First-Class Citizens - Johannes Doerfert, Shilei Tian, Joseph Huber</li><li>Building an End-to-End Toolchain for Fully Homomorphic Encryption with MLIR - Alexander Viand</li></ul><p><strong>Lightning Talks:</strong></p><ul><li>LLVM Office Hours: addressing LLVM engagement and contribution barriers - Kristof Beyls</li><li>Improved Fuzzing of Backend Code Generation in LLVM - Yuyang Rong</li><li>Interactive Programming for LLVM TableGen - David Spickett</li><li>Efficient JIT-based remote execution - Anubhab Ghosh</li><li>FFTc: An MLIR Dialect for Developing HPC Fast Fourier Transform Libraries - Yifei He</li><li>Recovering from Errors in Clang-Repl and Code Undo - Purva Chaudhari, Jun Zhang</li><li>10 commits towards GlobalISel for PowerPC - Kai Nacke, Amy Kwan</li><li>Nonstandard reductions with SPRAY - Jan Hueckelheim, Johannes Doerfert</li><li>Type Resugaring in Clang for Better Diagnostics and Beyond - Matheus Izvekov</li><li>Swift Bindings for LLVM - Egor Zhdan</li><li>Min-sized Function Coverage with IRPGO - Ellis Hoag, Kyungwoo Lee</li><li>High-Performance GPU-to-CPU Transpilation and Optimization via High-Level Parallel Constructs in Polygeist/MLIR - William S. Moses, Ivan R. Ivanov</li><li>Tools for checking and writing non-trivial DWARF programs - Chris Jackson</li><li>Analysis of RISC-V Vector Performance Using MCA Tools - Michael Maitland</li><li>Optimizing Clang with BOLT using CMake - Amir Ayupov</li><li>Exploring OpenMP target offloading for the GraphCore architecture - Jose M Monsalve Daiz</li></ul><p><strong>Posters (more posters to be announced at a later date):</strong></p><ul><li>Removal of Undef: Move Uninitialized Memory to Poison - John McIver</li><li>Optimizing Julia’s ORC JIT - Prem Chintalapudi</li><li>An LLVM-Based Compiler for Quantum-Classical Applications - Xin-Chuan Wu</li><li>Specializing Code to New Architectures via Dynamic Adaptive Recompilation - Quinn Pham, Dhanrajbir Singh Hira</li><li>LLFPTrax: Tracking ill-conditioned floating-point inputs using relative error amplification in LLVM - Tanmay Tirpankar</li><li>LLVM continuous upstream integration and testing - Jay Azurin, Keerthana Subramani</li><li>Automatic indirect memory access instructions generation for pointer chasing patterns - Adam Perdeusz</li></ul><p>Thank you to the volunters on the Program Committee for all of their hard work and time spent reviewing proposals. A special thanks also goes out to this year’s chair - Anton Korobeynikov. Here is the complete 2022 LLVM Developers’ Meeting Program Committee:</p><ul><li>Kristof Beyls</li><li>Andrey Bokhanko</li><li>Chelsea Cassanova</li><li>Johannes Doerfert</li><li>Florian Hahn</li><li>Petr Hosek</li><li>Min-Yih Hsu</li><li>Anton Korobeynikov (Chair)</li><li>Aditya Kumar</li><li>Hem Neema</li><li>Diego Novillo</li><li>Fangrui Song</li><li>J. Ryan Stinnett</li><li>Caroline Tice</li><li>Mircea Trofin</li></ul><p>Registration closes on October 31st, so register today for the <a href="https://llvm.swoogo.com/2022devmtg/2359289">2022 LLVM Developers’ Meeting</a>.</p>
- Text formatting in C++ using libc++https://blog.llvm.org/posts/2022-08-14-libc++-format/Tue, 27 Sep 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-08-14-libc++-format/<p>Historically formatting text in C++, using the standard library, has beenunpleasant. It is possible to get nice output with the stream operators, but itis very verbose due to the stream manipulators. The other option is using<code>printf</code>, which is convenient but only supports a limited number of types andis not extendable. A non-standard option is using the<a href="https://fmt.dev/latest/index.html">{fmt}</a> library. This article provides ashort introduction to the parts of this library that were standardized in C++20as <code>std::format</code>, as well as the current implementation status in LLVM 15.</p><h2 id="what-is-stdformat">What is <code>std::format</code></h2><p><code>std::format</code> is a text formatting library using format strings similar toPython’s <a href="https://docs.python.org/3/library/stdtypes.html#str.format">format</a>and extensible for user defined types.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><format></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><iostream></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"Hello {} in C++{}"</span>, <span style="color:#e6db74">"std::format"</span>, <span style="color:#ae81ff">20</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Writes the following output:</p><pre tabindex="0"><code>Hello std::format in C++20</code></pre><p>The <code>{}</code> indicates a replacement field like <code>%</code> in <code>printf</code>. With<code>std::format</code> the argument types are known, so it is not required to specifythem in the replacement field.</p><p>The desired output format and the positional argument to use for eachreplacement field can also be specified.(For brevity, the following examples omit the required includes.)</p><p>Writes the first positional argument using different bases, a prefix, andzero padding to 8 columns.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"{0:#08b}, {0:#08o}, {0:08}, {0:#08x}"</span>, <span style="color:#ae81ff">16</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>0b010000, 00000020, 00000016, 0x000010</code></pre><p>It is possible to use an upper case prefix and hexadecimal digits.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"{0:#08B}, {0:#08o}, {0:08}, {0:#08X}"</span>, <span style="color:#ae81ff">15</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>0B001111, 00000017, 00000015, 0X00000F</code></pre><p>The alignment and fill character can be specified.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout</span></span><span style="display:flex;"><span> <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"{:#<8} {:*>8} {:-^5}"</span>, <span style="color:#e6db74">"Hello"</span>, <span style="color:#e6db74">"world"</span>, <span style="color:#e6db74">'!'</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>Hello### ***world --!--</code></pre><p>When printing tables it is nice to be able to specify the alignment and widthof the columns. However, formatting Unicode text can be especially tricky,since not every <code>char</code> (or <code>wchar_t</code>) is one “character”.</p><p>For example the letter Ã, can be written in two ways:</p><ul><li>LATIN CAPITAL LETTER A WITH ACUTE</li><li>LATIN CAPITAL LETTER A + COMBINING ACUTE ACCENT</li></ul><p>This combining of multiple “characters” is used in several scripts and inemojis. (This “combined multiple characters” is known as<a href="https://www.unicode.org/reports/tr29/">extended grapheme clusters</a> inUnicode.) The library has implemented these rules so it will count both formsof à as using one column in the output.</p><p>Another issue with text formatting is that not all every “character” has thesame column width. Based on the “character” the column width is estimated to beone or two columns.</p><p>Below is an example taken from the <a href="https://wg21.link/p1868r2">paper</a> thatintroduced the width estimation algorithm in <code>std::format</code>:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">input</span> {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> text;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> info;</span></span><span style="display:flex;"><span>};</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> input inputs[] <span style="color:#f92672">=</span> {</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">"Text"</span>, <span style="color:#e6db74">"Description"</span>},</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">"-----"</span>,</span></span><span style="display:flex;"><span> <span style="color:#e6db74">"------------------------------------------------------------------------"</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"--------------"</span>},</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\x41</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+0041 { LATIN CAPITAL LETTER A }"</span>},</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xC3\x81</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+00C1 { LATIN CAPITAL LETTER A WITH ACUTE }"</span>},</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\x41\xCC\x81</span><span style="color:#e6db74">"</span>,</span></span><span style="display:flex;"><span> <span style="color:#e6db74">"U+0041 U+0301 { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }"</span>},</span></span><span style="display:flex;"><span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xc4\xb2</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+0132 { LATIN CAPITAL LIGATURE IJ }"</span>}, <span style="color:#75715e">// IJ</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xce\x94</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+0394 { GREEK CAPITAL LETTER DELTA }"</span>}, <span style="color:#75715e">// Î</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xd0\xa9</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+0429 { CYRILLIC CAPITAL LETTER SHCHA }"</span>}, <span style="color:#75715e">// Щ</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xd7\x90</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+05D0 { HEBREW LETTER ALEF }"</span>}, <span style="color:#75715e">// ×</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xd8\xb4</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+0634 { ARABIC LETTER SHEEN }"</span>}, <span style="color:#75715e">// Ø´</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xe3\x80\x89</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+3009 { RIGHT-POINTING ANGLE BRACKET }"</span>}, <span style="color:#75715e">// ã</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xe7\x95\x8c</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+754C { CJK Unified Ideograph-754C }"</span>}, <span style="color:#75715e">// ç</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xf0\x9f\xa6\x84</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"U+1F921 { UNICORN FACE }"</span>}, <span style="color:#75715e">// ð¦</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> {<span style="color:#e6db74">"</span><span style="color:#ae81ff">\xf0\x9f\x91\xa8\xe2\x80\x8d\xf0\x9f\x91\xa9\xe2\x80\x8d</span><span style="color:#e6db74">"</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"</span><span style="color:#ae81ff">\xf0\x9f\x91\xa7\xe2\x80\x8d\xf0\x9f\x91\xa6</span><span style="color:#e6db74">"</span>,</span></span><span style="display:flex;"><span> <span style="color:#e6db74">"U+1F468 U+200D U+1F469 U+200D U+1F467 U+200D U+1F466 "</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"{ Family: Man, Woman, Girl, Boy } "</span>} <span style="color:#75715e">// ð¨âð©âð§âð¦</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> };</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">auto</span> input: inputs) {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"{:>5} | {}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>, input.text, input.info);</span></span><span style="display:flex;"><span> }</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>(Note the column width is intended to look good on a terminal. The author hasobserved differences in quality of the output depending on the browser used.)</p><pre tabindex="0"><code> Text | Description----- | -------------------------------------------------------------------------------------- A | U+0041 { LATIN CAPITAL LETTER A } à | U+00C1 { LATIN CAPITAL LETTER A WITH ACUTE } AÌ | U+0041 U+0301 { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT } IJ | U+0132 { LATIN CAPITAL LIGATURE IJ } Î | U+0394 { GREEK CAPITAL LETTER DELTA } Щ | U+0429 { CYRILLIC CAPITAL LETTER SHCHA } × | U+05D0 { HEBREW LETTER ALEF } Ø´ | U+0634 { ARABIC LETTER SHEEN } ã | U+3009 { RIGHT-POINTING ANGLE BRACKET } ç | U+754C { CJK Unified Ideograph-754C } ð¦ | U+1F921 { UNICORN FACE } ð¨âð©âð§âð¦ | U+1F468 U+200D U+1F469 U+200D U+1F467 U+200D U+1F466 { Family: Man, Woman, Girl, Boy }</code></pre><p>Attempting to format a value as the wrong type (e.g. formatting a string as anumber) will result in a compilation error, instead of a runtime error with<code>printf</code>. Most of the major compilers provide a warning to try to detectincorrect format specifiers in <code>printf</code>, but this is not part of thespecification, and in particular embedded compilers often don’t provide thatwarning. In contrast, <code>std::format</code> is <em>specified</em> to produce a compilationerror, which is implemented in the library itself using C++20 <code>consteval</code>functions.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"{0:#08B}, {0:#08o}, {0:08}, {0:#08X}"</span>, <span style="color:#e6db74">"15"</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>The compiler output starts with this error, followed by a lot of not too useful messages.</p><pre tabindex="0"><code>error: call to consteval function 'std::basic_format_string<char, const char (&)[3]>::basic_format_string<char[37]>' is not a constant expression std::cout << std::format("{0:#08B}, {0:#08o}, {0:08}, {0:#08X}", "15");</code></pre><p>In addition to outputting the formatted result to a string, it is also possible:</p><ul><li>to output the result to an arbitrary output iterator,</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>format_to(</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>ostream_iterator<span style="color:#f92672"><</span><span style="color:#66d9ef">char</span><span style="color:#f92672">></span>(std<span style="color:#f92672">::</span>cout, <span style="color:#e6db74">""</span>),</span></span><span style="display:flex;"><span> <span style="color:#e6db74">"Hello {} in C++{}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"std::format"</span>, <span style="color:#ae81ff">20</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><ul><li>to determine the output size,</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>formatted_size(<span style="color:#e6db74">"Hello {} in C++{}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"std::format"</span>, <span style="color:#ae81ff">20</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>27</code></pre><ul><li>or limit the size of the output.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>format_to(</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>ostream_iterator<span style="color:#f92672"><</span><span style="color:#66d9ef">char</span><span style="color:#f92672">></span>(std<span style="color:#f92672">::</span>cout, <span style="color:#e6db74">""</span>),</span></span><span style="display:flex;"><span> <span style="color:#ae81ff">11</span>, <span style="color:#e6db74">"Hello {} in C++{}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>, <span style="color:#e6db74">"std::format"</span>, <span style="color:#ae81ff">20</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>Hello std</code></pre><p>An example of formatting user defined types is available in the standardlibrary. It has formatting support for the <code>chrono</code> library. (This is notavailable in libc++ yet.) These formatters are quite complex. For other typesit is possible quickly create a formatter. For example for the following <code>enum class</code>:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">enum</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">color</span> { red, green, blue };</span></span></code></pre></div><p>Adding a formatter based on an existing formatter can be done like:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">template</span> <span style="color:#f92672"><></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">std</span><span style="color:#f92672">::</span>formatter<span style="color:#f92672"><</span>color<span style="color:#f92672">></span> <span style="color:#f92672">:</span> std<span style="color:#f92672">::</span>formatter<span style="color:#f92672"><</span><span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*></span> {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">constexpr</span> <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> color_names[] <span style="color:#f92672">=</span> {<span style="color:#e6db74">"red"</span>, <span style="color:#e6db74">"green"</span>, <span style="color:#e6db74">"blue"</span>};</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">auto</span> <span style="color:#a6e22e">format</span>(color c, <span style="color:#66d9ef">auto</span><span style="color:#f92672">&</span> ctx) <span style="color:#66d9ef">const</span> <span style="color:#f92672">-></span> <span style="color:#66d9ef">decltype</span>(ctx.out()) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> base <span style="color:#f92672">=</span> formatter<span style="color:#f92672"><</span><span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*></span>;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> base<span style="color:#f92672">::</span>format(color_names[<span style="color:#66d9ef">static_cast</span><span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span>(c)], ctx);</span></span><span style="display:flex;"><span> }</span></span><span style="display:flex;"><span>};</span></span></code></pre></div><p>Now all features of the <code>const char*</code> formatter are available in the colorformatter:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>format(<span style="color:#e6db74">"{:#<10}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">{:+^10}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">{:->10}</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>,</span></span><span style="display:flex;"><span> color<span style="color:#f92672">::</span>red, color<span style="color:#f92672">::</span>green, color<span style="color:#f92672">::</span>blue);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>red#######++green+++------blue</code></pre><p>More examples and details of the specification can be found in this<a href="https://hackingcpp.com/cpp/libs/fmt.html">{fmt} cheet sheet</a>.</p><h2 id="the-status-in-llvm-15">The status in LLVM 15</h2><p>In LLVM 15 most of the basic text formatting is complete. All major papershave been implemented, but some defect reports are not implemented. The libc++team also wants to work on performance improvements and improvements to thecompile-time errors. Some of these improvements have already landed in <code>main</code>and will be included in LLVM 16, while others are only planned.</p><p>Since the library is not entirely complete and the ABI may need to change (dueto planned improvements but also changes voted by the C++ Committee), it isshipped as an experimental feature in LLVM 15. To use the code in libc++ youneed to compile the code like:</p><pre tabindex="0"><code>clang -std=c++20 -stdlib=libc++ -fexperimental-library -ofoo foo.cpp</code></pre><p>Format support for <code>chrono</code> is unavailable. Initial work has landed forLLVM 16, but none of it is available in LLVM 15. The <code>chrono</code> libraryitself lacks support for time zones, leap seconds, and some of the less commonclocks. These need to be available before the formatting support for <code>chrono</code>can be completed.</p><h2 id="formatting-improvements-in-c23">Formatting improvements in C++23</h2><p>In the examples the output is first formatted in a <code>std::string</code> beforestreaming it to the output. To avoid the temporary <code>std::string</code> it ispossible to use <code>std::format_to</code>, but that doesn’t have an ergonomic syntax.In C++23 there will be <code>std::print</code>.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>print(<span style="color:#e6db74">"Hello {} in C++{}"</span>, <span style="color:#e6db74">"std::format"</span>, <span style="color:#ae81ff">20</span>);</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>Hello std::format in C++20</code></pre><p>There is little support for formatting containers. In C++23 it will becomepossible to format ranges and containers.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>print(<span style="color:#e6db74">"{::*^5}"</span>, std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span>{<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">3</span>});</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><pre tabindex="0"><code>[**1**, **2**, **3**]</code></pre><p>Some progress on formatting ranges has been made, but the main focus in theshort term will be to finish C++20’s format implementation.</p><h2 id="closing-words">Closing words</h2><p>Starting with C++20, formatting text becomes a lot more pleasant and C++23 haseven more improvements lined up. This should provide long awaited functionalityin C++ and allow replacing several uses of <code><iostream></code> by a more convenient,faster and safer alternative.</p><h2 id="acknowledgements">Acknowledgements</h2><p>Huge thanks to Victor Zverovich, the author of {fmt}. He has been heavilyinvolved in getting <code>std::format</code> in the C++ Standard. He has aided reviewinglibc++’s implementation and his insights and comments have improved the qualityof the implementation.</p>
- August 2022 LLVM relicensing update & further suggestions for helphttps://blog.llvm.org/posts/2022-08-14-relicensing-update/Wed, 17 Aug 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-08-14-relicensing-update/<p>The last update on LLVM relicensing was <a href="https://blog.llvm.org/posts/2021-11-18-relicensing-update/">done about 8 monthsago</a>. Since thenwe’ve made substantial progress, so I thought it’s worthwhile to share anotherupdate.</p><p>The TL;DR is:</p><ul><li>Out of the about 32 million LOC that were contributed under the old license,we’ve reduced the lines of code that aren’t relicensed yet from 6% to only2%.</li><li>8 months ago, we were still searching for ways to contact 808 individuals whocontributed to LLVM over the past 20 years. We managed to reduce that numberto 421 individuals now.</li><li>We’ve also reduced the number of companies or universities to get a relicensingagreement from from 133 to 122.</li></ul><p>Read on to find out how we achieved that great progress and how you can helpwith getting us closer to our end goal of having LLVM fully relicensed.</p><p>First of all, a big thank you to everyone who responded to the call for help inthe <a href="https://blog.llvm.org/posts/2021-11-18-relicensing-update/">November 2021 blogpost</a> and the <a href="https://www.youtube.com/watch?v=aAFDfhD-jDs">2021LLVM dev meeting presentation</a>.This level of progress would not have been possible without your action!</p><p>Next to receiving more relicensing agreements, we also started exploring someof the tactics described in <a href="https://discourse.llvm.org/t/board-meeting-minutes-may-2022/63628">the previousupdate</a>under section “the end game”, for the pieces of code that we end up notreceiving a relicensing agreement for, as described in the next sections.</p><h2 id="threshold-of-originality">Threshold of originality</h2><p>Remember that licenses exists because of copyright law – the license is howthe copyright owners of the code in LLVM give rights to users and othercontributors to use their code in lots of useful and interesting ways.</p><p>This also means that if a piece of code is not protected by copyright law,there is no need for it to be covered by a license.</p><p>Some pieces of code are not covered by copyright law. For example, copyrightlaw contains a concept called <a href="https://en.wikipedia.org/wiki/Threshold_of_originality">“Threshold oforiginality”</a>. It meansthat a work needs to be “sufficiently original” for it to be considered to becovered by copyright. There could be a lot of different interpretations intowhat it means for a code contribution to be sufficiently original for it to becovered by copyright. A threshold that is often used in open source projectsthat use <a href="https://en.wikipedia.org/wiki/Contributor_License_Agreement">contributor license agreements(CLA)</a> is toassume that any contribution that’s 10 lines of code or less does not meet thethreshold of originality and therefore copyright does not apply. In <a href="https://discourse.llvm.org/t/board-meeting-minutes-may-2022/63628">their May2022 boardmeeting</a>,the LLVM Foundation decided to make the same assumption for the relicensingproject: contributions of 10 lines of code or less are assumed to not becovered by copyright.Therefore, we don’t need relicensing agreements for those.</p><p>Furthermore, there are a few commits that don’t seem to meet the“threshold-of-originality” even though they’re changing/adding more than 10lines. We also consider those to not needing a relicensing agreement. Oneexample is <a href="https://github.com/llvm/llvm-project/commit/cd13ef01a21e">thiscommit</a>, which onlyremoves the full stop at the end of a few sentences.</p><h2 id="code-no-longer-present-in-top-of-trunk">Code no longer present in Top-of-Trunk.</h2><p>We started exploring which of the not-yet-relicensed code is still in thecurrent top-of-trunk code base. Some big contributions that weren’t covered yetare no longer there, such as for example the Microblaze and PIC16 backends. Wemanually checked and marked commits contributing to just these backends as notneeding to be covered by relicensing agreements.</p><p>To help with finding more code that is no longer in the code base, I wrote asimple heuristic script that searches in current top-of-trunk if lines from aspecific commit can still be found in the code base. If for a given commit, noor very few lines can be found in current top-of-trunk, that’s a strongindication that that code is probably no longer there. That heuristic scriptindicates that for about 5% of the not-yet-relicensed commits, the code does nolonger seem to be present. I still need to find time to manually verify thecode in these commits is indeed no longer in the code base. This manualverification would be something that someone could easily help me with. Ifanyone reading this would like to volunteer for helping with that - please dolet me know!</p><h2 id="next-steps">Next steps</h2><p>In our quest to get nearer to 100% relicensing coverage, I believe thefollowing are the most impactful next steps to take:</p><ul><li>Continue accepting more relicensing agreements, from individuals and fromcorporations. An up-to-date list of who we still need to get agreements fromis published as a <a href="https://docs.google.com/spreadsheets/d/18_0Hog_eSwES8lKwf7WJal3yBwwcYfvPu1yCfZnTcek/edit?usp=sharing">spreadsheet here</a>.<ul><li>We found that it can help a lot when corporations can get a list of whichcommits they’re agreeing to relicense. If you’re progressing getting acorporation/company to sign, please do send an email to<a href="mailto:[email protected]">[email protected]</a> asking forthe list of commits that the company may own copyright on.</li></ul></li><li>Go through the commits that look like they may no longer be in top-of-trunk,and verify that manually.</li></ul><h2 id="how-can-you-help">How can you help?</h2><ul><li><p>You could check if you know any individual still listed in<a href="https://docs.google.com/spreadsheets/d/18_0Hog_eSwES8lKwf7WJal3yBwwcYfvPu1yCfZnTcek/edit?usp=sharing">this up-to-date spreadsheet</a>.If you do know any of the people, please do reach out directly to them - I’moften the bottleneck when you share contact details with me and rely on me toreach out to them. If they do have any questions, I’m more than happy to tryand answer them.</p></li><li><p>You could check if you know who the right people are to contact at any of theremaining companies/corporations and talk with them directly or share theircontact details with us at<a href="mailto:[email protected]">[email protected]</a>. They are alsolisted in the <a href="https://docs.google.com/spreadsheets/d/18_0Hog_eSwES8lKwf7WJal3yBwwcYfvPu1yCfZnTcek/edit?usp=sharing">samespreadsheet</a>,on the sheet starting with “Corporations”.</p></li><li><p>If you’d be interested in helping to check if specific commits are stillpresent in the current code base, please do let me know at<a href="mailto:[email protected]">[email protected]</a>.</p></li></ul>
- LLVM security group and 2021 security transparency reporthttps://blog.llvm.org/posts/2022-01-22-security-group-transparency-reports/Sat, 22 Jan 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-01-22-security-group-transparency-reports/<p>Over the past few years, the LLVM project has seen the creation of a securitygroup, which aims to enable responsible disclosure and fixing ofsecurity-related issues affecting the LLVM project.</p><p>The <a href="https://llvm.org/docs/Security.html">LLVM security group</a> was establishedon the 10th of July 2020 by the act of the <a href="https://github.com/llvm/llvm-project/commit/7bf73bcf6d93">initialcommit</a> describingthe purpose of the group and the processes it follows. Many of the group’sprocesses were still not well-defined enough for the group to operate well.Over the course of 2021, the key processes were defined well enough to enablethe group to operate reasonably well:</p><ul><li>We defined details on how to report security issues, see <a href="https://github.com/llvm/llvm-project/commit/c9dbaa4c86d2">this commit on20th of May 2021</a>.</li><li>We refined the nomination process for new group members, see <a href="https://github.com/llvm/llvm-project/commit/4c98e9455aad">thiscommit on 30th of July2021</a>.</li><li>We wrote a first annual transparency report, which is published at<a href="https://llvm.org/docs/SecurityTransparencyReports.html">https://llvm.org/docs/SecurityTransparencyReports.html</a>There is a copy of the 2021 transparency report below.</li></ul><p>Over the course of 2021, we had 2 people leave the LLVM Security group and 4people join.</p><p>In 2021, the security group received 13 issue reports that were made publiclyvisible before 31st of December 2021. The security group judged 2 of thesereports to be security issues:</p><ul><li><a href="https://bugs.chromium.org/p/llvm/issues/detail?id=5">https://bugs.chromium.org/p/llvm/issues/detail?id=5</a></li><li><a href="https://bugs.chromium.org/p/llvm/issues/detail?id=11">https://bugs.chromium.org/p/llvm/issues/detail?id=11</a></li></ul><p>Both issues were addressed with source changes: #5 in clangd/vscode-clangd, and#11 in llvm-project. No dedicated LLVM release was made for either.</p><p>We believe that with the publishing of the first annual transparency report,the security group now has implemented all necessary processes for the group tooperate as promised. The group’s processes can be improved further, and we doexpect further improvements to get implemented in 2022. Many of the potentialimprovements end up being discussed on the <a href="https://llvm.org/docs/GettingInvolved.html#online-sync-ups">monthly public call on LLVM’ssecurity group</a>.</p>
- New passes in clang-tidy to detect (some) Trojan Sourcehttps://blog.llvm.org/posts/2022-01-12-trojan-source/Wed, 12 Jan 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-01-12-trojan-source/<h1 id="trojan-source">Trojan Source</h1><p>The original <a href="https://trojansource.codes/">Trojan Source paper</a> encompasses afamily of attacks that rely on Unicode properties to make code <em>look</em> differentfrom how a compiler <em>processes</em> it. For instance the following code taken fromthe paper:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><stdio.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><stdbool.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">bool</span> isAdmin <span style="color:#f92672">=</span> false;</span></span><span style="display:flex;"><span> <span style="color:#75715e">/*â® } â¦if (isAdmin)â© â¦begin admins only */</span></span></span><span style="display:flex;"><span> <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">"You are an admin.</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>);</span></span><span style="display:flex;"><span> <span style="color:#75715e">/* end admins only â® { â¦*/</span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>looks like there is a guard on <code>isAdmin</code> while the compiler actually reads thefollowing byte stream</p><pre tabindex="0"><code>/* <U+0x202E> } <U+0x2066> if (isAdmin) <U+0x2069> <U+0x2066> begin admins only */</code></pre><p>This issue got submitted before the official release to the LLVM Security group,and while we agreed this was more of a display issue than an actualcompiler-related issue, we also agreed having a <code>clang-tidy</code> check for eachflaws described in the paper could not hurt.</p><h1 id="using-clang-tidy">Using clang-tidy</h1><p>The tool named <code>clang-tidy</code> can run a bunch of extra passes on a codebase,detecting coding convention issues, API misuses, security flaws etc. We havebeen adding three new checkers:</p><h2 id="detecting-misleading-bidirectional-characters">Detecting misleading bidirectional characters</h2><p>The new check <code>misc-misleading-bidirectional</code> parses each comment and stringliteral from the codebase and looks for unterminated bidirectional sequence,i.e. sequence that leak past the end of comment or string literal, makingregular code being displayed right-to-left instead of the usual left-to-right.In the case of the example above we get a warning close to:</p><pre tabindex="0"><code>5:3: warning: comment contains misleading bidirectional Unicode characters [misc-misleading-bidirectional]</code></pre><h2 id="detecting-misleading-identifiers">Detecting misleading identifiers</h2><p>C++ allows for some Unicode codepoints within identifiers, including identifiersthat have a strong right-to-left direction, which can lead to misleadingstatements. For instance in the following,</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#960050;background-color:#1e0010">×</span> <span style="color:#f92672">=</span> <span style="color:#960050;background-color:#1e0010">×</span>;</span></span></code></pre></div><p>Are we assigining to <code>×</code> or to <code>×</code>? We are actually doing the latter, andthat is confusing. The pass <code>misc-misleading-identifier</code> detect thatconfiguration and outputs a warning similar to</p><pre tabindex="0"><code>10:3: warning: identifier has right-to-left codepoints [misc-misleading-identifier]</code></pre><h2 id="detecting-confusing-identifiers">Detecting confusing identifiers</h2><p>Who never received a spam using unicode characters that look alike asciicharacters to bypass some hypothetical anti-spam scanning? C like language donot escape the trend, and it is perfeclty valid and confusing to define</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> foo;</span></span></code></pre></div><p>at some point of the program, and</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c++" data-lang="c++"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#960050;background-color:#1e0010">ð</span>oo;</span></span></code></pre></div><p>elsewhere. The <code>misc-homoglyph</code> checker detects such confusable identifiers(a.k.a. <em>homoglyph</em>) based on a list of<a href="https://www.unicode.org/Public/security/latest/confusables.txt">confusables.txt</a>maintained by the Unicode consortium. In the case above, one would get a warningsimilar to</p><pre tabindex="0"><code>7:5: warning: ðoo is confusable with foo [misc-homoglyph]</code></pre><h1 id="concluding-words">Concluding Words</h1><p>As described in this post, we chose to implement Trojan Source counter-measureas several <code>clang-tidy</code> checkers. Doing so instead of implementing them as Clang warningis a trade-off on parse time.</p><p>The interested reader can discover the alternative GCC aproach in this<a href="https://developers.redhat.com/articles/2022/01/12/prevent-trojan-source-attacks-gcc-12">dedicated blogpost</a>!</p>
- Improving LLVM Infrastructure - Part 1: Mailing listshttps://blog.llvm.org/posts/2022-01-07-moving-to-discourse/Fri, 07 Jan 2022 00:00:00 +0000https://blog.llvm.org/posts/2022-01-07-moving-to-discourse/<p>When the LLVM Project was open sourced in 2003, it was a small project with a small community. The tools selected to support the project were chosen during a different time and a different situation.</p><p>Now, almost 18 years later, the project has grown tremendously and those infrastructure choices are not necessarily the right choices today. According to a recent <a href="https://www.phoronix.com/scan.php?page=news_item&px=LLVM-Record-Growth-2021">article</a>, the LLVM community experienced record growth in 2021 with 1400 contributors to the LLVM Project. This is incredible growth! While there is a very real cost to change, it is clear that we need to invest in modernizing these tools to support the current and further growth of LLVM.</p><p>Recently, the LLVM Project moved its source code repository and bug tracker to GitHub in an effort to grow the LLVM community and make contributing to the project easier. While these changes were neither quick or easy, the benefits to the project outweigh the time and efforts to make the move. The growth in contributors since the move to GitHub is just one metric showing the gains from the change.</p><p>This year, the LLVM Foundation, which provides the majority of the LLVM Project infrastructure, will be spearheading the effort to evaluate and identify improvements for the remaining tools and software the project utilizes. We will be looking at mailing lists, chat servers, code review tools, and other parts of our infrastructure. This is part 1 in our blog post series describing the upcoming changes (if any) to LLVM infrastructure.</p><p><strong>Project Communication - Mailing Lists</strong></p><p>Mailman and IRC have been the primary means of communication for the LLVM Project for the last 18 years. As the project has grown, we added <a href="http://lists.llvm.org">mailing lists</a> for subprojects like Clang, but the main list (llvm-dev) has remained unchanged. This list is meant to cover all of LLVM which includes everything from mid-level optimizations, to back-end optimizations, to the numerous LLVM backends. It has been the catchall for any topic not covered by another list. Due to the growth in LLVM and the size of the project, this list is very high traffic and requires a lot of work to filter messages that one may be interested in. It is increasingly clear that a mailing list may not be the best form of communication in the lack of features to make it easy to filter, respond and track topics of interest.</p><p>In 2019, LLVM started to experiment with <a href="https://www.discourse.org">Discourse</a> as an alternative to its mailing lists. Discourse is an open source discussion platform built with an amazing list of modern features, such as the following:</p><ul><li>Fully supported Email interface - Discourse supports the ability to interact through email if you do not like to use the web or app interfaces.</li><li>Categories and subcategories - This breaks the LLVM project into smaller pieces and users can subscribe to topics that they care most about versus having to do their own filtering.</li><li>Single Account Sign-On - Users can use their existing GitHub account to use Discourse and get access to all categories.</li><li>Dynamic notifications - Immediately notifies users when they are tagged, get a new reply, or sends email when you are offline.</li><li>Simple - Discourse uses a flat forum where replies are dynamically loaded and flow down the page in a line.</li><li>Mobile support - App available for iOS and Android, but you can also just use the web interface.</li><li>Better Moderation - The community has the ability to self moderate through flagging and spreads the work across a larger group of moderators.</li><li>Enhanced spam blocking - Out of the box spam filtering that eliminates obvious spam before it gets to moderators.</li><li>Safety - It has an enhanced trust system that allows the community to build natural immunity from trolls, bad actors, and spammers, and also reinforces positive behavior through likes and badges.</li></ul><p>The majority of the community was in favor of the move when the move to Discourse was discussed extensively on the LLVM mailing lists. This provides the features mentioned above in addition to a more modern communication. We did hear of one feature some would miss compared to Mailman: the ability to reply to someone directly through email. However, while it may not be ideal for some, we feel this is a worthwhile tradeoff to gain the other benefits, e.g. better safety for LLVM developers and users in general.</p><p><strong>Moving to Discourse</strong></p><p>As a consequence of the above discussion, we are planning to move most mailing lists to Discourse. We are excited that it will bring many new features to help improve communication for existing contributors and users, and also make the project more accessible to newcomers as most are familiar with using forums such as Discourse.</p><p>However, while Discourse is a great solution for community discussions, it is not clear if it is a good place to host commit messages and post-commit review. Therefore, the commit lists wonât be part of the initial migration to Discourse - they will remain on mailing lists for now.</p><p>The plan to move to Discourse will involve the following:</p><ul><li>January 7-9 - Re-configure the existing LLVM Discourse to the new category/subcategory structure (see below)</li><li>January 10-20 (sometime during these 2 weeks) - The LLVM mailing list archives are migrated to Discourse and it is sanity checked by volunteers of the LLVM community. This sanity check can take a week or more.</li><li>Feb 1 - The mailing lists (except commits) are put into read only mode and all users must migrate to use Discourse.</li><li>Feb 1-4 (approx) - The final merge is done from Mailman to Discourse. <strong>We encourage all LLVM community members to start using Discourse on Jan 10th to minimize any disruption once the mailing lists become read only and the final messages are merged to Discourse.</strong> However, please be assured that all mail will be merged to Discourse and you will be able to continue any threads started there once that is completed.</li></ul><p>The mailman archives on the LLVM server may eventually be removed, but there is no final decision or deadline on this yet.</p><p><strong>Mapping from Mailing Lists to Discourse Categories</strong></p><p>The existing LLVM Discourse will be modified to have the following categories/subcategories:</p><ul><li><p>Announcements</p></li><li><p>Clang Frontend</p><ul><li>Using Clang</li><li>Building Clang</li><li>Static Analyzer</li><li>clangd</li></ul></li><li><p>Subprojects</p><ul><li>LLD Linker</li><li>Flang Fortran Frontend</li><li>LLDB Debugger</li></ul></li><li><p>Code Generation</p><ul><li>Common Infrastructure</li><li>AArch64</li><li>ARM</li><li>Mips</li><li>PowerPC</li><li>RISCV</li><li>WebAssembly</li><li>X86</li><li>Other</li></ul></li><li><p>IR & Optimizations</p><ul><li>Loop Optimizations</li></ul></li><li><p>Community</p><ul><li>Women in Compilers and Tools</li><li>Job Postings</li><li>US Developer Meeting</li><li>EuroLLVM</li><li>Google Summer of Code</li><li>Community.o</li><li>LLVM Foundation</li></ul></li><li><p>Project Infrastructure</p><ul><li>Release Testers</li><li>Website</li><li>Documentation</li><li>GitHub</li><li>Code Review</li><li>Discord</li><li>Mailing Lists and Forums</li><li>IRC</li><li>Infrastructure Working Group</li><li>Policies</li><li>LLVM Dev List Archives</li></ul></li><li><p>Runtimes</p><ul><li>C</li><li>C++</li><li>OpenCL</li><li>OpenMP</li><li>Sanitizers</li></ul></li><li><p>Incubator</p><ul><li>CIRCT</li><li>mlir-npcomp</li></ul></li><li><p>MLIR</p><ul><li>Announcements</li><li>Newsletter</li><li>TCP-WG</li></ul></li></ul><p><strong>The Mailman archives will be mapped as follows:</strong></p><table><thead><tr><th>Mailing lists</th><th>category in Discourse</th></tr></thead><tbody><tr><td>All-commits</td><td>no migration at the moment</td></tr><tr><td>Bugs-admin</td><td>no migration at the moment</td></tr><tr><td>cfe-commits</td><td>no migration at the moment</td></tr><tr><td>cfe-dev</td><td>Clang Frontend</td></tr><tr><td>cfe-users</td><td>Clang Frontend/Using Clang</td></tr><tr><td>clangd-dev</td><td>Clang Frontend/clangd</td></tr><tr><td>devmtg-organizers</td><td>Obsolete</td></tr><tr><td>Docs</td><td>Obsolete</td></tr><tr><td>eurollvm-organizers</td><td>Obsolete</td></tr><tr><td>flang-commits</td><td>no migration at the moment</td></tr><tr><td>flang-dev</td><td>Subprojects/Flang Fortran Frontend</td></tr><tr><td>gsoc</td><td>Obsolete</td></tr><tr><td>libc-commits</td><td>no migration at the moment</td></tr><tr><td>libc-dev</td><td>Runtimes/C</td></tr><tr><td>Libclc-dev</td><td>Runtimes/OpenCL</td></tr><tr><td>libcxx-bugs</td><td>no migration at the moment</td></tr><tr><td>libcxx-commits</td><td>no migration at the moment</td></tr><tr><td>libcxx-dev</td><td>Runtimes/C++</td></tr><tr><td>lldb-commits</td><td>no migration at the moment</td></tr><tr><td>lldb-dev</td><td>Subprojects/lldb</td></tr><tr><td>llvm-admin</td><td>no migration at the moment</td></tr><tr><td>llvm-announce</td><td>Announce</td></tr><tr><td>llvm-branch-commits</td><td>no migration at the moment</td></tr><tr><td>llvm-bugs</td><td>no migration at the moment</td></tr><tr><td>llvm-commits</td><td>no migration at the moment</td></tr><tr><td>llvm-dev</td><td>Project Infrastructure/LLVM Dev List Archives</td></tr><tr><td>llvm-devmeeting</td><td>Community/US Developer Meeting</td></tr><tr><td>llvm-foundation</td><td>Community/LLVM Foundation</td></tr><tr><td>Mlir-commits</td><td>no migration at the moment</td></tr><tr><td>Openmp-commits</td><td>no migration at the moment</td></tr><tr><td>Openmp-dev</td><td>Runtimes/OpenMP</td></tr><tr><td>Parallel_libs-commits</td><td>no migration at the moment</td></tr><tr><td>Parallel_libs-dev</td><td>Runtimes/C++</td></tr><tr><td>Release-testers</td><td>Project Infrastructure/Release Testers</td></tr><tr><td>Test-list</td><td>Obsolete</td></tr><tr><td>vmkit-commits</td><td>Obsolete</td></tr><tr><td>WiCT</td><td>Community/Women in Compilers and Tools</td></tr><tr><td>www-scripts</td><td>Obsolete</td></tr></tbody></table><p>For help with migrating to Discourse, please see the <a href="https://llvm.org/docs/DiscourseMigrationGuide.html">User Guide</a> and discuss on the <a href="https://llvm.discourse.group">LLVM Discourse forums</a>.</p>
- LLVM relicensing update & call for helphttps://blog.llvm.org/posts/2021-11-18-relicensing-update/Thu, 18 Nov 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-11-18-relicensing-update/<p>In this blog post, I’d like to summarize the main points I talked about in therelicensing update presentation at the 2021 LLVM Developer’s meeting.</p><p>The very short summary is that we are currently in the long tail phase ofcollecting relicensing agreements of past contributors. We already at the timeof this writing have more than 94% of older code relicensed. We hope to crowdsource getting through the long tail to get as close to 100% as possible.</p><h1 id="call-for-help">Call for help</h1><p>You can help by looking through <a href="https://docs.google.com/spreadsheets/d/18_0Hog_eSwES8lKwf7WJal3yBwwcYfvPu1yCfZnTcek/edit?usp=sharing">the list of remaining individuals andcorporations we need to get agreementsfrom</a>,and reaching out to them, or letting us know at <a href="mailto:[email protected]">[email protected]</a> howwe can reach out to them. Also, if you’d happen to have any other information that you think could help us, please do let us know at <a href="mailto:[email protected]">[email protected]</a>.</p><p>More detailed guidance on how you can help are available at<a href="https://foundation.llvm.org/docs/relicensing_long_tail">https://foundation.llvm.org/docs/relicensing_long_tail</a>.</p><p>In the rest of this blog post, I’m going to give a bit more historicalbackground and describe the current status in more detail.</p><h1 id="the-llvm-relicensing-effort-phases-over-time">The LLVM relicensing effort: phases over time</h1><p>The relicensing effort started some time ago. Let me first very briefly describethe various phases before going in more detail. In the years leading up to 2015,it became clear that there were some issues with the license LLVM had at thetime.</p><p>A different license was the answer to those issues. Between roughly 2015 and2017 the focus was on deciding what different license would be best suited.</p><p>Once it was decided what the new license was going to be, we started working ongetting all code to be covered by this new license. That includes gettingagreement from all copyright holders of existing code to share their pastcontributions under the new license. As you can see on the timeline, gettingthose agreements is the current focus of the relicensing effort.</p><p>Maybe we won’t be able to get an agreement for every single past contribution.In that case, we have a number of options to get to the point where we can claimthat all code in the LLVM project is covered by the new LLVM license. We callthis phase of relicensing “the end game”.</p><p><img src="https://blog.llvm.org/img/relicensing2021/timeline.png" alt="timeline"></p><h1 id="why-relicense">Why relicense?</h1><p>The old license consists of 3 components: the UIUC license that covered all thecode, the MIT license that additionally covered the code in run-time libraries,and a few sentences on granting patent rights in the developer policy.</p><p>This caused<a href="https://lists.llvm.org/pipermail/llvm-dev/2015-October/091536.html">the following 3 issues</a>:</p><ol><li><p>Some were blocked from contributing because of the text in the patent sectionin the developer policy. The wording could be interpreted as requiring givingunnecessarily broad access to patent rights when contributing to LLVM. Thatmade it impossible for some companies to contribute.</p></li><li><p>The run time libraries were dual licensed under the UIUC and MIT license; therest of the code only under the UIUC license. Therefore, we could not easilymove code to run time libraries from other parts. The reason run timelibraries were dual licensed was to enable linking to run time librarybinaries without requiring attribution to LLVM.</p></li><li><p>The wording on patent rights in the developer policy was fuzzy and imprecise,leading to uncertainty over whether it did provide the intended protection.</p></li></ol><h1 id="a-new-license">A new license</h1><p>After exploring a range of options, it was decided that the best solution to solve these issues was to have all code licensed under the <a href="https://foundation.llvm.org/relicensing/LICENSE.txt">Apache-2.0 with LLVM exception</a> license:</p><ul><li><p>Apache-2.0 contains well-understood patent granting which addresses the firstand third issue.</p></li><li><p>The LLVM exception is there for 2 reasons:</p><ul><li><p>It removes a potential incompatibility with using LLVM code in combinationwith GPLv2 code.</p></li><li><p>It removes the requirement for developers using LLVM tools to tell the usersof the binaries they produce that those binaries may contain some codeoriginating from LLVM. Such a situation can easily arise when parts of theLLVM run-time libraries are linked in as part of the normal compilationprocess.</p><p>The LLVM exception enables the run-time libraries to be covered by the exactsame single license as the rest of the code base.</p></li></ul></li></ul><h1 id="getting-all-code-covered-by-the-new-license">Getting all code covered by the new license</h1><p>After a decision was made of what the new license should be, we started workingon having all code covered by it.</p><p>As a first step, we made sure that all new contributions were covered by the newlicense. This happened after the 8.0 release branch was created. The 100kcommits since are covered by the new license.</p><p>The remaining task is to also get the earlier contributions covered by the newlicense. This consists of about 300k commits totaling about 32 million lines ofcontributed code.</p><p><img src="https://blog.llvm.org/img/relicensing2021/getting_all_code_covered.png" alt="Getting all code covered"></p><p>What needs to be done to get those earlier contributions covered?</p><p>The reason we need a license in the first place is copyright. Most codecontributions are covered by copyright. Which means that the person or companyowning the copyright has a lot of decision power over what can legally be donewith that code. By covering the code with a license, it becomes clear whatothers are permitted to do with that code. If there isn’t a license associatedwith copyrighted code there isn’t all that much useful that others can do withit.</p><p>Basically, to get existing code to be covered by a new license, we need to findwho owns the copyright on it, and ask them to agree with offering theircopyrighted work under the new license.</p><p>The copyright owner can be either an individual, for example the person whowrote the code originally; or a company, for example a company that employed theperson who wrote the code.</p><h1 id="asking-agreement-from-copyright-owners">Asking agreement from copyright owners</h1><p>We started asking for their agreements. By examining the version control log ofthe 300k-ish commits we need to get agreements for, we found that about 2800different people or email addresses made a contribution.</p><p>We reached out to all of them and asked them two things. First, if anycorporation may own the copyright on any of their contributions. Secondly, ifthey agree with relicensing the contributions they copyright own personally.</p><p>So far, we’ve heard of about 220 unique corporations potentially copyrightowning some past contribution. We also started reaching out to those, but havenot asked every single one just yet.</p><h1 id="status-as-of-november-2021">Status as of November 2021</h1><p>So after 2.5 years since we started asking – where are we with gettingagreements to relicense?</p><p>The chart below summarize the current status. It shows a treemap where eachrectangle represents the contributions made by one person. The size of eachrectangle represents how many lines of code the person contributed.</p><p><img src="https://blog.llvm.org/img/relicensing2021/relicensing-status-treemap.svg" alt="Treemap showing LLVM relicensing status"></p><p>When the rectangle is green, it means all their contributions are fully coveredby relicensing agreements.</p><p>When the rectangle is orange, it means we have not yet received such anagreement. When the rectangle is orange with green stars, it means somecontributions by that person are covered and others not. This can happen forexample when the person has worked for multiple companies over time and onlysome of those companies have agreed with the relicensing so far.</p><p>We already have over 94% of all contributed lines of code between 2001 and 2019covered by a licensing agreement. We only have a good 5% of lines of code to gostill.</p><p>As you can see, most of the missing agreements are with “long tail”contributors. By long tail contributors here we mean the many contributors whocontributed relatively fewer lines of code. We focussed on reaching out to thebigger contributors first. To reach out well to the long tail of contributors,we’re hoping to get help from the wider LLVM community.</p><h1 id="help-wanted">Help wanted!</h1><p>Please do consider helping us with reaching any of the people or corporations inthe long tail. Please have a look at <a href="https://docs.google.com/spreadsheets/d/18_0Hog_eSwES8lKwf7WJal3yBwwcYfvPu1yCfZnTcek/edit?usp=sharing">the up-to-date list of people andcorporations</a>we can use help with getting in touch with.</p><p>You can find more detailed guidance on how you can help on the <a href="https://foundation.llvm.org/docs/relicensing_long_tail/">LLVM foundationwebsite’s relicensing long tailpage</a>.</p><p>If you do think you could help us with reaching out to someone on the list, oryou may have some other information that could help us, please do let us know byemailing <a href="mailto:[email protected]">[email protected]</a>.</p><h1 id="relicensing-end-game">Relicensing end game</h1><p>We are currently in the phase of getting as many relicensing agreements aspossible. We do expect that we may not be able to get absolutely 100% of allpast contributions covered by an agreement. What can we do to achieve currenttop-of-mainline to be fully covered by the new license?</p><p>We will need to decide on a contribution-by-contribution basis what the optionsavailable are to achieve that goal. We have at least the following options.</p><ul><li><p>We can check if copyright even applies to the particular contribution. Verysmall contributions may not be covered by copyright, and hence may not need alicense agreement.</p></li><li><p>It may well be that code contributed a long time ago is no longer in the codebase.</p></li><li><p>If copyright does apply and the code is still in the code base, we can removethe contribution. Depending on whether current contributors and users stillvalue the effect of that contribution, it may need to be reimplemented.</p></li></ul>
- apt.llvm.org - moving from physical server to the cloudhttps://blog.llvm.org/posts/2021-11-02-apt.llvm.org-moving-from-physical-server-to-the-cloud/Tue, 02 Nov 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-11-02-apt.llvm.org-moving-from-physical-server-to-the-cloud/<p>In this blog post, I would like to explain how I migrated<a href="https://apt.llvm.org">apt.llvm.org</a> from physical hardware hosted ina datacenter to the Google cloud. This has resulted in better securityand faster builds for LLVM Debian/Ubuntu nightly builds.</p><h1 id="previous-infrastructure">Previous infrastructure</h1><p>About 10 years ago, Nick Lewycky from Google offered to replace my mixof old and terrible servers with 16 blade servers in a chassis and acontrol server. Below are pictures of the front and back of theseservers, which have served us faithfully for 10 years:</p><hr><p><img src="https://blog.llvm.org/img/gcp/servers-front.png" alt="Old server - front"> <img src="https://blog.llvm.org/img/gcp/servers-back.png" alt="Old server - back"></p><hr><p>The hosting was sponsored by <a href="https://www.irill.org/"><em>IRILL</em></a>, atInria, next to Versailles.</p><p>This setup was running using a PXE install with preseed to set upeverything on the 16 blades.</p><p>While it served us very well for years, it is now holding us back.</p><ul><li>Some of the blades are dying;</li><li>Old hardware - it takes from 4 to 7 hours per build;</li><li>All blades are always on even if no build is executed;</li><li>Even if it happened rarely, I had to drive to the DC to fix somesystems.</li></ul><h1 id="new-infrastructure">New infrastructure</h1><p>As part of the <a href="https://openssf.org/"><em>OpenSSF initiative</em></a>, Google andthe Linux foundation offered a budget to migrate this service on GoogleCloud Platform (GCP).</p><p>As Jenkins has been working very well, I reused this approach andimported the previous configurations (available on<a href="https://github.com/opencollab/llvm-jenkins.debian.net/tree/master/jobs"><em>https://github.com/opencollab/llvm-jenkins.debian.net/tree/master/jobs</em></a>).</p><p>I followed most of the tutorial provided on GCP, <a href="https://cloud.google.com/architecture/using-jenkins-for-distributed-builds-on-compute-engine"><em>Using Jenkins fordistributed builds on ComputeEngine</em></a>.</p><p>The architecture is the following:</p><p><img src="https://blog.llvm.org/img/gcp/gcp-archi-infra.png" alt="The schema of the infra"></p><p>Similar to puppet or chef, Salt is the configuration management toolused to configure the various systems. A salt server configures both theJenkins controller and the reference node. This node is a preconfiguredVM with all the dependencies and tools to start the build. This node ishalted most of the time and only started when the image needs to beupdated.</p><p>For example, the list of Virtual Machines now usually looks like thefollowing screenshot:</p><p><img src="https://blog.llvm.org/img/gcp/gcp-list-server.png" alt="GCP - list of servers"></p><ul><li>5 build VMs - off after 5 minutes without activity</li><li>The template VM (off as it is only started to update the image)</li><li>The jenkins orchestrator</li></ul><h2 id="build-servers">Build servers</h2><p>The controller is always on and starts/ends the build nodes.</p><p>The reference node is configured and updated using this script, based ongcloud, the Google cloud CLI:</p><p><a href="https://github.com/opencollab/llvm-jenkins.debian.net/blob/master/image-update.sh"><em>https://github.com/opencollab/llvm-jenkins.debian.net/blob/master/image-update.sh</em></a></p><p>This script performs the following steps:</p><ul><li>starts the reference node and then ssh into it.</li><li>Perform the needed changes (ex: new chroot for a new distro version,new build hooks, etc).</li><li>Once the changes are performed.</li></ul><p>Usually:</p><ul><li>Salt update</li><li>Refresh the chroots</li><li><em>git pull</em> llvm-project</li><li>Stops the VM</li><li>Creates a new image.</li><li>Archives the old image.</li><li>This image will be used by Jenkins to start new VMs.</li></ul><p>The node image contains the various i386 and amd64 chroot for supportedDebian and Ubuntu installs. The LLVM repository is also checked out toavoid doing a long clone with many files on every VM startup.</p><p>Thanks to this, the jobs just need to perform a small <em>git pull</em> insteadof a full clone.</p><p><img src="https://blog.llvm.org/img/gcp/gcp-image-node.png" alt="GCP - image node"></p><p>The size of this image is 6.67gb. This approach saves about 10 minutesof the build pipeline (skipping the creation of the chroot + fullclone).</p><p>This wasn’t easy. I had to iterate 25 times to have a proper imagesupporting all the use cases.</p><p>GCP provides a shared file system mechanism available as an NFS mountagecalled <a href="https://cloud.google.com/filestore"><em>Filestore</em></a>. Each buildnode has access to it and will update the various repositories just likeif it was a local file system.</p><h2 id="benefits-and-cost">Benefits and cost</h2><p>The first benefit is security. This is based on the Google cloudinfrastructure, so it benefits from all their security work.</p><p>The fact that the VMs are always cycled and recreated from a clean imagewill also help. They are not directly accessible from the Internet (theyleverage cloud NAT to be able to download packages from the Internet),so it will be harder to attack.</p><p>An amd64 build now runs in parallel takes **about 50 minutes **insteadof almost 7 hours.</p><p>In terms of cost, depending on the activity, the daily cost varies from70 to 150 US$/day.</p><p>Now that the migration has been completed, it is now possible toconsider some builds leveraging PGO and LTO for faster binaries.</p><h2 id="thanks">Thanks</h2><p>Thanks to Laurent Vaylet from the GCP team for the help and patienceanswering my newbie questions, and also thanks to Google and the LinuxFoundation for the GCP credits and support.</p>
- Generating relocatable code for ARM processorshttps://blog.llvm.org/posts/2021-10-01-generating-relocatable-code-for-arm-processors/Fri, 01 Oct 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-10-01-generating-relocatable-code-for-arm-processors/<h2 id="abstract">Abstract</h2><p>By upgrading the LLVM compiler, we solved the problem when neither LLVM nor the GCC could create the correct Position Independent Code for Cortex M controllers, with the code running in Flash memory rather than in RAM. Now the binary image of the program can be flashed to an arbitrary address and run from it, without being moved to another place.</p><p>Updating the microcontrollerâs âfirmwareâ is a dangerous process. Before, any hardware failure during the update could brick your device. Nowadays, devices usually have their own boot loader which lets you restart the update before your deviceâs functionality is lost. Until the update is not complete the device will not work. The fanciest way to update is to use two separate regions for the âfirmwareâ â the main region and the reserve region. In the picture below, they are marked by red and blue accordingly. Initially, the red region is active, while the update will be loaded into the blue region. This way boot failure is not a big deal. The red region will still be running everything. And if the update is successful, the blue region will become active. The next update will be loaded into the red region, and so on. Each update will lead to this switch.</p><p><img src="https://habrastorage.org/webt/mg/po/wi/mgpowihvb5euptcm2vflo2nd-ua.png" alt="img1"></p><p>Unfortunately, with Cortex M systems such an approach cannot be used directly. The program is tied to absolute addresses and cannot be run in an arbitrary place. This article explains why that is the case and how we made the program relocatable by modifying the LLVM compiler.</p><h2 id="introduction">Introduction</h2><p>Someone who has read the documentation may say that compilers already have options to create relocatable code. In the case of LLVM it is -fropi, -frwpi and others. That is where we started our tests too. It turned out that these options were very convenient for the systems where the program was loaded entirely into RAM. In this case, both constants (which were located in the code) and variables (which were located in the data section) were located in the same big segment. This is why it could be easily moved within the RAM.</p><p><img src="https://habrastorage.org/webt/ll/xz/e2/llxze2mozfqk3xsf-2oaqzpvmdw.png" alt="img2"></p><p>For Cortex M controllers it was not that easy. Their code was located in a high-volume ROM while the data was stored in a low-volume RAM. In addition, those entities were located in different parts of the Flash/RAM.</p><p><img src="https://habrastorage.org/webt/5j/ot/po/5jotpomsjyrkaizkxtqlvlqq96i.png" alt="img3"></p><p>Use of these options led to either the data being shifted by the same offset as the program⦠But RAM was much smaller than ROM! Thus, data went out of the allowed bounds.</p><p><img src="https://habrastorage.org/webt/zm/bm/bu/zmbmbuj94znuhn1bbwgibvsdylk.png" alt="img4"></p><p>Or to a huge table of pointers to the code constants being created in RAM. The size of this table significantly raised the amount of used RAM. Therefore, sometimes the amount of RAM provided by Cortex M controllers was just not enough.</p><p><img src="https://habrastorage.org/webt/fn/xy/vk/fnxyvkhm4ffgl9lcwcn3aacmskm.png" alt="img5"></p><p>It became clear that for the target platform (Cortex M controllers) we had to make changes to the compiler.</p><h2 id="basic-principles">Basic Principles</h2><p>To keep things coherent, letâs start with the basics. In computers, data and code are located in the global memory. In the given architecture (just like with almost all other architectures) a linear address space is used, so the location of an object can be defined by a number. In order to perform a certain operation with a memory cell, the processor must know the address of this cell.</p><p>This is where things became complicated. Both maximum instruction and address sizes are 32 bits. Therefore, you could not just emplace 32-bit address into instruction â it had to have enough space for the instructionâs code. One of the solutions was to use relative addressing. At runtime, the program counter register contained the address of the current instruction. That was a full-size 32-bit register the contents of which was being controlled by the hardware. By reading it the program could know its own location in the Flash. There was enough space within the instruction for some offset, so a significant range of addresses around the current location became available. For example, if you needed to call a function that was located near the currently running function, the processor performed a jump with one instruction.</p><p><em>Here, function MyFunc is located near the call location:</em></p><pre><code> bl MyFunc ... .type MyFunc,%functionMyFunc: ...</code></pre><p><img src="https://habrastorage.org/webt/rk/dd/kw/rkddkw3vysf1ogmjfleykgoflqs.png" alt="img6"></p><p>However, it was only a partial solution, because not all jumps were relative, some were absolute. There was a solution though. We put the absolute address into the Flash directly within the code, somewhere near the place where it was being used. Then in a similar fashion, we performed a PC-relative load of this address into a register and loaded the value itself relative to the register with the next command. A more advanced method was to use a movw, movt instruction pair. The target 32-bit address was cut into two halves which was loaded into the register in two steps. Although it meant using two commands, it led to saving extra addressing.</p><p><em>Loading the contents of global_result_data7 address into the r0 register:</em></p><pre><code> movwr0, :lower16:global_result_data7 movtr0, :upper16:global_result_data7 ldrr0, [r0]</code></pre><p>Letâs take a closer look at the register loading process, where the variable global_result_data7 had the address 0x12345678:</p><p><img src="https://habrastorage.org/webt/yz/b2/yt/yzb2ytpms1lpr4oghmrrpaelq5y.png" alt="img7"></p><p>Now, when we figured out how the processor operated with the addresses, it is time to explain where they come from. The Flash/RAM is (with some exceptions) uniform, which means that the function with the address 0x1000 may as well be located at the 0x2000, the only requirement is for the address to be known. The linker is responsible for address assignment. It receives all objects of the program as input and allocates space for them according to the attached configuration file. This way, every object gets its own address, and these addresses are written down to where the functions are being used. Moreover, it is worth noting that Flash/RAM does not have to start from the zero address, the starting address 0x08000000 is quite common as well. This value must be added to all global addresses.</p><h2 id="problem-definition">Problem Definition</h2><p>So, we had a binary image, suitable for loading into the deviceâs Flash/RAM. When we wrote it from the initial address defined at linking time and then ran it, the program worked. All data was located in the expected places, all the called addresses had the necessary functions, and so on. One may wonder, what if we had loaded the image from a different address? The first thing that comes to mind â everything would have fallen apart. The program would have accessed the cell value from the address 0x1000, but it would be actually located in a completely different place. However, letâs imagine a basic program consisting of only one instruction â infinite loop. Obviously, such a program was quite relocatable: and because such a short jump was performed PC-relatively, it automatically âadjustedâ to its new location. Moreover, if all jumps/calls in the program were relative, it could be quite big and complex; at least all functions were called correctly. Everything was fine until the program tried to use a global address with a value that was offset relative to the expectations.</p><p>Now it is time to ask a question: was it an issue? Whatâs wrong with the program being tied to absolute addresses? Whatâs the benefit of a program that can run from an arbitrary address? One can argue that it is a good thing if it is cost-effective. Still it could have a much more specific use. For example, the device could receive a code snippet from the outside, which would expand the features of the already existing program, and load it as an addition to the current code. It would be very convenient if this code could work regardless of its location in the Flash. Lastly, there would be a possibility of a complete firmware update release. It also had to be located somewhere in the Flash and then given control of the device. Notably, we do not know where it ends up, so the ability to run from arbitrary addresses is a necessity.</p><p>Therefore, the task of achieving relocatable code is worth looking into. It should be noted that in serious systems it is solved by using virtual memory. Logical addresses used in the program are silently mapped to physical addresses, so there are no problems. However, it is a completely different technological level. We were focused on the Cortex-M, without the MMU module. This is why in our case we had to âadjustâ the global addresses by adding a programâs memory offset value. Because all address calculations came down to offsets and the difference of pointers, no other changes were required.</p><p>It brought up a new task â to retrieve the programâs offset value in the Flash relative to its initial address that was defined at linking time. For example, one could use the following trick. Global addresses remained the same, while the PC value was different. You got the difference between a global address and a PC one during run from a ânormal addressâ and âhardcodedâ it into the program. When run from an offset address this difference was different, and calculating how much it had changed gave you the offset value. However, as it will be shown later, there is a more direct way to get the offset value, so for now, letâs just say that the offset value is known.</p><h2 id="implementation-initial-approach">Implementation (Initial Approach)</h2><p>So, the processor loaded the global address into the register. When you use assembler, you only have to insert a specific instruction right after it, which will add the offset value to the result.</p><p><em>DoOperation function receives the global address global_operation5, which is modified by a r9 register value:</em></p><pre><code>movwr0, :lower16:global_operation5movtr0, :upper16:global_operation5addr0, r9blDoOperation</code></pre><p><img src="https://habrastorage.org/webt/1h/qd/tt/1hqdtt3aadhvapfrvw1ma4lwoi0.png" alt="img8"></p><p>To do this, we had to reserve the register for permanent storage of this value. Certainly, we could load it from RAM each time, but expected losses (ROM volume and processor cycles) were higher than if we were to lose one register. But what should we do if we coded in C? Obviously, the whole scheme only made sense when we did not have to modify the source code. Itâs one thing to make some special manipulations here and there, but no major changes are allowed. Fortunately, the compiler could deal with the given task with only a minor modification.</p><p>The thing is, the compiler knows perfectly well what exactly it is doing. We used LLVM because we had extensive experience in modifying this compiler, so going forward we will discuss LLVM only. LLVM has a mechanism for separate address space which allows us to bind an attribute to a pointer, which defines data location. In our case, we assumed that only ROM content was moved, while RAM addresses stayed the same. In this case, we set a separate address space for constant global objects (functions, constant data, string literals â everything that went into the read-only memory).</p><p><em>Here we set a separate address space for constant data and map it to global objects:</em></p><pre><code>llvm::Optional<LangAS> ARMTargetInfo::getConstantAddressSpace() const { return getLangASFromTargetAS(REL_ROM_AS);}LangAS getGlobalVarAddressSpace(CodeGenModule &CGM, const VarDecl *D) const override { if (D && CGM.isTypeConstant(D->getType(), false)) { auto ConstAS = CGM.getTarget().getConstantAddressSpace(); assert(ConstAS && "No const AddressSpace"); return ConstAS.getValue(); } return TargetCodeGenInfo::getGlobalVarAddressSpace(CGM, D);}</code></pre><p>This attribute âlivedâ inside the type during the whole compilation; during object address loading there was a way to recognize the ROM allocation and insert the instructions necessary for the offset.</p><h2 id="static-initialization-issue">Static Initialization Issue</h2><p>Unfortunately, there was a scenario that we could not process with the given method. We had a global pointer array, which was initialized with a mix of ROM and RAM addresses.</p><p><em>Array arr contains two addresses: for ROM and for RAM:</em></p><pre><code> int ro; const int rw; const int *arr[] = { &ro, &rw };</code></pre><p>This initialization was performed statically, which meant that the linker allocated Flash and filled it with numbers, which were represented as symbolic addresses.</p><p><em>Static initialization of array arr:</em></p><pre><code>.typearr,%object.section.rodata,"a",%progbitsarr:.long ro.long rw.size arr, 8</code></pre><p>It did not know the future offset value yet, so it could not do anything. It shall be noted that linkers come in all shapes and sized, they can have various advanced features, but for that time, we stuck to simple binary images. So, we had an array of numbers. Still we could do nothing at runtime as well, because we did not know which addresses were from ROM and which were from RAM anymore. So, did our whole idea just go down the drain?</p><p>Essentially, there was a very costly but quite versatile solution. If we had known the RAM and ROM address ranges, we could have sent the whole addressing through a special function that, based on the address value, defined where it was from and modified it if necessary. However, the overhead expenses it required were enormous. In this case, the solution was purely theoretical, and obviously, unusable for real-world applications, apart from some individual cases.</p><h2 id="implementation-new-approach">Implementation (New Approach)</h2><p>We wished we had modified the addresses during the firmware loading. Of course, it required us to change the program for loading the image into the Flash, as well as to provide additional information about the image itself, but that idea actually sounded plausible. As was said above, the ability to run from any loading address came at a cost of a small increase in code size and slightly lower performance. If we had fixed all bottlenecks directly in the binary image, the relocatability could have been achieved without the aforementioned performance/efficiency losses. There were possible pitfalls, but the idea was worth trying out.</p><p>The first method was rough though a promising one. We wondered what if we had made two firmware variants be loaded from different addresses and compared afterwards. Only the addresses should have changed, so we would have seen all the places that needed modification. However, it turned out that there were many more differences than that. Some of them might have been disregarded as irrelevant to our task, but there were no guarantees that we would always be able to distinguish valid issues from artifacts. And in the end, the whole method itself sounded too naive for serious applications.</p><p>Taking into consideration the above, it was obvious that we had to change at least some addresses used for global pointers initialization. For simplicity, we supposed that during code generation an intermediate assembler file was created and that we had the ability to intervene with this process. A new idea emerged then. Each time the compiler used a global address for initialization, we could see which address space it used, and if it was from ROM, we could put a label before it.</p><p><em>We put markers before ROM address initialization.</em></p><pre><code>mainMenu:Reloc2: .long mainMenuEntriesC .long mainMenuEntriesMReloc3: .long mainMenuEntriesC+8</code></pre><p>At the end of the module, we added a section with a special name and put all those labels in it.</p><p><em>Labels are put into the reloc_patch section:</em></p><pre><code>.section .reloc_patch,"aw",%progbits.globl _Reloc_3877008883__Reloc_3877008883_: .long Reloc1 .long Reloc2 .long Reloc3</code></pre><p>In the linker script, we defined this section as KEEP so it would remain intact, because, obviously, there were no uses of its data. Later, when the executable file was being linked, all the added sections were joined together and the labels got specific values corresponding to the binary image addresses. The key moment here is that those addresses were equal to the offsets in the output file. Therefore, we could locate the places that needed changes. One subtle aspect to be noted, if the initialized data was located in RAM, their initialization would be located in ROM with a known offset. Therefore, we needed two sections: one for ROM and one for RAM data. The first was processed as listed above, while for the addresses of the second section we had to subtract the initial RAM address and add the initialization block offset which was defined in the linker script file.</p><p>Then we wrote a small utility program that recovered our sections from the ELF representation and got the offset list for the global addresses.</p><p>It shall be noted that there is a simple way to get relocation tables using standard means, i.e. a linker creates sections in ELF when âq opcode is set. These tables contain all the data we retrieved using the described above method and can be used for our purposes as well. However, they are too big, while we aimed at less memory usage. Moreover, we would use only small bits of them; therefore, we would have to deal with a table relocation parsing issue. On the on hand, we would save efforts by leaving compiler as it is, on the other, it would bring up another problem. Thus, we decided in favor of the method described above.</p><h2 id="development-of-the-approach">Development of the Approach</h2><p>That was enough to modify the firmware at load time but we went even further. We defined a simple set of commands, like this one:</p><p><code>âDâ [qty] {data}</code> â write the following qty bytes from the input stream</p><p><code>âAâ [qty]</code> â interpret qty as addresses, add a specific value to them and print them to the output</p><p><em>Send four bytes to the output stream and correct two addresses:</em></p><p><code>âDâ 0x4 0x62 0x54 0x86 0x12 âAâ 0x2 0x00001000 0x00001008</code></p><p><em>If the offset is 0x4000, the result would be like this (for clarity we do not decompose the numbers into bytes):</em></p><p><code>0x62 0x54 0x86 0x12 0x00005000 0x00005008</code></p><p>Then we turned the initial binary image into a stream of such commands. All data up until the first address that needed modification were skipped without changes, then followed the command that modified one or a couple of addresses, then some data again, and so on, until the end of the file. That way, the information for address correction was embedded into the binary image. On one hand, the resulting file was no longer firmware suitable for booting flashing. But then we were able to process it âon the flyâ in streaming mode as we received it, using a small buffer. Thus, we had to modify the loader program a little to change the addresses according to the received commands rather than just writing the input stream into the board Flash/RAM. Moreover, we created an additional utility program that accepted such a file and a starting address as input and then created a firmware.</p><p>We went even further. As mentioned above, some addresses were âhardcodedâ into the movw, movt instruction pairs. The compiler could tell which of them corresponded to ROM address loading, put labels there and make another section for them. Also, we added a command that chose two words from the stream, interpreted them as loading instruction pairs, retrieved the address, changed it, and then put it back in. Thus, the additional steps during runtime became unnecessary. Apart from that, we got the ability to modify the program at ease (for example, changing the version number, etc.).</p><p>This also allowed us to give the program the offset value if necessary. To do that, we created a function with a special name that wrote the constant value to a RAM cell. In code this function started with two movw, movt pairs â the first was to load RAM cell address and the second was for the constant itself.</p><p><em>Retrieving the offset in the RAM cell and r9 register:</em></p><pre><code>int rel_code = 0;int set_rel_code() { rel_code = 0x12345678; return rel_code;}void __attribute__((section(".text_init"))) Reset_Handler(void) { set_rel_code(); asm(âmov r9, r0â); ...}</code></pre><p>We added another stream command that had not been added the offset to the value hardcoded in the load instruction pair, but it actually changed the value to the one being given. As a result, the function put the offset value itself into RAM, and after the functionâs call this value was available. All in all, that opened quite a broad range of possibilities, so the additional difficulties look justified.</p><h2 id="current-limitations">Current Limitations</h2><p>Undoubtedly, the need to work with the intermediate assembler file is a flaw of the implementation. It can be neglected because it is hard to say what it exactly affects. Perhaps, we would get rid of it in the future versions by creating labels directly within the compilerâs internal representation. There is also nothing good in that service sections used for retrieving displacements of the binary image, actually take up memory space. However, we could give them fictional addresses where the Flash/RAM is absent as long as there are no errors during loading.</p><h2 id="conclusion">Conclusion</h2><p>The LLVM compiler was modified to generate binary code that could be tied to any address before loading to the flash memory without using the additional source code or development environment. All the necessary information is contained in the binary code.</p>
- Meet the LLVM Outreachy Interns!https://blog.llvm.org/posts/2021-07-14-llvm-and-outreachy/Wed, 14 Jul 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-07-14-llvm-and-outreachy/<p>The LLVM Project is participating in the <a href="https://www.outreachy.org">Outreachy</a> program for the first time. Two interns have been selected: Sushma Unnibhavi & Pooja Yadav.</p><p>Outreachy provides paid, remote internships with the goal of increasing diversity in open source. Outreachy interns work with mentors from open source communites on projects in programming, user experience, documentation, illustration, graphical design, data science, project marketing, user advocacy, or community event planning.</p><p>Pooja will be working with her mentor Kit Barton on her project to <em>Create Documentation and Tutorials for the LLVM Global Instruction Selection Framework</em>. Sushma will be working with her mentor Anshil Gandhi on her project to <em>Implement GlobalISel for the M68k backend in LLVM</em>. T</p><p>Thank you to the <a href="https://foundation.llvm.org/docs/sponsors/">sponsors</a> of the <a href="https://foundation.llvm.org">LLVM Foundation</a> as their support has made these internships possible. In addition, we would like to give a huge thank you to Kit and Anshil for mentoring!</p><p>We asked Sushma and Pooja a few questions about themselves and the project they are working on. Here are their answers:</p><p><strong>Sushma Unnibhavi</strong></p><p><em>Can you tell us about yourself and your background?</em></p><p>I am Sushma, a final year Information Science Engineering undergradfrom India. My hobbies include drawing, dancing and reading. I lovewriting code. I have been obsessed with the idea of using software tosolve practical problems. I love to dig into problems and solve themwith modern technology. I am constantly learning because I neversettle. I focus on making high-quality decisions and love meeting newpeople and hearing new perspectives. My specialities include learningnew skills and programming languages and problem-solving.</p><p><em>How did you hear about Outreachy and why did you apply?</em></p><p>I first came to know about Outreachy from my brother and searched forit right away. I found out that Outreachy seeks interns who aretalented and have a zeal to learn while most of the other internshipssought for the experience. I have always wanted to contribute to opensource but never got proper guidance. Then I read the experiences ofprevious Outreachy interns which really motivated me. Many of themdidnât have any prior experience and they were supported so much fromthe mentors that made them reach greater heights. This made methinkâ¦..If they can, why canât I? Hence I decided to apply toOutreachy. The way I have seen myself grow by contributing to LLVM inthe one month time span of the contribution period is reallysurprising.</p><p><em>Which project will you be working on?</em></p><p>I will be implementing GloballSel for M68k. I will be adding minimalsupport necessary to select a function that returns sum of two i32values. This includes some very naive and hardcoded argument/returnlowering as well as handling of copy and add instructions throughoutglobalisel pipeline. I will also be implementing lowering foroperations including add, sub, mul, div, comp, phi, load and store.</p><p><em>What are you most looking forward to during your internship?</em></p><p>One thing I am looking forward to in this internship is a greatlearning experience. When I first started contributing to LLVM, Ithought I wouldnât stand a chance because I had never worked on aproject with such a huge codebase and that too working on compilerswas a nightmare for me. Through this internship I want to let go ofthis fear and become more confident. I want to prove to myself thatwith hard work and consistency nothing is impossible.</p><p><strong>Pooja Yadav</strong></p><p><em>Can you tell us about yourself and your background?</em></p><p>Hi! I am Pooja Yadav from India. I am currently pursuing my undergraduate degree in Computer Science and Engineering at National Institute of Technology, Goa, India. I have been interested in computer science since high school and feel lucky to get the branch of my choice in one of the deemed universities in India for my Btech degree. I like badminton and skipping in sports and I was a national player in rope skipping at my high school. Sometimes, to relax myself I draw sketches and play with paints sometimes. It is really therapeutic.</p><p>I am also a supporter of equity and diversity in the tech field. I am the General Secretory of SPIE student chapter of our college and we have organised many events to support equity. diversity and inclusion.</p><p><em>How did you hear about Outreachy and why did you apply?</em></p><p>I heard about Outreachy in my second year of college from one of my seniors who is also an Outreachy alum. So, I also thought about participating in it. Outreachy provides great opportunity to people subjected to systematic bias and underrepresented in the technical industry. This was what encouraged me to participate in it. I got introduced to the vast ocean of computer science field in my first year of college and It seemed so overwhelming to me. So, I thought Outreachy would be a good place to start and that is how I got introduced to open source. I tried for Outreachy internship last year also but my final application was not selected. However, I learned a lot of things and was determined to try this year as well. I met many amazing people during the contribution period. All mentors and participants were very friendly and it was always a pleasure to talk to them. Mentors were very patient to answer all my questions, even the dumbest one. Also, the projects were so exciting and I wanted to dive into one of them because I knew that would raise my learning curve to another level. And this year the LLVM project on which I would be working got my interest. So, I decided to contribute to it and luckily I got selected for it.</p><p><em>Which project will you be working on?</em></p><p>The project on which I am working is ‘Create Documentation and Tutorials for the LLVM Global Instruction Selection Framework’. Working on it was quite adventurous during my contribution period and currently I am learning a lot of things. This project is about reading present documentation of GlobalISel and updating or making the required changes. Then make a good tutorial for GIobalISel which would help many contributors in future; beginners as well as professionals. For creating documentation and tutorials I have to understand everything about GlobalIsel. So I am learning along as I move ahead in my project.</p><p><em>What are you most looking forward to during your internship?</em></p><p>I had never heard about LLVM IR before. When I first read about it I was intrigued by the idea of improving the performance of a compiler with one more intermediate representation i.e machine IR and how we can write a generalised IR for compilers so that we don’t need to do it from scratch for every backend. I have learnt many things while working on this project, which include other things apart from this project topic like the concept of compilers, git, open source contributing rules, interaction with other contributors, communication skills, etc.</p><p>I am looking forward to learning more about this project and contributing my best to it. I like to explore different fields and this is a great opportunity to observe what other contributors are doing and learn from their project as well.</p>
- Smaller debug info with constructor type hominghttps://blog.llvm.org/posts/2021-04-05-constructor-homing-for-debug-info/Mon, 05 Apr 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-04-05-constructor-homing-for-debug-info/<h1 id="constructor-type-homing-for-debug-info">Constructor type homing for debug info</h1><h2 id="background">Background</h2><p>Class type information is a large contributor to debug info size. Clang already has a few optimizations to reduce the size of class type information based on the assumption that debug info can be spread out over multiple compilation units. So, instead of emitting class type info in every compilation unit that references a class, we only really have to emit it in one place. (For all the other references, emitting the much smaller forward declaration of the class is sufficient.) As an example, one of the existing optimizations is vtable homing, where the type info for a dynamic C++ class is only emitted when its vtable is emitted.</p><h2 id="constructor-type-homing">Constructor type homing</h2><p>Constructor homing is a similar optimization that applies to almost all classes with constructors. It emits type information for a class wherever its constructor definition is emitted. Unlike with vtable homing, the type info for a class could be emitted more than once, but it has a large impact on debug info because it applies to a large percentage of classes. If all of a class’s constructors are defined out of line, the class type information will only be emitted once. If there are constructors defined inline, the inline constructors, and therefore class type information, will be emitted in every compilation unit that calls a constructor.</p><p>Constructor homing assumes that if a user wants a class to have debug info, then that class was constructed somewhere in the program. This is a reasonable assumption to make, as classes viewed in the debugger probably exist in program memory, and any class that exists in memory must have been constructed.</p><p>Even though all classes have constructors, there are some types of classes that constructor homing doesn’t apply to: trivial classes, aggregate classes, and classes with constexpr constructors. It’s possible to create instances of these classes without emitting a constructor, so we can’t guarantee that the debug info will be emitted. However, these types of classes tend to be fairly small, so we would probably see less of an improvement from using constructor homing on them.</p><p>Constructor homing can be enabled with <code>-Xclang -fuse-ctor-homing</code>. Eventually, the plan is to enable it by default in Clang so that it happens as part of <code>-fno-standalone-debug</code>. In terms of Clang’s <code>-debug-info-kind=</code> flags, constructor homing is implemented as <code>-debug-info-kind=constructor</code>, one level below <code>-debug-info-kind=limited</code>.</p><h2 id="size-improvements">Size improvements</h2><p>Emitting less class type info gives us a significant reduction in object file sizes. In a Chrome debug build on Linux (which uses split dwarf for debug info), .o and .dwo file sizes with constructor type homing are about 30% smaller (with a 20% overall reduction in build directory size). In a Clang debug build on Linux, .o file sizes are about 48% smaller (and the overall build directory is 38% smaller). On Windows, both Chrome and Clang had 37% smaller .obj files.</p><p>The smaller object file size also results in an improvement in link times and GDB load times. On Windows, linking Chrome with constructor homing is 6% faster, while linking Clang is 34% faster. On Linux there was no noticeable difference in link time in Chrome, but linking Clang is 25% faster.</p><p>Measured on my machine, without using <code>--gdb-index</code>, the GDB load time for Clang is about 2m30s without constructor homing, and 1 minute with. If <code>--gdb-index</code> is enabled, the GDB startup time is about a second regardless, and the binary size is about 30% smaller with constructor homing.</p><h2 id="potential-pitfalls">Potential pitfalls</h2><p>Ideally, constructor homing shouldn’t change the debug info that’s available when debugging, but there are some cases where it does. Even though this is undefined behavior in C++, it is possible to define a class with a non-trivial constructor and create an instance of it without calling the constructor (this is often done in C code, where there are no constructors):</p><pre tabindex="0"><code>Foo *p = malloc(sizeof(Foo));p->someField = 1;</code></pre><p>The constructor for Foo is never called, so its debug info is never emitted.</p><p>After enabling constructor type homing in Chrome, we discovered that there are a few classes in libc++ that avoid calling the constructor, and for various reasons, that would be difficult to change. To ensure that they still have debug info, there’s a new attribute in Clang called <code>[[standalone_debug]]</code>. If a class has the attribute it will have the same debug info as if it were built with -fstandalone-debug. This can be used to get debug info for classes that otherwise would have had their type info omitted with constructor homing (or with any of the other debug info optimizations).</p><p>I’ve also looked into whether there are other common cases where constructor homing omits debug info. Manually comparing the debug info available in a Clang build showed some missing types. There were a few classes that were not used anywhere. There were also one or two pseudo-namespace classes that only had static methods and were therefore never constructed. Looking at diffs of the debug info is somewhat difficult given how many object files and types there are (most of the missing types I saw were because the type wasn’t constructed in the particular binary or set of object files I compared), so there may have been other cases I missed.</p><h1 id="summary">Summary</h1><p>Constructor type homing is a new optimization that greatly reduces the size of debug info in object files. Currently it can be enabled with the cc1 flag <code>-fuse-ctor-homing</code>, and the plan is to enable it by default as part of <code>-fno-standalone-debug</code> in Clang. If you want to make your debug builds smaller, try adding <code>-Xclang -fuse-ctor-homing</code> to your build and let us know how much object file size it saves.</p>
- Women in Compilers and Tools Meetup Serieshttps://blog.llvm.org/posts/2021-03-31-womenincompilerstoolsmeetup/Wed, 31 Mar 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-03-31-womenincompilerstoolsmeetup/<p>As today is the last day of Women’s History Month, it seems fitting to announce a new meetup series for Women in Compilers and Tools.</p><p>The <a href="https://www.meetup.com/meetup-group-ifwtlvwd/">LLVM Women in Compilers and Tools Meetup Series</a> is a free virtual event held each month. It is a platform where all women (trans, non-binary, and cis) in various stages in their career, speak openly, discuss, and network with others. This series will feature talks, tutorials, mentoring events and regularly highlights individuals for their contributions to the compiler, programming languages, and tools field and offers continued discussions concluding each event.</p><p>This series is organized by <a href="https://community-dot-o.llvm.org/groups/">The Women in Compilers and Tools</a> (WiCT) <a href="https://community-dot-o.llvm.org/">Community.o</a> group. This working group is composed of volunteers in the <a href="https://llvm.org">LLVM community</a> and supported by the <a href="https://foundation.llvm.org">LLVM Foundation</a>.</p><p>In this series launch, we will be hearing from The Women in Compilers and Tools (WiCT) working group. This working group is composed of volunteers in the LLVM community who’ve put together this series. The WiCT working group will provide a Birds of a Feather style talk where attendees can learn more about the series and what to look forward to in the coming months! This will be a great opportunity to ask questions and network with LLVM community members and enthusiasts.</p><p>The <a href="https://www.meetup.com/meetup-group-ifwtlvwd/events/277283914/">first meetup</a> will occur on Thursday, April 22, 2021 at 6pm PDT and feature the following members of the WiCT working group:</p><hr><p><strong>Anupama Chandrasekhar</strong>, <em>NVIDIA</em></p><p>Anupama is a Software Engineer at Nvidia working on graphics drivers, compilers, self driving cars and other cool technologies. Prior to this she was graphics software engineer at Intel working on the integrated GPU. Her prior work includes graphics/compute compiler development for GPUs, DX and Metal driver development and GPU performance. Her main interests are programming languages and compilers. She received her MS in Computer Science and Electrical Engineering from Pennsylvania State University and B.E in Electronics from Anna University, Chennai, India.</p><p><strong><a href="https://twitter.com/CyndyIshida">Cyndy Ishida</a></strong>, <em>Apple</em></p><p>Cyndy Ishida has been a Compiler Engineer at Apple, Inc. since 2019 concentrating on library support with Clang tooling. Prior to working at Apple, she completed internships at Virtu Financial, Microsoft and Facebook related to C++ development. Cyndy is relatively new to the LLVM community and began her involvement by contributing Mach-O Support to TextAPI, which serves as a condensed textual representation of dynamic libraries from a linking perspective. She is additionally a Board Member for the LLVM Foundation and aided in launching Community.o, The Foundationâs Diversity & Inclusion initiative and co-organized The Community.o Summit.</p><p><strong><a href="https://twitter.com/tonic888">Tanya Lattner</a></strong>, <em>LLVM Foundation</em></p><p>Tanya Lattner is the President and Chief Executive Officer of the LLVM Foundation, a nonprofit supporting the open source software project LLVM (llvm.org). As CEO, Tanya designs programs to support the LLVM project through educational events such as developers conferences and workshops, student support through travel grants, community outreach, and increasing diversity within the project through the Community.o Program.She has a Bachelors of Science in Electrical Engineering from the University of Portland and a Masters Degree in Computer Science from the University of Illinois Urbana-Champaign. Tanya has over 10 years experience as a software engineer primarily focusing on compilers and related tools. She also has 5 patents from her work on code obfuscation, which use compiler techniques to prevent tampering or reverse engineering by hackers.</p><p><strong><a href="https://twitter.com/jubitaneja">Jubi Taneja</a></strong>, <em>University of Utah</em></p><p>Jubi Taneja is a PhD candidate at the University of Utah. She will graduate and go on to work full-time with the Machine Learning Compiler group at Microsoft Research starting in the summer of 2021. Her research broadly focuses on compiler optimizations, correctness, and static analysis, with the goal of helping compiler developers use formal methods. She started her learning of compilers at IIT Bombay as an undergraduate research fellow. She earned her B.E. with a Gold Medal from Punjabi University, India. She is a SIGPLAN Long-Term Mentor for international PL researchers since summer 2020. She has been mentoring high school and undergraduate students from India for the past 10 years.</p><hr><p>If you are interested in attending, please register <a href="https://www.meetup.com/meetup-group-ifwtlvwd/events/277283914/">here</a>.</p>
- The New Pass Managerhttps://blog.llvm.org/posts/2021-03-26-the-new-pass-manager/Fri, 26 Mar 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-03-26-the-new-pass-manager/<h1 id="llvms-new-pass-manager">LLVM’s New Pass Manager</h1><h2 id="what-is-a-pass-manager">What is a pass manager?</h2><p>A pass manager schedules transformation passes and analyses to be run on IR in a specific order. Passes can run on an entire module, a single function, or something more abstract such as a strongly connected component (SCC) in a call graph or a loop inside of a function. Scheduling can be simple, such as running a list of module passes, or running function passes on every function inside a module. Scheduling can also be more involved, such as making sure we visit SCCs in the call graph in the correct order.</p><p>A pass manager is also responsible for managing analysis results. Analyses (e.g. dominator tree) should be shared between passes whenever possible for efficiency reasons, since recomputing analyses can be expensive. To do so, the pass manager must cache results and recompute them when they are invalidated by transforms.</p><p>For testing purposes, we can add specific passes to a pass manager to test those passes. However, the typical use case is to run a predetermined pass pipeline. For example, <code>clang -O2</code> runs a predetermined set of passes on the input IR.</p><h2 id="what-is-llvms-new-pass-manager">What is LLVM’s new pass manager?</h2><p>LLVM currently has two separate pass managers: the legacy pass manager (legacy PM) and the new pass manager (new PM). When referring to “legacy PM” and “new PM”, this includes all of the surrounding infrastructure, not just the entity that manages passes.</p><p>The legacy PM has been in use for a very long time and did its job fairly well. However, there were some missing features required for better optimization opportunities, most notably the ability to use function analysis results for arbitrary functions from the inliner. The specific motivating use case was that the inliner wanted to look at the profile data of callees recursively, especially in regards to deferred inlining where the inliner wants to look through simple “wrapper” functions. The legacy PM did not support retrieval of analyses for arbitrary functions in a CGSCC pass. A CGSCC pass runs on a specific strongly connected component (SCC) of the call graph. The pass manager makes sure we visit SCCs bottom-up so that callees are as optimized as possible when we get to their callers and callers have as precise information as possible. LLVM’s inliner is a CGSCC pass due to being a bottom-up inliner. This major limitation of the legacy PM, along with other warts, prompted the desire for a new pass manager.</p><p>Currently the new PM applies only to the middle-end optimization pipeline working with LLVM IR. The backend codegen pipeline still works only with the legacy PM, mostly because most codegen passes don’t work on LLVM IR, but rather machine IR (MIR), and nobody has yet put in the time to create the new PM infrastructure for MIR passes and to migrate all of the backends to use the new PM. Migrating to the new PM for the codegen pipeline likely won’t unlock performance gains since there are almost no interprocedural codegen passes. However, it would clean up a lot of technical debt.</p><h2 id="design">Design</h2><p>With the legacy PM, each pass declares which analyses it requires and preserves, and the pass manager schedules those analyses as passes to be run if they aren’t currently cached or have been invalidated. Declaring ahead of time which analyses a pass may need is unnecessary boilerplate, and a pass might not end up using all analyses in all cases.</p><p>The new PM takes a different approach of completely separating analyses and normal passes. Rather than having the pass manager take care of analyses, a separate analysis manager is in charge of computing, caching, and invalidating analyses. Passes can simply request an analysis from the analysis manager, allowing for lazily computing analyses. In order for a pass to communicate that analyses have been invalidated, it returns which analyses it has preserved. The pass manager tells the analysis manager to handle invalidated cached analyses. This results in less boilerplate and better separation of concerns between passes and analyses.</p><p>Since the legacy PM modelled analyses as passes to be scheduled and run, we can’t efficiently access analyses to arbitrary functions. For a function analysis, the corresponding analysis pass will only contain the info for the current function, which is created during the latest run of the analysis pass. We can manually create analyses for other functions, but they won’t be cached anywhere, leading to lots of redundant work and unacceptable compile time regressions. Since analyses are handled by an analysis manager in the new PM, the analysis manager can cache arbitrary analyses for arbitrary functions.</p><p>To support CGSCC analyses, we need a key to cache analyses. For things like functions and loops, we have persistent data structures for those to use as keys. However, the legacy CGSCC pass manager only stored the functions in the current SCC in memory and did not have a persistent call graph data structure to use as keys to cache analyses. So we need to keep the whole graph in memory to have something to use as a key. And if we have a persistent call graph, we need to make sure it is up to date if passes change its structure. To avoid too much redundant work regenerating a potentially large but sparse graph, we need to incrementally update the graph. This is the reason behind the complexity of the CGSCC pass manager in the new PM.</p><p>Within an SCC, a transform might break a call graph cycle and split the SCC. One issue with the legacy CGSCC infrastructure is that it simply stores all the functions in the current SCC in an array, then iterates through the functions in that order without ever revisiting functions. Consider the following SCC containing two functions.</p><pre tabindex="0"><code>void foo() { bar();}void bar() { if (false) { foo(); }}</code></pre><p>Say we first visit foo, then visit bar and remove the dead call.</p><pre tabindex="0"><code>void foo() { bar();}void bar() {}</code></pre><p>We now want to revisit foo since we have better information, most notably that foo is in its own SCC. The legacy CGSCC pass manager would simply move on to the next part of the call graph. So as part of the new PM’s incremental call graph update, if an SCC is split, we make sure to visit the newly split SCCs bottom-up. This may involve revisiting a function we have already visited, but that is intentional as to give passes a chance to observe more precise information.</p><p>When adding passes to the legacy pass manager, the nesting of different pass types is implicit. For example, adding function passes after a module pass implicitly creates a function pass manager over a contiguous list of function passes. This is fine in theory, although it can be a little confusing. And some pipelines want to run a CGSCC pass independently of a function pass that comes right after, rather than nesting the function pass into the CGSCC pass via a CGSCC pass manager. The new PM makes the nesting more explicit by only allowing pass managers to contain passes of the equivalent type. For example, a function pass manager can only contain function passes. To add a loop pass to a function pass manager, the loop pass must be wrapped in a loop-to-function adaptor to turn it into a function pass. The IR nesting in the new PM is module (-> CGSCC) -> function -> loop, where the CGSCC nesting is optional. Requiring the CGSCC nesting was considered to simplify things, but the extra runtime overhead of building the call graph and the extra code for proper nesting to run function passes was enough to make the CGSCC nesting optional.</p><p>The legacy pass manager relies on many global flags and registries. This is supported by macros generating functions and variables to initialize passes, and any users of the legacy pass manager must make sure to call a function to initialize these passes. But we need some way for a pass manager builder to be aware of all passes for testing purposes. The way the new PM does this is by having the pass manager builder include the definitions of all passes, then use a large mapping of pass IDs to pass constructors to create a function that parses a textual description of a pipeline and adds passes. Users of a pass manager builder can add plugins that register parsing callbacks to handle custom out-of-tree passes. Although there is a global list of functions, there is no mutable global state since each pass manager builder can parse pass pipelines without going through a global registry. Other options, like debugging the execution of a pass manager, are also specified via the constructor, and not through a global flag.</p><p>There has been a desire to parallelize LLVM passes for a long time. Although the pass manager infrastructure is not the only blocker, the legacy PM did have a couple of issues blocking parallelization.At the call graph level, only sibling SCCs can be parallelized. Creating SCCs on demand makes it hard to find sibling SCCs. The new PM’s computation of the entire call graph makes it easy to find sibling SCCs to parallelize SCC passes on.Module analyses can be computed from function passes in the legacy PM. Some passes only use analyses if they are cached, so parallelization can cause non-determinism since a module analysis may or may not exist based on other parallel pipelines. The new PM only allows function passes to access cached module analyses and does not allow running them. This has the downside of needing to make sure that certain higher-level analyses are present before running a lower-level pipeline, e.g. making sure GlobalsAA has been computed before running a function pipeline.</p><h2 id="making-the-new-pass-manager-the-default-pass-manager">Making the new pass manager the default pass manager</h2><p>Some major users of LLVM switched to using the new PM by default many years ago. There were some efforts upstream to make the new PM work for all use cases. For example, all Clang tests had been passing with the new PM for a while. However, a vast majority of LLVM tests were still only testing the legacy PM. <code>opt</code>, the program typically used to test passes, had syntax to run passes using the legacy PM, <code>opt -instcombine</code>, and syntax to run passes using the new PM, <code>opt -passes=instcombine</code>. The vast majority of tests used the legacy PM syntax, so if the new PM were to be switched on by default, most LLVM tests wouldn’t be testing the new PM passes. (a good number of tests already manually ran against both)</p><p>To make tests using <code>opt</code> run against the new PM, we can either manually make them run twice, once against the legacy PM and once against the new PM, or we can automatically translate <code>opt -instcombine</code> to <code>opt -passes=instcombine</code> when the new PM is on by default. Rather than update every test, an <code>-enable-new-pm</code> option was added to <code>opt</code>, which translates the legacy syntax to the new syntax.</p><p>With this new option, we started discovering what features the legacy PM had that existing users of the new PM weren’t concerned with. Turning this on locally of course initially caused many tests to fail. Many passes hadn’t yet been ported to the new PM and some <code>opt</code> features didn’t work with the new PM. We ported passes and features that made sense to port to the new PM, and pinned tests using legacy PM features that didn’t make sense to port to the new PM.</p><p>Some of the more interesting issues with the new PM uncovered with <code>-enable-new-pm</code>:</p><ul><li>The <code>optnone</code> function attribute didn’t cause optional passes to be skipped. Using the existing pass instrumentation framework, which calls callbacks before and after running a pass, and also allows passes to be skipped, this was a very simple pass instrumentation. However, some passes must be run to preserve correctness, so we ended up marking some passes as required.</li><li><a href="https://llvm.org/docs/OptBisect.html">Opt-bisect</a> wasn’t supported in the new PM. It is used for bisecting which pass in a pipeline causes a miscompile by skipping passes after a certain point. This similarly was fairly easily implemented via pass instrumentation. This similarly always runs required passes.</li><li>Various target-specific tests were failing. Upon inspection, some passes that were expected to be run in something like the -O2 pipeline weren’t being run. Some backend targets add custom passes into the default pipelines. Some of these passes are required for correctness, such as passes to lower target-specific intrinsics. The legacy PM had a way for a <code>TargetMachine</code> to inject passes into default pipelines via <code>TargetMachine::adjustPassManager()</code>. A new PM equivalent was introduced and the target-specific passes in the optimization pipeline were ported to the new PM. This wasn’t previously an issue because existing users of the new PM were mostly concerned with x86, which didn’t use this feature in the legacy PM.</li><li>Some coroutine tests were asserting in the CGSCC infrastructure. It turns out that the new PM CGSCC infrastructure didn’t support extracting parts of a function into another (aka outlining) in a CGSCC pass. There were some initial failed attempts at hacks to work around this issue, which didn’t properly update the call graph and didn’t handle recursion from newly outlined functions. Finally we came up with a solution that fit into the existing CGSCC infrastructure and properly kept the call graph valid, although coroutine-specific call graph transformations had to be accomodated.</li></ul><h2 id="improvements">Improvements</h2><p>Various projects/companies have already been using the new PM for performance reasons for many years. Separately, Chrome recently started using PGO and ThinLTO to make Chrome faster, each with noticeable performance wins. After the new PM was turned on by default in LLVM, Chrome followed suit and turned on the new PM, seeing 3-4% improvements in Speedometer 2.0 for Linux and Windows, on top of a 8-9MB size decrease. It’s likely that better usage of profile information as well as better handling of larger ThinLTO call graphs lead to these improvements.</p><p>However, smaller applications with tiny hotspots likely won’t see much benefit from the new PM since the improvements brought on by the new PM tend to be more relevant to large codebases.</p><p>Aside from user-facing improvements, this also helps LLVM’s code health by standardizing on one of the two pass managers for the optimization. While we can’t yet remove the legacy pass manager, we can start the deprecation of it, at least for the optimization pipeline. Then hopefully at some point we can start to remove parts of the optimization pipeline that are legacy PM-specific.</p><h2 id="whats-next">What’s next?</h2><p>To begin the process of removing the use of the legacy PM in the optimization pipeline, we need to make sure that anything using the legacy PM has an alternative using the new PM. Just to list a couple: bugpoint, the LLVM C API, GPU divergence analysis.</p><p>As mentioned before, the codegen pipeline still only works with the legacy PM. Although there has been work to start making the codegen pipeline work with the new PM, it is still very far from being usable. This is a great entry point into LLVM, please ask on llvm-dev for more information if you’re interested.</p>
- Cling -- Beyond Just Interpreting C++https://blog.llvm.org/posts/2021-03-25-cling-beyond-just-interpreting-cpp/Thu, 25 Mar 2021 10:00:00 +0000https://blog.llvm.org/posts/2021-03-25-cling-beyond-just-interpreting-cpp/<h1 id="interactive-c-with-cling">Interactive C++ with Cling</h1><p>In our previous blog post <a href="https://blog.llvm.org/posts/2020-12-21-interactive-cpp-for-data-science/">“Interactive C++ for Data Science”</a>we described eval-style programming, interactive C++ in Notebooks and CUDA. Thispost will discuss some developed applications of Cling supportinginteroperability and extensibility. We aim to demonstrate template instantiationon demand; embedding Cling as a service; and showcase an extension enablingon-the-fly automatic differentiation.</p><h2 id="template-instantiation-on-demand">Template Instantiation on Demand</h2><p>Cling implements a facility called <code>LookupHelper</code>, which takes C++ code andchecks if a declaration with that qualified name already exists. For instance:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#e6db74">"cling/Interpreter/Interpreter.h"</span></span></span><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#e6db74">"cling/Interpreter/LookupHelper.h"</span></span></span><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#e6db74">"clang/AST/Decl.h"</span></span></span><span style="display:flex;"><span>[cling] <span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">S</span>{};</span></span><span style="display:flex;"><span>[cling] cling<span style="color:#f92672">::</span>LookupHelper<span style="color:#f92672">&</span> LH <span style="color:#f92672">=</span> gCling<span style="color:#f92672">-></span>getLookupHelper()</span></span><span style="display:flex;"><span>(cling<span style="color:#f92672">::</span>LookupHelper <span style="color:#f92672">&</span>) <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#ae81ff">0x7fcba3c0bfc0</span></span></span><span style="display:flex;"><span>[cling] <span style="color:#66d9ef">auto</span> D <span style="color:#f92672">=</span> LH.findScope(<span style="color:#e6db74">"std::vector<S>"</span>,</span></span><span style="display:flex;"><span> cling<span style="color:#f92672">::</span>LookupHelper<span style="color:#f92672">::</span>DiagSetting<span style="color:#f92672">::</span>NoDiagnostics)</span></span><span style="display:flex;"><span>(<span style="color:#66d9ef">const</span> clang<span style="color:#f92672">::</span>Decl <span style="color:#f92672">*</span>) <span style="color:#ae81ff">0x1216bdcd8</span></span></span><span style="display:flex;"><span>[cling] D<span style="color:#f92672">-></span>getDeclKindName()</span></span><span style="display:flex;"><span>(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span> <span style="color:#f92672">*</span>) <span style="color:#e6db74">"ClassTemplateSpecialization"</span></span></span></code></pre></div><p>In this particular case, <code>findScope</code> instantiates the template and returns itsclang AST representation. Template instantiation on demand addresses the commonlibrary problem of template combinatorial explosion. Template instantiation ondemand and conversion of textual qualified C++ names into entity metainformation has proven to be a very powerful mechanism aiding data serializationand language interoperability.</p><h2 id="language-interop-on-demand">Language Interop on Demand</h2><p>An example is <a href="https://cppyy.readthedocs.io/">cppyy</a>, which provides automaticPython bindings, at runtime, to C++ code through Cling. Python is itself adynamic language executed by an interpreter, thus making the interaction withC++ code more natural when intermediated by Cling. Examples include runtimetemplate instantiations, function (pointer) callbacks, cross-languageinheritance, automatic downcasting, and exception mapping. Many advanced C++features such as placement new, multiple virtual inheritance,variadic templates, etc., are naturally resolved by the LookupHelper.</p><p>cppyy achieves high performance through an all-lazy approach to runtime bindingsconstruction and specializations of common cases through runtime reflection.As such, it has a much lower call overhead than e.g. pybind11, and looping overa <code>std::vector</code> through cppyy is faster than looping over a numpy array of thesame type. Taking it a step further, its implementation for PyPy, a fullycompatible Python interpreter sporting at <a href="https://pypy.org">tracing JIT</a>, canin many cases provide native access to C++ code in PyPy’s JIT, includingoverload resolution and JIT hints that allow for aggressive optimizations.</p><p>Thanks to Cling’s runtime reflection, cppyy makes maintaining a large softwarestack simpler: except for cppyy’s own python-interpreter binding, it does nothave any compiled code that is Python-dependent. I.e., cppyy-based extensionmodules require no recompilation when switching Python versions (or even whenswitching between the CPython and PyPy interpreters, say).</p><p>The example below shows the tight integration of C++ and python; shows the tightback and forth communication of the template instantiation and thecross-inheritance overrides; and the runtime behaviors (everything happens atruntime, there is no compiled code here).</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">import</span> cppyy</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>cppyy<span style="color:#f92672">.</span>cppdef(<span style="color:#e6db74">r</span><span style="color:#e6db74">"""\</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">template<typename T> class Producer {</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">private:</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> T m_value;</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"></span></span></span><span style="display:flex;"><span><span style="color:#e6db74">protected:</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> virtual T produce_imp() = 0;</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"></span></span></span><span style="display:flex;"><span><span style="color:#e6db74">public:</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> Producer(const T& value) : m_value(value) </span><span style="color:#e6db74">{}</span><span style="color:#e6db74"></span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> virtual ~Producer() </span><span style="color:#e6db74">{}</span><span style="color:#e6db74"></span></span></span><span style="display:flex;"><span><span style="color:#e6db74"></span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> T produce_total() { return m_value + produce_imp(); }</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">};</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"></span></span></span><span style="display:flex;"><span><span style="color:#e6db74">class Consumer {</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">public:</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> template<typename T></span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> void consume(Producer<T>& p) {</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> std::cout << "received: \"" << p.produce_total() << "\"\n";</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> }</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">};"""</span>)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">factory</span>(base_v, <span style="color:#f92672">*</span>derived_v):</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">_F</span>(cppyy<span style="color:#f92672">.</span>gbl<span style="color:#f92672">.</span>Producer[type(base_v)]):</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">def</span> __init__(self, base_v, <span style="color:#f92672">*</span>derived_v):</span></span><span style="display:flex;"><span> super()<span style="color:#f92672">.</span>__init__(base_v)</span></span><span style="display:flex;"><span> self<span style="color:#f92672">.</span>_values <span style="color:#f92672">=</span> derived_v</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">produce_imp</span>(self):</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> type(base_v)(sum(self<span style="color:#f92672">.</span>_values))</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> _F(base_v, <span style="color:#f92672">*</span>derived_v)</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>consumer <span style="color:#f92672">=</span> cppyy<span style="color:#f92672">.</span>gbl<span style="color:#f92672">.</span>Consumer()</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> producer <span style="color:#f92672">in</span> [factory(<span style="color:#f92672">*</span>x) <span style="color:#66d9ef">for</span> x <span style="color:#f92672">in</span> \</span></span><span style="display:flex;"><span> ((<span style="color:#e6db74">"hello "</span>, <span style="color:#ae81ff">42</span>), (<span style="color:#ae81ff">3.</span>, <span style="color:#ae81ff">0.14</span>, <span style="color:#ae81ff">0.0015</span>))]:</span></span><span style="display:flex;"><span> consumer<span style="color:#f92672">.</span>consume(producer)</span></span></code></pre></div><p>Output:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>python3 cppyy_demo.py</span></span><span style="display:flex;"><span>received: <span style="color:#e6db74">"hello 42"</span></span></span><span style="display:flex;"><span>received: <span style="color:#e6db74">"3.1415"</span></span></span></code></pre></div><p>In the snippet we create python classes based on python arguments, which derivefrom a templated C++ class instantiated with a type. The python class providesthe implementation for a protected function that is called from a publicfunction, resulting in the expected return value, which is printed. We aim tohighlight:</p><ul><li>Python creates classes at runtime, as can Cling, even when they aredeclared in a module (the relevant classes are here created in a factorymethod);</li><li>Templated C++ classes can be instantiated on the fly from Python, by takingthe type of the argument (i.e. using introspection at runtime in Python) tocreate the C++ base class for the Python class.</li><li>Cross-language derivation is at runtime, with no support needed from the C++class, other than a virtual destructor and virtual methods;</li><li>C++ “protected” methods can be overridden in Python, even though Python hasno such concept and you can not actually call protected methods from boundC++ objects in Python;</li><li>It all works straight out of the box.</li></ul><p>cppyy is used in several large code bases in physics, chemistry, mathematics,and biology. It is readily installable through[pip from PyPI] (<a href="https://pypi.org/project/cppyy/">https://pypi.org/project/cppyy/</a>) and through<a href="https://anaconda.org/conda-forge/cppyy">conda</a>.</p><p>Another example is Symmetry Integration Language (SIL), a D-baseddomain-specific language of functional flavor developed and used internally by<a href="https://symmetryinvestments.com">Symmetry Investments</a>. One of the main goalsof SIL is to be easily interoperable with all sorts of languages and systems,and this is achieved through various plugins. To call C++ code, SIL uses aplugin called <code>sil-cling</code>, which acts as a middle ground between SIL and Cling.However, sil-cling does not interact directly with Cling, but throughcppyy-backend, that is cppyy’s C/C++ wrapper around Cling that provides a stableC/C++ reflection API.</p><p>There are two core types that are exposed from sil-cling to SIL. One is<code>CPPNamespace</code>, which exposes a C++ namespace and allows free function calling,access to namespace’s variables, and object instantiation for the classesdefined in that namespace. The other is <code>ClingObj</code>, which is a proxy for a C++object, allowing construction, method calling and the manipulation of theobject’s data members. Given that cppyy represents C++ classes, structs andnamespaces as ‘scopes’ and reflection information about any of these C++entities is obtained through its associated ‘scope’ object, both wrapper typesexposed to SIL hold a reference to their associated scope object which isqueried whenever the wrapper types are used to call C++ code.</p><p>All the calls that are done from SIL through the two wrapper types have 3arguments: the wrapper object used, the name of the C++ function that needs tobe called, and (if needed) a sequence of arguments for that function. Once theoverload resolution and the argument conversion are done, sil-cling calls theappropriate cppyy function that will wrap the call and dispatch it to Cling forJIT compilation. At the moment, sil-cling can be used to call C++ libraries like<code>Boost.Asio</code>, <code>dlib</code> or <code>Xapian</code>.</p><p>The example below creates a Boost Asio-based client-server application writtenin SIL using the sil-cling plugin. Server.sil contains the SIL code for theserver. It starts by including the relevant header files, using <code>cppCompile</code>.The next step is to create wrapper objects for the namespaces that are needed,and this is done by calling cppNamespace with the names of the namespaces thatone needs to access. These CPPNamespace wrappers are used to instantiate classesthat are defined inside the C++ namespaces that they wrap. Using these wrappers,an endpoint, an acceptor socket (which listens for incoming connections) and anactive socket (which handles communication with the client) are created. Thenthe server waits for a connection and, once a client connects, it reads itsmessage and sends a reply.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-d" data-lang="d"><span style="display:flex;"><span><span style="color:#75715e">// Server.sil</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#f92672">import</span> <span style="color:#960050;background-color:#1e0010">* </span>from silcling</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> format from format</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">cppCompile</span> <span style="color:#f92672">(</span><span style="color:#e6db74">"#include <boost/asio.hpp>"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>cppCompile <span style="color:#f92672">(</span><span style="color:#e6db74">"#include \"helper.hpp\""</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// CPPNamespace wrappers</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>asio <span style="color:#f92672">=</span> cppNamespace<span style="color:#f92672">(</span><span style="color:#e6db74">"boost::asio"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>tcp <span style="color:#f92672">=</span> cppNamespace<span style="color:#f92672">(</span><span style="color:#e6db74">"boost::asio::ip::tcp"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>helpers <span style="color:#f92672">=</span> cppNamespace<span style="color:#f92672">(</span><span style="color:#e6db74">"helpme"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Using namespace wrappers to instantiate classes - creates ClingObj(s)</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>ioService <span style="color:#f92672">=</span> asio<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"io_service"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>endpoint <span style="color:#f92672">=</span> tcp<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"endpoint"</span><span style="color:#f92672">,</span> tcp<span style="color:#f92672">.</span><span style="color:#a6e22e">v4</span><span style="color:#f92672">(),</span> <span style="color:#ae81ff">9999</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Acceptor socket - incoming connections</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>acceptorSocket <span style="color:#f92672">=</span> tcp<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"acceptor"</span><span style="color:#f92672">,</span> ioService<span style="color:#f92672">,</span> endpoint<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Active socket - communication with client</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>activeSocket <span style="color:#f92672">=</span> tcp<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"socket"</span><span style="color:#f92672">,</span> ioService<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Waiting for connection and use the activeSocket to connect with the client</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>helpers<span style="color:#f92672">.</span><span style="color:#a6e22e">accept</span><span style="color:#f92672">(</span>acceptorSocket<span style="color:#f92672">,</span> activeSocket<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Waiting for message</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>message <span style="color:#f92672">=</span> helpers<span style="color:#f92672">.</span><span style="color:#a6e22e">getData</span><span style="color:#f92672">(</span>activeSocket<span style="color:#f92672">);</span></span></span><span style="display:flex;"><span>print<span style="color:#f92672">(</span>format<span style="color:#f92672">(</span><span style="color:#e6db74">"[Server]: Received \"%s\" from client."</span><span style="color:#f92672">,</span> message<span style="color:#f92672">.</span><span style="color:#a6e22e">getString</span><span style="color:#f92672">()))</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Send reply</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>reply <span style="color:#f92672">=</span> <span style="color:#e6db74">"Hello \'"</span> <span style="color:#f92672">~</span> message<span style="color:#f92672">.</span><span style="color:#a6e22e">getString</span><span style="color:#f92672">()</span> <span style="color:#f92672">~</span> <span style="color:#e6db74">"\'!"</span></span></span><span style="display:flex;"><span>helpers<span style="color:#f92672">.</span><span style="color:#a6e22e">sendData</span><span style="color:#f92672">(</span>activeSocket<span style="color:#f92672">,</span> reply<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>print<span style="color:#f92672">(</span>format<span style="color:#f92672">(</span><span style="color:#e6db74">"[Server]: Sent \"%s\" to client."</span><span style="color:#f92672">,</span> reply<span style="color:#f92672">))</span></span></span></code></pre></div><p>Client.sil contains the SIL code for the client. As the server, it includes therelevant headers, creates wrappers for the required namespaces and uses them tocreate an endpoint and a socket. Then the client connects to the server, sends amessage, and waits for the server’s reply. Once the reply arrives, the clientprints it to the screen.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-d" data-lang="d"><span style="display:flex;"><span><span style="color:#75715e">// Client.sil</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#f92672">import</span> <span style="color:#960050;background-color:#1e0010">* </span>from silcling</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> format from format</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#a6e22e">cppCompile</span> <span style="color:#f92672">(</span><span style="color:#e6db74">"#include <boost/asio.hpp>"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>cppCompile <span style="color:#f92672">(</span><span style="color:#e6db74">"#include \"helper.hpp\""</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>asio <span style="color:#f92672">=</span> cppNamespace<span style="color:#f92672">(</span><span style="color:#e6db74">"boost::asio"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>tcp <span style="color:#f92672">=</span> cppNamespace<span style="color:#f92672">(</span><span style="color:#e6db74">"boost::asio::ip::tcp"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>helpers <span style="color:#f92672">=</span> cppNamespace<span style="color:#f92672">(</span><span style="color:#e6db74">"helpme"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Scope resolution operator <-> address::static_method() or address::static_member</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>address <span style="color:#f92672">=</span> classScope<span style="color:#f92672">(</span><span style="color:#e6db74">"boost::asio::ip::address"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>ioService <span style="color:#f92672">=</span> asio<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"io_service"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>endpoint <span style="color:#f92672">=</span> tcp<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"endpoint"</span><span style="color:#f92672">,</span> address<span style="color:#f92672">.</span><span style="color:#a6e22e">from_string</span><span style="color:#f92672">(</span><span style="color:#e6db74">"127.0.0.1"</span><span style="color:#f92672">),</span> <span style="color:#ae81ff">9999</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Creating socket</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>client_socket <span style="color:#f92672">=</span> tcp<span style="color:#f92672">.</span><span style="color:#a6e22e">obj</span><span style="color:#f92672">(</span><span style="color:#e6db74">"socket"</span><span style="color:#f92672">,</span> ioService<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Connect</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>client_socket<span style="color:#f92672">.</span><span style="color:#a6e22e">connect</span><span style="color:#f92672">(</span>endpoint<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>message <span style="color:#f92672">=</span> <span style="color:#e6db74">"demo"</span></span></span><span style="display:flex;"><span>helpers<span style="color:#f92672">.</span><span style="color:#a6e22e">sendData</span><span style="color:#f92672">(</span>client_socket<span style="color:#f92672">,</span> message<span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>print<span style="color:#f92672">(</span>format<span style="color:#f92672">(</span><span style="color:#e6db74">"[Client]: Sent \"%s\" to server."</span><span style="color:#f92672">,</span> message<span style="color:#f92672">))</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>message <span style="color:#f92672">=</span> helpers<span style="color:#f92672">.</span><span style="color:#a6e22e">getData</span><span style="color:#f92672">(</span>client_socket<span style="color:#f92672">);</span></span></span><span style="display:flex;"><span>print<span style="color:#f92672">(</span>format<span style="color:#f92672">(</span><span style="color:#e6db74">"[Client]: Received \"%s\" from server."</span><span style="color:#f92672">,</span> message<span style="color:#f92672">.</span><span style="color:#a6e22e">getString</span><span style="color:#f92672">()))</span></span></span></code></pre></div><p>Output:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">[</span>Client<span style="color:#f92672">]</span>: Sent <span style="color:#e6db74">"demo"</span> to server.</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>Server<span style="color:#f92672">]</span>: Received <span style="color:#e6db74">"demo"</span> from client.</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>Server<span style="color:#f92672">]</span>: Sent <span style="color:#e6db74">"Hello demo"</span> to client.</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>Client<span style="color:#f92672">]</span>: Received <span style="color:#e6db74">"Hello demo"</span> from server.</span></span></code></pre></div><h2 id="interpretercompiler-as-a-service">Interpreter/Compiler as a Service</h2><p>The design of Cling, just like Clang, allows it to be used as a library. In thenext example we show how to incorporate libCling in a C++ program. Cling can beused on-demand, as a service, to compile, modify or describe C++ code. Theexample program shows several ways in which compiled and interpreted C++ caninteract:</p><ul><li><code>callCompiledFn</code> – The cling-demo.cpp defines an in global variable,<code>aGlobal</code>; a static float variable, <code>anotherGlobal</code>; and its accessors. The<code>interp</code> argument is an earlier created instance of the Cling interpreter.Just like in standard C++, it is sufficient to forward declare the compiledentities to the interpreter to be able to use them. Then, the executioninformation from the different calls to process is stored in a generic Cling<code>Value</code> object which is used to exchange information between compiled andinterpreted code.</li><li><code>callInterpretedFn</code> – Complementing <code>callCompiledFn</code>, compiled code cancall an interpreted function by asking Cling to form a function pointer froma given mangled name. Then the call uses the standard C++ syntax.</li><li><code>modifyCompiledValue</code> – Cling has full understanding of C++ and thus we cansupport complex low-level operations on stack-allocated memory. In theexample we ask the compiler for the memory address of the local variable locand ask the interpreter, at runtime, to square its value.</li></ul><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">// cling-demo.cpp</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// g++ ... cling-demo.cpp; ./cling-demo</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#75715e">#include</span> <span style="color:#75715e"><cling/Interpreter/Interpreter.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><cling/Interpreter/Value.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><cling/Utils/Casting.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><iostream></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><string></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><sstream></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">/// Definitions of declarations injected also into cling.</span></span></span><span style="display:flex;"><span><span style="color:#75715e">/// NOTE: this could also stay in a header #included here and into cling, but</span></span></span><span style="display:flex;"><span><span style="color:#75715e">/// for the sake of simplicity we just redeclare them here.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">int</span> aGlobal <span style="color:#f92672">=</span> <span style="color:#ae81ff">42</span>;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">static</span> <span style="color:#66d9ef">float</span> anotherGlobal <span style="color:#f92672">=</span> <span style="color:#ae81ff">3.141</span>;</span></span><span style="display:flex;"><span><span style="color:#66d9ef">float</span> <span style="color:#a6e22e">getAnotherGlobal</span>() { <span style="color:#66d9ef">return</span> anotherGlobal; }</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">setAnotherGlobal</span>(<span style="color:#66d9ef">float</span> val) { anotherGlobal <span style="color:#f92672">=</span> val; }</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">///\brief Call compiled functions from the interpreter.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">callCompiledFn</span>(cling<span style="color:#f92672">::</span>Interpreter<span style="color:#f92672">&</span> interp) {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// We could use a header, too...</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.declare(<span style="color:#e6db74">"int aGlobal;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"float getAnotherGlobal();</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"void setAnotherGlobal(float val);</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> cling<span style="color:#f92672">::</span>Value res; <span style="color:#75715e">// Will hold the result of the expression evaluation.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.process(<span style="color:#e6db74">"aGlobal;"</span>, <span style="color:#f92672">&</span>res);</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"aGlobal is "</span> <span style="color:#f92672"><<</span> res.getAs<span style="color:#f92672"><</span><span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span><span style="color:#f92672">></span>() <span style="color:#f92672"><<</span> <span style="color:#e6db74">'\n'</span>;</span></span><span style="display:flex;"><span> interp.process(<span style="color:#e6db74">"getAnotherGlobal();"</span>, <span style="color:#f92672">&</span>res);</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"getAnotherGlobal() returned "</span> <span style="color:#f92672"><<</span> res.getAs<span style="color:#f92672"><</span><span style="color:#66d9ef">float</span><span style="color:#f92672">></span>() <span style="color:#f92672"><<</span> <span style="color:#e6db74">'\n'</span>;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> setAnotherGlobal(<span style="color:#ae81ff">1.</span>); <span style="color:#75715e">// We modify the compiled value,</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.process(<span style="color:#e6db74">"getAnotherGlobal();"</span>, <span style="color:#f92672">&</span>res); <span style="color:#75715e">// does the interpreter see it?</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"getAnotherGlobal() returned "</span> <span style="color:#f92672"><<</span> res.getAs<span style="color:#f92672"><</span><span style="color:#66d9ef">float</span><span style="color:#f92672">></span>() <span style="color:#f92672"><<</span> <span style="color:#e6db74">'\n'</span>;</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#75715e">// We modify using the interpreter, now the binary sees the new value.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.process(<span style="color:#e6db74">"setAnotherGlobal(7.777); getAnotherGlobal();"</span>);</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"getAnotherGlobal() returned "</span> <span style="color:#f92672"><<</span> getAnotherGlobal() <span style="color:#f92672"><<</span> <span style="color:#e6db74">'\n'</span>;</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">/// Call an interpreted function using its symbol address.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">callInterpretedFn</span>(cling<span style="color:#f92672">::</span>Interpreter<span style="color:#f92672">&</span> interp) {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Declare a function to the interpreter. Make it extern "C" to remove</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// mangling from the game.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.declare(<span style="color:#e6db74">"extern </span><span style="color:#ae81ff">\"</span><span style="color:#e6db74">C</span><span style="color:#ae81ff">\"</span><span style="color:#e6db74"> int plutification(int siss, int sat) "</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"{ return siss * sat; }"</span>);</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">void</span><span style="color:#f92672">*</span> addr <span style="color:#f92672">=</span> interp.getAddressOfGlobal(<span style="color:#e6db74">"plutification"</span>);</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> func_t <span style="color:#f92672">=</span> <span style="color:#66d9ef">int</span>(<span style="color:#66d9ef">int</span>, <span style="color:#66d9ef">int</span>);</span></span><span style="display:flex;"><span> func_t<span style="color:#f92672">*</span> pFunc <span style="color:#f92672">=</span> cling<span style="color:#f92672">::</span>utils<span style="color:#f92672">::</span>VoidToFunctionPtr<span style="color:#f92672"><</span>func_t<span style="color:#f92672">*></span>(addr);</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"7 * 8 = "</span> <span style="color:#f92672"><<</span> pFunc(<span style="color:#ae81ff">7</span>, <span style="color:#ae81ff">8</span>) <span style="color:#f92672"><<</span> <span style="color:#e6db74">'\n'</span>;</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">/// Pass a pointer into cling as a string.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">modifyCompiledValue</span>(cling<span style="color:#f92672">::</span>Interpreter<span style="color:#f92672">&</span> interp) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> loc <span style="color:#f92672">=</span> <span style="color:#ae81ff">17</span>; <span style="color:#75715e">// The value that will be modified</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span> <span style="color:#75715e">// Update the value of loc by passing it to the interpreter.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> std<span style="color:#f92672">::</span>ostringstream sstr;</span></span><span style="display:flex;"><span> <span style="color:#75715e">// on Windows, to prefix the hexadecimal value of a pointer with '0x',</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#75715e">// one need to write: std::hex << std::showbase << (size_t)pointer</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> sstr <span style="color:#f92672"><<</span> <span style="color:#e6db74">"int& ref = *(int*)"</span> <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>hex <span style="color:#f92672"><<</span> std<span style="color:#f92672">::</span>showbase <span style="color:#f92672"><<</span> (size_t)<span style="color:#f92672">&</span>loc <span style="color:#f92672"><<</span> <span style="color:#e6db74">';'</span>;</span></span><span style="display:flex;"><span> sstr <span style="color:#f92672"><<</span> <span style="color:#e6db74">"ref = ref * ref;"</span>;</span></span><span style="display:flex;"><span> interp.process(sstr.str());</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"The square of 17 is "</span> <span style="color:#f92672"><<</span> loc <span style="color:#f92672"><<</span> <span style="color:#e6db74">'\n'</span>;</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>(<span style="color:#66d9ef">int</span> argc, <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> <span style="color:#66d9ef">const</span><span style="color:#f92672">*</span> argv) {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Create the Interpreter. LLVMDIR is provided as -D during compilation.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> cling<span style="color:#f92672">::</span>Interpreter interp(argc, argv, LLVMDIR);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> callCompiledFn(interp);</span></span><span style="display:flex;"><span> callInterpretedFn(interp);</span></span><span style="display:flex;"><span> modifyCompiledValue(interp);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Output:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>./cling-demo</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>aGlobal is <span style="color:#ae81ff">42</span></span></span><span style="display:flex;"><span>getAnotherGlobal<span style="color:#f92672">()</span> returned 3.141</span></span><span style="display:flex;"><span>getAnotherGlobal<span style="color:#f92672">()</span> returned <span style="color:#ae81ff">1</span></span></span><span style="display:flex;"><span>getAnotherGlobal<span style="color:#f92672">()</span> returned 7.777</span></span><span style="display:flex;"><span><span style="color:#ae81ff">7</span> * 8 <span style="color:#f92672">=</span> <span style="color:#ae81ff">56</span></span></span><span style="display:flex;"><span>The square of <span style="color:#ae81ff">17</span> is <span style="color:#ae81ff">289</span></span></span></code></pre></div><p>Crossing the compiled-interpreted boundary relies on the stability of Clang’simplementation of the host’s application binary interface (ABI). Over the yearsit has been very reliable for both Unix and Windows however, Cling is heavilyused to interact with GCC-compiled codebases and is sensitive to ABIincompatibilities between GCC and Clang with respect to the Itanium ABIspecification.</p><h2 id="extensions">Extensions</h2><p>Just like Clang, Cling can be extended by plugins. The next example demonstratesembedded use of Cling’s extension for automatic differentiation,<a href="https://compiler-research.org/clad/">Clad</a>. Clad transforms the clang’s AST toproduce derivatives and gradients of mathematical functions. When creating theCling instance we specify -fplugin and the path to the plugin itself. Then wedefine a target function, pow2, and ask for its derivative with respect to itsfirst argument.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><cling/Interpreter/Interpreter.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><cling/Interpreter/Value.h></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">// Derivatives as a service.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">gimme_pow2dx</span>(cling<span style="color:#f92672">::</span>Interpreter <span style="color:#f92672">&</span>interp) {</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Definitions of declarations injected also into cling.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.declare(<span style="color:#e6db74">"double pow2(double x) { return x*x; }"</span>);</span></span><span style="display:flex;"><span> interp.declare(<span style="color:#e6db74">"#include <clad/Differentiator/Differentiator.h>"</span>);</span></span><span style="display:flex;"><span> interp.declare(<span style="color:#e6db74">"auto dfdx = clad::differentiate(pow2, 0);"</span>);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> cling<span style="color:#f92672">::</span>Value res; <span style="color:#75715e">// Will hold the evaluation result.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> interp.process(<span style="color:#e6db74">"dfdx.getFunctionPtr();"</span>, <span style="color:#f92672">&</span>res);</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">using</span> func_t <span style="color:#f92672">=</span> <span style="color:#66d9ef">double</span>(<span style="color:#66d9ef">double</span>);</span></span><span style="display:flex;"><span> func_t<span style="color:#f92672">*</span> pFunc <span style="color:#f92672">=</span> res.getAs<span style="color:#f92672"><</span>func_t<span style="color:#f92672">*></span>();</span></span><span style="display:flex;"><span> printf(<span style="color:#e6db74">"dfdx at 1 = %f</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>, pFunc(<span style="color:#ae81ff">1</span>));</span></span><span style="display:flex;"><span>}</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>(<span style="color:#66d9ef">int</span> argc, <span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*</span> <span style="color:#66d9ef">const</span><span style="color:#f92672">*</span> argv) {</span></span><span style="display:flex;"><span> std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span><span style="color:#f92672">*></span> argvExt(argv, argv<span style="color:#f92672">+</span>argc);</span></span><span style="display:flex;"><span> argvExt.push_back(<span style="color:#e6db74">"-fplugin=etc/cling/plugins/lib/clad.dylib"</span>);</span></span><span style="display:flex;"><span> <span style="color:#75715e">// Create cling. LLVMDIR is provided as -D during compilation.</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> cling<span style="color:#f92672">::</span>Interpreter interp(argvExt.size(), <span style="color:#f92672">&</span>argvExt[<span style="color:#ae81ff">0</span>], LLVMDIR);</span></span><span style="display:flex;"><span> gimme_pow2dx(interp);</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Output:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>./clad-demo</span></span><span style="display:flex;"><span>dfdx at 1 <span style="color:#f92672">=</span> 2.000000</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2><p>We have demonstrated Cling’s capabilities for template instantiation on demand;incorporating an interpreter in third-party code; and facilitating interpreterextension. The lazy template instantiation in an embedded interpreter provides aservice which is very suitable for interoperability with C++. Extending such aservice with domain-specific capabilities such as automatic differentiation canbe an key enabler for various science cases and for other broader communities.</p><h2 id="acknowledgements">Acknowledgements</h2><p>The author would like to thank Sylvain Corlay, Simeon Ehrig, David Lange,Chris Lattner, Javier Lopez Gomez, Wim Lavrijsen, Axel Naumann, Alexander Penev,Xavier Valls Pla, Richard Smith, Martin Vassilev, Ioana Ifrim who contributed tothis post.</p><p>You can find out more about our activities at<a href="https://root.cern/cling/">https://root.cern/cling/</a> and<a href="https://compiler-research.org">https://compiler-research.org</a>.</p>
- LLVM meets Code Property Graphshttps://blog.llvm.org/posts/2021-02-23-llvm-meets-code-property-graphs/Tue, 23 Feb 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-02-23-llvm-meets-code-property-graphs/<p>The code property graph (CPG) is a data structure designed to mine large codebases for instances of programming patterns via a domain-specific query language. It was first introduced in the proceedings of the IEEE Security and Privacy conference in 2014 (<a href="https://ieeexplore.ieee.org/abstract/document/6956589">publication</a>, <a href="https://www.sec.cs.tu-bs.de/pubs/2014-ieeesp.pdf">PDF</a>) in the context of vulnerability discovery in C system code and the Linux kernel in particular. The core ideas of the approach are the following:</p><ul><li>the CPG combines several program representations into one</li><li>the CPG is stored in a graph database</li><li>the graph database comes with a DSL allowing to traverse and query the CPG</li></ul><p>Currently, the CPG infrastructure is supported by several tools:</p><ul><li><a href="https://ocular.shiftleft.io">Ocular</a> - a proprietary code analysis tool supporting Java, Scala, C#, Go, Python, and JavaScript languages</li><li><a href="https://joern.io">Joern</a> - an open-source counterpart of Ocular supporting C and C++</li><li><a href="https://plume-oss.github.io/plume-docs/">Plume</a> - an open-source tool supporting Java Bytecode</li></ul><p>This article presents <a href="https://www.shiftleft.io">ShiftLeft</a>’s open-source implementation of <a href="https://github.com/ShiftLeftSecurity/llvm2cpg">llvm2cpg</a> - a standalone tool that brings LLVM Bitcode support to Joern.But before we dive into details, let us say few more words about CPG and Joern.</p><h1 id="code-property-graph">Code Property Graph</h1><p>The core idea of the CPG is that different classic program representations are merged into a property graph, a single data structure that holds information about the program’s syntax, control- and intra-procedural data-flow.</p><p>Graphically speaking, the following piece of code:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">foo</span>() {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> x <span style="color:#f92672">=</span> <span style="color:#a6e22e">source</span>();</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> (x <span style="color:#f92672"><</span> MAX) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">int</span> y <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">*</span> x;</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">sink</span>(y);</span></span><span style="display:flex;"><span> }</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>combines these three different representations:</p><p><img src="https://blog.llvm.org/img/cpg/different-representations.png" alt="Different program representations"></p><p>into a single representation - Code Property Graph:</p><p><img src="https://blog.llvm.org/img/cpg/cpg.png" alt="Code Property Graph"></p><h1 id="joern">Joern</h1><p>The property graph is stored in a graph database and made accessible via a domain-specific language (DSL) to identify programming patterns based on a DSL for graph traversals. The query language allows a seamless transition between the original code representations, making it possible to combine aspects of the code from different views these representations offer.</p><p>One of the primary interfaces to the code property graphs is a tool called <a href="https://joern.io">Joern</a>. It provides the mentioned DSL and allows to query the CPG to discover specific properties of a program.Here are some examples of the Joern’s DSL:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-scala" data-lang="scala"><span style="display:flex;"><span>joern<span style="color:#f92672">></span> cpg<span style="color:#f92672">.</span>typeDecl<span style="color:#f92672">.</span>name<span style="color:#f92672">.</span>p</span></span><span style="display:flex;"><span><span style="color:#a6e22e">List</span><span style="color:#f92672">[</span><span style="color:#66d9ef">String</span><span style="color:#f92672">]</span> <span style="color:#66d9ef">=</span> <span style="color:#a6e22e">List</span><span style="color:#f92672">(</span><span style="color:#e6db74">"ANY"</span><span style="color:#f92672">,</span> <span style="color:#e6db74">"int"</span><span style="color:#f92672">,</span> <span style="color:#e6db74">"void"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>joern<span style="color:#f92672">></span> cpg<span style="color:#f92672">.</span>method<span style="color:#f92672">.</span>name<span style="color:#f92672">.</span>p</span></span><span style="display:flex;"><span><span style="color:#a6e22e">List</span><span style="color:#f92672">[</span><span style="color:#66d9ef">String</span><span style="color:#f92672">]</span> <span style="color:#66d9ef">=</span> <span style="color:#a6e22e">List</span><span style="color:#f92672">(</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"foo"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"<operator>.multiplication"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"source"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"<operator>.lessThan"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"<operator>.assignment"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"sink"</span></span></span><span style="display:flex;"><span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>joern<span style="color:#f92672">></span> cpg<span style="color:#f92672">.</span>method<span style="color:#f92672">(</span><span style="color:#e6db74">"foo"</span><span style="color:#f92672">).</span>ast<span style="color:#f92672">.</span>isControlStructure<span style="color:#f92672">.</span>code<span style="color:#f92672">.</span>p</span></span><span style="display:flex;"><span><span style="color:#a6e22e">List</span><span style="color:#f92672">[</span><span style="color:#66d9ef">String</span><span style="color:#f92672">]</span> <span style="color:#66d9ef">=</span> <span style="color:#a6e22e">List</span><span style="color:#f92672">(</span><span style="color:#e6db74">"if (x < MAX)"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span>joern<span style="color:#f92672">></span> cpg<span style="color:#f92672">.</span>method<span style="color:#f92672">(</span><span style="color:#e6db74">"foo"</span><span style="color:#f92672">).</span>ast<span style="color:#f92672">.</span>isCall<span style="color:#f92672">.</span>map<span style="color:#f92672">(</span>c <span style="color:#66d9ef">=></span> c<span style="color:#f92672">.</span>file<span style="color:#f92672">.</span>name<span style="color:#f92672">.</span>head <span style="color:#f92672">+</span> <span style="color:#e6db74">":"</span> <span style="color:#f92672">+</span> c<span style="color:#f92672">.</span>lineNumber<span style="color:#f92672">.</span>get <span style="color:#f92672">+</span> <span style="color:#e6db74">" "</span> <span style="color:#f92672">+</span> c<span style="color:#f92672">.</span>name <span style="color:#f92672">+</span> <span style="color:#e6db74">": "</span> <span style="color:#f92672">+</span> c<span style="color:#f92672">.</span>code<span style="color:#f92672">).</span>p</span></span><span style="display:flex;"><span><span style="color:#a6e22e">List</span><span style="color:#f92672">[</span><span style="color:#66d9ef">String</span><span style="color:#f92672">]</span> <span style="color:#66d9ef">=</span> <span style="color:#a6e22e">List</span><span style="color:#f92672">(</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"main.c:2 <operator>.assignment: x = source()"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"main.c:2 source: source()"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"main.c:3 <operator>.lessThan: x < MAX"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"main.c:4 <operator>.assignment: y = 2 * x"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"main.c:4 <operator>.multiplication: 2 * x"</span><span style="color:#f92672">,</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"main.c:5 sink: sink(y)"</span></span></span><span style="display:flex;"><span><span style="color:#f92672">)</span></span></span></code></pre></div><p>Besides the DSL, Joern comes with a data-flow tracker enabling more sophisticated queries, such as “is there a user controlled malloc in the program?”</p><p>The DSL is much more powerful than in the example, but that is out of scope of this article. Please, refer to the <a href="https://docs.joern.io/home">documentation</a> to learn more.</p><h1 id="llvm-and-cpg">LLVM and CPG</h1><p>This part is split into two smaller parts: the first one covers a few implementation details, the second one shows an example of how to use <code>llvm2cpg</code>.If you are not interested in the implementation - scroll down :)</p><h2 id="implementation-details">Implementation Details</h2><p>When we decided to add LLVM support for CPG, one of the first questions was: how do we map bitcode representation onto CPG?</p><p>We took a simple approach - let’s pretend the SSA representation is just a flat source program. In other words, the following bitcode</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#66d9ef">define</span> <span style="color:#66d9ef">i32</span> @sum(<span style="color:#66d9ef">i32</span> %a, <span style="color:#66d9ef">i32</span> %a) {</span></span><span style="display:flex;"><span> %r = <span style="color:#66d9ef">add</span> <span style="color:#66d9ef">nsw</span> <span style="color:#66d9ef">i32</span> %a, %b</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">ret</span> <span style="color:#66d9ef">i32</span> %r</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>can be seen as a C program:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>i32 <span style="color:#a6e22e">sum</span>(i32 a, i32 b) {</span></span><span style="display:flex;"><span> i32 r <span style="color:#f92672">=</span> <span style="color:#a6e22e">add</span>(a, b);</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> r;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>From the high-level perspective, the approach is simple, but there are some tiny details we had to overcome.</p><h3 id="instruction-semantics">Instruction semantics</h3><p>We can map some of the LLVM instructions back onto the internal CPG operations. Here are some examples:</p><ul><li><code>add</code>, <code>fadd</code> -> <code><operator>.addition</code></li><li><code>bitcast</code> -> <code><operator>.cast</code></li><li><code>fcmp eq</code>, <code>icmp eq</code> -> <code><operator>.equals</code></li><li><code>urem</code>, <code>srem</code>, <code>frem</code> -> <code><operator>.modulo</code></li><li><code>getelementptr</code> -> a combination of <code><operator>.pointerShift</code>, <code><operator>.indexAccess</code>, and <code><operator>.memberAccess</code> depending on the underlying types of the GEP operand</li></ul><p>Most of these <code><operator>.*</code>s have special semantics, which plays a crucial role in the Joern and Ocular built-in data-flow trackers.</p><p>Unfortunately, not every LLVM instruction has a corresponding operator in the CPG. In those cases, we had to fall back to function calls.For example:</p><ul><li><code>select i1 %cond, i32 %v1, i32 %v3</code> turns into <code>select(cond, v1, v2)</code></li><li><code>atomicrmw add i32* %ptr, i32 1</code> turns into <code>atomicrmwAdd(ptr, 1)</code> (same for any other <code>atomicrmw</code> operator)</li><li><code>fneg float %val</code> turns into <code>fneg(val)</code></li></ul><p>The only instruction we could not map to the CPG is the <code>phi</code>: CPG doesn’t have a Phi node concept.We had to eliminate <code>phi</code> instructions using <code>reg2mem</code> machinery.</p><h3 id="redundancy">Redundancy</h3><p>For a small C program</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">sum</span>(<span style="color:#66d9ef">int</span> a, <span style="color:#66d9ef">int</span> b) {</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> a <span style="color:#f92672">+</span> b;</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>Clang emits a lot of redundant instructions by default</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#66d9ef">define</span> <span style="color:#66d9ef">i32</span> @sum(<span style="color:#66d9ef">i32</span> %0, <span style="color:#66d9ef">i32</span> %1) {</span></span><span style="display:flex;"><span> %3 = <span style="color:#66d9ef">alloca</span> <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> %4 = <span style="color:#66d9ef">alloca</span> <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">store</span> <span style="color:#66d9ef">i32</span> %0, <span style="color:#66d9ef">i32</span>* %3, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> <span style="color:#66d9ef">store</span> <span style="color:#66d9ef">i32</span> %1, <span style="color:#66d9ef">i32</span>* %4, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> %5 = <span style="color:#66d9ef">load</span> <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span>* %3, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> %6 = <span style="color:#66d9ef">load</span> <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span>* %4, <span style="color:#66d9ef">align</span> <span style="color:#ae81ff">4</span></span></span><span style="display:flex;"><span> %7 = <span style="color:#66d9ef">add</span> <span style="color:#66d9ef">nsw</span> <span style="color:#66d9ef">i32</span> %5, %6</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">ret</span> <span style="color:#66d9ef">i32</span> %7</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>instead of a more concise version</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#66d9ef">define</span> <span style="color:#66d9ef">i32</span> @sum(<span style="color:#66d9ef">i32</span> %0, <span style="color:#66d9ef">i32</span> %1) {</span></span><span style="display:flex;"><span> %3 = <span style="color:#66d9ef">add</span> <span style="color:#66d9ef">nsw</span> <span style="color:#66d9ef">i32</span> %1, %0</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">ret</span> <span style="color:#66d9ef">i32</span> %3</span></span><span style="display:flex;"><span>}</span></span></code></pre></div><p>In general, this is not a problem, but it adds more complexity for the data-flow tracker and needlessly increases the graph’s size.One of the considerations was to run optimizations before emitting CPG for the bitcode. Still, in the end, we decided to offload this work to an end-user: if you want fewer instructions, then apply the optimizations manually before emitting the CPG.</p><h3 id="type-equality">Type Equality</h3><p>The other issue is related to the way LLVM handles types. If two modules in the same context use the same struct with the same name, LLVM renames the other struct to prevent name collisions. For example</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#75715e">; Module1</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>%struct.Point = <span style="color:#66d9ef">type</span> { <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span> }</span></span></code></pre></div><p>and</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#75715e">; Module 2</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>%struct.Point = <span style="color:#66d9ef">type</span> { <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span> }</span></span></code></pre></div><p>when loaded into the same context yield two types</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span>%struct.Point = <span style="color:#66d9ef">type</span> { <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span> }</span></span><span style="display:flex;"><span>%struct.Point.1 = <span style="color:#66d9ef">type</span> { <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span> }</span></span></code></pre></div><p>We wanted to deduplicate these types for a better user experience and only emit <code>Point</code> in the final graph.</p><p>The obvious solution was to consider two structs with “similar” names and the same layout to be the same.However, we could not rely on the <code>llvm::StructType::isLayoutIdentical</code> because, despite the name, it produces misleading results.</p><p>According to <code>llvm::StructType::isLayoutIdentical</code> the structs <code>Point</code> and <code>Pair</code> have identical layout, but <code>PointWrap</code> and <code>PairWrap</code> are not.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-llvm" data-lang="llvm"><span style="display:flex;"><span><span style="color:#75715e">; these two have identical layout</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>%Point = <span style="color:#66d9ef">type</span> { <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span> }</span></span><span style="display:flex;"><span>%Pair = <span style="color:#66d9ef">type</span> { <span style="color:#66d9ef">i32</span>, <span style="color:#66d9ef">i32</span> }</span></span><span style="display:flex;"><span></span></span><span style="display:flex;"><span><span style="color:#75715e">; these two DO NOT have identical layout</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>%PointWrap = <span style="color:#66d9ef">type</span> { %Point }</span></span><span style="display:flex;"><span>%PairWrap = <span style="color:#66d9ef">type</span> { %Pair }</span></span></code></pre></div><p>This happens because <code>llvm::StructType::isLayoutIdentical</code> determines equality based on the pointers. That is, if all the struct elements are identical, then the layout identical.It also meant we could not use this approach to compare types from different LLVM contexts.We had to roll out our custom solution based on the <a href="https://lowlevelbits.org/type-equality-in-llvm/">Tree Automata</a> to solve this issue.</p><hr><p>There are few more details, but the article is getting longer than it needs to be.So let’s look at how to use <code>llvm2cpg</code> with Joern.</p><h2 id="example">Example</h2><p>Once you have <a href="https://docs.joern.io/installation">Joern</a> and <a href="http://github.com/ShiftLeftSecurity/llvm2cpg/releases/latest">llvm2cpg</a> installed the usage is straightforward:</p><ol><li>Convert a program into LLVM Bitcode</li><li>Emit CPG</li><li>Load the CPG into Joern and start the analysis</li></ol><p>Here are the steps codified:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cat main.c</span></span><span style="display:flex;"><span>extern int MAX;</span></span><span style="display:flex;"><span>extern int source<span style="color:#f92672">()</span>;</span></span><span style="display:flex;"><span>extern void sink<span style="color:#f92672">(</span>int<span style="color:#f92672">)</span>;</span></span><span style="display:flex;"><span>void foo<span style="color:#f92672">()</span> <span style="color:#f92672">{</span></span></span><span style="display:flex;"><span> int x <span style="color:#f92672">=</span> source<span style="color:#f92672">()</span>;</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">(</span>x < MAX<span style="color:#f92672">)</span> <span style="color:#f92672">{</span></span></span><span style="display:flex;"><span> int y <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span> * x;</span></span><span style="display:flex;"><span> sink<span style="color:#f92672">(</span>y<span style="color:#f92672">)</span>;</span></span><span style="display:flex;"><span> <span style="color:#f92672">}</span></span></span><span style="display:flex;"><span><span style="color:#f92672">}</span></span></span><span style="display:flex;"><span>$ clang -S -emit-llvm -g -O1 main.c -o main.ll</span></span><span style="display:flex;"><span>$ llvm2cpg -output<span style="color:#f92672">=</span>/tmp/cpg.bin.zip main.ll</span></span></code></pre></div><p>Now you get the CPG saved at <code>/tmp/cpg.bin.zip</code> which you can load into Joern and find if there is a flow from the <code>source</code> function to the <code>sink</code>:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ joern</span></span><span style="display:flex;"><span>joern> importCpg<span style="color:#f92672">(</span><span style="color:#e6db74">"/tmp/cpg.bin.zip"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>joern> run.ossdataflow</span></span><span style="display:flex;"><span>joern> def source <span style="color:#f92672">=</span> cpg.call<span style="color:#f92672">(</span><span style="color:#e6db74">"source"</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span>joern> def sink <span style="color:#f92672">=</span> cpg.call<span style="color:#f92672">(</span><span style="color:#e6db74">"sink"</span><span style="color:#f92672">)</span>.argument</span></span><span style="display:flex;"><span>joern> sink.reachableByFlows<span style="color:#f92672">(</span>source<span style="color:#f92672">)</span>.p</span></span><span style="display:flex;"><span>List<span style="color:#f92672">[</span>String<span style="color:#f92672">]</span> <span style="color:#f92672">=</span> List<span style="color:#f92672">(</span></span></span><span style="display:flex;"><span> <span style="color:#e6db74">"""_____________________________________________________</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| tracked | lineNumber| method| file |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">|====================================================|</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| source | 5 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| <operator>.assignment | 5 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| <operator>.lessThan | 6 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| <operator>.shiftLeft | 7 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| <operator>.shiftLeft | 7 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| <operator>.assignment | 7 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">| sink | 8 | foo | main.c |</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">"""</span></span></span><span style="display:flex;"><span><span style="color:#f92672">)</span></span></span></code></pre></div><p>Which indeed exists!</p><h1 id="conclusion">Conclusion</h1><p>To conclude, let us outline some of the advantages and constraints implied by LLVM Bitcode:</p><ul><li>the “surface” of the LLVM language is smaller than that of C and C++</li><li>many high-level details do not exist at the IR level</li><li>the program must be compiled, thus limiting the range of programs that one can analyze with Joern</li></ul><p><a href="https://docs.joern.io/llvm2cpg/hello-llvm">Here</a> you can find more tutorials and information.</p><p>If you get any questions, feel free to ping <a href="https://twitter.com/fabsx00">Fabs</a> or <a href="https://twitter.com/1101_debian">Alex</a> on Twitter, or better come over to the <a href="https://gitter.im/joern-code-analyzer/community">Joern chat</a>.</p>
- Introducing Community.o and the Community.o Summithttps://blog.llvm.org/posts/2021-02-10-community-dot-o/Wed, 10 Feb 2021 00:00:00 +0000https://blog.llvm.org/posts/2021-02-10-community-dot-o/<p><img src="https://blog.llvm.org/img/community-dot-o-logo.png" alt="Community.o"></p><p>The LLVM Foundation is excited to announce <a href="https://community-dot-o.llvm.org">Community.o</a>! This is a new face to the <a href="https://foundation.llvm.org">LLVM Foundationâs</a> Diversity and Inclusion and Women in Compilers and Tools program. Weâve adopted a name to represent what this program hopes to accomplish which is to build a strong, healthy, and diverse open source community. We believe that this can only be achieved by including people from all backgrounds, genders, and experiences and by ensuring that everyone feels welcome, included, and empowered to contribute.</p><p>Why <a href="https://community-dot-o.llvm.org">Community.o?</a> The name is inspired by the compilation model where object files link together for a final program, much like how folks from different backgrounds come together to make up llvmâs community and shared goal of inclusivity.</p><p>While our main focus is on the <a href="https://llvm.org">LLVM community</a> and the field of compilers and tools, we want to collaborate with other open source communities and provide resources and exchange ideas.</p><p>Are you interested in learning more, getting involved with Community.o or joining a specific group such as Women in Compilers and Tools? Please see the <a href="https://community-dot-o.llvm.org">Community.o website</a>.</p><p><img src="https://blog.llvm.org/img/SummitLogo.png" alt="Community.o Summit"></p><p>On March 8-10, we will host our first <a href="https://llvm.swoogo.com/community-o-summit/">Community.o Summit</a>! This 3-day virtual event is an inclusive space for underrepresented groups and newcomers, anywhere in their career, interested in learning and contributing to compilers, tools, and programming languages. Weâll highlight members from different open source communities making incredible efforts to support a thriving environment. Summit attendees will enjoy interesting talks, panels, workshops, and have ample networking opportunities. Additionally, this summit will be engaging for anyone interested in increasing the diversity within the LLVM community or their related affiliations.</p><p>While the event is free, attendance is limited to provide the best experience for attendees and allow for better collaboration and networking. Please see the <a href="https://llvm.swoogo.com/community-o-summit/">Community.o Summit</a> website for more information and to apply to attend by February 26, 2021.</p>
- Bringing Stack Clash Protection to Clang / X86 â the Open Source Wayhttps://blog.llvm.org/posts/2021-01-05-stack-clash-protection/Sat, 30 Jan 2021 10:00:00 +0000https://blog.llvm.org/posts/2021-01-05-stack-clash-protection/<h1 id="context">Context</h1><p>Stack clash is an attack that dates back to 2017, when the Qualys Research Teamreleased an advisory with a <a href="https://blog.qualys.com/vulnerabilities-research/2017/06/19/the-stack-clash">joint blog post</a>. It basicallyexploits large stack allocation (greater than <code>PAGE_SIZE</code>) that can lead tostack read/write <em>not</em> triggering the <a href="https://lkml.org/lkml/2017/6/22/345">stack guard page</a> allocated by the LinuxKernel.</p><p>Shortly after the advisory got released, GCC provided a <a href="https://gcc.gnu.org/legacy-ml/gcc-patches/2017-07/msg00556.html">countermeasure</a> activated by <code>-fstack-clash-protection</code> thatbasically consists in splitting large allocation in chunks of <code>PAGE_SIZE</code>,with a probe in each chunk to trigger the kernel stack guard page.</p><p>This has been a major security difference between GCC and Clang since then. Ithas even been identified as a blocker by Fedora to move from GCC to Clang as thecompiler for some projects that already made the move upstream, leading to <a href="https://pagure.io/fesco/issue/2020">extramaintenance</a> for packagers.</p><p>Support for this flag <a href="https://reviews.llvm.org/D68720">landed in Clang in 2020</a>,only for X86, SystemZ and PowerPC. Its implementation is a result of a fruitfulcollaboration between LLVM, Firefox and Rust developers.</p><p>Rust already had a countermeasure implemented in the form of a runtime call toperform the stack probing. With LLVM catching up, using a more lightweightapproach got <a href="https://github.com/rust-lang/rust/pull/77885">investigated in Rust</a>.</p><h1 id="countermeasure-description">Countermeasure Description</h1><p>The Clang implementation for X86 is derived from the GCC implementation, with afew distinctions. The core ideas are:</p><ol><li><p>thanks to X86 calling convention, we get a free probe at each call site,which means that each function starts with a probed stack</p></li><li><p>when probing the stack in the function prologue, we don’t probe the tail ofthe allocation. Stated otherwise, if the stack size is <code>PAGE_SIZE + PAGE_SIZE/2</code>,we want to probe only once. This is important to limit the numberof probes: if the stack size is lower than <code>PAGE_SIZE</code> no probe is needed</p></li><li><p>because a signal can interrupt the execution flow any time, at no pointshould we have two stack allocations (lower than <code>PAGE_SIZE</code>) without a probein between.</p></li></ol><p>The probing strategy for stack allocation varies based on the size of the stackallocation. If it’s smaller than <code>PAGE_SIZE</code>, thanks to (2) no probing isneeding. If it’s below a small multiple of <code>PAGE_SIZE</code>, then the probing loopcan be unrolled. Otherwise a probing loop alternates stack allocation of<code>PAGE_SIZE</code> bytes and probe, starting with the allocation thanks to (1).</p><p>As side effect of (2) is that when performing a dynamic allocation, we need toprobe <em>before</em> updating the stack, otherwise we got a hole in the protection.This probe cannot be done after the stack update, even with an offset, becauseof (3). Otherwise we end up with a bug as this one found in <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97928">GCC</a></p><p>The following scheme attempts to summarize the allocation and probinginteraction between static and dynamic allocations:</p><pre><code> + ----- <- ------------ <- ------------- <- ------------ + | |[free probe] -> [page alloc] -> [alloc probe] -> [tail alloc] + -> [dyn probe] -> [page alloc] -> [dyn probe] -> [tail alloc] + | | + <- ----------- <- ------------ <- ----------- <- ------------ +</code></pre><h1 id="validation-with-firefox">Validation with Firefox</h1><p>Firefox provides an amazing test bench to evaluate the impact of compilerchanges. Indeed, with more than 12MLOC of C/C++ and 3MLOC of Rust built usingPGO/LTO and <a href="https://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html">XLTO</a>, most of the important cases are covered.</p><p>Moreover, Firefox being supported on a large set of operating system andarchitectures, it was a great way to test the Stack Clash protection on variousset of configurations.</p><p>The work is detailed in the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1588710">bug 1588710</a>.</p><h2 id="functional-testing">Functional Testing</h2><p>To make sure that Firefox would perform as expected, we leveraged the huge testsuite to verify that the product would still work as expected with this option.</p><p>We used the <a href="https://hacks.mozilla.org/2020/07/testing-firefox-more-efficiently-with-machine-learning/"><code>try auto</code></a>, a new command which will run the mostappropriate set of tests for such kind of changes during the development phase.Then, once the patch landed into Mozilla-central (Firefox nightly), the wholetest suite is executed, presenting about 29 days of machine time for about 9000tasks.</p><p>Thanks to this infrastructure, we have identified an <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1588710#c40">issue with<code>alloca(0)</code></a> generating buggy machine code.Fortunately, the <a href="https://bugs.llvm.org/show_bug.cgi?id=47657">fix</a> was already in the trunk version of LLVM.We cherry-picked the fix in our custom Clang build which addressed our issue.</p><h2 id="performance-testing">Performance Testing</h2><p>Over the years, Mozilla has developed a few tools to evaluate performanceimpact of changes, from micro-benchmark to page loads. These tools have been keyto improve Firefox overall performances but also evaluate the impact of the <a href="https://blog.mozilla.org/nfroyd/2018/05/29/when-implementation-monoculture-right-thing/">moveto Clang</a> on all platforms done a couple years ago.</p><p>The usual procedure to evaluate performances improvements/regressions is to:</p><ol><li><p>Run two builds with benchmarks. One without the patch, one with it.</p></li><li><p>Leverage the tooling to rerun the benchmark (usually 5 to 20 times) to limitthe noise.</p></li><li><p>Compare the various benchmark to see if significant regressions can beidentified.</p></li></ol><p>In the context of this project, we run the usual benchmarks sensitive to C++changes and we haven’t identified any <a href="https://treeherder.mozilla.org/perfherder/comparesubtest?originalProject=try&newProject=try&newRevision=62108fa48bd15fe01f1a0f1ffab133af9b4207cc&originalSignature=1904137&newSignature=1904137&framework=10&originalRevision=a47c98b909b61035dae2e1e00883f2ade0fef129">regression</a> in term ofperformances.</p><h2 id="current-status">Current status</h2><p>Firefox nightly on Linux is now compiled with the stack-clash-option fromJanuary 8th 2021. We have not detected any regressions since it landed.If everything goes well, this change should ship with Firefox 86 (planned formid February 2021).</p><h1 id="validation-with-rust">Validation With Rust</h1><p>Rust has long supported the callback style of the LLVM <code>probe-stack</code> attribute,using the function <code>__rust_probestack</code> defined in its own compiler builtinslibrary. In Rust’s spirit of safety, this attribute is added to <em>all</em> functions,letting LLVM sort out which actually need probing. However, forcing such a callinto every function with a large stack frame is not ideal for performance,especially for those cases that could use just a few unrolled probes inline.Furthermore, Rust only has this callback implemented for its Tier 1 (mostsupported) targets, namely i686 and x86_64, leaving other architectures withoutprotection so far. Therefore, letting LLVM generate inline stack probes isbeneficial both for the performance of avoiding a call and for the increasedarchitecture support.</p><p>Since the Rust compiler is written in Rust itself, with stack probing enabled bydefault, it makes a great functional test for any new code generation feature.The compiler is bootstrapped in stages, first building with a prior version,then rebuilding with the result of that first stage. Codegen issues are oftenrevealed if the compiler crashes during that rebuild, and experiments withinline stack probes were no different, leading to fixes in<a href="https://reviews.llvm.org/D82867">D82867</a> and<a href="https://reviews.llvm.org/D90216">D90216</a>. Both of these were simple errors thatwere not apparent in existing FileCheck tests, showing the importance ofactually executing generated code.</p><p>An <a href="https://github.com/rust-lang/rust/issues/70143">issue</a> also led to the realization that there was a moregeneral bug impacting both GCC and LLVM implementation of<code>-fstack-clash-protector</code>, leading to a new patch set on the LLVM side.Essentially, the observed behavior is the following:</p><p>Alignment requirements behave similarly to allocation with respect to the stack:they (may) make it grow. For instance the stack allocation for an <code>char foo[4096] __attribute__((aligned(2048)));</code> is done through:</p><pre><code>and rsp, -2048sub rsp, 6024</code></pre><p>Both <code>and</code> and the <code>sub</code> actually update the stack! To take that effect intoaccount, the LLVM patch considers the <code>and rsp, -2048</code> as a <code>sub rsp, 2048</code>when computing the probing distance, which means considering the worstcase scenario.</p><p>For future work on the Rust side, inline stack probes will replace<code>__rust_probestack</code> on i686 and x86_64 soon in <a href="https://github.com/rust-lang/rust/pull/77885">Rustpr77885</a>, and that will include<a href="https://perf.rust-lang.org/">perf results</a> to monitor the effect. After that,additional architectures can be functionally tested and enabled for inline stackprobes as well, increasing the reach of Rust’s memory safety.</p><h1 id="validation-with-a-binary-tracer">Validation with a Binary Tracer</h1><p>None of the above validation validates the security aspect of the protection. Tohave more confidence on the actual probing scheme implementation, we implementeda binary tracer based on the (awesome) <a href="https://github.com/QBDI/QBDI">QBDI</a>Dynamic Binary Instrumentation framework. This Proof Of Concept (POC) isavailable on GitHub:<a href="https://github.com/serge-sans-paille/stack-clash-tracer">stack-clash-tracer</a></p><p>This tool instruments all stack allocation and memory access of a runningbinary, logs them and checks that no stack allocation is greater than<code>PAGE_SIZE</code> and that we get an actual probing between two allocations.</p><p>Here is a sample session that showcases large stack allocation issues:</p><pre><code>$ cat main.c#include <alloca.h>#include <string.h>int main(int argc, char**argv) { char buffer[5000]; strcpy(buffer, argv[0]); char* dynbuffer = alloca(argc * 1000); strcpy(dynbuffer, argv[0]); return buffer[argc] + dynbuffer[argc];}$ gcc main.c -o main$ LD_PRELOAD=./libstack_clash_tracer.so ./main 1[sct][error] stack allocation is too big (5024)$ LD_PRELOAD=./libstack_clash_tracer.so ./main 1 2 3 4 5[sct][error] stack allocation is too big (5024)[sct][error] stack allocation is too big (6016)</code></pre><p>The same code, compiled with <code>-fstack-clash-protection</code>, is safer (apart fromthe stupid use of <code>strcpy</code>, that is)</p><pre><code>$ gcc main.c -fstack-clash-protection -o main$ LD_PRELOAD=./libstack_clash_tracer.so ./main 1$ LD_PRELOAD=./libstack_clash_tracer.so ./main 1 2 3 4 5</code></pre><p>Small bonus of this compiler-independent approach: we can verify both GCC andClang implementation <code>:-)</code></p><pre><code>$ clang main.c -fstack-clash-protection -o main$ LD_PRELOAD=./libstack_clash_tracer.so ./main 1$ LD_PRELOAD=./libstack_clash_tracer.so ./main 1 2 3 4 5</code></pre><p>To come back on the Firefox test case, before we landed the change, we couldsee:</p><pre><code>$ LD_PRELOAD=./libstack_clash_tracer.so firefox-bin[sct][error] stack allocation is too big (4168)</code></pre><p>Once Firefox nightly shipped with stack clash protection, this warningdisappears.</p><h1 id="conclusion">Conclusion</h1><p>Aside from the technical aspects of the countermeasure, it is interesting tonote that its Clang implementation was derived from the GCC implementation, butled to an issue being reported in the GCC codebase. The Clang-generated code gotvalidated by Firefox People, tested by Rust people who reported several bugs,some impacting both Clang and GCC implementation, the circle is complete!</p><h1 id="references">References</h1>
- Interactive C++ for Data Sciencehttps://blog.llvm.org/posts/2020-12-21-interactive-cpp-for-data-science/Sun, 20 Dec 2020 10:00:00 +0000https://blog.llvm.org/posts/2020-12-21-interactive-cpp-for-data-science/<h1 id="interactive-c-for-data-science">Interactive C++ for Data Science</h1><p>In our previous blog post <a href="https://blog.llvm.org/posts/2020-11-30-interactive-cpp-with-cling/">“Interactive C++ with Cling”</a>we mentioned that exploratory programming is an effective way to reduce thecomplexity of the problem. This post will discuss some applications of Clingdeveloped to support data science researchers. In particular, interactivelyprobing data and interfaces makes complex libraries and complex data moreaccessible to users. We aim to demonstrate some of Clingâs features at scale;Clingâs eval-style programming support; projects related to Cling; and showinteractive C++/CUDA.</p><h2 id="eval-style-programming">Eval-style programming</h2><p>A Cling instance can access itself through its runtime. The example creates a<code>cling::Value</code> to store the execution result of the incremented variable <code>i</code>.That mechanism can be used further to support dynamic scopes extending the namelookup at runtime.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>cling<span style="color:#f92672">/</span>Interpreter<span style="color:#f92672">/</span>Value.h<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>cling<span style="color:#f92672">/</span>Interpreter<span style="color:#f92672">/</span>Interpreter.h<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> <span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;</span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> cling<span style="color:#f92672">::</span>Value V;</span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> gCling<span style="color:#f92672">-></span>evaluate(<span style="color:#e6db74">"++i"</span>, V);</span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> i</span></span><span style="display:flex;"><span>(<span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">2</span></span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> V</span></span><span style="display:flex;"><span>(cling<span style="color:#f92672">::</span>Value <span style="color:#f92672">&</span>) boxes [(<span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">2</span>]</span></span></code></pre></div><p><code>V</code> “boxes” the expression result providing extended lifetime if necessary.The <code>cling::Value</code> can be used to communicate expression values from theinterpreter to compiled code.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> <span style="color:#f92672">++</span>i</span></span><span style="display:flex;"><span>(<span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">3</span></span></span><span style="display:flex;"><span>[cling]<span style="color:#960050;background-color:#1e0010">$</span> V</span></span><span style="display:flex;"><span>(cling<span style="color:#f92672">::</span>Value <span style="color:#f92672">&</span>) boxes [(<span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">2</span>]</span></span></code></pre></div><p>This mechanism introduces a delayed until runtime evaluation which enables somefeatures increasing the dynamic look and feel of the C++ language.</p><h2 id="the-root-data-analysis-package">The ROOT data analysis package</h2><p>The main tool for storage, research and visualization of scientific data in thefield of high energy physics (HEP) is the specialized software package <a href="https://root.cern">ROOT</a>.ROOT is a set of interconnected components that assist scientists from datastorage and research to their visualization when published in a scientificpaper. ROOT has played a significant role in scientific discoveries such asgravitational waves, the great cavity in the Pyramid of Cheops, the discovery ofthe Higgs boson by the Large Hadron Collider. For the last 5 years, Cling hashelped to analyze 1 EB physical data, serving as a basis for over 1000scientific publications, and supports software run across a distributed millionCPU core computing facility.</p><p>ROOT uses Cling as a reflection information service for data serialization. TheC++ objects are stored in a binary format, vertically. The content of a loadeddata file is made available to the users and C++ objects become a first classcitizen.</p><p>A central component of ROOT enabled by Cling is eval-style programming. We usethis in HEP to make it easy to inspect and use C++ objects stored by ROOT.Cling enables ROOT to inject available object names into the name lookup whena file is opened:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[root] ntuple<span style="color:#f92672">-></span>GetTitle()</span></span><span style="display:flex;"><span>error: use of undeclared identifier <span style="color:#960050;background-color:#1e0010">'</span>ntuple<span style="color:#960050;background-color:#1e0010">'</span></span></span><span style="display:flex;"><span>[root] TFile<span style="color:#f92672">::</span>Open(<span style="color:#e6db74">"tutorials/hsimple.root"</span>); ntuple<span style="color:#f92672">-></span>GetTitle() <span style="color:#75715e">// #1</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>(<span style="color:#66d9ef">const</span> <span style="color:#66d9ef">char</span> <span style="color:#f92672">*</span>) <span style="color:#e6db74">"Demo ntuple"</span></span></span><span style="display:flex;"><span>[root] gFile<span style="color:#f92672">-></span>ls();</span></span><span style="display:flex;"><span>TFile<span style="color:#f92672">**</span> tutorials<span style="color:#f92672">/</span>hsimple.root Demo ROOT file with histograms</span></span><span style="display:flex;"><span> TFile<span style="color:#f92672">*</span> tutorials<span style="color:#f92672">/</span>hsimple.root Demo ROOT file with histograms</span></span><span style="display:flex;"><span> OBJ: TH1F hpx This is the px distribution : <span style="color:#ae81ff">0</span> at: <span style="color:#ae81ff">0x7fadbb84e390</span></span></span><span style="display:flex;"><span> OBJ: TNtuple ntuple Demo ntuple : <span style="color:#ae81ff">0</span> at: <span style="color:#ae81ff">0x7fadbb93a890</span></span></span><span style="display:flex;"><span> KEY: TH1F hpx;<span style="color:#ae81ff">1</span> This is the px distribution</span></span><span style="display:flex;"><span> [...]</span></span><span style="display:flex;"><span> KEY: TNtuple ntuple;<span style="color:#ae81ff">1</span> Demo ntuple</span></span><span style="display:flex;"><span>[root] hpx<span style="color:#f92672">-></span>Draw()</span></span></code></pre></div><p>The ROOT framework injects additional names to the name lookup on two stages.First, it builds an invalid AST by marking the occurrence of ntuple (#1), thenit is transformed into<code>gCling->EvaluateT</*return type*/void>("ntuple->GetTitle()", /*context*/);</code>On the next stage, at runtime, ROOT opens the file, reads its preambule andinjects the names via the external name lookup facility in clang. Thetransformation becomes more complex if <code>ntuple->GetTitle()</code> takes arguments.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure1.png"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure1.png "image_tooltip") ---> <p align="center"> Figure 1. Interactive plot of the <i>px</i> distribution read from a root file. </p></div><h2 id="c-in-notebooks">C++ in Notebooks</h2><p><em>Section Author:</em> <strong>Sylvain Corlay, QuantStack</strong></p><p>The <a href="https://jupyter-notebook.readthedocs.io/en/stable/notebook.html">Jupyter Notebook</a>technology allows users to create and share documents that contain live code,equations, visualizations and narrative text. It enables data scientists toeasily exchange ideas or collaborate by sharing their analyses in astraight-forward and reproducible way. Language agnosticism is a key designprinciple for the Jupyter project, and the Jupyter frontend communicates withthe kernel (the part of the infrastructure that runs the code) through awell-specified protocol. Kernels have been developed for dozens of programminglanguages, such as R, Julia, Python, Fortran (through the LLVM-based LFortranproject).</p><p>Jupyter’s official C++ kernel relies on <a href="https://github.com/jupyter-xeus/xeus">Xeus</a>,a C++ implementation of the kernel protocol, and Cling. An advantage of using areference implementation for the kernel protocol is that a lot of features comefor free, such as rich mime type display, interactive widgets, auto-complete,and much more.</p><p>Rich mime-type rendering for user-defined types can be specified by providingan overload of <code>mime_bundle_repr</code> for the said type, which is picked up byargument dependent lookup.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure2.png"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure2.png "image_tooltip") ---> <p align="center"> Figure 2. Inline rendering of images in JupyterLab for a user-defined image type. </p></div><p>Possibilities with rich mime type rendering are endless, such as rich display ofdataframes with HTML tables, or even mime types that are rendered in thefront-end with JavaScript extensions.</p><p>An advanced example making use of rich rendering with Mathjax is the SymEnginesymbolic computing library.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure3.png"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure3.png "image_tooltip") ---> <p align="center"> Figure 3. Using rich mime type rendering in Jupyter with the Symengine package. </p></div><p>Xeus-cling comes along with an implementation of the Jupyter widgets protocolwhich enables bidirectional communication with the backend.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure4.gif"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure4.gif "image_tooltip") ---> <p align="center"> Figure 4. Interactive widgets in the JupyterLab with the C++ kernel. </p></div><p>More complex widget libraries have been enabled through this framework like<a href="https://github.com/jupyter-xeus/xleaflet">xleaflet</a>.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure5.gif"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure5.gif "image_tooltip") ---> <p align="center"> Figure 5. Interactive GIS in C++ in JupyterLab with xleaflet. </p></div><p>Other features include rich HTML help for the standard library and third-partypackages:</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure6.png"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure6.png "image_tooltip") ---> <p align="center"> Figure 6. Accessing cppreference for std::vector from JupyterLab by typing `?std::vector`. </p></div><p>The Xeus and Xeus-cling kernels were recently incorporated as subprojects toJupyter, and are governed by its code of conduct and general governance.</p><p>Planned future developments for the xeus-cling kernel include: adding supportfor the Jupyter console interface, through an implementation of the Jupyter<code>is_complete</code> message, currently lacking; adding support for cling“dot commands” as Jupyter magics; and supporting the new debugger protocol thatwas recently added to the Jupyter kernel protocol, which will enable the use ofthe JupyterLab visual debugger with the C++ kernel.</p><p>Another tool that brings interactive plotting features to xeus-cling is xvega,which is at an early stage of development, produces vega charts that can bedisplayed in the notebook.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure7.png"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure7.png "image_tooltip") ---> <p align="center"> Figure 7. The xvega plotting library in the xeus-cling kernel. </p></div><h2 id="cuda-c">CUDA C++</h2><p><em>Section Author:</em> <strong>Simeon Ehrig, HZDR</strong></p><p>The Cling CUDA extension brings the workflows of interactive C++ to GPUs withoutlosing performance and compatibility to existing software. To execute CUDA C++Code, Cling activates an extension in the compiler frontend to understand theCUDA C++ dialect and creates a second compiler instance that compiles the codefor the GPU.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure8.png"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure8.png "image_tooltip") ---> <p align="center"> Figure 8. CUDA/C++ information flow in Cling. </p></div><p>Like the normal C++ mode, the CUDA C++ mode uses AST transformation to enableinteractive CUDA C++ or special features as the Cling print system. In contrastto the normal Cling compiler pipeline used for the host code, the devicecompiler pipeline does not use all the transformations of the host pipeline.Therefore, the device pipeline has some special transformation.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>iostream<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>cublas_v2.h<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>pragma cling(load <span style="color:#e6db74">"libcublas.so"</span>) <span style="color:#75715e">// link a shared library</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// set parameters</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// allocate memory</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// ...</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>[cling] __global__ <span style="color:#66d9ef">void</span> init(<span style="color:#66d9ef">float</span> <span style="color:#f92672">*</span>matrix, <span style="color:#66d9ef">int</span> size){</span></span><span style="display:flex;"><span>[cling] <span style="color:#f92672">?</span> <span style="color:#66d9ef">int</span> x <span style="color:#f92672">=</span> blockIdx.x <span style="color:#f92672">*</span> blockDim.x <span style="color:#f92672">+</span> threadIdx.x;</span></span><span style="display:flex;"><span>[cling] <span style="color:#f92672">?</span> <span style="color:#66d9ef">if</span> (x <span style="color:#f92672"><</span> size)</span></span><span style="display:flex;"><span>[cling] <span style="color:#f92672">?</span> matrix[x] <span style="color:#f92672">=</span> x;</span></span><span style="display:flex;"><span>[cling] <span style="color:#f92672">?</span> }</span></span><span style="display:flex;"><span>[cling]</span></span><span style="display:flex;"><span>[cling] <span style="color:#75715e">// launching a function direct in the global space</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>[cling] init<span style="color:#f92672"><<<</span>blocks, threads<span style="color:#f92672">>>></span>(d_A, dim<span style="color:#f92672">*</span>dim);</span></span><span style="display:flex;"><span>[cling] init<span style="color:#f92672"><<<</span>blocks, threads<span style="color:#f92672">>>></span>(d_B, dim<span style="color:#f92672">*</span>dim);</span></span><span style="display:flex;"><span>[cling]</span></span><span style="display:flex;"><span>[cling] cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, dim, dim, dim, <span style="color:#f92672">&</span>alpha, d_A, dim, d_B, dim, <span style="color:#f92672">&</span>beta, d_C, dim);</span></span><span style="display:flex;"><span>[cling] cublasGetVector(dim<span style="color:#f92672">*</span>dim, <span style="color:#66d9ef">sizeof</span>(h_C[<span style="color:#ae81ff">0</span>]), d_C, <span style="color:#ae81ff">1</span>, h_C, <span style="color:#ae81ff">1</span>);</span></span><span style="display:flex;"><span>[cling] cudaGetLastError()</span></span><span style="display:flex;"><span>(cudaError_t) (cudaError<span style="color:#f92672">::</span>cudaSuccess) <span style="color:#f92672">:</span> (<span style="color:#66d9ef">unsigned</span> <span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">0</span></span></span></code></pre></div><p>Like the normal C++ mode, the CUDA mode can be used in a Jupyter Notebook.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-12-21-figure9.gif"><br /> <!--- ![alt_text](/img/cling-2020-12-21-figure9.gif "image_tooltip") ---> <p align="center"> Figure 9. CUDA/C++ information flow in Cling. </p></div><p>A special property of Cling in CUDA mode is that the Cling application becomes anormal CUDA application at the time of the first CUDA API call. This enables theCUDA SDK with Cling. For example, you can use the CUDA profiler<code>nvprof ./cling -xcuda</code> to profile your interactive application.<a href="https://hub.docker.com/r/sehrig/cling">This docker</a> container can be used toexperiment with Cling’s CUDA mode.</p><p>Planned future developments for the CUDA mode include: Supporting of thecomplete current CUDA API; Redefining CUDA Kernels; Supporting other GPU SDK’slike HIP (AMD) and SYCL (Intel).</p><h2 id="conclusion">Conclusion</h2><p>We see the use of Interactive C++ as an important tool to develop forresearchers in the data science community. Cling has enabled ROOT to be the“go to” data analysis tool in the field of High Energy Physics for everythingfrom efficient I/O to plotting and fitting. The interactive CUDA backend allowseasy integration of research workflows and simpler communication between C++ andCUDA. As Jupyter Notebooks have become a standard way for data analysts toexplore ideas, Xeus-cling ensures that great interactive C++ ingredients areavailable in every C++ notebook.</p><p>In the next blog post we will focus on Cling enabling features beyondinteractive C++, and in particular language interoperability.</p><h2 id="acknowledgements">Acknowledgements</h2><p>The author would like to thank Sylvain Corlay, Simeon Ehrig, David Lange,Chris Lattner, Javier Lopez Gomez, Wim Lavrijsen, Axel Naumann, Alexander Penev,Xavier Valls Pla, Richard Smith, Martin Vassilev, who contributed to this post.</p><p>You can find out more about our activities at<a href="https://root.cern/cling/">https://root.cern/cling/</a> and<a href="https://compiler-research.org">https://compiler-research.org</a>.</p>
- Interactive C++ with Clinghttps://blog.llvm.org/posts/2020-11-30-interactive-cpp-with-cling/Mon, 30 Nov 2020 10:00:00 +0000https://blog.llvm.org/posts/2020-11-30-interactive-cpp-with-cling/<h1 id="interactive-c-with-cling">Interactive C++ with Cling</h1><p>The C++ programming language is used for many numerically intensive scientificapplications. A combination of performance and solid backward compatibility hasled to its use for many research software codes over the past 20 years. Despiteits power, C++ is often seen as difficult to learn and inconsistent with rapidapplication development. Exploration and prototyping is slowed down by the longedit-compile-run cycles during development.</p><p><a href="https://github.com/root-project/cling/">Cling</a> has emerged as a recognizedcapability that enables interactivity, dynamic interoperability and rapidprototyping capabilities to C++ developers. Cling supports the full C++ featureset including the use of templates, lambdas, and virtual inheritance. Cling isan interactive C++ interpreter, built on top of the Clang and <a href="llvm.org">LLVM</a>compiler infrastructure. The interpreter enables interactive exploration andmakes the C++ language more welcoming for research.</p><p>The main tool for storage, research and visualization of scientific data in thefield of high energy physics (HEP) is the specialized software package<a href="root.cern/">ROOT</a>. ROOT is a set of interconnected components that assistscientists from data storage and research to their visualization when publishedin a scientific paper. ROOT has played a significant role in scientificdiscoveries such as gravitational waves, the great cavity in the Pyramid ofCheops, the discovery of the Higgs boson by the Large Hadron Collider. For thelast 5 years, Cling has helped to analyze 1 EB physical data, serving as a basisfor over 1000 scientific publications, and supports software run across adistributed million CPU core computing facility.</p><p>Recently we started a project aiming to leverage our experience in interactiveC++, just-in-time compilation technology (JIT), dynamic optimizations, and largescale software development to greatly reduce the impedance mismatch between C++and Python. We will generalize Cling to offer a robust, sustainable andomnidisciplinary solution for C++ language interoperability.The scope of ourobjectives is to:</p><ul><li>advance the interpretative technology to provide a state-of-the-art C++execution environment,</li><li>enable functionality which can provide native-like, dynamic runtimeinteroperability between C++ and Python (and eventually other languages suchas Julia and Swift)</li><li>allow seamless utilization of heterogeneous hardware (such as hardwareaccelerators)</li></ul><p>Project results will be integrated into the widely used tools LLVM, Clang andCling. The outcome of the proposed work is a platform which provides a C++compiler as a service (CaaS) for both rapid application development andcomputational performance.</p><p>The rest of this post intends to demonstrate the design and several features ofCling. Want to follow along? You can get cling from conda</p><pre tabindex="0"><code>conda config --add channels conda-forgeconda install clingconda install llvmdev=5.0.0</code></pre><p>or from docker-hub if you don’t already use conda:</p><pre tabindex="0"><code>docker pull compilerresearch/clingdocker run -t -i compilerresearch/cling</code></pre><p>Either way, type “cling” to start its interactive shell:</p><pre tabindex="0"><code>cling****************** CLING ******************* Type C++ code and press enter to run it ** Type .q to exit ********************************************[cling]$[cling]$ #include "cling/Interpreter/Interpreter.h"[cling]$ gCling->allowRedefinition(false)</code></pre><p>We will explain the purpose for these commands, and other alternatives for usingcling in further parts of this post.</p><h1 id="interpreting-c">Interpreting C++</h1><p>Exploratory programming (or Rapid Application Development) is an effective wayto gain understanding of the requirements for a project; to reduce thecomplexity of the problem; and to provide an early validation of the systemdesign and implementation. In particular, interactively probing data andinterfaces makes complex libraries and complex data more accessible to users.It is important in data science, computational science and debugging. Itsignificantly reduces the time consumed by edit-run cycles during development.In practice, only few programming languages offer both a compiler and aninterpreter translating them into machine code, although whether a language isto be interpreted or compiled is a property of the implementation.</p><p>Languages which enable exploratory programming tend to have interpreters whichshorten the compile-link cycle; this generally has a noticeable cost inperformance. Language developers who acknowledge the use case of exploratoryprogramming may also put syntactic sugar, but that is mostly for convenience andterseness. The performance penalty is largely mitigated by using just-in-time(JIT) or ahead-of-time (AOT) compilation technology.</p><p>For the sake of this post series, interpreting C++ means enabling exploratoryprogramming for C++ while mitigating the performance cost with JIT compilation.Figure 1 shows an illustrative example of exploratory programming. It becomestrivial to orient the shape, choose size and color or compare to previoussettings. The invisible compile-link cycle aids interactive use which allowssome qualitatively different approaches to program development and enhancedproductivity.</p><div style="max-width:1095px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-11-30-figure1.gif" style="max-width:90%;"><br /> <!--- ![alt_text](/img/cling-2020-11-30-figure1.gif "image_tooltip") ---> <p align="center"> Figure 1. Interactive OpenGL Demo, adapted from [here](https://www.youtube.com/watch?v=eoIuqLNvzFs). </p></div><h2 id="design-principles">Design principles</h2><p>Some of the design goals of cling include:</p><ul><li>Do not pay for what you do not use – prioritize performance of processingcorrect code. For example, in order to provide error recovery do not penalizeusers typing syntactically and semantically correct C++; and interactive C++transformations are only done when necessary and can be disabled.</li><li>Reuse Clang & LLVM at (almost) any cost – do not reinvent the wheel. If afeature is not available, then try finding a minimalistic way to implement itand propose it for a review to the LLVM community. Otherwise find the minimalpatch, even at the cost of misusing API, which satisfies the requirements.</li><li>Continuous feature delivery – focus on a minimal feature, its integrationin the main use-case (ROOT), deployment in production, repeat.</li><li>Library design – allow Cling to be used as a library from third partyframeworks.</li><li>Learn and evolve – experiment with user experience. There is no formalspecification or consensus on overall user experience. Apply lessons learnedfrom the legacy from CINT.</li></ul><h2 id="architecture">Architecture</h2><p>Cling accepts partial input and ensures that the compiler process keeps runningto act on code as it comes in. It includes an API providing access to theproperties of recently compiled chunks of code. Cling can apply customtransformations to each chunk before execution. Cling orchestrates the existingLLVM and Clang infrastructure following a data flow described in Figure 2.</p><div style="max-width:600px; margin:0 auto;"> <img src="https://blog.llvm.org/img/cling-2020-11-30-figure2.svg"><br /> <!--- ![alt_text](/img/cling-2020-11-30-figure2.svg "image_tooltip") ---><p align="center">Figure 2. Information flow in Cling</p></div>In short:<ol><li>The tool controls the input infrastructure by interactive prompt or by aninterface allowing the incremental processing of input (â).</li><li>It sends the input to the underlying clang library for compilation (â).</li><li>Clang compiles the input, possibly wrapped into a function, into an AST (â).</li><li>When necessary the AST is further transformed in order to attach specificbehavior (â).</li></ol><p>For example, reporting execution results, or other interpreter-related features.Once the high-level AST representation is ready, it is sent for lowering to anLLVM-specific assembly format, the LLVM IR (â). The LLVM IR is the input formatfor LLVMâs just-in-time compilation infrastructure. Cling instructs the JIT torun specified functions (â
), translating them into machine code (MC) targetingthe underlying device architecture (eg. Intel x86 or NVPTX) (â,â).</p><p>The C++ standard is developed towards compilers and does not cover interactiveuse well. Execution of statements on the global scope, reporting executionresults, and entity redefinitions are the three most important features when itcomes to user friendliness. Long running interpreter sessions are prone totyping errors and make flawless error recovery essential. More advanceduse-cases require extra flexibility at runtime and lookup rules extensionsaiding eval-style programming. Efficient watermark-based code removal isimportant when C++ is used as scripting language.</p><h2 id="execution-of-statements">Execution of statements</h2><p>Cling processes C++ incrementally. Incremental input consists of one or multipleC++ statements. C++ does not allow expressions in the global scope.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>vector<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>iostream<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling] std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span> v <span style="color:#f92672">=</span> {<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>,<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>}; v[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">++</span>;</span></span><span style="display:flex;"><span>[cling] std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"v[0]="</span> <span style="color:#f92672"><<</span> v[<span style="color:#ae81ff">0</span>] <span style="color:#f92672"><<</span><span style="color:#e6db74">"</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>;</span></span><span style="display:flex;"><span>v[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">=</span><span style="color:#ae81ff">2</span></span></span></code></pre></div><p>Instead, Cling moves each input into a unique wrapper function. Eg:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">__unique_1</span> () { std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span> v <span style="color:#f92672">=</span> {<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>,<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>};v[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">++</span>;; } <span style="color:#75715e">// #1</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">__unique_2</span> () { std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"v[0]="</span> <span style="color:#f92672"><<</span> v[<span style="color:#ae81ff">0</span>] <span style="color:#f92672"><<</span><span style="color:#e6db74">"</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>;; } <span style="color:#75715e">// #2</span></span></span></code></pre></div><p>After the clang AST is built, cling detects that wrapper #1 contains adeclaration and moves the declaration’s AST node to the global scope, such that<code>v</code> can be referenced by subsequent inputs. Wrapper #2 contains a statement andis executed as is. Internally to Cling, the example is transformed to:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><vector></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e">#include</span> <span style="color:#75715e"><iostream></span><span style="color:#75715e"></span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span> v <span style="color:#f92672">=</span> {<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>,<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>};</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">__unique_1</span> () { v[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">++</span>;; }</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">__unique_2</span> () { std<span style="color:#f92672">::</span>cout <span style="color:#f92672"><<</span> <span style="color:#e6db74">"v[0]="</span> <span style="color:#f92672"><<</span> v[<span style="color:#ae81ff">0</span>] <span style="color:#f92672"><<</span><span style="color:#e6db74">"</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">"</span>;; }</span></span></code></pre></div><p>Cling runs these wrappers after they are compiled to machine code.</p><h2 id="reporting-execution-results">Reporting execution results</h2><p>An integral part of interactivity is printing expression values. Typing <code>printf</code>each time is laborious and does not naturally include object type information.Instead, omitting the semicolon of the last statement of the input tells Clingto report the expression result. When wrapping the input, Cling textuallyattaches a semicolon to the end of it. If an execution report is requested thecorresponding wrapper AST does not contain a <em>NullStmt</em> (modelling extrasemicolons).</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling] <span style="color:#960050;background-color:#1e0010">#</span>include <span style="color:#f92672"><</span>vector<span style="color:#f92672">></span></span></span><span style="display:flex;"><span>[cling] std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span> v <span style="color:#f92672">=</span> {<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>,<span style="color:#ae81ff">3</span>,<span style="color:#ae81ff">4</span>,<span style="color:#ae81ff">5</span>} <span style="color:#75715e">// Note the missing semicolon</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>(std<span style="color:#f92672">::</span>vector<span style="color:#f92672"><</span><span style="color:#66d9ef">int</span><span style="color:#f92672">></span> <span style="color:#f92672">&</span>) { <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">3</span>, <span style="color:#ae81ff">4</span>, <span style="color:#ae81ff">5</span> }</span></span></code></pre></div><p>A transformation injects extra code depending on the properties of theparticular entity such as if it is copyable, if it is a wrapper temporary or anarray. Cling can report information about non-copyable or temporary objects byproviding a âmanagedâ storage. The managed storage (<em>cling::Value</em>) is also usedfor exchanging values between interpreted and compiled code in embedded setup.</p><h2 id="entity-redefinition">Entity Redefinition</h2><p>Name redefinition is an important scripting feature. It is also essential fornotebook-based C++ as each cell is a somewhat separate computation. C++ does notsupport redefinitions of entities.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> <span style="color:#75715e">#include <string></span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> std::string v</span></span><span style="display:flex;"><span><span style="color:#f92672">(</span>std::string &<span style="color:#f92672">)</span> <span style="color:#e6db74">""</span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> <span style="color:#75715e">#include <vector></span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> std::vector<int> v</span></span><span style="display:flex;"><span>input_line_7:2:19: error: redefinition of <span style="color:#e6db74">'v'</span> with a different type: <span style="color:#e6db74">'std::vector<int>'</span> vs <span style="color:#e6db74">'std::string'</span> <span style="color:#f92672">(</span>aka <span style="color:#e6db74">'basic_string<char, char_traits<char>, allocator<char> >'</span><span style="color:#f92672">)</span></span></span><span style="display:flex;"><span> std::vector<int> v</span></span><span style="display:flex;"><span> ^</span></span><span style="display:flex;"><span>input_line_4:2:14: note: previous definition is here</span></span><span style="display:flex;"><span> std::string v</span></span><span style="display:flex;"><span> ^</span></span></code></pre></div><p>Cling implements entity redefinition using inline namespaces and rewires clanglookup rules to give higher priority to more recent declarations. The fulldescription of this feature was published as a conference paper on CC 2020(<a href="https://doi.org/10.1145/3377555.3377901">ACM conference on Compiler Construction</a>).We enable it by calling <code>gCling->allowRedefinition()</code>:</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> <span style="color:#75715e">#include "cling/Interpreter/Interpreter.h"</span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> gCling->allowRedefinition<span style="color:#f92672">()</span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> <span style="color:#75715e">#include <vector></span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> std::vector<int> v</span></span><span style="display:flex;"><span><span style="color:#f92672">(</span>std::vector<int> &<span style="color:#f92672">)</span> <span style="color:#f92672">{}</span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> <span style="color:#75715e">#include <string></span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> std::string v</span></span><span style="display:flex;"><span><span style="color:#f92672">(</span>std::string &<span style="color:#f92672">)</span> <span style="color:#e6db74">""</span></span></span></code></pre></div><h2 id="invalid-code-error-recovery">Invalid Code. Error Recovery</h2><p>When used in interactive mode, invalid C++ does not terminate the session.Instead invalid code is discarded. The underlying clang process keeps theinvalid AST nodes in its internal data structures for better error diagnosticsand recovery, expecting the process will end shortly after issuing thediagnostics. This particular example is more challenging because it firstcontains both valid and invalid constructs. The error recovery should undo asignificant amount of changes in internal structures such as the name lookup andthe AST. Cling is used in many high-performance environments; usingcheckpointing is not a viable option as it introduces overhead for correct code.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> <span style="color:#75715e">#include <vector></span></span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> std::vector<int> v; v<span style="color:#f92672">[</span>0<span style="color:#f92672">]</span>.error_here;</span></span><span style="display:flex;"><span>input_line_4:2:26: error: member reference base type <span style="color:#e6db74">'std::__1::__vector_base<int, std::__1::allocator<int> >::value_type'</span> <span style="color:#f92672">(</span>aka <span style="color:#e6db74">'int'</span><span style="color:#f92672">)</span> is not a structure or union</span></span><span style="display:flex;"><span> std::vector<int> v; v<span style="color:#f92672">[</span>0<span style="color:#f92672">]</span>.error_here;</span></span><span style="display:flex;"><span> ~~~~^~~~~~~~~~~</span></span></code></pre></div><p>In order to handle the example, Cling models the incremental input into a<em>Transaction</em>. A transaction represents the delta of the changes of internaldata structures of Clang. Cling listens to events coming from various Clangcallbacks such as declaration creation, deserialization and macro definition.This information is sufficient to undo the changes and continue with a validstate. The implementation is very intricate and in many cases requires extrawork depending on the input declaration kinds.</p><p>Cling also protects against null pointer dereferences via a code transformation,avoiding a session crash.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span> int *p <span style="color:#f92672">=</span> nullptr; *p</span></span><span style="display:flex;"><span>input_line_3:2:21: warning: null passed to a callee that requires a non-null argument <span style="color:#f92672">[</span>-Wnonnull<span style="color:#f92672">]</span></span></span><span style="display:flex;"><span> int *p <span style="color:#f92672">=</span> nullptr; *p</span></span><span style="display:flex;"><span> ^</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>cling<span style="color:#f92672">]</span></span></span></code></pre></div><p>The implementation of error recovery and code unloading still has rough edgesand it is being improved constantly.</p><h2 id="code-removal">Code Removal</h2><p>Incremental, interactive C++ assumes long lived sessions where not only syntaxerror can happen but also semantic ones. That poses one level of extracomplexity if we want to re-execute the same code with minor adjustments.</p><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>[cling] .L Adder.h <span style="color:#75715e">// #1, similar to #include "Adder.h"</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>[cling] Add(<span style="color:#ae81ff">3</span>, <span style="color:#ae81ff">1</span>) <span style="color:#75715e">// int Add(int a, int b) {return a - b; }</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>(<span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">2</span></span></span><span style="display:flex;"><span>[cling] .U Adder.h <span style="color:#75715e">// reverts the state prior to #1</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>[cling] .L Adder.h</span></span><span style="display:flex;"><span>[cling] Add(<span style="color:#ae81ff">3</span>, <span style="color:#ae81ff">1</span>) <span style="color:#75715e">// int Add(int a, int b) {return a + b; }</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>(<span style="color:#66d9ef">int</span>) <span style="color:#ae81ff">4</span></span></span></code></pre></div><p>In the example, we include a header file with the <em>.L</em> meta command;“uninclude” it with <em>.U</em> and âreincludeâ it with <em>.L</em> to re-read the modifiedfile. Unlike in the error recovery case, Cling cannot fence the machine codelowering infrastructure and needs to undo state changes in clang CodeGen and thellvm JIT and machine code infrastructure. The implementation of this featurerequires expertise in a big portion of the LLVM toolchain.</p><h1 id="conclusion">Conclusion</h1><p>Cling has been one of the systems enabling interactive C++ for more than a decade.Clingâs extensibility and fast prototyping features is of fundamental importancefor researchers in high-energy physics, and an enabler for many of thetechnologies that they rely on. Cling has several unique features tailored tothe challenges which come with incremental C++. Our work on interactive C++ isalways evolving. In the next blog post we will focus on interactive C++ for DataScience; Eval-Style Programming; Interactive CUDA; and C++ in notebooks.</p><p>You can find out more about our activities at<a href="https://root.cern/cling/">https://root.cern/cling/</a> and<a href="https://compiler-research.org">https://compiler-research.org</a>.</p><h1 id="acknowledgements">Acknowledgements</h1><p>The author would like to thank Sylvain Corlay, Simeon Ehrig, David Lange,Chris Lattner, Javier Lopez Gomez, Wim Lavrijsen, Axel Naumann, Alexander Penev,Xavier Valls Pla, Richard Smith, Martin Vassilev, who contributed to this post.</p>
- The 2020 Virtual LLVM Developers' Meeting Programhttps://blog.llvm.org/posts/2020-08-23-llvmdevmtgprogram/Sun, 23 Aug 2020 17:00:06 -0700https://blog.llvm.org/posts/2020-08-23-llvmdevmtgprogram/<p><img src="https://blog.llvm.org/img/750x300-1.png" alt="2020 Virtual LLVM Developers’ Meeting"></p><p>The LLVM Foundation is excited to announce the <a href="https://llvm.org/devmtg/2020-09/">2020 Virtual LLVM Developers’ Meeting</a> program! Registration will open this week.</p><p><strong>Keynote:</strong></p><ul><li>Undef and Poison: Present and Future - <em>J. Lee</em></li></ul><p><strong>Technical Talks:</strong></p><ul><li>Clang & Linux: Asm Goto with Outputs - <em>B. Wendling; N. Desaulniers</em></li><li>LLVM Libc: Current Status, Challenges and Future Plans- <em>S. Reddy; G. Chatelet; P. Asker; D. Finkelstein</em></li><li>Branch Coverage: Squeezing more out of LLVM Source-based Code Coverage - <em>A. Phipps</em></li><li>Memory tagging in LLVM and Android - <em>E. Stepanov; K. Serebryany; P. Collingbourne; M. Phillips</em></li><li>Towards a representation of arbitrary alias graph in LLVM IR for Fortran code - <em>K. Li; T. Islam</em></li><li>Control-flow sensitive escape analysis in Falcon JIT - <em>A. Pilipenko</em></li><li>Extending Clang for checking compliance with automotive coding standards - <em>M. Vujosevic Janicic</em></li><li>An Update on Optimizing Multiple Exit Loops - <em>P. Reames</em></li><li>Code Size Compiler Optimizations and Techniques - <em>A. Kumar</em></li><li>Accelerate Matrix Multiplication Using the New POWER Outer Product Instructions- <em>B. Saleil; J. Carvalho</em></li><li>CIL : Common MLIR Dialect for C/C++ and Fortran- <em>P. NR; V. M; Ranjith; Srihari</em></li><li>Building compiler extension for LLVM 10.0.1 - <em>S. Guelton</em></li><li>LLVM-based mutation testing for C and C++ - <em>A. Denisov; S. Pankevich</em></li><li>Matrix Support in Clang and LLVM- <em>F. Hahn</em></li><li>Adding CUDA® Support to Cling: JIT Compile to GPUs - <em>S. Ehrig</em></li><li>The Present and Future of Interprocedural Optimization in LLVM - <em>J. Doerfert; B. Homerding; S. Baziotis; S. Stipanovic; H. Ueno; K. Dinel; S. Okumura; L. Chen</em></li><li>Pushing Back Lit’s Boundaries to Test Libc++ - <em>L. Dionne</em></li><li>Evolving âconvergentâ: Lessons from Control Flow in AMDGPU - <em>N. Hähnle</em></li><li>How to update debug info in compiler transformations - <em>A. Prantl; V. Kumar</em></li><li>Proposal for A Framework for More Effective Loop Optimizations - <em>M. Kruse; H. Finkel</em></li><li>Changing Everything With Clang Plugins: A Story About Syntax Extensions, Clang’s AST, and Quantum Computing = <em>H. Finkel; A. Mccaskey</em></li><li>(OpenMP) Parallelism-Aware Optimizations - <em>J. Doerfert; S. Stipanovic; H. Mosquera; J. Chesterfield; G. Georgakoudis; J. Huber</em></li><li>Checked C: Adding memory safety support to LLVM- <em>M. Grang; K. Kjeer</em></li></ul><p><strong>Tutorials:</strong></p><ul><li>Everything I know about debugging LLVM - <em>N. Desaulniers</em></li><li>LLVM in a Bare Metal Environment - <em>H. Qadeer</em></li><li>PGO: Add per-callsite counters - <em>P. Kosov; Y. Sergey</em></li><li>Understanding Changes made by a Pass in the Opt Pipeline. - <em>J. Schmeiser</em></li><li>Using clang-tidy for customized checkers and large scale source tree refactoring - <em>V. Bridgers</em></li><li>Finding Your Way Around the LLVM Dependence Analysis Zoo - <em>S. Baziotis; S. Moll</em></li><li>Using the clang static analyzer to find bugs - <em>V. Bridgers</em></li><li>A Deep Dive into the Interprocedural Optimization Infrastructure - <em>J. Doerfert; B. Homerding; S. Baziotis; S. Stipanovic; H. Ueno; K. Dinel; S. Okumura; L. Chen</em></li><li>MLIR Tutorial - <em>M. Amini</em></li></ul><p><strong>Lightning Talks:</strong></p><ul><li>Finding and Outlining Similarities in LLVM IR - <em>A. Litteken</em></li><li>A fast algorithm for global code motion of congruent instructions - <em>A. Kumar; S. Pop</em></li><li>From Implicit Pass Dependencies to Effectiveness Prediction - <em>H. Ueno; J. Doerfert; E. Park; G. Georgakoudis; T. Jayatilaka; S. Badruswamy</em></li><li>Using Clang as An Alternative C/C++ Frontend of The ROSE Source-to-Source Compiler - <em>A. Wang; P. Lin; C. Liao; Y. Yan</em></li><li>OpenACC support in Flang with a MLIR dialect - <em>V. Clement; J. Vetter</em></li><li>Fragmenting the DWARF to Enable Dead Debug Data Elimination - <em>J. Henderson</em></li><li>Source-based Code Coverage for Embedded Use Cases - <em>A. Phipps; C. Addison</em></li><li>pre-merge checks for LLVM - <em>M. Goncharov; C. Kühnel</em></li><li>Getting stack size just right on XCore - <em>J. McCrea</em></li><li>Compile Faster with the Program Repository and ccache - <em>Y. Yi; P. Bowen-Huggett</em></li><li>GWP-TSan: Zero-Cost Detection of Data Races in Production - <em>M. Morehouse; K. Serebryany</em></li><li>CompilerInvocation to -cc1 command line - <em>D. Grumberg</em></li><li>Outer-Loop Vectorization Legality Analysis for RV: One Step Closer to a Powerful Vectorizer for LLVM - <em>S. Baziotis</em></li><li>Flang Update - <em>S. Scalpone</em></li><li>Code Feature Analysis, Tracking, and Future Usage - <em>T. Jayatilaka; J. Doerfert; G. Georgakoudis; E. Park; H. Ueno; S. Badruswamy</em></li><li>Lowering XLA HLO using RISE - A Functional Pattern-based MLIR Dialect - <em>M. Lücke; A. Smith; M. Steuwer</em></li><li>SYCL for CUDA: An overview of implementing PI for CUDA - <em>A. Johnston</em></li><li>Extending LLDB to More Scripting Languages - <em>J. Devlieghere</em></li><li>Adding a Subtarget Support to LLVM in Five Minutes - <em>E. Yakubova</em></li></ul><p><strong>Birds of a Feather:</strong></p><ul><li>ClangBuiltLinux BoF - <em>N. Desaulniers</em></li><li>Loop Optimization BoF - <em>M. Kruse; K. Barton</em></li><li>LLVM Just-In-Time Compilers BoF - <em>L. Hames</em></li><li>Code Size Optimization - <em>S. Bartell; V. Adve</em></li></ul><p><strong>Student Research Competition</strong></p><ul><li>Enzyme: High-Performance Automatic Differentiation of LLVM - <em>W. Moses; V. Churavy</em></li><li>SPAM: Stateless Permutation of Application Memory with LLVM - <em>M. Ziad; M. Arroyo; S. Sethumadhavan</em></li><li>HPVM-FPGFA: Leveraging Compiler Optimizations for Hardware-Agnostic FPGA Programming - <em>A. Ejjeh; K. Kanwar; M. Kotsifakou; V. Adve; R. Rutenbar</em></li><li>Guided Linking: shrinking and speeding up dynamically linked code - <em>S. Bartell; V. Adve</em></li><li>ApproxTuner: A Compiler and Runtime System for Adaptive Approximations - <em>H. Sharif; M. Kotsifakou; Y. Zhao; A. Kothari; B. Schreiber; E. Wang; Y. Sarita; N. Zhao; K. Joshi; V. Adve; S. Misailovic; S. Adve</em></li></ul><p><strong>Posters:</strong></p><ul><li>CIRCT: MLIR for Hardware Design - <em>S. Neuendorffer; C. Lattner; A. Wilson</em></li><li>An Approach to Generate Correctly Rounded Math Libraries for New Floating Point Variants - <em>J. Lim; M. Aanjaneya; J. Gustafson; S. Nagarakatte</em></li><li>Compiling a Higher-Order Smart Contract Language to LLVM - <em>V. Nagaraj; J. Johannsen; A. Trunov; G. Pirlea; A. Kumar; I. Sergey</em></li><li>To -jInfinity & Beyond - <em>W. Moses; K. Kwok; L. Sha</em></li><li>llvm-diva â Debug Information Visual Analyzer - <em>C. Enciso</em></li><li>Quickly Finding RISC-V Code Quality Issues with Differential Analysis - <em>L. Marques</em></li><li>Error estimates of floating-point numbers and Jacobian matrix computation in Clad - <em>V. Vassilev; A. Penev; R. Shakhov</em></li><li>Data Dependency using MSSA: Analysis and Contrast - <em>R. Sharma</em></li><li>Connecting Clang to The ROSE Source-to-Source Compiler - <em>A. Wang; P. Lin; C. Liao; Y. Yan</em></li><li>Incremental Compilation Support in Clang - <em>V. Vassilevv; D. Lange</em></li></ul>
- Announcing the new LLVM Foundation Boardhttps://blog.llvm.org/posts/2020-08-21-new-llvm-foundation-board/Fri, 21 Aug 2020 17:54:06 -0700https://blog.llvm.org/posts/2020-08-21-new-llvm-foundation-board/<p>The LLVM Foundation is pleased to announce its new Board of Directors, which includes:</p><ul><li>Kit Barton</li><li>Kristof Beyls</li><li>Mike Edwards (Treasurer)</li><li>Hal Finkel</li><li>Cyndy Ishida</li><li>Anton Korobeynikov</li><li>Tanya Lattner (President)</li><li>Chris Lattner</li><li>Tom Stellard (Secretary)</li></ul><p>Three new members and six continuing members were elected to the nine person board. Thank you to retiring board members Chandler Carruth, Arnaud de Grandmaison, and John Regehr for all of their contributions to the board.</p><p>We were pleased to have many qualified applicants to the Board of Directors this year, which enabled us to make the board stronger than ever. Unfortunately, this also meant that we could not include everyone that we wanted to. Our goal was to create a balanced board of individuals from a wide range of backgrounds and locations, and to provide a voice to many groups within the LLVM community. This is always a challenge with such a large and vibrant community, and such a small board.</p><p>About the board of directors (listed alphabetically by last name):</p><p><strong>Kit Barton:</strong></p><p>Kit Barton has been contributing to LLVM since 2015. His contributions have primarily been to the PowerPC backend and loop optimizations including the loop fusion pass. He has presented multiple technical talks, and tutorials at theLLVM Dev conferences over the last two years.</p><p>In addition to the contributions to LLVM, over the last two years Kit has driven the effort within IBM to migrate their proprietary C/C++ and Fortran compilers to leverage LLVM technology. He has also been involved in organizing the LLVM Meetups in Toronto as well as the Loop Optimization Working Group.</p><p>Kit is currently the technical lead for C/C++ and Fortran compilers on POWER and z/OS at IBM.</p><p><strong>Kristof Beyls:</strong></p><p>Kristof Beyls has worked on LLVM since about 2010, initially as part of tech leading the migration of Arm’s C/C++ toolchain to be based on LLVM technology. Since then, Kristof has worked on a large number of code generation projects using LLVM. He has contributed to LLVM in the areas of security mitigations, performance tuning, Arm backends, test-suite, LNT, etc.</p><p>He has been helping with the organization of EuroLLVM meetings since the start; has been organizing the FOSDEM LLVM dev rooms for the past couple of years and has organized a few socials in Belgium. He has also been on the program committee for a few of the dev meetings.</p><p>Kristof is Senior Principal Engineer at Arm.</p><p><strong>Mike Edwards:</strong></p><p>Mike Edwards has been involved with the LLVM Project since 2016 and has been most active behind the scenes working on infrastructure related issues. Mike joined the LLVM Foundation Board in 2018 and was elected Treasurer. Mike has used the past two years to help further the Foundations programs and support the many efforts of the Foundation to reach new users of LLVM technologies. Mike is looking forward to working with the new Board Members elected this year to help further the program development and outreach of the Foundation.</p><p>Mike is currently working as a Software Engineer at Apple, Inc. working on the Continuous Integration and Quality Engineering efforts for LLVM and Clang development.</p><p><strong>Hal Finkel:</strong></p><p>Hal Finkel has been an active contributor to the LLVM project since 2011. He is the code owner for the PowerPC target, the alias-analysis infrastructure, and other components.</p><p>In addition to his numerous technical contributions, Hal has chaired the LLVM in HPC workshop, which is held in conjunction with Super Computing (SC), starting in 2014. This workshop provides a venue for the presentation of peer-reviewed HPC-related researching LLVM from both industry and academia. He has also been involved in organizing an LLVM-themed BoF session at SC and LLVM socials, in addition to organizing community technical calls for Flang and aliasing analysis.</p><p>Hal is Lead for Compiler Technology and Programming Languages at Argonne National Laboratoryâs Leadership Computing Facility. His team at Argonne works on several LLVM-based projects. Hal also teaches a compilers course at the University of Chicago’s Masters Program in Computer Science.</p><p><strong>Cyndy Ishida:</strong></p><p>Cyndy Ishida is relatively new to the LLVM community. She began her involvement by contributing Mach-O Support to TextAPI in the past year, which serves as a condensed textual representation of dynamic libraries from a static linking perspective.</p><p>In addition to open source contributions, Cyndy has participated in the program committee for the 2020 US LLVM Developersâ Meeting and in the 2019 US Women in Compilers and Tools Workshop. With a long standing admiration for the LLVM Project and Foundation, Cyndy is passionate about supporting and expanding the community. She is excited to use her position to aid in educational outreach efforts as a driver to grow the set of diverse developers that make up the open source community, and is focused on advocating for inclusivity in the LLVM project.</p><p>Cyndy is a Compiler Engineer at Apple, Inc. concentrating on enhancing library support with Clang tooling.</p><p><strong>Anton Korobeynikov:</strong></p><p>Anton Korobeynikov has been an active contributor to the LLVM project since 2006. Over the years, he has numerous technical contributions to areas including Windows support, ELF features, debug info, exception handling, and backends such as ARM and x86. He was the original author of the MSP430 and original System Z backend.</p><p>In addition to his technical contributions, Anton has maintained LLVMâs participation in Google Summer of Code by managing applications, deadlines, and overall organization. He also supports the LLVM infrastructure and has been on numerous program committees for the LLVM Developersâ Meetings (both US and EuroLLVM).</p><p>Anton is currently an associate professor at the Saint Petersburg State University and has served on the LLVM Foundation board of directors for the last 6 years.</p><p><strong>Tanya Lattner:</strong></p><p>Tanya Lattner has been involved in the LLVM project for over 16 years. She began as a graduate student who wrote her master’s thesis using LLVM, and continued on using and extending LLVM technologies at various jobs during her career as a compiler engineer.</p><p>Tanya has been organizing the US LLVM Developersâ meeting since 2008 and attended every developer meeting. She was the LLVM release manager for 3 years, moderates the LLVM mailing lists, and helps administer the LLVM infrastructure servers, mailing lists, bugzilla, etc. Tanya has also been on the program committee for the US LLVM Developersâ meeting (4 years) and the EuroLLVM Developersâ Meeting (1 year).</p><p>With the support of the initial board of directors, Tanya created the LLVM Foundation, defined its charitable and education mission, and worked to get 501(c)(3) status. She is passionate about the LLVM Community and wants to help see it thrive and grow for years to come.</p><p>Tanya is the Chief Operating Officer and has served as the President of the LLVM Foundation board for the last 6 years.</p><p><strong>Chris Lattner:</strong></p><p>Chris Lattner is the founder of the LLVM project and has a lengthy history of technical contributions to the project over the years. He drove much of the early implementation, architecture, and design of LLVM, Clang, and MLIR. Chris actively participates in the LLVM Developersâ meeting, served on the LLVM Board of Directors for many years, and helps drive important discussions and policy decisions related to the LLVM project.</p><p>Outside of LLVM, Chris has served in a wide range of technical leadership positions at Apple, Tesla, Google, and SiFive. These have spanned domains including compiler infrastructure, developer tools in general, machine learning infrastructure, autonomous vehicles, and microprocessor design. More details are available in his resumé page.</p><p><strong>Tom Stellard:</strong></p><p>Tom Stellard has been contributing to the LLVM project since 2012. He was the original author of the AMDGPU backend and was also an active contributor to libclc. He has been the LLVM projectâs stable release manager since 2014.</p><p>Tom is currently a Software Engineer at Red Hat and is the technical lead for emerging toolchains including Clang/LLvm. He also maintains the LLVM packages for the Fedoraproject.</p>
- The New Clang _ExtInt Feature Provides Exact Bitwidth Integer Typeshttps://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.htmlTue, 21 Apr 2020 17:13:00 +0000https://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html<b>Author</b>: <a href="mailto:[email protected]" rel="nofollow">Erich Keane</a>, Compiler Frontend Engineer, Intel Corporation<br /><br />Earlier this month I finally committed a patch to implement the extended-integer type class, <span style="font-family: monospace;">_ExtInt</span> after nearly two and a half years of design and implementation. These types allow developers to use custom width integers, such as a 13-bit signed integer. This patch is currently designed to track <span style="font-family: monospace;"><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2472.pdf">N2472</a></span>, a proposal being actively considered by the ISO WG14 C Language Committee. We feel that these types are going to be extremely useful to many downstream users of Clang, and provides a language interface for LLVM's extremely powerful integer type class.<br /><br /><h3>Motivation</h3>LLVM-IR has the ability to represent integers with a bitwidth from 1 all the way to 16,777,215(<span style="font-family: monospace;">(1<<24)-1</span>), however the C language is limited to just a few power-of-two sizes. Historically, these types have been sufficient for nearly all programming architectures, since power-of-two representation of integers is convenient and practical.<br /><br />Recently, Field-Programmable Gate Array (FPGA) tooling, called High Level Synthesis Compilers (HLS), has become practical and powerful enough to use a general purpose programming language for their generation. These tools take C or C++ code and produce a transistor layout to be used by the FPGA. However, once programmers gained experience in these tools, it was discovered that the standard C integer types are incredibly wasteful for two main reasons.<br /><br />First, a vast majority of the time programmers are not using the full width of their integer types. It is rare for someone to use all 16, 32, or 64 bits of their integer representation. On traditional CPUs this isn't much of a problem as the hardware is already in place, so having bits never set comes at zero cost. On the other hand, on FPGAs logic gates are an incredibly valuable resource, and HLS compilers should not be required to waste bits on large power of two integers when they only need a small subset of that! While the optimizer passes are capable of removing some of these widths, a vast majority of this hardware needs to be emitted.<br /><br />Second, the C language requires that integers smaller than <span style="font-family: monospace;">int</span> are promoted to operations on the 'int' type. This further complicates hardware generation, as promotions to <span style="font-family: monospace;">int</span> are expensive and tend to stick with the operation for an entire statement at a time. These promotions typically have semantic meaning, so simply omitting them isn't possible without changing the meaning of the source code. Even worse, the proliferation of <span style="font-family: monospace;">auto</span> has resulted in user code results in the larger integer size being quite viral throughout a program.<br /><br />The result is massively larger FPGA/HLS programs than the programmer needed, and likely much larger than they intended. Worse, there was no way for the programmer express their intent in the cases where they do not need the full width of a standard integer type.<br /><br /><h3> Using the <span style="font-family: monospace;">_ExtInt</span> Language Feature</h3>The patch as accepted and committed into LLVM solves most of the above problems by providing the <span style="font-family: monospace;">_ExtInt</span> class of types. These types translate directly into the corresponding LLVM-IR integer types. The <span style="font-family: monospace;">_ExtInt</span> keyword is a type-specifier (like <span style="font-family: monospace;">int</span>) that accepts a required integral constant expression parameter representing the number of bits to be used. More succinctly: <span style="font-family: monospace;">_ExtInt(7)</span> is a signed integer type using 7 bits. Because it is a type-specifier, it can also be combined with <span style="font-family: monospace;">signed</span> and <span style="font-family: monospace;">unsigned</span> to change the signedness (and overflow behavior!) of the values. So "<span style="font-family: monospace;">unsigned _ExtInt(9) foo;"</span> declares a variable <span style="font-family: monospace;">foo</span> that is an unsigned integer type taking up 9 bits and represented as an <span style="font-family: monospace;">i9</span> in LLVM-IR.<br /><br />The <span style="font-family: monospace;">_ExtInt</span> types as implemented do not participate in any implicit conversions or integer promotions, so all math done on them happens at the appropriate bit-width. The WG14 paper proposes integer promotion to the largest of the types (that is, adding an <span style="font-family: monospace;">_ExtInt(5)</span> and an <span style="font-family: monospace;">_ExtInt(6)</span> would result in an <span style="font-family: monospace;">_ExtInt(6)</span>), however the implementation does not permit that and <span style="font-family: monospace;">_ExtInt(5) + _ExtInt(6)</span> would result in a compiler error. This was done so that in the event that WG14 changes the design of the paper, we will be able to implement it without breaking existing programs. In the meantime, this can be worked around with explicit casts: <span style="font-family: monospace;">(_ExtInt(6))AnExtInt5 + AnExtInt6</span> or <span style="font-family: monospace;">static_cast<ExtInt(6)>(AnExtInt5) + AnExtInt6.</span><br /><br />Additionally, for C++, clang supports making the bitwidth parameter a dependent expression, so that the following is legal:<br /><span style="font-family: monospace;">template<size_t WidthA, size_t WidthB><br /> _ExtInt(WidthA + WidthB) lossless_mul(_ExtInt(WidthA) a, _ExtInt(WidthB) b) {<br /> return static_cast<</span><span style="font-family: monospace;"><span style="font-family: monospace;">_ExtInt(WidthA + WidthB)>(a) </span></span><br /><span style="font-family: monospace;"><span style="font-family: monospace;"> * static_cast<</span></span><span style="font-family: monospace;"><span style="font-family: monospace;"><span style="font-family: monospace;">_ExtInt(WidthA + WidthB)</span></span>>(b);<br />} </span><br /><br />We anticipate that this ability and these types will result in some extremely useful pieces of code, including novel uses of 256 bit, 512 bit, or larger integers, plus uses of 8 and 16 bit integers for those who can't afford promotions. For example, one can now trivially implement an extended integer type struct that does all operations provably losslessly, that is, adding two 6 bit values would result in a 7 bit value.<br /><br />In order to be consistent with the C Language, expressions that include a standard type will still follow integral promotion and conversion rules. All types smaller than <span style="font-family: monospace;">int</span> will be promoted, and the operation will then happen at the largest type. This can be surprising in the case where you add a <span style="font-family: monospace;">short</span> and an <span style="font-family: monospace;">_ExtInt(15)</span>, where the result will be <span style="font-family: monospace;">int</span>. However, this ends up being the most consistent with the C language specification.<br /><br />Additionally, when it comes to conversions, these types 'lose' to the C standard types of the same size or greater. So, an <span style="font-family: monospace;">int</span> added to a <span style="font-family: monospace;">_ExtInt(32)</span> will result in an <span style="font-family: monospace;">int</span>. However, an <span style="font-family: monospace;">int</span> and a <span style="font-family: monospace;">_ExtInt(33)</span>will be the latter. This is necessary to preserve C integer semantics.<br /><h3>History</h3>As mentioned earlier, this feature has been a long time coming! In fact, this is likely the fourth implementation that was done along the way in order to get to this point. Additionally, this is far from over, we very much hope that upon acceptance of this by the WG14 Standards Committee that additional extensions and features will become available.<br /><br />I was approached to implement this feature in the Fall of 2017 by my company's FPGA group, which had the problems mentioned above. They had attempted a solution that used some clever parsing to make these look like templates, and implemented them extensively throughout the compiler. As I was concerned about the flexibility and usability of these types in the type and template system, we opted to implement these as a type-attribute under the controversially named Arbitrary Precision Int (spelled <span style="font-family: monospace;">__ap_int</span>). This spelling was heavily influenced by the vector-types implementations in GCC and Clang.<br /><br />We then were able to wrap a set of typedefs (or dependent <span style="font-family: monospace;">__ap_int</span> types) in a structure that provided exactly the C and C++ interface we wished to expose. As this was a then proprietary implementation, it was kept in our downstream implementation, where it received extensive testing and usage.<br /><br />Roughly a year later (and a little more than year ago from today!) I was authorized to contribute our implementation to the open source LLVM community! I decided to significantly refactor the implementation in order to better fit into the Clang type system, and uploaded it for <a href="https://reviews.llvm.org/D73967">review</a>.This (now third!) implementation of this feature was proposed via RFC and code review at the same time.<br /><br />While the usefulness was immediately acknowledged, it was rejected by the Clang code owner for two reasons: First the spelling was considered unpalatable, and Second it was a pure extension without standardization. This began the nearly year-long effort to come up with a standards proposal that would better define and describe the feature as well as come up with a spelling that was more in line with the standard language.<br /><br />Thanks to the invaluable feedback and input from Richard Smith, my coworkers Melanie Blower, Tommy Hoffner, and myself were able to propose the spelling _ExtInt for standardization. Additionally, the feature again re-implemented at the beginning of this year and eventually accepted and committed!<br /><br />The standardization paper (<span style="font-family: monospace;"><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2472.pdf">N2472</a></span>) was presented at this Spring's WG14 ISO C Language Committee Meeting where it received near unanimous support. We expect to have an updated version of the paper with wording ready for the next WG14 meeting, where we hope it will receive sufficient support to be accepted into the language.<br /><h3>Future Extensions</h3>While the feautre as committed in Clang is incredibly useful, it can be taken further. There are a handful of future extensions that we wish to implement once guidance from WG14 has been given on their direction and implementation.<br /><br />First, we believe the special integer promotion/conversion rules, which omit automatic promotion to <span style="font-family: monospace;">int</span> and instead provide operations at the largest type are both incredibly useful and powerful. While we have received positive encouragement from WG14, we hope that the wording paper we provide will both clarify the mechanism and definition in a way that supports all common uses.<br /><br />Secondly, we would like to choose a printf/scanf specifier that permits specifying the type for the C language. This was the topic of the WG14 discussion, and also received strong encouragement. We intend to come up with a good representation, then implement this in major implementations.<br /><br />Finally, numerous people have suggested implementing a way of spelling literals of this type. This is important for two reasons: First, it allows using literals without casts in expressions in a way that doesn't run afoul of promotion rules. Second, it provides a way of spelling integer literals larger than <span style="font-family: monospace;"><span class="t-lines">UINTMAX_MAX</span></span>, which can be useful for initializing the larger versions of these types. While the spelling is undecided, we intend something like: <span style="font-family: monospace;">1234X</span> would result in an integer literal with the value <span style="font-family: monospace;">1234</span> represented in an <span style="font-family: monospace;">_ExtInt(11)</span>, which is the smallest type capable of storing this value. <br /><br />However, without the integer promotion/conversion rules above, this feature isn't nearly as useful. Additionally, we'd like to be consistent with whatever the C language committee chooses. As soon as we receive positive guidance on the spelling and syntax of this type, we look forward to providing an implementation.<br /><h3>Conclusion</h3>In closing, we encourage you to try using this and provide feedback to both myself, my proposal co-authors, and the C committee itself! We feel this is a really useful feature and would love to get as much user experience as possible. Feel free to contact myself and my co-authors with any questions or concerns!<br /><br /><b>-</b><a href="mailto:[email protected]" rel="nofollow">Erich Keane</a>, Intel Corporation
- Deterministic builds with clang and lldhttps://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.htmlThu, 07 Nov 2019 12:34:00 +0000https://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html<div dir="ltr" style="text-align: left;" trbidi="on">Deterministic builds can lower continuous integration costs and give you more confidence in your build and test process. This post outlines what it means for a build to be deterministic, the advantages of deterministic builds, and how to achieve them using LLVM tools.<br /><h3 style="text-align: left;">What is a deterministic build, and its advantages</h3>A build is called <i>deterministic </i>or <i>reproducible </i>if running it twice produces exactly the same build outputs.<br /><br />There are several degrees of build determinism that are increasingly useful but increasingly difficult to achieve:<br /><br /><ol style="text-align: left;"><li><i>Basic </i>determinism: Doing a full build of the same source code in the same directory on the same machine produces exactly the same output every time, in the sense that a content hash of the final build artifacts and of all intermediate files does not change.</li><ul><li>Once you have this, if all your builders are configured the same way (OS version, toolchain, build path, checkout path, â¦), they can share build artifacts, for example by using distcc.</li><li>This also allows local caching of test suite results keyed by a hash of test binary and test input files.</li><li>Illustrative example: <span style="font-family: "courier new" , "courier" , monospace;">./build src out ; mv out out.old ; ./build src out ; diff -r out out.old</span></li></ul><li><i>Incremental </i>basic determinism: Like basic determinism, but the output binaries also donât change in partial rebuilds. In build systems that track file modification times to decide when to rebuild, this means for example that updating the modification time on a C++ source file (without doing any actual changes) and rebuilding will produce the same output as a full build.</li><ul><li>This allows having build bots that donât do full builds each time, while still allowing caching of compile artifacts and test results.</li><li>Illustrative example: <span style="font-family: "courier new" , "courier" , monospace;">./build src out ; cp -r out out.old ; touch src/foo.c ; ./build src out ; diff -r out out.old</span></li></ul><li><i>Local </i>determinism: Like incremental basic determinism, but builds are also independent of the name of the build directory. Builds of the same source code on the same machine produce exactly the same output every time, independent of the location of the source checkout directory or the build directory.</li><ul><li>This allows machines to have several build directories at different locations but still share compile and test caches.</li><li>Illustrative example:<span style="font-family: "courier new" , "courier" , monospace;"> cp -r src src2 ; ./build src out ; ./build src2 out2 ; diff -r out out2</span></li></ul><li><i>Universal </i>determinism: Like 3, but builds are also independent of the machine the build runs on. Everybody that checks out the project at a given revision into any directory and builds it following the build instructions ends up with exactly the same bits in the build output.</li><ul><li>Since exact local OS and locally installed packages no longer matter, this allows devs to share compile and test caches with bots, without having to use difficult-to-setup containers.</li><li>It also allows easy verification of builds done by others to make sure output binaries havenât been tampered with.</li><li>Illustrative example: <span style="font-family: "courier new" , "courier" , monospace;">./build src out ; ssh remote ./build src out && scp remote:out out2 ; diff -r out out2</span></li></ul></ol><h3 style="text-align: left;">Plan of attack</h3>To make sure that a deterministic build stays deterministic, you should set up a builder that verifies that your build is deterministic. Even if your build isnât deterministic yet, you can set up a bot that verifies that some parts of your build are deterministic and then expand the checks over time.<br /><br />For example, you could have a bot that does a full build in a fixed build directory, then moves the build artifacts out of the way, and does another full build, and once your compiles have basic determinism, add a step that checks that object files between the two builds directories are the same. You could even add incremental checking for specific subdirectories or build targets while you work towards full basic determinism.<br /><br />Once your links are deterministic, check that binaries are identical as well. Once all your build steps are deterministic, compare all files in the two build directories.<br /><br />Once your build has incremental determinism, do an incremental build for the first build and a full build for the second build. Once your build has local determinism, do the two builds at different build paths.<br /><h4>Getting to basic determinism</h4>Basic determinism needs tools (compiler, linker, etc) that are deterministic. Tools internally must not output things in hash table order, multi-threaded programs must not write output in the order threads finish, etc. All of LLVMâs tools have deterministic outputs when run with the right flags but not necessarily by default.<br /><br />The C standard defines the predefined macros <span style="font-family: "courier new" , "courier" , monospace;">__TIME__</span> and <span style="font-family: "courier new" , "courier" , monospace;">__DATE__</span> that expand to the time a source file is compiled. Several compilers, including clang, also define the non-standard <span style="font-family: "courier new" , "courier" , monospace;">__TIMESTAMP__</span>. This is inherently nondeterministic. You should not use these macros, and you can use <span style="font-family: "courier new" , "courier" , monospace;">-Wdate-time</span> to make the compiler emit a warning when they are used.<br /><br />If they are used in third-party code you donât control, you can use<span style="background-color: #fff2cc;"> <span style="font-family: "courier new" , "courier" , monospace;">-Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__=</span></span> to make them expand to nothing.<br /><br />When targeting Windows, clang and clang-cl by default also embed the current time in a timestamp field in the output .obj file, because Microsoftâs link.exe in <span style="font-family: "courier new" , "courier" , monospace;">/incremental</span> mode silently mislinks files if that field isnât set correctly. If you donât use link.exeâs <span style="font-family: "courier new" , "courier" , monospace;">/incremental</span> flag, or if you link with lld-link, you should pass <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">/Brepro</span> to clang-cl to make it not write the current timestamp into its output.<br /><br />Both link.exe and lld-link also write the current timestamp into output .dll or .exe files. To make them instead write a hash of the binary into this field, you can pass <span style="font-family: "courier new" , "courier" , monospace;">/Brepro</span> to the linker as well. However, some tools, such as Windows 7âs app compatibility database, try to interpret that field as an actual timestamp and can get confused if itâs set to a hash of the binary. For this case, lld-link also offers a <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">/timestamp:</span> flag that you can give an explicit timestamp thatâs written into the output. You could use this to for example write the time of the commit the code is built at instead of the current time to make it deterministic. (But see the footnote on embedding commit hashes below.)<br /><br />Visual Studioâs assemblers ml.exe and ml64.exe also insist on writing the current time into their output. In situations like this, where you canât easily fix the tool to write the right output in the first place, you need to write wrappers that fix up the file after the fact. As an example, <a href="https://cs.chromium.org/chromium/src/build/toolchain/win/ml.py" style="background-color: #fff2cc;">ml.py</a> is the wrapper the Chromium project uses to make mlâs output deterministic.<br /><br />macOSâs libtool and ld64 also insist on writing timestamps into their outputs. You can set the environment variable <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">ZERO_AR_DATE</span> to 1 in a wrapper to make their output deterministic, but that confuses lldb of older Xcode versions.<br /><br />Gcc sometimes uses random numbers in certain symbol mangling situations. Clang does not do this, so thereâs no need to pass <span style="font-family: "courier new" , "courier" , monospace;">-frandom-seed</span> to clang.<br /><br />Itâs a good idea to make your build independent of environment variables as much as possible, so that accidental local changes in the environment donât affect the build output. You should pass <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">/X</span> to clang-cl to make it ignore <span style="font-family: "courier new" , "courier" , monospace;">%INCLUDE%</span> and explicitly pass system include directories via the <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">-imsvc</span> switch instead. Likewise, very new lld-link versions (LLVM 10 and newer, at the time of this writing still unreleased) understand the flag <span style="background-color: #fff2cc;"><span style="font-family: "courier new" , "courier" , monospace;">/lldignoreenv</span></span> flag, which makes lld-link ignore the <span style="font-family: "courier new" , "courier" , monospace;">%LIB%</span> environment variable; explicitly pass system library directories via <span style="background-color: #fff2cc;"><span style="font-family: "courier new" , "courier" , monospace;">/libpath:</span></span>.<br /><br /><b>Footnote on embedding git hashes into the binary</b><br />It might be tempting to embed the git commit hash or svn revision that a binary was built at into the binaryâs --version output, or use the revision as a cache key to invalidate on-disk caches when the version changes.<br /><br />This doesnât affect your buildâs determinism, but it does affect the hit rate if youâre using deterministic builds to cache test run results. If your binary embeds the current commit, it is guaranteed to change on every single commit, and you wonât be able to cache test results across commits. Even commits that just fix typos in comments, add non-code documentation, or that only affect code used by some but not all of your binaries will change every binary.<br /><br />For cache invalidation, consider using something finer-grained, such as only the latest commit of the directory containing the cache handling code, or the hash of all source files containing the cache handling code.<br /><br />For --version output, if your build is fully deterministic, the hash of the binary itself (and its dynamic library dependencies) can serve as a stable version identifier. You can keep a map of binary hash to all commit hashes that produce that binary somewhere.<br /><br />Windows only: For the same reason, just using the timestamp of the latest commit as a /timestamp: might not be the best option. Rounding the timestamp of the latest commit to 6h (or similar) granularity is a possible approach for not having the timestamp change the binary on every commit, while still keeping the timestamp close to reality. For production builds, the symbol server key for binaries is a (executable size, timestamp) pair, so here having fairly granular timestamps is important to not map binaries from consecutive commits to the same symbol server key. Depending on how often you push production binaries to your symbol servers, you might want to use the timestamp of the latest commit as <span style="font-family: "courier new" , "courier" , monospace;">/timestamp:</span> for official builds, or you might want to round to finer granularity than you do on dev builds.<br /><h4 style="text-align: left;">Getting to incremental determinism</h4>Having deterministic incremental builds mostly requires having correct incremental builds, meaning that if a file is changed and the build reruns, everything that uses this file needs to be rebuilt.<br /><br />This is very build system dependent, so this post canât say much about it.<br /><br />In general, every build step needs to correctly declare all the inputs it depends on.<br /><br />Some tools, such as Visual Studioâs link.exe in <span style="font-family: "courier new" , "courier" , monospace;">/incremental</span> mode, by design write a different output every time. Donât use inherently incrementally non-deterministic tools like that if you care about build determinism.<br /><br />The build should not depend on environment variables, since build systems usually donât model dependencies on environment variables.<br /><h4 style="text-align: left;">Getting to local determinism</h4>Making build outputs independent of the names of the checkout or build directory means that build outputs must not contain absolute paths, or relative paths that contain the name of either directory.<br /><br />A possible way to arrange for that is to put all build directories into the checkout directory. For example, if your code is at path/to/src, then you could have âoutâ in your .gitignore and build directories at path/to/src/out/debug, path/to/src/out/release, and so on. The relative path from each build artifact to the source is with â../../â followed by the path of the source file in the source directory, which is identical for each build directory.<br /><br />The C standard defines the predefined macro <span style="font-family: "courier new" , "courier" , monospace;">__FILE__</span> that expands to the name of the current source file. Clang expands this to an absolute path if it is invoked with an absolute path (`clang -c /absolute/path/to/my/file.cc`), and to a relative path if it is invoked with a relative path (`clang ../../path/to/my/file.cc`). To make your build locally deterministic, <span style="background-color: #fff2cc;">pass relative paths to your .cc files to clang</span>.<br /><br />By default, clang will internally use absolute paths to refer to compiler-internal headers. Pass <span style="background-color: #fff2cc;"><span style="font-family: "courier new" , "courier" , monospace;">-no-canonical-prefixes</span></span> to make clang use relative paths for these internal files.<br /><br />Passing relative paths to clang makes clang expand <span style="font-family: "courier new" , "courier" , monospace;">__FILE__</span> to a relative path, but paths in debug information are still absolute by default. Pass <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">-fdebug-compilation-dir .</span> to make paths in debug information relative to the build directory. (Before LLVM 9, this is an internal clang flag that must be used as `<span style="font-family: "courier new" , "courier" , monospace;">-Xclang -fdebug-compilation-dir -Xclang .</span>`) When using clangâs integrated assembler (the default), <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">-Wa,-fdebug-compilation-dir,.</span> will do the same for object files created from assembly input. (For ml.exe / ml64.exe, see the script linked to from the âBasic determinismâ section above.)<br /><br />Using this means that debuggers wonât automatically find the source code belonging to your binary. At the moment, thereâs no way to tell debuggers to resolve relative paths relative to the location of the binary (<a href="http://dwarfstd.org/ShowIssue.php?issue=171130.2">DWARF proposal</a>, <a href="https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/402">gdb patch</a>). See the end of this section for how to configure common debuggers to work correctly.<br /><br />There are a few flags that try to make compilers produce relative paths in outputs even if the filename passed to the compiler is absolute (<span style="font-family: "courier new" , "courier" , monospace;">-fdebug-prefix-map</span>, <span style="font-family: "courier new" , "courier" , monospace;">-ffile-prefix-map</span>, <span style="font-family: "courier new" , "courier" , monospace;">-fmacro-prefix-map</span>). <span style="background-color: #fff2cc;">Do not use these flags</span>.<br /><ul style="text-align: left;"><li>They work by adding lhs=rhs replacement patterns, and the lhs must be an absolute path to remove the absolute path from the output. That means that while they make the compile output path-independent, they make the compile command itself path-dependent, which hinders distributed compile caching. With <span style="font-family: "courier new" , "courier" , monospace;">-grecord-gcc-switches</span> or <span style="font-family: "courier new" , "courier" , monospace;">-frecord-gcc-switches</span> the compile command is embedded in debug info or even the object file itself, so in that case the flags even break local determinism. (Both <span style="font-family: "courier new" , "courier" , monospace;">-grecord-gcc-switches</span> and <span style="font-family: "courier new" , "courier" , monospace;">-frecord-gcc-switches</span> default to false in clang.)</li><li>They donât affect the paths in dwo files when using fission; passing relative paths to the compiler is the only way to make these paths relative.</li></ul>On Windows, itâs very unusual to have PDBs with relative paths. You can pass <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">/pdbsourcepath:X:\fake\prefix</span> to lld-link to make it resolve all relative paths in object files against a fixed absolute path to make sure your final PDBs contain absolute paths. Since the absolute path is against a fixed prefix, this doesnât impair determinism. With this, both binaries and PDBs created by clang-cl and lld-link will be fully deterministic and build path independent.<br /><br />Also on Windows, the linker by default puts the absolute path the to the generated PDB file in the output binary. Pass <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">/pdbaltpath:%_PDB%</span> when you pass <span style="font-family: "courier new" , "courier" , monospace;">/debug</span> to make the linker write a relative path to the generated PDB file instead. If you have custom build steps that extract PDB names from binaries, you have to make sure these scripts work with relative paths. Microsoftâs tools (debuggers, ETW) work fine with this set in most situations, and you can add a symbol search path in the cases where they donât (when the binaries are copied before being run).<br /><br /><b>Getting debuggers to work well with locally deterministic builds</b><br />At the moment, no debugger offers an option to resolve relative paths in debug info against the directory the debugged binary is in.<br /><br />Some debuggers (gdb, lldb) do try to resolve relative paths against the cwd, so a simple way to make debugging work is to cd into your build directory before debugging.<br /><br />If you donât want to require devs to cd into the build directory for debugging to work, you have to do debugger-specific configuration tweaks.<br /><br />To make sure devs donât miss this, you could have your custom init script set an env var and query if itâs set early during your test binary startup, and exit with a message like âAdd `source /path/to/your/project/gdbinit` to your ~/.gdbinitâ if the environment variable isnât set.<br /><br /><i>gdb</i><br />`dir path/to/build/dir` tells gdb what directory to resolve relative paths against.<br /><br />`show debug-file-directory` prints the list of directories gdb looks in for dwo files. Query that, append `:path/to/build/dir`, and call `set debug-file-directory` to add your build dir to that search path.<br /><br />For an example, see <a href="https://chromium.googlesource.com/chromium/src/+/master/tools/gdb/gdbinit#78">Chromiumâs gdbinit</a> (which also does a few other unrelated things).<br /><br /><i>lldb</i><br />`settings set target.source-map ../.. /absolute/path/to/build/dir` can map the â../..â prefix that all .cc files will refer to when using the setup described above with an absolute path. This requires Xcode 10.3 or newer; the lldb shipping with Xcode 10.1 has problems with this setup.<br /><br />For an example, see <a href="https://chromium.googlesource.com/chromium/src/+/master/tools/lldb/lldbinit.py">Chromiumâs lldbinit</a>.<br /><br /><i>Visual Studioâs debugger and windbg</i><br />If you use the setup described above, <span style="font-family: "courier new" , "courier" , monospace;">/PDBSourcePath:X:\fake\prefix</span> will combine with the â..\..\my\file.ccâ relative paths to make your code appear at âX:\my\file.ccâ. To make Windows debuggers find them, you have two options:<br /><ol style="text-align: left;"><li>Run `subst X: C:\src\real\root` in cmd.exe before launching the debuggers to create a virtual drive that maps X: to the actual source location. Both windbg and Visual Studio will load code over X: this way.</li><li>Add âC:\src\real\rootâ to each debuggerâs source search path.</li><ul><li><a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/source-window#source-path">Windbg</a>: Run `.srcpath+ C:\src\real\root`. You can also set this via the _NT_SOURCE_PATH environment variable, or via File->Source File Path (Ctrl+P). Or pass `-srcpath C:\src\real\root` when launching windbg from the command line.</li><li>Visual Studio: The IDE has a <a href="https://docs.microsoft.com/en-us/visualstudio/debugger/debug-source-files-common-properties-solution-property-pages-dialog-box?view=vs-2019">âDebug Source Filesâ property</a>. Add C:\src\real\root to âDirectories containing source codeâ to Project->Properties (Alt+F7)->Common Properties->Debug Source Files->Directories containing source code.</li></ul></ol>Alternatively, you could pass the absolute path to the actual build directory to <span style="font-family: "courier new" , "courier" , monospace;">/PDBSourcePath:</span> instead of something like âX:\fake\prefixâ. That way, all PDBs have âcorrectâ absolute paths in them, while your compile steps are still path-independent and can share a cache across machines. However, since executables contain a reference to the PDB hash, none of your binaries will be path-independent. This setup doesnât require any debugger configuration, but it doesnât allow your builds to be locally deterministic.<br /><h4 style="text-align: left;">Getting to universal determinism</h4>By now, your build output is deterministic as long as everyone uses the same compiler, and linker binaries, and as long as everyone uses the version of the SDK and system libraries.<br /><br />Making your build independent of that requires making sure that everyone automatically uses the same compiler, linker, and SDK.<br /><br />This might seem like a lot of work, but in addition to build determinism this work also gives you cross builds (where you can e.g. build the Linux version of your product on a Windows host).<br /><br />It also versions the compiler, linker, and SDK used within your code, which means you will be able to update all your bots and devs to new versions automatically (and if an update causes issues, itâs easy to revert it).<br /><br />You need to store the currently-used compiler, linker, and SDK versions in a file in your source control repository, and from some kind of hook that runs after pulling the newest version of the source, download compiler, linker, and SDK of the right version from some kind of cloud storage service.<br /><br />You then need to modify your build files to use <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">--sysroot</span> (Linux), <span style="background-color: #fff2cc; font-family: "courier new" , "courier" , monospace;">-isysroot</span> (macOS), <span style="background-color: #fff2cc;"><span style="font-family: "courier new" , "courier" , monospace;">-imsvc</span></span> (Windows) to use these hermetic SDKs for builds. They need to be somewhere below your source root to not regress build directory name invariance.<br /><br />You also want to make sure your build doesnât depend on environment variables, as already mentioned in the âGetting to incremental determinismâ, since environments between different machines can be very different and difficult to control.<br /><br />Build steps shouldnât embed the hostname of the current machine or the logged-in user name in the build output, or similar.<br /><h4 style="text-align: left;">Summary</h4>This post explained what deterministic builds are, how build determinism spans a spectrum (local, fixed-build-dir-path-only to fully host-OS-independent) instead of just being binary, and how you can use LLVMâs tools to make your build deterministic. It also touched on techniques you can use to make your test caches more effective.<br /><br /><i>Thanks to Elly Fong-Jones for helping edit and structure this post, and to Adrian McCarthy, Bob Haarman, Bruce Dawson, Dirk Pranke, Fumitoshi Ukai, Hans Wennborg, Kai Naschinski, Reid Kleckner, Rui Ueyama, and Takuto Ikuta for reading drafts and suggesting improvements.</i></div>
- Closing the gap: cross-language LTO between Rust and C/C++https://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.htmlThu, 19 Sep 2019 05:15:00 +0000https://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.htmlLink time optimization (LTO) is LLVM's way of implementing whole-program optimization. <i>Cross-language</i> LTO is a new feature in the Rust compiler that enables LLVM's link time optimization to be performed across a mixed C/C++/Rust codebase. It is also a feature that beautifully combines two respective strengths of the Rust programming language and the LLVM compiler platform:<br /><ul><li style="text-indent: 0;">Rust, with its lack of a language runtime and its low-level reach, has an almost unique ability to seamlessly integrate with an existing C/C++ codebase, and</li><li style="text-indent: 0;">LLVM, as a language agnostic foundation, provides a common ground where the source language a particular piece of code was written in does not matter anymore.</li></ul>So, what does cross-language LTO do? There are two answers to that:<br /><ul><li style="text-indent: 0;">From a technical perspective it allows for codebases to be optimized without regard for implementation language boundaries, making it possible for important optimizations, such as function inlining, to be performed across individual compilation units even if, for example, one of the compilation units is written in Rust while the other is written in C++.</li><li style="text-indent: 0;">From a psychological perspective, which arguably is just as important, it helps to alleviate the nagging feeling of inefficiency that many performance conscious developers might have when working on a piece of software that jumps back and forth a lot between functions implemented in different source languages.</li></ul>Because Firefox is a large, performance sensitive codebase with substantial parts written in Rust, cross-language LTO has been a long-time favorite wish list item among Firefox developers. As a consequence, we at Mozilla's Low Level Tools team took it upon ourselves to implement it in the Rust compiler.<br /><br />To explain how cross-language LTO works it is useful to take a step back and review how traditional compilation and "regular" link time optimization work in the LLVM world.<br /><br /><br /><h3>Background - A bird's eye view of the LLVM compilation pipeline</h3>Clang and the Rust compiler both follow a similar compilation workflow which, to some degree, is prescribed by LLVM:<br /><ol><li style="text-indent: 0;">The compiler front-end generates an LLVM bitcode module (<code>.bc</code>) for each compilation unit. In C and C++ each source file will result in a single compilation unit. In Rust each crate is translated into at least one compilation unit.<br /><pre><code style="background-color: #e7e7e7; display: block;"><br /> .c --clang--> .bc<br /><br /> .c --clang--> .bc<br /><br /><br /> .rs --+<br /> |<br /> .rs --+--rustc--> .bc<br /> |<br /> .rs --+<br /><br /></code></pre></li><li style="text-indent: 0;">In the next step, LLVM's optimization pipeline will optimize each LLVM module in isolation: <pre><code style="background-color: #e7e7e7; display: block;"><br /> .c --clang--> .bc --LLVM--> .bc (opt)<br /><br /> .c --clang--> .bc --LLVM--> .bc (opt)<br /><br /><br /> .rs --+<br /> |<br /> .rs --+--rustc--> .bc --LLVM--> .bc (opt)<br /> |<br /> .rs --+<br /><br /></code></pre></li><li style="text-indent: 0;">LLVM then lowers each module into machine code so that we get one object file per module: <pre><code style="background-color: #e7e7e7; display: block;"><br /> .c --clang--> .bc --LLVM--> .bc (opt) --LLVM--> .o<br /><br /> .c --clang--> .bc --LLVM--> .bc (opt) --LLVM--> .o<br /><br /><br /> .rs --+<br /> |<br /> .rs --+--rustc--> .bc --LLVM--> .bc (opt) --LLVM--> .o<br /> |<br /> .rs --+<br /><br /></code></pre></li><li style="text-indent: 0;">Finally, the linker will take the set of object files and link them together into a binary: <pre><code style="background-color: #e7e7e7; display: block;"><br /> .c --clang--> .bc --LLVM--> .bc (opt) --LLVM--> .o ------+<br /> |<br /> .c --clang--> .bc --LLVM--> .bc (opt) --LLVM--> .o ------+<br /> |<br /> +--ld--> bin<br /> .rs --+ |<br /> | |<br /> .rs --+--rustc--> .bc --LLVM--> .bc (opt) --LLVM--> .o --+<br /> |<br /> .rs --+<br /><br /></code></pre></li></ol>This is the regular compilation workflow if no kind of LTO is involved. As you can see, each compilation unit is optimized in isolation. The optimizer does not know the definition of functions inside of other compilation units and thus cannot inline them or make other kinds of decisions based on what they actually do. To enable inlining and optimizations to happen across compilation unit boundaries, LLVM supports link time optimization.<br /><br /><br /><h3>Link time optimization in LLVM</h3>The basic principle behind LTO is that some of LLVM's optimization passes are pushed back to the linking stage. Why the linking stage? Because that is the point in the pipeline where the entire program (i.e. the whole set of compilation units) is available at once and thus optimizations across compilation unit boundaries become possible. Performing LLVM work at the linking stage is facilitated via a <a href="http://llvm.org/docs/GoldPlugin.html">plugin</a> to the linker.<br /><br />Here is how LTO is concretely implemented:<br /><ul><li style="text-indent: 0;">the compiler translates each compilation unit into LLVM bitcode (i.e. it skips lowering to machine code),<br /> </li><li style="text-indent: 0;">the linker, via the LLVM linker plugin, knows how to read LLVM bitcode modules like regular object files, and<br /> </li><li style="text-indent: 0;">the linker, again via the LLVM linker plugin, merges all bitcode modules it encounters and then runs LLVM optimization passes before doing the actual linking.</li></ul>With these capabilities in place a new compilation workflow with LTO enabled for C++ code looks like this: <br /><pre><code style="background-color: #e7e7e7; display: block;"><br /> .c --clang--> .bc --LLVM--> .bc (opt) ------------------+ - - +<br /> | |<br /> .c --clang--> .bc --LLVM--> .bc (opt) ------------------+ - - +<br /> | |<br /> +-ld+LLVM--> bin<br /> .rs --+ |<br /> | |<br /> .rs --+--rustc--> .bc --LLVM--> .bc (opt) --LLVM--> .o -+<br /> |<br /> .rs --+<br /><br /></code></pre>As you can see our Rust code is still compiled to a regular object file. Therefore, the Rust code is opaque to the optimization taking place at link time. Yet, looking at the diagram it seems like that shouldn't be too hard to change, right?<br /><br /><br /><h3>Cross-language link time optimization</h3>Implementing cross-language LTO is conceptually simple because the feature is built on the shoulders of giants. Since the Rust compiler uses LLVM all the important building blocks are readily available. The final diagram looks very much as you would expect, with <code>rustc</code> emitting optimized LLVM bitcode and the LLVM linker plugin incorporating that into the LTO process with the rest of the modules: <br /><pre><code style="background-color: #e7e7e7; display: block;"><br /> .c --clang--> .bc --LLVM--> .bc (opt) ---------+<br /> |<br /> .c --clang--> .bc --LLVM--> .bc (opt) ---------+<br /> |<br /> +-ld+LLVM--> bin<br /> .rs --+ |<br /> | |<br /> .rs --+--rustc--> .bc --LLVM--> .bc (opt) -----+<br /> |<br /> .rs --+<br /><br /></code></pre>Nonetheless, achieving a production-ready implementation still turned out to be a significant time investment. After figuring out how everything fits together, the main challenge was to get the Rust compiler to produce LLVM bitcode that was compatible with both the bitcode that Clang produces and with what the linker plugin would accept. Some of the issues we ran into where:<br /><ul><li style="text-indent: 0;">The Rust compiler and Clang are both based on LLVM but they might be using different versions of LLVM. This was further complicated by the fact that Rust's LLVM version often does not match a specific LLVM release, but can be an arbitrary revision from LLVM's repository. We learned that all LLVM versions involved really have to be a close match in order for things to work out. The Rust compiler's documentation now offers a <a href="https://doc.rust-lang.org/rustc/linker-plugin-lto.html#toolchain-compatibility">compatibility table</a> for the various versions of Rust and Clang.<br /> </li><li style="text-indent: 0;">The Rust compiler by default performs a special form of LTO, called <a href="https://clang.llvm.org/docs/ThinLTO.html">ThinLTO</a>, on all compilation units of the same crate before passing them on to the linker. We quickly learned, however, that the LLVM linker plugin crashes with a segmentation fault when trying to perform another round of ThinLTO on a module that had already gone through the process. No problem, we thought and instructed the Rust compiler to disable its own ThinLTO pass when compiling for the cross-language case and indeed everything was fine -- until the segmentation faults mysteriously returned a few weeks later even though ThinLTO was still disabled.<br /><br />We noticed that the problem only occurred in a specific, presumably innocent setting: again two passes of LTO needed to happen, this time the first was a <a href="https://www.llvm.org/docs/LinkTimeOptimization.html">regular LTO</a> pass within <code>rustc</code> and the output of that would then be fed into ThinLTO within the linker plugin. This setup, although computationally expensive, was desirable because it produced faster code and allowed for better dead-code elimination on the Rust side. And in theory it should have worked just fine. Yet somehow <code>rustc</code> produced symbol names that had apparently gone through ThinLTO's mangling even though we checked time and again that ThinLTO was disabled for Rust. We were beginning to seriously question our understanding of LLVM's inner workings as the problem persisted while we slowly ran out of ideas on how to debug this further.<br /><br />You can picture the proverbial lightbulb appearing over our heads when we figured out that Rust's pre-compiled standard library would still have ThinLTO enabled, no matter the compiler settings we were using for our tests. The standard library, including its LLVM bitcode representation, is compiled as part of Rust's binary distribution so it is always compiled with the settings from Rust's build servers. Our local full LTO pass within <code>rustc</code> would then pull this troublesome bitcode into the output module which in turn would make the linker plugin crash again. Since then ThinLTO is <a href="https://github.com/rust-lang/rust/pull/55264">turned off</a> for <code>libstd</code> by default.<br /> </li><li style="text-indent: 0;">After the above fixes, we succeeded in compiling the entirety of Firefox with cross-language LTO enabled. Unfortunately, we discovered that no actual cross-language optimizations were happening. Both Clang and <code>rustc</code> were producing LLVM bitcode and LLD produced functioning Firefox binaries, but when looking at the machine code, not even trivial functions were being inlined across language boundaries. After days of debugging (and unfortunately without being aware of <a href="http://llvm.org/docs/Remarks.html">LLVM's optimization remarks</a> at the time) it turned out that Clang was emitting a <code>target-cpu</code> attribute on all functions while <code>rustc</code> didn't, which made LLVM reject inlining opportunities.<br /><br />In order to prevent the feature from silently regressing for similar reasons in the future we put quite a bit of effort into extending the Rust compiler's testing framework and CI. It is now able to compile and run a compatible version of Clang and uses that to perform end-to-end tests of cross-language LTO, making sure that small functions will indeed get inlined across language boundaries.</li></ul>This list could still go on for a while, with each additional target platform holding new surprises to be dealt with. We had to progress carefully by putting in regression tests at every step in order to keep the many moving parts in check. At this point, however, we feel confident in the underlying implementation, with Firefox providing a large, complex, multi-platform test case where things have been working well for several months now.<br /><br /><br /><h3>Using cross-language LTO: a minimal example</h3>The exact build tool invocations differ depending on whether it is <code>rustc</code> or Clang performing the final linking step, and whether Rust code is compiled via Cargo or via <code>rustc</code> directly. Rust's <a href="https://doc.rust-lang.org/rustc/linker-plugin-lto.html">compiler documentation</a> describes the various cases. The simplest of them, where <code>rustc</code> directly produces a static library and Clang does the linking, looks as follows: <br /><pre><code style="background-color: #e7e7e7; display: block;"><br /> # Compile the Rust static library, called "xyz"<br /> rustc --crate-type=staticlib -O -C linker-plugin-lto -o libxyz.a lib.rs<br /><br /> # Compile the C code with "-flto"<br /> clang -flto -c -O2 main.c<br /><br /> # Link everything<br /> clang -flto -O2 main.o -L . -lxyz<br /><br /></code></pre>The <code>-C linker-plugin-lto</code> option instructs the Rust compiler to emit LLVM bitcode which then can be used for both "full" and "thin" LTO. Getting things set up for the first time can be quite cumbersome because, as already mentioned, all compilers and the linker involved must be compatible versions. In theory, most major linkers will work; in practice LLD seems to be the most reliable one on Linux, with Gold in second place and the BFD linker needing to be at least version 2.32. On Windows and macOS the only linkers properly tested are LLD and <code>ld64</code> respectively. For <code>ld64</code> Firefox uses a patched version because the LLVM bitcode that <code>rustc</code> produces likes to trigger a <a href="https://github.com/froydnj/ld64-aliases-bug">pre-existing issue</a> this linker has with ThinLTO.<br /><br /><br /><h3>Conclusion</h3>Cross-language LTO has been enabled for Firefox release builds on Windows, macOS, and Linux for several months at this point and we at Mozilla's Low Level Tools team are pleased with how it turned out. While we still <a href="https://github.com/rust-lang/rust/issues/60059">need to work</a> on making the initial setup of the feature easier, it already enabled removing duplicated logic from Rust components in Firefox because now code can simply call into the equivalent C++ implementation and rely on those calls to be inlined. Having cross-language LTO in place and continuously tested will definitely lower the psychological bar for implementing new components in Rust, even if they are tightly integrated with existing C++ code.<br /><br />Cross-language LTO is available in the Rust compiler since version 1.34 and works together with Clang 8. Feel free to give it a try and report any problems in the Rust <a href="https://github.com/rust-lang/rust/issues">bug tracker</a>.<br /><br /><br /><h3>Acknowledgments</h3>I'd like to thank my Low Level Tools team colleagues David Major, Eric Rahm, and Nathan Froyd for their invaluable help and encouragement, and I'd like to thank Alex Crichton for his tireless reviews on the Rust side.
- Announcing the program for the 2019 LLVM Developers' Meeting - Bay Areahttps://blog.llvm.org/2019/09/announcing-program-for-2019-llvm.htmlWed, 04 Sep 2019 07:16:00 +0000https://blog.llvm.org/2019/09/announcing-program-for-2019-llvm.htmlAnnouncing the program for the <a href="http://llvm.org/devmtg/2019-10/">2019 LLVM Developers' Meeting</a> in San Jose, CA! This program is the largest we have ever had and has over 11 tutorials, 29 technical talks, 24 lightning talks, 2 panels, 3 birds of a feather, 14 posters, and 4 SRC talks. Be sure to <a href="https://www.eventbrite.com/e/2019-llvm-developers-meeting-bay-area-tickets-63481303287">register</a> to attend this event and hear some of these great talks.<br /><br /><b>Keynotes</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#keynote1">Generating Optimized Code with GlobalISel </a>- Volkan Keles, Daniel Sanders</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#keynote2">Even Better C++ Performance and Productivity: Enhancing Clang to Support Just-in-Time Compilation of Templates</a>- Hal Finkel</li></ul><b>Technical Talks</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech1">Using LLVM's portable SIMD with Zig </a>- Shawn Landden</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech2">Code-Generation for the Arm M-profile Vector Extension </a>- Sjoerd Meijer</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech3">Alive2: Verifying Existing Optimizations </a>- Nuno Lopes</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech4">The clang constexpr interpreter </a>- Nandor Licker</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech5">Souper-Charging Peepholes with Target Machine Info </a>- Min-Yih Hsu</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech6">Transitioning the Networking Software Toolchain to Clang/LLVM </a>- Ivan Baev, Jeremy Stenglein, Bharathi Seshadri</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech7">Link Time Optimization For Swift </a>- Jin Lin</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech8">Hot Cold Splitting Optimization Pass In LLVM </a>- Aditya Kumar</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech9">Making UB hurt less: security mitigations through automatic variable initialization </a>- JF Bastien</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech10">Propeller: Profile Guided Large Scale Performance Enhancing Relinker </a>- Sriraman Tallam</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech11">From C++ for OpenCL to C++ for accelerator devices </a>- Anastasia Stulova</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech12">LLVM-Canon: Shooting for Clear Diffs </a>- Michal Paszkowski</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech13">Better C++ debugging using Clang Modules in LLDB </a>- Raphael Isemann</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech14">Ownership SSA and Semantic SIL </a>- Michael Gottesman</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech15">arm64e: An ABI for Pointer Authentication </a>- Ahmed Bougacha, John McCall</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech16">Porting by a 1000 Patches: Bringing Swift to Windows </a>- Saleem Abdulrasool</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech17">The Penultimate Challange: Constructing bug reports in the Clang Static Analyzer </a>- Kristóf Umann</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech18">Address Spaces in LLVM </a>- Matt Arsenault</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech19">An MLIR Dialect for High-Level Optimization of Fortran </a>- Eric Schweitz</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech20">Loop-transformation #pragmas in the front-end </a>- Michael Kruse</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech21">Optimizing builds on Windows: some practical considerations </a>- Alexandre Ganea</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech22">LLVM-Reduce for testcase reduction </a>- Diego Treviño Ferrer</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech23">Memoro: Scaling an LLVM-based Heap profiler </a>- Thierry Treyer</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech24">The Attributor: A Versatile Inter-procedural Fixpoint Iteration Framework </a>- Johannes Doerfert</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech25">LLVM Tutorials: How to write Beginner-Friendly, Inclusive Tutorials </a>- Meike Baumgärtner</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tech26">Maturing an LLVM backend: Lessons learned from the RISC-V target </a>- Alex Bradbury</li></ul><b>Tutorials</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut1">Getting Started With LLVM: Basics </a>- Jessica Paquette, Florian Hahn</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut2">ASTImporter: Merging Clang ASTs </a>- Gábor Márton</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut3">Developing the Clang Static Analyzer </a>- Artem Dergachev</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut4">Writing an LLVM Pass: 101 </a>- Andrzej Warzynski</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut5">Writing Loop Optimizations in LLVM </a>- Kit Barton, Ettore Tiotto, Hal Finkel, Michael Kruse, Johannes Doerfert</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut6">The Attributor: A Versatile Inter-procedural Fixpoint Iteration Framework </a>- Johannes Doerfert</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut7">Getting Started with the LLVM Testing Infrastructure </a>- Brian Homerding, Michael Kruse</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut8">An overview of Clang </a>- Sven Van Haastregt, Anastasia Stulova</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut9">An overview of LLVM </a>- Eric Christopher, Sanjoy Das, Johannes Doerfert</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut10">How to Contribute to LLVM </a>- Chris Bieneman, Kit Barton</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#tut11">My First Clang Warning </a>- Dmitri Gribenko, Meike Baumgartner</li></ul><b>Student Research Competition</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src1">Cross-Translation Unit Optimization via Annotated Headers </a>- William S. Moses</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src2">Quantifying Dataflow Analysis with Gradients in LLVM </a>- Abhishek Shah</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src1">Floating Point Consistency in the Wild: A practical evaluation of how compiler optimizations affect high performance floating point code </a>- Jack J Garzella</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src1">Static Analysis of OpenMP Data Mapping for Target Offloading </a>- Prithayan Barua</li></ul><b>Panels</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#pan1">Panel: Inter-procedural Optimization (IPO) </a>- Teresa Johnson, Philip Reames, Chandler Carruth, Johannes Doerfert</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#pan2">The Loop Optimization Working Group </a>- Kit Barton, Michael Kruse, TBD</li></ul><b>Birds of a Feather</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#bof1">LLDB </a>- Jonas Devlieghere</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#bof2">Towards Better Code Generator Design and Unification for a Stack Machine </a>- Leonid Kholodov, Dmitry Borisenkov</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#bof3">Debug Info </a>- Adrian Prantl</li></ul><b>Lightning Talks</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit1">GWP-ASan: Zero-Cost Detection of MEmory Safety Bugs in Production </a>- Matt Morehouse</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit2">When 3 Memory Models Arenââ¬â¢t Enough ââ¬â OpenVMS on x86 </a>- John Reagan</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit3">FileCheck: learning arithmetic </a>- Thomas Preud'homme</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit4">-Wall Found Programming Errors and Engineering Effort to Enable Across a Large Codebase </a>- Aditya Kumar</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit5">Handling 1000s of OpenCL builtin functions in Clang </a>- Sven van Haastregt</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit6">NEC SX-Aurora as a Scalable Vector Playground </a>- Kazuhisa Ishizaka</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit7">Implementing Machine Code Optimizations for RISC-V </a>- Lewis Revill</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit8">Optimization Remarks Update </a>- Francis Visoiu Mistrih</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit9">Supporting Regular and Thin LTO with a Single LTO Bitcode Format </a>- Matthew Voss</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit10">Transitioning Appleââ¬â¢s Downstream llvm-project Repositories to the Monorepo </a>- Alex Lorenz</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit11">A Unified Debug Server For Deeply Embedded Systems and LLDB </a>- Simon Cook</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit12">State of LLDB and Deeply Embedded RISC-V </a>- Simon Cook</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit13">Supporting a Vendor ABI Variant in Clang </a>- Paul Robinson</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit14">Speculative Compilation in ORC JIT </a>- Praveen Velliengiri</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit15">Optimization Remarks for Human Beings </a>- William Bundy</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit16">Improving the Optimized Debugging Experience </a>- Orlando Cazalet-Hyams</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit17">Improving your TableGen Descriptions </a>- Javed Absar</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit18">Loom: Weaving Instrumentation for Program Analysis </a>- Brian Kidney</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit19">Clang Interface Stubs: Syntax Directed Stub Library Generation. </a>- Puyan Lotfi</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit20">Flang Update </a>- Steve Scalpone</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit21">Lowering tale: Supporting 64 bit pointers in RISCV 32 bit LLVM backend </a>- Reshabh Sharma</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit22">Virtual Function Elimination in LLVM </a>- Oliver Stannard</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit23">Making a Language Cross Platform: Libraries and Tooling </a>- Gwen Mittertreiner</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit24">Grafter - A use case to implement an embedded DSL in C++ and perform source to source traversal fusion transformation using Clang </a>- Laith Sakka</li></ul><b>Posters</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#post1">TON Labs Backend for TON Blockchain </a>- Dmitry Borisenkov, Dmitry Shtukenberg, Leonid Kholodov</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#post2">LLVM Build Times Using a Program Repository </a>- Rusell Gallop, Phil Camp</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#post3">RISC-V Bit Manipulation Support in the Clang/LLVM Toolchain </a>- Scott Egerton, Paolo Savini</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#post4">Attributor, a Framework for Interprocedural Information Deduction </a>- Johannes Doerfert, Hideto Ueno, Stefan Stipanovic</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#post6">Overflows Be Gone: Checked C for Memory Safety </a>- Mandeep Singh Grang</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src1">Cross-Translation Unit Optimization via Annotated Headers </a>- William S. Moses</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src2">Quantifying Dataflow Analysis with Gradients in LLVM </a>- Abhishek Shah</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src3">Floating Point Consistency in the Wild: A practical evaluation of how compiler optimizations affect high performance floating point code </a>- Jack J Garzella</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#src4">Static Analysis of OpenMP Data Mapping for Target Offloading </a>- Prithayan Barua</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit6">NEC SX-Aurora as a Scalable Vector Playground </a>- Kazuhisa Ishizaka</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit11">A Unified Debug Server For Deeply Embedded Systems and LLDB </a>- Simon Cook</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit14">Speculative Compilation in ORC JIT </a>- Praveen Velliengiri</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit18">Loom: Weaving Instrumentation for Program Analysis </a>- Brian Kidney</li><li><a href="https://llvm.org/devmtg/2019-10/talk-abstracts.html#lit21">Lowering tale: Supporting 64 bit pointers in RISCV 32 bit LLVM backend </a>- Reshabh Sharma</li></ul><div><br /></div><div><br /></div>
- The LLVM Project is Moving to GitHubhttps://blog.llvm.org/2019/08/the-llvm-project-is-moving-to-github.htmlThu, 01 Aug 2019 16:17:00 +0000https://blog.llvm.org/2019/08/the-llvm-project-is-moving-to-github.html<h2 dir="ltr" style="line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 16pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The LLVM Project is Moving to GitHub</span></h2><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">After several years of discussion and planning, the LLVM project is getting ready to complete the migration of its source code from SVN to GitHub! At last yearâs developer meeting, many interested community members convened at a series of round tables to lay out a plan to completely migrate LLVM source code from SVN to GitHub by the 2019 U.S. Developerâs Meeting. We have made great progress over the last nine months and are on track to complete the migration on October 21, 2019.</span></div><b id="docs-internal-guid-f32f98d3-7fff-9e07-9f74-3d7b965098f0" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">As part of the migration to GitHub we are maintaining the âmonorepoâ layout which currently exists in SVN. This means that there will be a single git repository with one top-level directory for each LLVM sub-project. This will be a change for those of you who are already using git and </span><span style="font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">accessing the code via the official sub-project git mirrors (e.g. </span><a href="https://git.llvm.org/git/llvm.git" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; color: #1155cc; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">https://git.llvm.org/git/llvm.git</span></a><span style="font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">) where each sub-project has its own repository.</span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">One of the first questions people ask when they hear about the GitHub plans is: Will the project start using GitHub pull requests and issues? And the answer to that for now is: no. The current transition plan focuses on migrating only the source code. We will continue to use </span><a href="https://reviews.llvm.org/" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Phabricator</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for code reviews, and </span><a href="http://bugs.llvm.org/" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">bugzilla</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for issue tracking after the migration is complete. We have not ruled out using pull requests and issues at some point in the future, but these are discussions we still need to have as a community.</span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The most important takeaway from this post, though, is that if you consume the LLVM source code in any way, you need to take action now to migrate your workflows. If you manage any continuous integration or other systems that need read-only access to the LLVM source code, you should begin pulling from the official </span><a href="https://github.com/llvm/llvm-project" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">GitHub</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> repository instead of SVN or the current sub-project mirrors. If you are a developer that needs to commit code, please use the </span><a href="https://llvm.org/docs/GettingStarted.html#for-developers-to-commit-changes-from-git" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">git-llvm</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> script for committing changes.</span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We have created a </span><a href="http://llvm.org/GitHubMigrationStatus.html" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">status</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> page, if you want to track the current progress of the migration. We will be posting updates to this page as we get closer to the completion date. If you run into issues of any kind with GitHub you can file a bug in </span><a href="http://bugs.llvm.org/" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">bugzilla</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and mark it as a blocker of the github tracking </span><a href="https://llvm.org/PR39393" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">bug</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">.</span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">This entire process has been a large community effort. Many many people have put in time discussing, planning, and implementing all the steps required to make this happen. Thank you to everyone who has been involved and letâs keep working to make this migration a success.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Blog post by Tom Stellard.</span></div><br class="Apple-interchange-newline" />
- LLVM and Google Season of Docshttps://blog.llvm.org/2019/05/llvm-and-google-season-of-docs.htmlFri, 24 May 2019 11:09:00 +0000https://blog.llvm.org/2019/05/llvm-and-google-season-of-docs.html<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The LLVM Project is pleased to announce that we have been selected to participate in Googleâs Season of Docs! </span></div><b id="docs-internal-guid-586dda0c-7fff-4151-4408-35b41e7affdd" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Our project idea list may be found here:</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><a href="http://llvm.org/SeasonOfDocs.html">http://llvm.org/SeasonOfDocs.html</a></span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">From now until May 29th, technical writers are encouraged to review the proposed project ideas and to ask any questions you have on our </span><span style="-webkit-text-decoration-skip: none; background-color: transparent; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;">[email protected]</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mailing list. Other documentation ideas are allowed, but we can not guarantee that a mentor will be found for the project. You are encouraged to discuss new ideas on the mailing list prior to submitting your technical writer application, in order to start the process of finding a mentor.</span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">When submitting your application for an LLVM documentation project, please consider the following:</span></div><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; caret-color: rgb(0, 0, 0); color: black; font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><br /></b><ul style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; list-style-type: disc; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 10pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Include Prior Experience:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Do you have prior technical writing experience? We want to see this! Considering including links to prior documentation or attachments of documentation you have written. If you canât include a link to the actual documentation, please describe in detail what you wrote, who the audience was, and any other important information that can help us gauge your prior experience. Please also include any experience with Sphinx or other documentation generation tools.</span></div></li><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; list-style-type: disc; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 10pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Take your time writing the proposal:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> We will be looking closely at your application to see how well it is written. Take the time to proofread and know who your audience is.</span></div></li><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; list-style-type: disc; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 10pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Propose your plan for our documentation project:</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> We have given a rough idea of what changes or topics we envision for the documentation, but this is just a start. We expect you to take the idea and expand or modify it as you see fit. Review our existing documentation and see how it would compliment or replace other pieces. Optionally include an overview or document design or layout plan in your application.</span></div></li><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; list-style-type: disc; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 10pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Become familiar with our project: </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We donât expect you to become a compiler expert, but we do expect you read up on our project to learn a bit about LLVM. </span></div></li></ul><br /><span style="font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">We look forward to working with some fabulous technical writers and improving our documentation. Again, please email </span><span style="-webkit-text-decoration-skip: none; font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;">[email protected]</span><span style="font-family: Arial; font-size: 11pt; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;"> with your questions.</span>
- LLVM Numerics Bloghttps://blog.llvm.org/2019/03/llvm-numerics-blog.htmlFri, 15 Mar 2019 15:47:00 +0000https://blog.llvm.org/2019/03/llvm-numerics-blog.html<div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">Keywords: Numerics, Clang, LLVM-IR, : 2019 LLVM Developers' Meeting, LLVMDevMtg.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">The goal of this blog post is to start a discussion about numerics in LLVM â where we are, recent work and things that remain to be done. There will be an informal discussion on numerics at the 2019 EuroLLVM conference next month. One purpose of this blog post is to refresh everyone's memory on where we are on the topic of numerics to restart the discussion.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">In the last year or two there has been a push to allow fine-grained decisions on which optimizations are legitimate for any given piece of IR. In earlier days there were two main modes of operation: fast-math and precise-math. When operating under the rules of precise-math, defined by IEEE-754, a significant number of potential optimizations on sequences of arithmetic instructions are not allowed because they could lead to violations of the standard. </span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">For example: </span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">The Reassociation optimization pass is generally not allowed under precise code generation as it can change the order of operations altering the creation of NaN and Inf values propagated at the expression level as well as altering precision. </span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">Precise code generation is often overly restrictive, so an alternative fast-math mode is commonly used where all possible optimizations are allowed, acknowledging that this impacts the precision of results and possibly IEEE compliant behavior as well. In LLVM, this can be enabled by setting the unsafe-math flag at the module level, or passing the -funsafe-math-optimizations to clang which then sets flags on the IR it generates. Within this context the compiler often generates shorter sequences of instructions to compute results, and depending on the context this may be acceptable. Fast-math is often used in computations where loss of precision is acceptable. For example when computing the color of a pixel, even relatively low precision is likely to far exceed the perception abilities of the eye, making shorter instruction sequences an attractive trade-off. In long-running simulations of physical events however loss of precision can mean that the simulation drifts from reality making the trade-off unacceptable.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="-webkit-text-stroke-width: initial;">Several years ago LLVM IR instructions gained the ability of being annotated with flags that can drive optimizations with more granularity than an all-or-nothing decision at the module level.</span><span style="-webkit-text-stroke-width: initial;"> </span><span style="-webkit-text-stroke-width: initial;">The IR flags in question are:</span><span style="-webkit-text-stroke-width: initial;"> </span><span style="font-kerning: none;"></span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;"><b>nnan, ninf, nsz, arcp, contract, afn, reassoc, nsw, nuw, exact</b>. </span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">Their exact meaning is described in the <a href="https://llvm.org/docs/LangRef.html#fast-math-flags%22%3ELLVM%20Language%20Reference%20Manual%3C/a%3E"><span style="-webkit-font-kerning: none;">LLVM Language Reference Manual</span></a>. When all the flags are are <b>enabled</b>, we get the current fast-math behavior. When these flags are <b>disabled</b>, we get precise math behavior. There are also several options available between these two models that may be attractive to some applications. In the past year several members of the LLVM community worked on making IR optimizations passes aware of these flags. When the unsafe-math module flag is not set these optimization passes will work by examining individual flags, allowing fine-grained selection of the optimizations that can be enabled on specific instruction sequences. This allows vendors/implementors to mix fast and precise computations in the same module, aggressively optimizing some instruction sequences but not others.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">We now have good coverage of IR passes in the LLVM codebase, in particular in the following areas:</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Intrinsic and libcall management</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Instruction Combining and Simplification</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Instruction definition</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* SDNode definition</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* GlobalIsel Combining and code generation</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Selection DAG code generation</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* DAG Combining</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Machine Instruction definition</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* IR Builders (SDNode, Instruction, MachineInstr)</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* CSE tracking</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Reassociation</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">* Bitcode</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">There are still some areas that need to be reworked for modularity, including vendor specific back-end passes. </span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none;">The following are some of the contributions mentioned above from the last 2 years of open source development:</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal; min-height: 10px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 114); -webkit-text-stroke-width: initial; color: #000072; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D45781">https://reviews.llvm.org/D45781</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : MachineInst support mapping SDNode fast math flags for support in Back End code generation</span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgba(0, 0, 0, 0.85098); color: black; font-variant-ligatures: no-common-ligatures;"> </span></div><div style="-webkit-text-stroke-color: rgba(0, 0, 0, 0.85098); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-family: Helvetica; font-stretch: normal; font-variant-ligatures: no-common-ligatures; line-height: normal; text-decoration: underline;"><a href="https://reviews.llvm.org/D46322">https://reviews.llvm.org/D46322</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); font-family: Helvetica; font-stretch: normal; font-variant-ligatures: no-common-ligatures; line-height: normal;"> :</span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> [SelectionDAG] propagate 'afn' and 'reassoc' from IR fast-math-flags</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 114); -webkit-text-stroke-width: initial; color: #000072; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D45710">https://reviews.llvm.org/D45710</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Fast Math Flag mapping into SDNode</span></div><div style="-webkit-text-stroke-color: rgba(0, 0, 0, 0.85098); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-family: Helvetica; font-stretch: normal; font-variant-ligatures: no-common-ligatures; line-height: normal; text-decoration: underline;"><a href="https://reviews.llvm.org/D46854">https://reviews.llvm.org/D46854</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); font-family: Helvetica; font-stretch: normal; font-variant-ligatures: no-common-ligatures; line-height: normal;"> : </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">[DAG] propagate FMF for all FPMathOperators</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 114); -webkit-text-stroke-width: initial; color: #000072; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D48180">https://reviews.llvm.org/D48180</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : updating isNegatibleForFree and GetNegatedExpression with fmf for fadd</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D48057:">https://reviews.llvm.org/D48057:</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> easing the constraint for isNegatibleForFree and GetNegatedExpression</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47954">https://reviews.llvm.org/D47954</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Utilize new SDNode flag functionality to expand current support for fdiv</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47918">https://reviews.llvm.org/D47918</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Utilize new SDNode flag functionality to expand current support for fma</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47909">https://reviews.llvm.org/D47909</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Utilize new SDNode flag functionality to expand current support for fadd</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47910">https://reviews.llvm.org/D47910</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Utilize new SDNode flag functionality to expand current support for fsub</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47911">https://reviews.llvm.org/D47911</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Utilize new SDNode flag functionality to expand current support for fmul</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D48289">https://reviews.llvm.org/D48289</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : refactor of visitFADD for AllowNewConst cases</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47388">https://reviews.llvm.org/D47388</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : propagate fast math flags via IR on fma and sub expressions</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47389">https://reviews.llvm.org/D47389</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : guard fneg with fmf sub flags</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47026">https://reviews.llvm.org/D47026</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : fold FP binops with undef operands to NaN</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47749">https://reviews.llvm.org/D47749</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : guard fsqrt with fmf sub flags</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D46447">https://reviews.llvm.org/D46447</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Mapping SDNode flags to MachineInstr flags</span></div><div style="-webkit-text-stroke-color: rgb(53, 134, 255); -webkit-text-stroke-width: initial; color: #3586ff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL334970">rL334970: [NFC] make MIFlag accessor functions consistant with usage model</a></span></div><div style="-webkit-text-stroke-color: rgb(53, 134, 255); -webkit-text-stroke-width: initial; color: #3586ff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL338604">rL338604: [NFC] small addendum to r334242, FMF propagation</a></span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D50195">https://reviews.llvm.org/D50195</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : extend folding fsub/fadd to fneg for FMF</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL339197">https://reviews.llvm.org/rL339197</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [NFC] adding tests for Y - (X + Y) --> -X</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D50417">https://reviews.llvm.org/D50417</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] fold fneg into constant operand of fmul/fdiv</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL339357">https://reviews.llvm.org/rL339357</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : extend folding fsub/fadd to fneg for FMF</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D50996">https://reviews.llvm.org/D50996</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : extend binop folds for selects to include true and false binops flag intersection</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL339938">https://reviews.llvm.org/rL339938</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : add a missed case for binary op FMF propagation under select folds</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D51145">https://reviews.llvm.org/D51145</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Guard FMF context by excluding some FP operators from FPMathOperator</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL341138">https://reviews.llvm.org/rL341138</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : adding initial intersect test for Node to Instruction association</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL341565">https://reviews.llvm.org/rL341565</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : in preparation for adding nsw, nuw and exact as flags to MI</span></div><div style="-webkit-text-stroke-color: rgb(53, 134, 255); -webkit-text-stroke-width: initial; color: #3586ff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D51738">https://reviews.llvm.org/D51738</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;"> : add IR flags to MI</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D52006">https://reviews.llvm.org/D52006</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Copy utilities updated and added for MI flags</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL342598">https://reviews.llvm.org/rL342598</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : add new flags to a DebugInfo lit test</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D53874">https://reviews.llvm.org/D53874</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstSimplify] fold 'fcmp nnan oge X, 0.0' when X is not negative</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D55668">https://reviews.llvm.org/D55668</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Add FMF management to common fp intrinsics in GlobalIsel</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL352396">https://reviews.llvm.org/rL352396</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [NFC] TLI query with default(on) behavior wrt DAG combines for fmin/fmax targetâ¦</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL316753">https://reviews.llvm.org/rL316753</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> (Fold fma (fneg x), K, y -> fma x, -K, y)</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D57630">https://reviews.llvm.org/D57630</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Move IR flag handling directly into builder calls for cases translated from Instructions in GlobalIsel</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL332756">https://reviews.llvm.org/rL332756</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : adding baseline fp fold tests for unsafe on and off</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL334035">https://reviews.llvm.org/rL334035</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : NFC: adding baseline fneg case for fmf</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL325832">https://reviews.llvm.org/rL325832</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstrTypes] add frem and fneg with FMF creators</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D41342">https://reviews.llvm.org/D41342</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] Missed optimization in math expression: simplify calls exp functions</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D52087">https://reviews.llvm.org/D52087</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [IRBuilder] Fixup CreateIntrinsic to allow specifying Types to Mangle.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D52075">https://reviews.llvm.org/D52075</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] Support (sub (sext x), (sext y)) --> (sext (sub x, y)) and (sub (zext x), (zext y)) --> (zext (sub x, y))</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/rL338059">https://reviews.llvm.org/rL338059</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] fold udiv with common factor from muls with nuw</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">Commit: e0ab896a84be9e7beb59874b30f3ac51ba14d025 : [InstCombine] allow more fmul folds with âreassoc'</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">Commit: 3e5c120fbac7bdd4b0ff0a3252344ce66d5633f9 : [InstCombine] distribute fmul over fadd/fsub</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D37427">https://reviews.llvm.org/D37427</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] canonicalize fcmp ord/uno with constants to null constant</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D40130">https://reviews.llvm.org/D40130</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstSimplify] fold and/or of fcmp ord/uno when operand is known nnan</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D40150">https://reviews.llvm.org/D40150</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [LibCallSimplifier] fix pow(x, 0.5) -> sqrt() transforms</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D39642">https://reviews.llvm.org/D39642</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [ValueTracking] readnone is a requirement for converting sqrt to llvm.sqrt; nnan is not</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D39304">https://reviews.llvm.org/D39304</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [IR] redefine 'reassoc' fast-math-flag and add 'trans' fast-math-flag</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D41333">https://reviews.llvm.org/D41333</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [ValueTracking] ignore FP signed-zero when detecting a casted-to-integer fmin/fmax pattern</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D5584">https://reviews.llvm.org/D5584</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : Optimize square root squared (PR21126)</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D42385">https://reviews.llvm.org/D42385</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstSimplify] (X * Y) / Y --> X for relaxed floating-point ops</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D43160">https://reviews.llvm.org/D43160</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstSimplify] allow exp/log simplifications with only 'reassocâ FMF</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D43398">https://reviews.llvm.org/D43398</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] allow fdiv folds with less than fully 'fastâ ops</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D44308">https://reviews.llvm.org/D44308</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [ConstantFold] fp_binop AnyConstant, undef --> NaN</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D43765">https://reviews.llvm.org/D43765</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstSimplify] loosen FMF for sqrt(X) * sqrt(X) --> X</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D44521">https://reviews.llvm.org/D44521</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstSimplify] fp_binop X, NaN --> NaN</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D47202">https://reviews.llvm.org/D47202</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [CodeGen] use nsw negation for abs</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D48085">https://reviews.llvm.org/D48085</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [DAGCombiner] restrict (float)((int) f) --> ftrunc with no-signed-zeros</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D48401">https://reviews.llvm.org/D48401</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] fold vector select of binops with constant ops to 1 binop (PR37806)</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D39669">https://reviews.llvm.org/D39669</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : DAG: Preserve nuw when reassociating adds</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D39417">https://reviews.llvm.org/D39417</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : InstCombine: Preserve nuw when reassociating nuw ops</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D51753">https://reviews.llvm.org/D51753</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [DAGCombiner] try to convert pow(x, 1/3) to cbrt(x)</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(53, 134, 255); color: #3586ff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D51630">https://reviews.llvm.org/D51630</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [DAGCombiner] try to convert pow(x, 0.25) to sqrt(sqrt(x))</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D53650">https://reviews.llvm.org/D53650</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [FPEnv] Last BinaryOperator::isFNeg(...) to m_FNeg(...) changes</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D54001">https://reviews.llvm.org/D54001</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">: [ValueTracking] determine sign of 0.0 from select when matching min/max FP</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://reviews.llvm.org/D51942">https://reviews.llvm.org/D51942</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">: [InstCombine] Fold (C/x)>0 into x>0 if possible</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="https://llvm.org/svn/llvm-project/llvm/trunk@348016">https://llvm.org/svn/llvm-project/llvm/trunk@348016</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures;"> : </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">[SelectionDAG] fold FP binops with 2 undef operands to undef</span></div><div style="-webkit-text-stroke-color: rgb(17, 141, 255); -webkit-text-stroke-width: initial; color: #118dff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346242">http://llvm.org/viewvc/llvm-project?view=revision&revision=346242</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> :</span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;"> propagate fast-math-flags when folding fcmp+fpext, part 2</span></div><div style="-webkit-text-stroke-color: rgb(17, 141, 255); -webkit-text-stroke-width: initial; color: #118dff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346240">http://llvm.org/viewvc/llvm-project?view=revision&revision=346240</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> </span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;">: propagate fast-math-flags when folding fcmp+fpext</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346238">http://llvm.org/viewvc/llvm-project?view=revision&revision=346238</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] propagate fast-math-flags when folding fcmp+fneg, part 2</span></div><div style="-webkit-text-stroke-color: rgb(17, 141, 255); -webkit-text-stroke-width: initial; color: #118dff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346169">http://llvm.org/viewvc/llvm-project?view=revision&revision=346169</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> </span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;">: [InstSimplify] fold select (fcmp X, Y), X, Y</span></div><div style="-webkit-text-stroke-color: rgb(17, 141, 255); -webkit-text-stroke-width: initial; color: #118dff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346234">http://llvm.org/viewvc/llvm-project?view=revision&revision=346234</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> </span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;">: propagate fast-math-flags when folding fcmp+fneg</span></div><div style="-webkit-text-stroke-color: rgb(17, 141, 255); -webkit-text-stroke-width: initial; color: #118dff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346147">http://llvm.org/viewvc/llvm-project?view=revision&revision=346147</a></span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"> </span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;">: [InstCombine] canonicalize -0.0 to +0.0 in fcmp</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=346143">http://llvm.org/viewvc/llvm-project?view=revision&revision=346143</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">: [InstCombine] loosen FP 0.0 constraint for fcmp+select substitution</span></div><div style="-webkit-text-stroke-color: rgb(17, 141, 255); -webkit-text-stroke-width: initial; color: #118dff; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=345734">http://llvm.org/viewvc/llvm-project?view=revision&revision=345734</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(0, 0, 0); color: black; font-variant-ligatures: no-common-ligatures;"> : [InstCombine] refactor fabs+fcmp fold; NFC</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=345728">http://llvm.org/viewvc/llvm-project?view=revision&revision=345728</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">: [InstSimplify] fold 'fcmp nnan ult X, 0.0' when X is not negative</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal;"><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures; text-decoration: underline;"><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=345727">http://llvm.org/viewvc/llvm-project?view=revision&revision=345727</a></span><span style="-webkit-font-kerning: none; -webkit-text-stroke-color: rgb(17, 141, 255); color: #118dff; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">: [InstCombine] add assertion that InstSimplify has folded a fabs+fcmp; NFC</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal; min-height: 10px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal; min-height: 10px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">While multiple people have been working on finer-grained control over fast-math optimizations and other relaxed numerics modes, there has also been some initial progress on adding support for <i>more</i> constrained numerics models. There has been considerable progress towards adding and enabling constrained floating-point intrinsics to capture FENV_ACCESS ON and similar semantic models.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">These experimental constrained intrinsics prohibit certain transforms that are not safe if the default floating-point environment is not in effect. Historically, LLVM has in practice basically âsplit the differenceâ with regard to such transforms; they havenât been explicitly disallowed, as LLVM doesnât model the floating-point environment, but they have been disabled when they caused trouble for tests or software projects. The absence of a formal model for licensing these transforms constrains our ability to enable them. Bringing language and backend support for constrained intrinsics across the finish line will allow us to include transforms that we disable as a matter of practicality today, and allow us to give developers an easy escape valve (in the form of FENV_ACCESS ON and similar language controls) when they need more precise control, rather than an ad-hoc set of flags to pass to the driver.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; min-height: 13px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">We should discuss these new intrinsics to make sure that they can capture the right models for all the languages that LLVM supports.</span></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal; min-height: 10px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 9px; font-stretch: normal; line-height: normal; min-height: 10px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;"></span><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">Here are some possible discussion items:</span></div><br /><ul><li style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; margin: 0px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">Should specialization be applied at the call level for edges in a call graph where the caller has special context to extend into the callee wrt to flags?</span></li><li style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; margin: 0px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">Should the inliner apply something similar to calls that meet inlining criteria?</span></li><li style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; margin: 0px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">What other part(s) of the compiler could make use of IR flags that are currently not covered?</span></li><li style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Menlo; font-size: 11px; font-stretch: normal; line-height: normal; margin: 0px;"><span style="font-kerning: none; font-variant-ligatures: no-common-ligatures;">What work needs to be done regarding code debt wrt current areas of implementation.</span></li></ul>
- FOSDEM 2019 LLVM developer room reporthttps://blog.llvm.org/2019/03/fosdem-2019-llvm-developer-room-report.htmlThu, 07 Mar 2019 02:33:00 +0000https://blog.llvm.org/2019/03/fosdem-2019-llvm-developer-room-report.html<h2 class="" lang="en-AU" style="color: #2e75b5; font-family: Calibri; font-size: 14pt; margin: 0in; text-size-adjust: auto;"><br /></h2><div class="" lang="en-AU" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">As well as at the LLVM developer meetings, the LLVM community is also present at a number of other events. One of those is FOSDEM, which has had a dedicated LLVM track since 2014.</span></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">Earlier this February, the LLVM dev room was back for the 6th time.</span></div><div class="" lang="en-AU" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;"><br /></span></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/">FOSDEM</a><span class="Apple-converted-space"> </span>is one of the largest open source conferences, attracting over 8000 developers attending over 30 parallel tracks, occupying almost all space of the ULB university campus in Brussels.</span></div><div class="" lang="en-AU" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><br /></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">In comparison to the LLVM developer meetings, this dev room offers more of an opportunity to meet up with developers from a very wide range of open source projects.</span></div><div class="" lang="en-AU" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><br /></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">As in previous years, the<span class="Apple-converted-space"> </span><a class="" href="https://fosdem.org/2019/schedule/track/llvm/">LLVM dev room program</a><span class="Apple-converted-space"> </span>consisted of presentations with a varied target audience, ranging from LLVM developers to LLVM users, including people not yet using LLVM but interested in discovering what can be done with it.<span class="Apple-converted-space"> </span></span></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">On the day itself, the room was completely packed for most presentations, often with people waiting outside to be able to enter for the next presentation.</span></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">Slides and videos of the presentations are available via the links below</span></div><div class="" lang="en-AU" style="caret-color: rgb(0, 0, 0); font-size: 11pt; margin: 0in; text-size-adjust: auto;"><br /></div><ul class="" style="caret-color: rgb(0, 0, 0); direction: ltr; margin-bottom: 0in; margin-left: 0.75in; margin-top: 0in; text-size-adjust: auto; unicode-bidi: embed;" type="circle"><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_irgen/"><span class="" lang="en-US">Roll your own compiler with LLVM</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Kai Nacke)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_bpf_rewriting/"><span class="" lang="en-US">Rewriting Pointer Dereferences in bcc with Clang</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Paul Chaignon)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_building/"><span class="" lang="en-US">Building an LLVM-based tool</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Alex Denisov)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_debug/"><span class="" lang="en-US">Debug info in optimized code - how far can we go?</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Nikola Prica, Djordje Todorovic)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_tablegen/"><span class="" lang="en-US">Lessons in TableGen</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Nicolai Hähnle)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_apollo/"><span class="" lang="en-US">LLVM for the Apollo Guidance Computer</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Lewis Revill)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_mix/"><span class="" lang="en-US">llvm.mix</span></a><span class="" lang="en-AU"> </span><a class="" href="https://fosdem.org/2019/schedule/event/llvm_mix/"><span class="" lang="en-US" style="font-style: italic;">Multi-stage compiler-assisted specializer generator built on LLVM</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>( Eugene Sharygin)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_smt_csa/"><span class="" lang="en-US">SMT-Based Refutation of Spurious Bug Reports in the Clang Static Analyzer</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Mikhail Gadelha)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_lld/"><span class="" lang="en-US">What makes LLD so fast?</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Peter Smith)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_kernel/"><span class="" lang="en-US">Compiling the Linux kernel with LLVM tools</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Nick Desaulniers and Bill Wendling)</span></span></li><li class="" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: Verdana, sans-serif;"><a class="" href="https://fosdem.org/2019/schedule/event/llvm_bisect/"><span class="" lang="en-US">It was working yesterday! Investigating regressions with llvmlab bisect</span></a><span class="" lang="en-AU"><span class="Apple-converted-space"> </span>(Leandro Nunes)</span></span></li></ul><div class="" lang="en-AU" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><br /></div><div class="" style="caret-color: rgb(0, 0, 0); margin: 0in; text-size-adjust: auto;"><span style="font-family: Verdana, sans-serif;">Finally, I want to express my gratitude to the LLVM Foundation, which sponsored travel expenses for a few presenters who couldn't otherwise have made it to the conference.</span></div>
- EuroLLVM'19 developers' meeting programhttps://blog.llvm.org/2019/02/eurollvm19-developers-meeting-program.htmlMon, 11 Feb 2019 09:49:00 +0000https://blog.llvm.org/2019/02/eurollvm19-developers-meeting-program.htmlThe LLVM Foundation is excited to announce the program for the EuroLLVM'19 developers' meeting (April 8 - 9 in Brussels / Belgium) !<br /><br /><b>Keynote</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Keynote_1"> MLIR: Multi-Level Intermediate Representation for Compiler Infrastructure</a> <i><i>Tatiana Shpeisman (Google), Chris Lattner (Google)</i></i></li></ul><b>Technical talks</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_1"> Switching a Linux distribution's main toolchains to LLVM/Clang</a> <i>Bernhard Rosenkränzer (Linaro, OpenMandriva, LinDev)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_2"> Just compile it: High-level programming on the GPU with Julia</a> <i>Tim Besard (Ghent University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_3"> The Future of AST Matcher-based Refactoring</a> <i>Stephen Kelly</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_4"> A compiler approach to Cyber-Security</a> <i>François de Ferrière (STMicroelectronics)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_5"> Compiler Optimizations for (OpenMP) Target Offloading to GPUs</a> <i>Johannes Doerfert (Argonne National Laboratory), Hal Finkel (Argonne National Laboratory)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_6"> Handling massive concurrency: Development of a programming model for GPU and CPU</a> <i>Matthias Liedtke (SAP)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_7"> Automated GPU Kernel Fusion with XLA</a> <i>Thomas Joerg (Google)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_8"> The Helium Haskell compiler and its new LLVM backend</a> <i>Ivo Gabe de Wolff (University of Utrecht)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_9"> Testing and Qualification of Optimizing Compilers for Functional Safety</a> <i>José Luis March Cabrelles (Solid Sands)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_10"> Improving Debug Information in LLVM to Recover Optimized-out Function Parameters</a> <i>Nikola Prica (RT-RK), Djordje Todorovic (RT-RK), Ananthakrishna Sowda (CISCO), Ivan Baev (CISCO)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_11"> LLVM IR in GraalVM: Multi-Level, Polyglot Debugging with Sulong</a> <i>Jacob Kreindl (Johannes Kepler University Linz)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_12"> LLDB Reproducers</a> <i>Jonas Devlieghere (Apple)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_13"> Sulong: An experience report of using the "other end" of LLVM in GraalVM.</a> <i>Roland Schatz (Oracle Labs), Josef Eisl (Oracle Labs)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_14"> SYCL compiler: zero-cost abstraction and type safety for heterogeneous computing</a> <i>Andrew Savonichev (Intel)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_15"> Handling all Facebook requests with JITed C++ code</a> <i>Huapeng Zhou (Facebook), Yuhan Guo (Facebook)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_16"> clang-scan-deps: Fast dependency scanning for explicit modules</a> <i>Alex Lorenz (Apple), Michael Spencer (Apple)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_17"> Clang tools for implementing cryptographic protocols like OTRv4</a> <i>Sofia Celi (Centro de Autonomia Digital)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_18"> Implementing the C++ Core Guidelines'; Lifetime Safety Profile in Clang</a> <i>Gabor Horvath (Eotvos Lorand University), Matthias Gehre (Silexica GmbH), Herb Sutter (Microsoft)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_19"> Changes to the C++ standard library for C++20</a> <i>Marshall Clow (CppAlliance)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_20"> Adventures with RISC-V Vectors and LLVM</a> <i>Robin Kruppe (TU Darmstadt), Roger Espasa (Esperanto Technologies)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_21"> A Tale of Two ABIs: ILP32 on AArch64</a> <i>Tim Northover (Apple)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_22"> LLVM Numerics Improvements</a> <i>Michael Berg (Apple), Steve Canon (Apple)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_23"> DOE Proxy Apps: Compiler Performance Analysis and Optimistic Annotation Exploration</a> <i>Brian Homerding (Argonne National Laboratory), Johannes Doerfert (Argonne National Laboratory)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Talk_24"> Loop Fusion, Loop Distribution and their Place in the Loop Optimization Pipeline</a> <i>Kit Barton (IBM), Johannes Doerfert (Argonne National Lab), Hal Finkel (Argonne National Lab), Michael Kruse (Argonne National Lab)</i></li></ul><b>Tutorials</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Tutorial_1"> Tutorial: Building a Compiler with MLIR</a> <i>Amini Mehdi (Google), Jacques Pienaar (Google), Nicolas Vasilache (Google)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Tutorial_2"> Building an LLVM-based tool: lessons learned</a> <i>Alex Denisov</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Tutorial_3"> LLVM IR Tutorial - Phis, GEPs and other things, oh my!</a> <i>Vince Bridgers (Intel Corporation), Felipe de Azevedo Piovezan (Intel Corporation)</i></li></ul><b>Student Research Competition</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#SRC_1"> Safely Optimizing Casts between Pointers and Integers</a> <i>Juneyoung Lee (Seoul National University, Korea), Chung-Kil Hur (Seoul National University, Korea), Ralf Jung (MPI-SWS, Germany), Zhengyang Liu (University of Utah, USA), John Regehr (University of Utah, USA), Nuno P. Lopes (Microsoft Research, UK)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#SRC_2"> An alternative OpenMP Backend for Polly</a> <i>Michael Halkenhäuser (TU Darmstadt)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#SRC_3"> Implementing SPMD control flow in LLVM using reconverging CFGs</a> <i>Fabian Wahlster (Technische Universität München), Nicolai Hähnle (Advanced Micro Devices)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#SRC_4"> Function Merging by Sequence Alignment</a> <i>Rodrigo Rocha (University of Edinburgh), Pavlos Petoumenos (University of Edinburgh), Zheng Wang (Lancaster University), Murray Cole (University of Edinburgh), Hugh Leather (University of Edinburgh)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#SRC_5"> Compilation and optimization with security annotations</a> <i>Son Tuan Vu (LIP6), Karine Heydemann (LIP6), Arnaud de Grandmaison (ARM), Albert Cohen (Google)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#SRC_6"> Adding support for C++ contracts to Clang</a> <i>Javier López-Gómez (University Carlos III of Madrid), J. Daniel GarcÃa (University Carlos III of Madrid)</i></li></ul><b>Lightning talks</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_1"> LLVM IR Timing Predictions: Fast Explorations via lli</a> <i>Alessandro Cornaglia (FZI - Research Center for Information Technology)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_2">Simple Outer-Loop-Vectorization == LoopUnroll-And-Jam + SLP</a> <i>Dibyendu Das (AMD)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_3"> Clacc 2019: An Update on OpenACC Support for Clang and LLVM</a> <i>Joel E. Denny (Oak Ridge National Laboratory), Seyong Lee (Oak Ridge National Laboratory), Jeffrey S. Vetter (Oak Ridge National Laboratory)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_4"> Targeting a statically compiled program repository with LLVM</a> <i>Phil Camp (SN Systems (Sony Interactive Entertainment)), Russell Gallop (SN Systems (Sony Interactive Entertainment))</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_5"> Does the win32 clang compiler executable really need to be over 21MB in size?</a> <i>Russell Gallop (SN Systems), Greg Bedwell (SN Systems)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_6"> Resolving the almost decade old checker dependency issue in the Clang Static Analyzer</a> <i>Kristóf Umann (Ericsson Hungary, Eötvös Loránd University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_7"> Adopting LLVM Binary Utilities in Toolchains</a> <i>Jordan Rupprecht (Google)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_8"> Multiplication and Division in the Range-Based Constraint Manager</a> <i>Ãdám Balogh (Ericsson Hungary Ltd.)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_9"> Statistics Based Checkers in the Clang Static Analyzer</a> <i>Ãdám Balogh (Ericsson Hungary Ltd.)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_10"> Flang Update</a> <i>Steve Scalpone (NVIDA / PGI / Flang)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_11"> Swinging Modulo Scheduling together with Register Allocation</a> <i>Lama Saba (Intel)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_12"> LLVM for the Apollo Guidance Computer</a> <i>Lewis Revill (University of Bath)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_13"> Catch dangling inner pointers with the Clang Static Analyzer</a> <i>Réka Kovács (Eötvös Loränd University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#LightningTalk_14"> Cross translation unit test case reduction</a> <i>Réka Kovács (Eötvös Loränd University)</i></li></ul><b>BoFs</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_1"> RFC: Towards Vector Predication in LLVM IR</a> <i>Simon Moll (Saarland University), Sebastian Hack (Saarland University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_2"> IPO --- Where are we, where do we want to go?</a> <i>Johannes Doerfert (Argonne National Laboratory), Kit Barton (IBM Toronto Lab)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_3"> LLVM binutils</a> <i>James Henderson (SN Systems (Sony Interactive Entertainment)), Jordan Rupprecht (Google)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_4"> RFC: Reference OpenCL Runtime library for LLVM</a> <i>Andrew Savonichev (Intel), Alexey Sachkov (Intel)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_5"> LLVM Interface Stability Guarantees BoF</a> <i>Stephen Kelly</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_6"> Clang Static Analyzer BoF</a> <i>Devin Coughlin (Apple), Gabor Horvath (Eotvos Lorand University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#BoF_7"> LLVM Numerics Improvements</a> <i>Michael Berg (Apple), Steve Canon (Apple)</i></li></ul><b>Posters</b><br /><ul><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_1"> Clava: C/C++ source-to-source from CMake using LARA</a> <i>João Bispo (FEUP/INESCTEC)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_2"> Safely Optimizing Casts between Pointers and Integers</a> <i>Juneyoung Lee (Seoul National University, Korea), Chung-Kil Hur (Seoul National University, Korea), Ralf Jung (MPI-SWS, Germany), Zhengyang Liu (University of Utah, USA), John Regehr (University of Utah, USA), Nuno P. Lopes (Microsoft Research, UK)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_3"> Scalar Evolution Canon: Click! Canonicalize SCEV and validate it by Z3 SMT solver!</a> <i>Lin-Ya Yu (Xilinx), Alexandre Isoard (Xilinx)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_4"> Splendid GVN: Partial Redundancy Elimination for Algebraic Simplification</a> <i>Li-An Her (National Tsing Hua University), Jenq-Kuen Lee (National Tsing Hua University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_5"> An alternative OpenMP Backend for Polly</a> <i>Michael Halkenhäuser (TU Darmstadt)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_6"> Does the win32 clang compiler executable really need to be over 21MB in size?</a> <i>Russell Gallop (SN Systems), G Bedwell (SN Systems)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_7"> Enabling Multi- and Cross-Language Verification with LLVM</a> <i>Zvonimir Rakamaric (University of Utah)</i></li><li><i><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_8">Instruction Tracing and dynamic codegen analysis to identify unique llvm performance issues.</a> <i>Biplob (IBM)</i></i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_9"> Handling all Facebook requests with JITed C++ code</a> <i>Huapeng Zhou (Facebook), Yuhan Guo (Facebook)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_10"> Implementing SPMD control flow in LLVM using reconverging CFGs</a> <i>Fabian Wahlster (Technische Universität München), Nicolai Hähnle (Advanced Micro Devices)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_11"> LLVM for the Apollo Guidance Computer</a> <i>Lewis Revill (University of Bath)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_12"> LLVM Miner: Text Analytics based Static Knowledge Extractor</a> <i>Hameeza Ahmed (NED University of Engineering and Technology), Muhammad Ali Ismail (NED University of Engineering and Technology)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_13"> Function Merging by Sequence Alignment</a> <i>Rodrigo Rocha (University of Edinburgh), Pavlos Petoumenos (University of Edinburgh), Zheng Wang (Lancaster University), Murray Cole (University of Edinburgh), Hugh Leather (University of Edinburgh)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_14"> Compilation and optimization with security annotations</a> <i>Son Tuan Vu (LIP6), Karine Heydemann (LIP6), Arnaud de Grandmaison (ARM), Albert Cohen (Google)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_15"> Cross translation unit test case reduction</a> <i>Réka Kovács (Eötvös Loränd University)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_16"> Leveraging Polyhedral Compilation in Chapel Compiler</a> <i>Sahil Yerawar (IIT Hyderabad), Siddharth Bhat (IIIT Hyderabad), Michael Ferguson (Cray Inc.), Philip Pfaffe (Karlsruhe Institute of Technology), Ramakrishna Upadrasta (IIT Hyderabad)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_17"> LLVM on AVR - textual IR as a powerful tool for making "impossible" compilers</a> <i>Carl Peto (Swift for Arduino/Petosoft)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_18"> Vectorizing Add/Sub Expressions with SLP</a> <i>Vasileios Porpodas (Intel Corporation, USA), Rodrigo C. O. Rocha (University of Edinburgh, UK), Evgueni Brevnov (Intel Corporation, USA), LuÃs F. W. Góes (PUC Minas, Brazil), Timothy Mattson (Intel Corporation, USA)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_19"> Adding support for C++ contracts to Clang</a> <i>Javier López-Gómez (University Carlos III of Madrid), J. Daniel GarcÃa (University Carlos III of Madrid)</i></li><li><a href="https://llvm.org/devmtg/2019-04/talks.html#Poster_20"> Optimizing Nondeterminacy: Exploiting Race Conditions in Parallel Programs</a> <i>William S. Moses (MIT CSAIL)</i></li></ul><div><div>If you are interested in any of this talks, you should <a href="https://www.eventbrite.com/e/eurollvm19-developers-meeting-brussels-belgium-tickets-53016346319" target="_blank">register</a> to attend the EuroLLVM'19. Tickets are limited !</div><div><br /></div><div>More information about the EuroLLVM'19 is available <a href="https://llvm.org/devmtg/2019-04/" target="_blank">here</a>. </div></div>
- 30% faster Windows builds with clang-cl and the new /Zc:dllexportInlines- flaghttps://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.htmlWed, 14 Nov 2018 04:49:00 +0000https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html<h2>Background</h2> <p>In the course of adding Microsoft Visual C++ (MSVC) compatible Windows support to Clang, we worked hard to make sure the <a href="https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=vs-2017">dllexport and dllimport declspecs</a> are handled the same way by Clang as by MSVC.</p> <p>dllexport and dllimport are used to specify what functions and variables should be externally accessible ("exported") from the currently compiled Dynamic-Link Library (DLL), or should be accessed ("imported") from another DLL. In the class declaration below, <code>S::foo()</code> will be exported when building a DLL:</p> <pre style="text-indent:0"><br />struct __declspec(dllexport) S {<br /> void foo() {}<br />};<br /></pre> <p>and code using that DLL would typically see a declaration like this:</p> <pre style="text-indent:0"><br />struct __declspec(dllimport) S {<br /> void foo() {}<br />};<br /></pre> <p>to indicate that the function is defined in and should be accessed from another DLL.</p> <p>Often the same declaration is used along with a <a href="https://chromium.googlesource.com/chromium/src/+/72.0.3608.5/base/base_export.h">preprocessor macro</a> to flip between dllexport and dllimport, depending on whether a DLL is being built or consumed.</p> <p>The basic idea of dllexport and dllimport is simple, but the semantics get more complicated as they interact with more facets of the C++ language: templates, inheritance, different kinds of instantiation, redeclarations with different declspecs, and so on. Sometimes the semantics are surprising, but by now we think clang-cl gets most of them right. And as the old maxim goes, once you know the rules well, you can start tactfully breaking them.</p> <p>One issue with dllexport is that for inline functions such as <code>S::foo()</code> above, the compiler must emit the definition <em>even if it's not used in the translation unit</em>. That's because the DLL must export it, and the compiler cannot know if any other translation unit will provide a definition.</p> <p>This is very inefficient. A dllexported class with inline members in a header file will cause definitions of those members to be emitted in <em>every translation unit that includes the header</em>, directly or indirectly. And as we know, C++ source files often end up including a lot of headers. This behaviour is also different from non-Windows systems, where inline function definitions are not emitted unless they're used, even in shared objects and dynamic libraries.</p> <h2>/Zc:dllexportInlines-</h2> <p>To address this problem, clang-cl recently gained a new command-line flag, <a href="https://clang.llvm.org/docs/UsersManual.html#the-zc-dllexportinlines-option">/Zc:dllexportInlines-</a> (MSVC uses the /Zc: prefix for <a href="https://docs.microsoft.com/en-us/cpp/build/reference/zc-conformance?view=vs-2017">language conformance options</a>). The basic idea is simple: since the definition of an inline function is available along with its declaration, it's not necessary to import or export it from a DLL — the inline definition can be used directly. The effect of the flag is to not apply class-level dllexport/dllimport declspecs to inline member functions. In the two examples above, it means <code>S::foo()</code> would not be dllexported or dllimported, even though the <code>S</code> class is declared as such.</p> <p>This is very similar to the <a href="https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-fvisibility-inlines-hidden">-fvisibility-inlines-hidden</a> Clang and GCC flag used on non-Windows. For C++ projects with many inline functions, it can significantly reduce the set of exported functions, and thereby the symbol table and file size of the shared object or dynamic library, as well as program load time.</p> <p>On Windows however, the main benefit is not having to emit the unused inline function definitions. This means the compiler has to do much less work, and reduces object file size which in turn reduces the work for the linker. For Chrome, we <a href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/xYVt4PFeObA/tc7CE3ojBgAJ">saw 30 % faster full builds</a>, 30 % shorter link times for blink_core.dll, and 40 % smaller total .obj file size.</p> <p>The reduction in .obj file size, combined with the enormous reduction in .lib files allowed by previously switching linkers to lld-link which uses thin archives, means that a typical Chrome build directory is now 60 % smaller than it would have been just a year ago.</p> <p>(Some of the same benefit can be had without this flag if the dllexport inline function comes from a pre-compiled header (PCH) file. In that case, the definition will be emitted in the object file when building the PCH, and so is not emitted elsewhere unless it's used.)</p> <h2>Compatibility</h2> <p>Using /Zc:dllexportInlines- is "half ABI incompatible". If it's used to build a DLL, inline members will no longer be exported, so any code using the DLL must use the same flag to not dllimport those members. However, the reverse scenario generally works: a DLL compiled without the flag (such as a system DLL built with MSVC) can be referenced from code that uses the flag, meaning that the referencing code will use the inline definitions instead of importing them from the DLL.</p> <p>Like -fvisibility-inlines-hidden, /Zc:dllexportInlines- breaks the C++ language guarantee that (even an inline) function has a unique address within the program. When using these flags, an inline function will have a different address when used inside the library and outside.</p> <p>Also, these flags can lead to link errors when inline functions, which would normally be dllimported, refer to internal symbols of a DLL:</p> <pre style="text-indent:0"><br />void internal();<br /><br />struct __declspec(dllimport) S {<br /> void foo() { internal(); }<br />}<br /></pre> <p>Normally, references to <code>S::foo()</code> would use the definition in the DLL, which also contains the definition of <code>internal()</code>, but when using /Zc:dllexportInlines-, the inline definition of <code>S::foo()</code> is used directly, resulting in a link error since no definition of <code>internal()</code> can be found.</p> <p>Even worse, if there is an inline definition of <code>internal()</code> containing a static local variable, the program will now refer to a different instance of that variable than in the DLL:</p> <pre style="text-indent:0"><br />inline int internal() { static int x; return x++; }<br /><br />struct __declspec(dllimport) S {<br /> int foo() { return internal(); }<br />}<br /></pre> <p>This could lead to very subtle bugs. However, since Chrome already uses -fvisibility-inlines-hidden, which has the same potential problem, we believe this is not a common issue.</p> <h2>Summary</h2> <p>/Zc:dllexportInlines- is like -fvisibility-inlines-hidden for DLLs and significantly reduces build times. We're excited that using Clang on Windows allows us to benefit from new features like this.</p> <h2>More information</h2> <p>For more information, see the <a href="https://clang.llvm.org/docs/UsersManual.html#the-zc-dllexportinlines-option">User's Manual for /Zc:dllexportInlines-</a>.</p> <p>The flag was added in Clang <a href="https://llvm.org/r346069">r346069</a>, which will be part of the Clang 8 release expected in March 2019. It's also available in the <a href="https://llvm.org/builds/">Windows Snapshot Build</a>.</p> <h2>Acknowledgements</h2> <p>/Zc:dllexportInlines- was implemented by Takuto Ikuta based on a prototype by Nico Weber.</p>
- Integration of libc++ and OpenMP packages into llvm-toolchainhttps://blog.llvm.org/2018/09/integration-of-libc-and-openmp-packages.htmlTue, 25 Sep 2018 08:29:00 +0000https://blog.llvm.org/2018/09/integration-of-libc-and-openmp-packages.html<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">A bit more than a year ago, we gave an </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"><a href="http://blog.llvm.org/2017/03/some-news-about-aptllvmorg.html">update about recent changes in apt.llvm.org</a></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">. Since then, we noticed an important increase of the usage of the service. Just last month, we saw more than 16.5TB of data being transferred from our CDN.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Thanks to the Google Summer of Code 2018, and after number of requests, we decided to focus our energy to bring new great projects from the LLVM ecosystems into </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"><a href="https://apt.llvm.org/">apt.llvm.org</a></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">.</span></div><div><br /></div><span id="docs-internal-guid-122fa429-7fff-ce8f-2a09-9dec6700e675"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Starting from version 7, libc++, libc++abi and OpenMP packages are available into the llvm-toolchain packages. This means that, just like clang, lldb or lldb, libc++, libc++abi and OpenMP packages are also built, tested and shipped on </span><span style="color: #1155cc; font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><a href="https://apt.llvm.org/" style="text-decoration-line: none;">https://apt.llvm.org/</a>.</span></span><br /><span id="docs-internal-guid-5eac656f-7fff-93be-d6ed-7d2759a4535e"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">The integration focuses to preserve the current usage of these libraries. The newly merged packages have adopted the llvm-toolchain versioning:</span><br /><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"><br /></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;"><span id="docs-internal-guid-5d62e05f-7fff-e14d-0c50-31e965f5c0d6"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">libc++ packages</span></span></span><br /><ul><li><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><span id="docs-internal-guid-b2f8be4b-7fff-5604-f87a-ca25bdd97e18"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">libc++1-7</span></span></span></span></li><li><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;"><span id="docs-internal-guid-a2a333d7-7fff-a25c-c5d4-c34505b88129"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">libc++-7-dev</span></span></span></span></span></li></ul><span id="docs-internal-guid-8c605b61-7fff-f726-ba8c-401b50835ca0"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">libc++abi packages</span></span><br /><ul><li><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><span id="docs-internal-guid-5203ff86-7fff-3c38-ae3c-d32665fb8d4f"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">libc++abi1-7</span></span></span></span></li><li><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;"><span id="docs-internal-guid-01426d62-7fff-5f1a-cd17-1acb65241ae3"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">libc++abi-7-dev</span></span></span></span></span></li></ul><span id="docs-internal-guid-1fc28e61-7fff-dbb6-6749-53b176e0e0c2"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">OpenMP packages</span></span><br /><ul><li><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><span id="docs-internal-guid-751b304c-7fff-24c0-953a-ce4405deaa52"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">libomp5-7</span></span></span></span></li><li><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><span style="font-size: 11pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">libomp-7-dev</span></span></span></li><li><span style="font-family: "arial";"><span style="font-size: 14.6667px; white-space: pre-wrap;">libomp-7-doc</span></span></li></ul><span id="docs-internal-guid-f84eaf02-7fff-be43-d8bc-ef510609f3ec"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">This packages are built twice a day for trunk. For version 7, only when new changes happen in the SVN branches.</span></span><br /><ul></ul></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-6e74fc9d-7fff-cec8-f74a-6df8706a7ae4"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;">Integration of libc++* packages</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-15524f01-7fff-4e4d-6d8c-fd387bece6d7"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Both libc++ and libc++abi packages are built at same time using the clang built during the process. The existing libc++ and libc++abi packages present in Debian and Ubuntu repositories will not be affected (they will be removed at some point). Newly integrated libcxx* packages are not co-installable with them.</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-bd64100d-7fff-666c-9f29-447f5b5aeeed"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Symlinks have been provided from the original locations to keep the library usage same.</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-24d86f69-7fff-c583-0732-85c34f57d446"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Example: /usr/lib/x86_64-linux-gnu/libc++.so.1.0 -> /usr/lib/llvm-7/lib/libc++.so.1.0</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-fb4b60c7-7fff-effa-85f3-1015ebd8d620"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">The usage of the libc++ remains super easy:</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-69f2fbb0-7fff-1c39-5670-241e4b0edeca"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Usage:</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-41ab907b-7fff-b51e-e5c5-ad61a6b30e0e"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">$ clang++-7 -std=c++11 -stdlib=libc++ foo.cpp</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-4a953a8c-7fff-df5d-3ca4-76fb11306a80"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">$ ldd ./a.out|grep libc++</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-1250612e-7fff-12f8-98af-a07f6cd562c2"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> libc++.so.1 => /usr/lib/x86_64-linux-gnu/libc++.so.1 (0x00007f62a1a90000)</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-34da2a2e-7fff-468f-8ba4-a7698b29b122"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> libc++abi.so.1 => /usr/lib/x86_64-linux-gnu/libc++abi.so.1 (0x00007f62a1a59000)</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-748944dd-7fff-ce84-8030-ee68a48bb092"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">In order to test new developments in libc++, we are also building the experimental features.</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-19d4819b-7fff-4051-782c-67508a15655c"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">For example, the following command will work out of the box:</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-fb08eaae-7fff-720e-a5af-22d36fba7424"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">$ clang++-7 -std=c++17 -stdlib=libc++ foo.cpp -lc++experimental -lc++fs</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-189f4079-7fff-ff2d-1d55-9d039dd77300"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;">Integration of OpenMP packages</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-eb46ad43-7fff-9868-f854-63a93e6d99f0"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">While </span><a href="https://tracker.debian.org/pkg/openmprtl" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">OpenMP packages</span></a><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"> have been present in the Debian and Ubuntu archives for a </span></span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">while, only a single version of the package was available.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-9615f4a3-7fff-ff5b-0c6f-94b18cd14d29"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">For now, the newly integrated packages creates a symlink from /usr/lib/libomp.so.5 to </span></span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">/usr/lib/llvm-7/lib/libomp.so.5 keeping the current usage same and making them non </span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">co-installable.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-53e9cb01-7fff-af4a-9532-eec2ef84fb7c"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">It can be used with clang through -fopenmp flag:</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-af3fc453-7fff-d096-505f-993de08734d7"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">$ clang -fopenmp foo.c</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-d6542b60-7fff-0347-0d01-5941ce41f7f0"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">The dependency packages providing the default libc++* and OpenMP package are also </span></span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">integrated in llvm-defaults. This means that the following command will install all these </span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">new packages at the current version:</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-96addc9b-7fff-9794-ff0a-f10371dbe598"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">$ apt-get install libc++-dev libc++abi-dev libomp-dev</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 12pt; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-ce21e6ca-7fff-17b3-6faf-72c098452ee1"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;">LLVM 7 => 8 transition</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-3748f10e-7fff-b3e6-b274-446c48e29b82"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">In parallel of the libc++ and OpenMP work,</span><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span><a href="https://apt.llvm.org/" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">https://apt.llvm.org/</span></a><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"> has been updated to </span></span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">reflect the branching of 7 from the trunk branches.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-f4abea1c-7fff-0b37-1c28-fdfc88b7f96a"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Therefore, we have currently on the platform:</span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><br /><div dir="ltr" style="margin-left: 0pt;"><table style="border-collapse: collapse; border: none;"><colgroup><col width="134"></col><col width="115"></col></colgroup><tbody><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-top: solid #000000 1pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">Stable</span></div></td><td style="border-bottom: solid #000000 1pt; border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-top: solid #000000 1pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">6.0</span></div></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-top: solid #000000 1pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">Qualification</span></div></td><td style="border-bottom: solid #000000 1pt; border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-top: solid #000000 1pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">7</span></div></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 1pt; border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-top: solid #000000 1pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">Development</span></div></td><td style="border-bottom: solid #000000 1pt; border-left: solid #000000 1pt; border-right: solid #000000 1pt; border-top: solid #000000 1pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">8</span></div></td></tr></tbody></table></div><span id="docs-internal-guid-5114ceee-7fff-3202-7f38-9d2f6b85a583"></span><br /><div dir="ltr" style="margin-left: 0pt;"><span id="docs-internal-guid-5114ceee-7fff-3202-7f38-9d2f6b85a583"><br /></span></div><span id="docs-internal-guid-5114ceee-7fff-3202-7f38-9d2f6b85a583"></span><div dir="ltr" style="margin-left: 0pt;"><span id="docs-internal-guid-5114ceee-7fff-3202-7f38-9d2f6b85a583"><span id="docs-internal-guid-9ecfb81b-7fff-8d17-16a6-2ef58b127a62"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Please note that, from version 7, the packages and libraries are called 7 (and not 7.0). </span></span></span></div><span id="docs-internal-guid-5114ceee-7fff-3202-7f38-9d2f6b85a583"><div dir="ltr" style="margin-left: 0pt;"><span id="docs-internal-guid-1132935b-7fff-32e1-97a7-d44a2a905231"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">For the rational and implementation, see </span><a href="https://reviews.llvm.org/D41869" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">https://reviews.llvm.org/D41869</span></a><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"> & </span></span><a href="https://reviews.llvm.org/D41808" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">https://reviews.llvm.org/D41808</span></a><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">.</span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><span id="docs-internal-guid-6fd5cf19-7fff-c3b2-d621-4ff2acb322e3"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">Stable packages of LLVM toolchain are already officially available </span><a href="https://tracker.debian.org/pkg/llvm-toolchain-7" style="text-decoration-line: none;"><span style="color: #1155cc; font-size: 12pt; vertical-align: baseline;">in Debian Buster</span></a><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;"> and </span></span></span><a href="https://launchpad.net/ubuntu/+source/llvm-toolchain-7" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">in Ubuntu Cosmic</span></a><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">.</span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><span id="docs-internal-guid-ce9e25ae-7fff-21e3-e2d0-f76cb2b89eb8"><span style="font-size: 18pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">Cosmic support</span></span></span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><span style="font-size: 18pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;"><br /></span></span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">In order to make sure that the LLVM toolchain does not have too many regressions with </span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">this new version, we also support the next Ubuntu version, 18.10, aka Cosmic.</span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-left: 0pt;"><span id="docs-internal-guid-71e97040-7fff-c2c7-d12e-eaa86bc7029b"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;">A Note on coinstallability</span></span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-left: 0pt;"><span id="docs-internal-guid-e630a53f-7fff-1ab7-5997-e54f23fcb0ba"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">We tried to make them coinstallable, in the resulting packages we had no control over </span></span><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">the libraries used during the runtime. This could lead to many </span><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">unforeseen</span><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"> issues. </span><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;">Keeping these in mind we settled to keep them conflicting with other versions.</span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 12pt; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-left: 0pt;"><span id="docs-internal-guid-506e92b8-7fff-29fc-37ab-1bba4513c609"><span style="font-family: "arial"; font-size: 18pt; vertical-align: baseline; white-space: pre-wrap;">Future work</span></span></div><div dir="ltr" style="margin-left: 0pt;"><ul><li><span style="font-family: "arial";"><span style="font-size: 24px; white-space: pre-wrap;"><span id="docs-internal-guid-433e97e7-7fff-6294-c143-0f184de8e97b"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">Code coverage build fails for newly integrated packages</span></span></span></span></li><li><span style="font-family: "arial";"><span style="font-size: 24px; white-space: pre-wrap;"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;"><span id="docs-internal-guid-bff3d48d-7fff-a432-738f-a5b778da69b7"><span style="font-size: 12pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline;">Move to a 2 phases build to generate clang binary using clang</span></span></span></span></span></li></ul><div><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><br /></span></span></div><div><span style="font-family: "arial"; font-size: 16px; white-space: pre-wrap;">Sources of the project are available on the gitlab instance of Debian: <a href="https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/tree/7">https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/tree/7</a> </span></div><div><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><br /></span></span></div><div><span style="font-family: "arial";"><span style="white-space: pre-wrap;"><br /></span></span></div><div><span id="docs-internal-guid-41151c85-7fff-d340-dce6-f45dc408e1c6"><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;">Reshabh Sharma & Sylvestre Ledru</span></span></div><div><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div><span style="font-family: "arial"; font-size: 12pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 14pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-left: 0pt;"><span style="font-family: "arial"; font-size: 14pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></span></div>
- Announcing the new LLVM Foundation Board of Directorshttps://blog.llvm.org/2018/09/announcing-new-llvm-foundation-board-of.htmlTue, 18 Sep 2018 09:00:00 +0000https://blog.llvm.org/2018/09/announcing-new-llvm-foundation-board-of.html<p>The <a href="http://llvm.org/foundation/">LLVM Foundation</a> is pleased to announce its new Board of Directors:</p> <br>Chandler Carruth <br>Mike Edwards (Treasurer) <br>Hal Finkel <br>Arnaud de Grandmaison <br>Anton Korobeynikov <br>Tanya Lattner (President) <br>Chris Lattner <br>John Regehr (Secretary) <br>Tom Stellard <p>Two new members and seven continuing members were elected to the nine person board. </p> <p>We want to thank David Kipping for his 2 terms on the board. David has been actively involved with the LLVM Developer Meetings and was the treasurer for the past 4 years. The treasurer is a time demanding position in that he supports the day to day operation of the foundation, balancing the books, and generates monthly treasurer reports. </p> <p>We also want to thank all the applicants to the board. When voting on new board members, we took into consideration all contributions (past and present) and current involvement in the LLVM community. We also tried to create a balanced board of individuals from a wide range of backgrounds and locations to provide a voice to as many groups within the LLVM community. Given this criteria and strong applicants, we increased the board from 8 members to 9.</p> <p>About the board of directors (listed alphabetically by last name):</p> <br><b>Chandler Carruth:</b><p>Chandler Carruth has been an active contributor to LLVM since 2007. Over the years, he has has worked on LLVMâs memory model and atomics, Clangâs C++ support, GCC-compatible driver, initial profile-aware code layout optimization pass, pass manager, IPO infrastructure, and much more. He is the current code owner of inlining and SSA formation.</p> <p>In addition to his numerous technical contributions, Chandler has led Googleâs LLVM efforts since 2010 and shepherded a number of new efforts that have positively and significantly impacted the LLVM project. These new efforts include things such as adding C++ modules to Clang, adding address and other sanitizers to Clang/LLVM, making Clang compatible with MSVC and available to the Windows C++ developer community, and much more. </p><p>Chandler works at Google Inc. as a technical lead for their C++ developer platform and has served on the LLVM Foundation board of directors for the last 4 years. </p> <b>Mike Edwards:</b><p>Mike Edwards is a relative newcomer to the LLVM community, beginning his involvement just a few years ago while working for Sony Playstation. Finding the LLVM community to be an incredibly amazing and welcoming group of people, Mike knew he had to find a way to contribute. Mikeâs previous work in DevOps led him to get involved in helping to work on the llvm.org infrastructure. Last year, with the help of the Board and several community members, Mike was able to get the llvm.org infrastructure moved onto a modern compute platform at Amazon Web Services. Mike is one of the maintainers of our llvm.org infrastructure. </p><p>Mike is currently working as a Software Engineer at Apple, Inc. working on the Continuous Integration and Quality Engineering efforts for LLVM and Clang development. </p> <b>Hal Finkel:</b><p>Hal Finkel has been an active contributor to the LLVM project since 2011. He is the code owner for the PowerPC target, the alias-analysis infrastructure, and other components. </p><p>In addition to his numerous technical contributions, Hal has chaired the LLVM in HPC workshop, which is held in conjunction with Super Computing (SC), for the last five years. This workshop provides a venue for the presentation of peer-reviewed HPC-related researching LLVM from both industry and academia. He has also been involved in organizing an LLVM-themed BoF session at SC and LLVM socials in Austin. </p><p>Hal is Lead for Compiler Technology and Programming Languages at Argonne National Laboratoryâs Leadership Computing Facility. </p> <b>Arnaud de Grandmaison:</b><p>Arnaud de Grandmaison has been hacking on LLVM projects since 2008. In addition to his open source contributions, he has worked for many years on private out-of-tree LLVM-based projects at Parrot, DiBcom, or Arm. He has also been a leader in the European LLVM community by organizing the EuroLLVM Developersâ meeting, Paris socials, and chaired or participated in numerous program committees for the LLVM Developersâ Meetings and other LLVM related conferences. </p><p>Arnaud has attended numerous LLVM Developersâ meetings and volunteered as moderator or presented as well. He also moderates several LLVM mailing lists. Arnaud is also very involved in community wide discussions and decisions such as re-licensing and code of conduct. </p><p>Arnaud is a Senior Principal Engineer at Arm. </p> <b>Anton Korobeynikov:</b><p>Anton Korobeynikov has been an active contributor to the LLVM project since 2006. Over the years, he has numerous technical contributions to areas including Windows support, ELF features, debug info, exception handling, and backends such as ARM and x86. He was the original author of the MSP430 and original System Z backend. </p><p>In addition to his technical contributions, Anton has maintained LLVMâs participation in Google Summer of Code by managing applications, deadlines, and overall organization. He also supports the LLVM infrastructure and has been on numerous program committees for the LLVM Developersâ Meetings (both US and EuroLLVM). </p><p>Anton is currently an associate professor at the Saint Petersburg State University and has served on the LLVM Foundation board of directors for the last 4 years. </p> <b>Tanya Lattner:</b><p>Tanya Lattner has been involved in the LLVM project for over 14 years. She began as a graduate student who wrote her master's thesis using LLVM, and continued on using and extending LLVM technologies at various jobs during her career as a compiler engineer. </p><p>Tanya has been organizing the US LLVM Developersâ meeting since 2008 and attended every developer meeting. She was the LLVM release manager for 3 years, moderates the LLVM mailing lists, and helps administer the LLVM infrastructure servers, mailing lists, bugzilla, etc. Tanya has also been on the program committee for the US LLVM Developersâ meeting (4+ years) and the EuroLLVM Developersâ Meeting. </p><p>With the support of the initial board of directors, Tanya created the LLVM Foundation, defined its charitable and education mission, and worked to get 501(c)(3) status. </p><p>Tanya is the Chief Operating Officer and has served as the President of the LLVM Foundation board for the last 4 years. </p> <b>Chris Lattner:</b><p>Chris Lattner is well known as the founder for the LLVM project and has a lengthy history of technical contributions to the project over the years. He drove much of the early implementation, architecture, and design of LLVM and Clang. </p><p>Chris has attended every LLVM Developersâ meeting, and presented at many of them. He helped drive the conception and incorporation of the LLVM Foundation, and has served as its secretary. Chris also grants commit access to the LLVM Project, moderates mailing lists, moderates and edits the LLVM blog, and drives important non-technical discussions and policy decisions related to the LLVM project. </p><p>Chris manages a team building machine learning infrastructure at Google and has served on the LLVM Foundation board of directors for the last 4 years. </p> <b>John Regehr:</b><p>John Regehr has been involved in LLVM for a number of years. As a professor of computer science at the University of Utah, his research specializes in compiler correctness and undefined behavior. He is well known within the LLVM community for the hundreds of bug reports his group has reported to LLVM/Clang. </p><p>John was a project lead for IOC, a Clang based integer overflow checker that eventually became the basis for the integer parts of UBSan. He was also the primary developer of C-Reduce which utilizes Clang as a library and is often used as a test case reducer for compiler issues. </p><p>In addition to his technical contributions, John has served on several LLVM-related program committees. He also has a widely read blog about LLVM and other compiler-related issues (Embedded in Academia). </p> <b>Tom Stellard:</b><p>Tom Stellard has been contributing to the LLVM project since 2012. He was the original author of the AMDGPU backend and was also an active contributor to libclc. He has been the LLVM projectâs stable release manager since 2014. </p><p>Tom is currently a Software Engineer at Red Hat and is the technical lead for emerging toolchains including Clang/LLvm. He also maintains the LLVM packages for the Fedora project.</p>
- Announcing the program for the 2018 LLVM Developers' Meeting Bay Areahttps://blog.llvm.org/2018/08/announcing-program-for-2018-llvm.htmlFri, 31 Aug 2018 16:29:00 +0000https://blog.llvm.org/2018/08/announcing-program-for-2018-llvm.htmlThe LLVM Foundation is excited to announce the program for the <a href="https://llvm.org/devmtg/2018-10/">2018 LLVM Developers' Meeting</a> in San Jose, CA on October 17 & 18. <br />As a reminder, ticket prices for the event will increase on September 17th. <a href="https://www.eventbrite.com/e/2018-llvm-developers-meeting-bay-area-tickets-47003409463">Purchase your tickets today</a>! <br /><b>Technical Talks</b><br /><ul><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk1">Lessons Learned Implementing Common Lisp with LLVM over Six Years</a> - Christian Schafmeister</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk2">Porting Function merging pass to thinlto</a> - Aditya Kumar</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk3">Build Impact of Explicit and C++ Standard Modules</a> - David Blaikie</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk4">Profile Guided Code Layout in LLVM and LLD</a> - Michael Spencer</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk5">Developer Toolchain for the Nintendo Switch</a> - Bob Campbell, Jeff Sirois</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk6">Methods for Maintaining OpenMP Semantics without Being Overly Conservative</a> - Jin Lin, Ernesto Su, Xinmin Tian</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk7">Understanding the performance of code using LLVM's Machine Code Analyzer (llvm-mca)</a> - Andrea Di Biagio, Matt Davis</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk8">Art Class for Dragons: Supporting GPU compilation without metadata hacks!</a> - Neil Hickey</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk9">Implementing an OpenCL compiler for CPU in LLVM</a> - Evgeniy Tyurin</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk10">Working with Standalone Builds of LLVM sub-projects</a> - Tom Stellard</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk11">Loop Transformations in LLVM: The Good, the Bad, and the Ugly</a> - Michael Kruse, Hal Finkel</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk12">Efficiently Implementing Runtime Metadata with LLVM</a> - Joe Groff, Doug Gregor</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk13">Coroutine Representations and ABIs in LLVM</a> - John McCall</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk14">Glow: LLVM-based machine learning compiler</a> - Nadav Rotem, Jakob Olesen</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk15">Graph Program Extraction and Device Partitioning in Swift for TensorFlow</a> - Mingsheng Hong, Chris Lattner</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk16">Memory Tagging, how it improves C++ memory safety, and what does it mean for compiler optimizations</a> - Kostya Serebryany, Evgenii Stepanov, Vlad Tsyrklevich</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk17">Improving code reuse in clang tools with clangmetatool</a> - Daniel Ruoso</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk18">Sound Devirtualization in LLVM</a> - Piotr Padlewski, Krzysztof Pszeniczny</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk24">Extending the SLP vectorizer to support variable vector widths</a> - Vasileios Porpodas, Rodrigo C. O. Rocha, LuÃs F. W. Góes</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk19">Revisiting Loop Fusion, and its place in the loop transformation framework.</a> - Johannes Doerfert, Kit Barton, Hal Finkel, Michael Kruse</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk20">Optimizing Indirections, using abstractions without remorse.</a> - Johannes Doerfert, Hal Finkel</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk21">Outer Loop Vectorization in LLVM: Current Status and Future Plans</a> - Florian Hahn, Satish Guggilla, Diego Caballero</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk22">Stories from RV: The LLVM vectorization ecosystem</a> - Simon Moll, Matthias Kurtenacker, Sebastian Hack</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#talk23">Faster, Stronger C++ Analysis with the Clang Static Analyzer</a> - George Karpenkov, Artem Dergachev</li></ul><b>Tutorials</b><br /><ul><li><a href="https://www.blogger.com/llvm.org/talk-abstracts.html#tutorial1">Updating ORC JIT for Concurrency</a> - Lang Hames, Breckin Loggins</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#tutorial2">Register Allocation: More than Coloring</a> - Matthias Braun</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#tutorial3">How to use LLVM to optimize your parallel programs</a> - William S. Moses</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#tutorial4">LLVM backend development by example (RISC-V)</a> - Alex Bradbury</li></ul><b>Birds of a Feather</b><br /><ul><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof1">Debug Info BoF</a> - Vedant Kumar, Adrian Prantl</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof0">Lifecycle of LLVM bug reports</a> - Kristof Beyls, Paul Robinson</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof2">GlobalISel Design and Development</a> - Amara Emerson</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof3">Migrating to C++14, and beyond!</a> - JF Bastien</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof4">Ideal versus Reality: Optimal Parallelism and Offloading Support in LLVM</a> - Xinmin Tian, Hal Finkel, TB Schardl, Johannes Doerfert, Vikram Adve</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof5">Implementing the parallel STL in libc++</a> - Louis Dionne</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof6">Clang Static Analyzer BoF</a> - Devin Coughlin</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#bof7">LLVM Foundation BoF</a> - LLVM Foundation Board of Directors</li></ul><b>Lightning Talks</b><br /><ul><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt1">Automatic Differentiation in C/C++ Using Clang Plugin Infrastructure</a> - Vassil Vassilev, Aleksandr Efremov</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt2">More efficient LLVM devs: 1000x faster build file generation, -j1000 builds, and O(1) test execution</a> - Nico Weber</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt3">Heap-to-Stack Conversion</a> - Hal Finkel</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt4">TWINS - This Workflow is Not Scrum: Adapting Agile for Open Source Interaction</a> - Joshua Magee</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt5">Mutating the clang AST from Plugins</a> - Andrei Homescu, Per Larsen</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt6">atJIT: an online, feedback-directed optimizer for C++</a> - Kavon Farvardin, Hal Finkel, Michael Kruse, John Reppy</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt7">Repurposing GCC Regression for LLVM Based Tool Chains</a> - Jeremy Bennett, Simon Cook, Ed Jones</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt8">ThinLTO Summaries in JIT Compilation</a> - Stefan Gränitz</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt9">Refuting False Bugs in the Clang Static Analyzer using SMT Solvers</a> - Mikhail R. Gadelha</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt0">Whatâs New In Outlining</a> - Jessica Paquette</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt10">DWARF v5 Highlights - Why You Care</a> - Paul Robinson, Pavel Labath, Wolfgang Pieb</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt11">Using TAPI to Understand APIs and Speed Up Builds</a> - Steven Wu, Juergen Ributzka</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt12">Hardware Interference Size</a> - JF Bastien</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt13">Dex: efficient symbol index for Clangd</a> - Kirill Bobyrev, Eric Liu, Sam McCall, Ilya Biryukov</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt14">Flang Update</a> - Steve Scalpone</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt15">clang-doc: an elegant generator for more civilized documentation</a> - Julie Hockett</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt16">Code Coverage with CPU Performance Monitoring Unit</a> - Ivan Baev, Bharathi Seshadri, Stefan Pejic</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt17">VecClone Pass: Function Vectorization via LoopVectorizer</a> - Matt Masten, Evgeniy Tyurin, Konstantina Mitropoulou</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt18">ISL Memory Management Using Clang Static Analyzer</a> - Malhar Thakkar, Ramakrishna Upadrasta</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt19">Eliminating always_inline in libc++: a journey of visibility and linkage</a> - Louis Dionne</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#lt20">Error Handling in Libraries: A Case Study</a> - James Henderson</li></ul><b>Posters</b><br /><ul><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster0">Gaining fine-grain control over pass management</a> - serge guelton, adrien guinet, pierrick brunet, juan manuel martinez, béatrice creusillet</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster1">Integration of OpenMP, libcxx and libcxxabi packages into LLVM toolchain</a> - Reshabh Sharma</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster2">Improving Debug Information in LLVM to Recover Optimized-out Function Parameters</a> - Ananthakrishna Sowda, Djordje Todorovic, Nikola Prica, Ivan Baev</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster3">Automatic Compression for LLVM RISC-V</a> - Sameer AbuAsal, Ana Pazos</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster4">Guaranteeing the Correctness of LLVM RISC-V Machine Code with Fuzzing</a> - Jocelyn Wei, Ana Pazos, Mandeep Singh Grang</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster5">NEC SX-Aurora - A Scalable Vector Architecture</a> - Kazuhisa Ishizaka, Kazushi Marukawa, Erich Focht, Simon Moll, Matthias Kurtenacker, Sebastian Hack</li><li><a href="https://llvm.org/devmtg/2018-10/talk-abstracts.html#poster8">Extending Clang Static Analyzer to enable Cross Translation Unit Analysis</a> - Varun Subramanian</li><li><a href="https://llvm.org/llvm-dev/2018-10/talk-abstracts.html#poster9">Leveraging Polyhedral Compilation in Chapel Compiler</a> - Siddharth Bhat, Michael Ferguson, Philip Pfaffe, Sahil Yerawar</li></ul>
- 2018 LLVM Foundation's Women in Compilers and Tools Workshophttps://blog.llvm.org/2018/08/2018-llvm-foundations-women-in.htmlThu, 23 Aug 2018 22:41:00 +0000https://blog.llvm.org/2018/08/2018-llvm-foundations-women-in.html<span id="docs-internal-guid-dd2b8ffe-7fff-6023-32ca-55732f828bdd"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-dd2b8ffe-7fff-6023-32ca-55732f828bdd"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: ">The LLVM Foundation is excited to announce our first half day Women in Compilers and Tools Workshop held the day before the </span><a href="http://llvm.org/devmtg/2018-10/" style="text-decoration: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 11pt; text-decoration: underline; vertical-align: baseline; ">2018 LLVM Developersâ Meeting - Bay Area</span></a><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; ">. The workshop will be held at the </span><a href="https://www.fairmont.com/san-jose/" style="text-decoration: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 11pt; text-decoration: underline; vertical-align: baseline; ">Fairmont Hotel</span></a><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline;"> on October 16th from 1:00-6:30PM and includes a cocktail reception.</span></span><br /><span id="docs-internal-guid-a42b87be-7fff-7c26-c9f8-3f49d14afe8b"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">This event aims to connect women in the field of compilers and tools and provide them with ideas and techniques to overcome barriers or enhance their careers. It also is open to anyone (not just women) who are interested in increasing diversity within the LLVM community, their workplace or university. </span><br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">Registration for the event will open on Monday, August 27th at 9:00AM PDT. Attendance is limited to 100 attendees and tickets will be priced at $50 (students $25). Please see the </span><a href="https://www.eventbrite.com/e/2018-llvm-foundations-women-in-compilers-and-tools-workshop-tickets-49442812784" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; text-decoration: underline; vertical-align: baseline; ">EventBrite registration page</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; "> for details.</span></div><b id="docs-internal-guid-3233e733-7fff-870b-0004-336c58e3aca6" style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">The workshop will consist of 3 topics described below:</span></div><b style="font-weight: normal;"><br /></b><ol> <li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space:"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">Inner Critic: How to Deal with Your Imposter Syndrome</span></div></li></ol> <div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; "><span class="Apple-tab-span" style="white-space:"> </span></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Presented by </span><a href="https://www.womencatalysts.com/" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; text-decoration: underline; vertical-align: baseline; ">Women Catalysts</span></a></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">You're smart. People really like you. And yet, you can't shake the feeling that maybe you don't really deserve your success. Or that someone else can do what you do better...and what if your boss can see it too? You are not alone: it's called the Imposter Syndrome. Believe it or not, the most confident and successful people often fear that</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; "> they are actually inadequate. The great Maya Angelou once said, "I have written 11 books, but each time I think, 'Uh-oh, they're going to find out now. I've run a game on everybody, and they're going to find me out.â" But it doesn't have to be that way. In this workshop, you'll learn to identify the voice of your Imposter Syndrome and develop with strategies for dealing with your inner critics.</span></div><b style="font-weight: normal;"><br /></b><ol start="2" style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;">Present! A Techie's Guide to Public Speaking</span></div></li></ol><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Presented by </span><a href="https://karencatlin.com/" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; text-decoration: underline; vertical-align: baseline;">Karen Catlin</span></a></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">To grow your career, you know what you need to do: improve your public speaking skills.</span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">Public speaking provides the visibility and professional credibility that helps you score the next big opportunity. But even more important is the fact that it transforms the way you communicate. Improved confidence and the ability to convey messages clearly will impact your relationships with your managers, coworkers, customers, industry peers, and even potential new hires.</span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">In this presentation, Karen Catlin will cover the importance of speaking at conferences and events, along with strategies to get started. She'll share some favorite tips from the book she co-authored with Poornima Vijayashanker, "Present! A Techie's Guide to Public Speaking." And she'll tell some embarrassing stories that are just too good to keep to herself. </span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">About Karen: After spending 25 years building software products, Karen Catlin is now an advocate for women in the tech industry. Sheâs a leadership coach, a keynote and TEDx speaker, and co-author of "Present! A Techieâs Guide to Public Speaking.â </span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">Formerly, Karen was a vice president of engineering at Macromedia and Adobe.</span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Karen holds a computer science degree from Brown University and serves as an advisor to Brown's Computer Science Diversity Initiative. Sheâs also on the Advisory Boards for The Womenâs CLUB of Silicon Valley and WEST (Women Entering & Staying in Technology). </span></div><b style="font-weight: normal;"><br /></b><ol start="3" style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; list-style-type: decimal; text-decoration: none; vertical-align: baseline; "><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline;"> Update on Women in Compilers & Tools Program</span></div></li></ol><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; "><span class="Apple-tab-span" style="white-space:"> </span></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline;">Presented by </span>Tanya Lattner</div> <div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; "><span class="Apple-tab-span""> </span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">Over the past year we have hosted panels and BoFs on women in compilers and tools. We now need to take many of the items discussed during the events and put them into action. We will discuss some key areas and potentially break into smaller groups to determine action plans and steps to move forward.</span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; "></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; ">FAQ:</span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; ">Do I need to attend the LLVM Developersâ Meeting to attend this event?</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; "></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">This is an independent event which is open to anyone. </span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; ">Is this a women only event?</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; "><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">Anyone is welcome to attend that values diversity within the field of compiler and tools. These topics can relate to anyone, not just women, and our mission is to improve inclusion and diversity in general. </span></div><b style="font-weight: normal;"><br /></b><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; =">Is there a financial hardship discount?</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; "><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; ">We have discounted the tickets for all attendees but please reach out to the organizer and we will decide on a case by case basis.</span></div><div><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; "><br /></span></div></div></div>
- DragonFFI: FFI/JIT for the C language using Clang/LLVMhttps://blog.llvm.org/2018/03/dragonffi-ffijit-for-c-language-using.htmlTue, 13 Mar 2018 07:45:00 +0000https://blog.llvm.org/2018/03/dragonffi-ffijit-for-c-language-using.html<style type="text/css"> pre.address { margin-bottom: 0 ; margin-top: 0 ; font: inherit } li { text-indent: 0; } pre.code .ln { color: grey; } /* line numbers */ pre.code, code { text-indent: 0; background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } pre.code .literal.string, code .literal.string { color: #0C5404 } pre.code .name.builtin, code .name.builtin { color: #352B84 } pre.code .deleted, code .deleted { background-color: #DEB0A1} pre.code .inserted, code .inserted { background-color: #A3D289} span.classifier { font-family: sans-serif ; font-style: oblique } span.classifier-delimiter { font-family: sans-serif ; font-weight: bold } span.interpreted { font-family: sans-serif } span.option { white-space: nowrap } span.pre { white-space: pre } span.problematic { color: red } span.section-subtitle { /* font-size relative to parent (h1..h6 element) */ font-size: 80% } </style> <br /><h3>Introduction</h3>A <a href="https://en.wikipedia.org/wiki/Foreign_function_interface" target="_blank">foreign function interface</a> is "a mechanism by which a program written in one programming language can call routines or make use of services written in another".<br />In the case of DragonFFI, we expose a library that allows calling C functions and using C structures from any languages. Basically, we want to be able to do this, let's say in Python:<br /><pre class="code python literal-block"><span class="keyword namespace">import</span> <span class="name namespace">pydffi</span><br /><span class="name">CU</span> <span class="operator">=</span> <span class="name">pydffi</span><span class="operator">.</span><span class="name">FFI</span><span class="punctuation">()</span><span class="operator">.</span><span class="name">cdef</span><span class="punctuation">(</span><span class="literal string double">"int puts(const char* s);"</span><span class="punctuation">);</span><br /><span class="name">CU</span><span class="operator">.</span><span class="name">funcs</span><span class="operator">.</span><span class="name">puts</span><span class="punctuation">(</span><span class="literal string double">"hello world!"</span><span class="punctuation">)</span><br /></pre>or, in a more advanced way, for instance to use <a href="https://www.libarchive.org/">libarchive</a> directly from Python:<br /><pre class="code python literal-block"><span class="keyword namespace">import</span> <span class="name namespace">pydffi</span><br /><span class="name">pydffi</span><span class="operator">.</span><span class="name">dlopen</span><span class="punctuation">(</span><span class="literal string double">"/path/to/libarchive.so"</span><span class="punctuation">)</span><br /><span class="name">CU</span> <span class="operator">=</span> <span class="name">pydffi</span><span class="operator">.</span><span class="name">FFI</span><span class="punctuation">()</span><span class="operator">.</span><span class="name">cdef</span><span class="punctuation">(</span><span class="literal string double">"#include <archive.h>"</span><span class="punctuation">)</span><br /><span class="name">a</span> <span class="operator">=</span> <span class="name">funcs</span><span class="operator">.</span><span class="name">archive_read_new</span><span class="punctuation">()</span><br /><span class="keyword">assert</span> <span class="name">a</span><br /><span class="operator">...</span><br /></pre>This blog post presents related works, their drawbacks, then how Clang/LLVM is used to circumvent these drawbacks, the inner working of DragonFFI and further ideas.<br />The code of the project is available on GitHub: <a href="https://github.com/aguinet/dragonffi">https://github.com/aguinet/dragonffi</a>. Python 2/3 wheels are available for Linux/OSX x86/x64. Python 3.6 wheels are available for Windows x64. On all these architectures, just use:<br /><pre class="code bash literal-block">$ pip install pydffi<br /></pre>and play with it :)<br /><br />See below for more information.<br /><br /><h3>Related work</h3><tt class="docutils literal">libffi</tt> is the reference library that provides a FFI for the C language. <tt class="docutils literal">cffi</tt> is a Python binding around this library that also uses <tt class="docutils literal">PyCParser</tt>to be able to easily declare interfaces and types. Both these libraries have limitations, among them:<br /><ul class="simple"><li><tt class="docutils literal">libffi</tt> does not support the Microsoft x64 ABI under Linux x64. It isn't that trivial to add a new ABI (hand-written ABI, get the ABI right, ...), while a lot of effort have already been put into compilers to get these ABIs right.</li><li><tt class="docutils literal">PyCParser</tt> only supports a very limited subset of C (no includes, function attributes, ...).</li></ul>Moreover, in 2014, Jordan Rose and John McCall from Apple made a <a href="https://llvm.org/devmtg/2014-10/Slides/Skip%20the%20FFI.pdf">talk</a> at the LLVM developer meeting of San José about how Clang can be used for C interoperability. This talk also shows various ABI issues, and has been a source of inspiration for DragonFFI at the beginning.<br /><br />Somehow related, Sean Callanan, who worked on <tt class="docutils literal">lldb</tt>, gave a <a href="http://llvm.org/devmtg/2017-10/#talk5">talk</a> in 2017 at the LLVM developer meeting of San José on how we could use parts of Clang/LLVM to implement some kind of <tt class="docutils literal">eval()</tt> for C++. What can be learned from this talk is that debuggers like <tt class="docutils literal">lldb</tt> must also be able to call an arbitrary C function, and uses debug information among other things to solve it (what we also do, see below :)).<br /><br />DragonFFI is based on Clang/LLVM, and thanks to that it is able to get around these issues:<br /><ul class="simple"><li>it uses Clang to parse header files, allowing direct usage of a C library headers without adaptation;</li><li>it support as many calling conventions and function attributes as Clang/LLVM do;</li><li>as a bonus, Clang and LLVM allows on-the-fly compilation of C functions, without relying on the presence of a compiler on the system (you still need the headers of the system's libc thought, or MSVCRT headers under Windows);</li><li>and this is a good way to have fun with Clang and LLVM! :)</li></ul>Let's dive in!<br /><h3>Creating an FFI library for C</h3><h4>Supporting C ABIs</h4>A C function is always compiled for a given C ABI. The C ABI isn't defined per the official C standards, and is system/architecture-dependent. Lots of things are defined by these ABIs, and it can be quite error prone to implement.<br /><br />To see how ABIs can become complex, let's compile this C code:<br /><br /><pre class="code c literal-block"><span class="keyword">typedef</span> <span class="keyword">struct</span> <span class="punctuation">{</span><br /> <span class="keyword type">short</span> <span class="name">a</span><span class="punctuation">;</span><br /> <span class="keyword type">int</span> <span class="name">b</span><span class="punctuation">;</span><br /><span class="punctuation">}</span> <span class="name">A</span><span class="punctuation">;</span><br /><br /><span class="keyword type">void</span> <span class="name function">print_A</span><span class="punctuation">(</span><span class="name">A</span> <span class="name">s</span><span class="punctuation">)</span> <span class="punctuation">{</span><br /> <span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"%d %d</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">s</span><span class="punctuation">.</span><span class="name">a</span><span class="punctuation">,</span> <span class="name">s</span><span class="punctuation">.</span><span class="name">b</span><span class="punctuation">);</span><br /><span class="punctuation">}</span><br /></pre><br />Compiled for Linux x64, it gives this LLVM IR:<br /><pre class="code llvm literal-block"><span class="keyword"><br /></span></pre><pre class="code llvm literal-block"><span class="keyword">target</span> <span class="keyword">datalayout</span> <span class="punctuation">=</span> <span class="literal string">"e-m:e-i64:64-f80:128-n8:16:32:64-S128"</span><br /><span class="keyword">target</span> <span class="keyword">triple</span> <span class="punctuation">=</span> <span class="literal string">"x86_64-pc-linux-gnu"</span><br /><br /><span class="name variable global">@.str</span> <span class="punctuation">=</span> <span class="keyword">private</span> <span class="keyword">unnamed_addr</span> <span class="keyword">constant</span> <span class="punctuation">[</span><span class="literal number">7</span> <span class="keyword">x</span> <span class="keyword">i8</span><span class="punctuation">]</span> <span class="keyword">c</span><span class="literal string">"%d %d\0A\00"</span><span class="punctuation">,</span> <span class="keyword">align</span> <span class="literal number">1</span><br /><br /><span class="keyword">define</span> <span class="keyword type">void</span> <span class="name variable global">@print_A</span><span class="punctuation">(</span><span class="keyword">i64</span><span class="punctuation">)</span> <span class="keyword">local_unnamed_addr</span> <span class="punctuation">{</span><br /> <span class="name variable anonymous">%2</span> <span class="punctuation">=</span> <span class="keyword">trunc</span> <span class="keyword">i64</span> <span class="name variable anonymous">%0</span> <span class="keyword">to</span> <span class="keyword">i32</span><br /> <span class="name variable anonymous">%3</span> <span class="punctuation">=</span> <span class="keyword">lshr</span> <span class="keyword">i64</span> <span class="name variable anonymous">%0</span><span class="punctuation">,</span> <span class="literal number">32</span><br /> <span class="name variable anonymous">%4</span> <span class="punctuation">=</span> <span class="keyword">trunc</span> <span class="keyword">i64</span> <span class="name variable anonymous">%3</span> <span class="keyword">to</span> <span class="keyword">i32</span><br /> <span class="name variable anonymous">%5</span> <span class="punctuation">=</span> <span class="keyword">shl</span> <span class="keyword">i32</span> <span class="name variable anonymous">%2</span><span class="punctuation">,</span> <span class="literal number">16</span><br /> <span class="name variable anonymous">%6</span> <span class="punctuation">=</span> <span class="keyword">ashr</span> <span class="keyword">exact</span> <span class="keyword">i32</span> <span class="name variable anonymous">%5</span><span class="punctuation">,</span> <span class="literal number">16</span><br /> <span class="name variable anonymous">%7</span> <span class="punctuation">=</span> <span class="keyword">tail</span> <span class="keyword">call</span> <span class="keyword">i32</span> <span class="punctuation">(</span><span class="keyword">i8</span><span class="punctuation">*,</span> <span class="punctuation">...)</span> <span class="name variable global">@printf</span><span class="punctuation">(</span><span class="keyword">i8</span><span class="punctuation">*</span> <span class="keyword">getelementptr</span> <span class="keyword">inbounds</span> <span class="punctuation">([</span><span class="literal number">7</span> <span class="keyword">x</span> <span class="keyword">i8</span><span class="punctuation">],</span> <span class="punctuation">[</span><span class="literal number">7</span> <span class="keyword">x</span> <span class="keyword">i8</span><span class="punctuation">]*</span> <span class="name variable global">@.str</span><span class="punctuation">,</span> <span class="keyword">i64</span> <span class="literal number">0</span><span class="punctuation">,</span> <span class="keyword">i64</span> <span class="literal number">0</span><span class="punctuation">),</span> <span class="keyword">i32</span> <span class="name variable anonymous">%6</span><span class="punctuation">,</span> <span class="keyword">i32</span> <span class="name variable anonymous">%4</span><span class="punctuation">)</span><br /> <span class="keyword">ret</span> <span class="keyword type">void</span><br /><span class="punctuation">}</span><br /></pre><br />What happens here is what is called <i>structure coercion</i>. To optimize some function calls, some ABIs pass structure values through registers. For instance, an <tt class="docutils literal"><span class="pre">llvm::ArrayRef</span></tt> object, which is basically a structure with a pointer and a size (see <a href="https://github.com/llvm-mirror/llvm/blob/release_60/include/llvm/ADT/ArrayRef.h#L51">https://github.com/llvm-mirror/llvm/blob/release_60/include/llvm/ADT/ArrayRef.h#L51</a>), is passed through registers (though this optimization isn't guaranteed by any standard).<br /><br />It is important to understand that ABIs are complex things to implement and we don't want to redo this whole work by ourselves, particularly when LLVM/Clang already know how.<br /><h4>Finding the right type abstraction</h4>We want to list every types that is used in a parsed C file. To achieve that goal, various information are needed, among which:<br /><ul class="simple"><li>the function types, and their calling convention</li><li>for structures: field offsets and names</li><li>for union/enums: field names (and values)</li></ul>On one hand, we have seen in the previous section that the LLVM IR is too Low Level (as in <b>Low Level</b> Virtual Machine) for this. On the other hand, Clang's AST is too high level. Indeed, let's print the Clang AST of the code above:<br /><pre class="code bash literal-block"><span class="operator">[</span>...<span class="operator">]</span><br /><span class="punctuation">|</span>-RecordDecl 0x5561d7f9fc20 <a.c:1:9, line:4:1> line:1:9 struct definition<br /><span class="punctuation">|</span> <span class="punctuation">|</span>-FieldDecl 0x5561d7ff4750 <line:2:3, col:9> col:9 referenced a <span class="literal string single">'short'</span><br /><span class="punctuation">|</span> <span class="literal string backtick">`</span>-FieldDecl 0x5561d7ff47b0 <line:3:3, col:7> col:7 referenced b <span class="literal string single">'int'</span><br /></pre>We can see that there is no information about the structure layout (padding, ...). There's also no information about the size of standard C types. As all of this depends on the backend used, it is not surprising that these informations are not present in the AST.<br /><br />The right abstraction appears to be the LLVM metadata produced by Clang to emit DWARF or PDB structures. They provide structure fields offset/name, various basic type descriptions, and function calling conventions. Exactly what we need! For the example above, this gives (at the LLVM IR level, with some inline comments):<br /><br /><pre class="code llvm literal-block"><span class="keyword">target</span> <span class="keyword">triple</span> <span class="punctuation">=</span> <span class="literal string">"x86_64-pc-linux-gnu"</span><br /><span class="name variable">%struct.A</span> <span class="punctuation">=</span> <span class="keyword">type</span> <span class="punctuation">{</span> <span class="keyword">i16</span><span class="punctuation">,</span> <span class="keyword">i32</span> <span class="punctuation">}</span><br /><span class="name variable global">@.str</span> <span class="punctuation">=</span> <span class="keyword">private</span> <span class="keyword">unnamed_addr</span> <span class="keyword">constant</span> <span class="punctuation">[</span><span class="literal number">7</span> <span class="keyword">x</span> <span class="keyword">i8</span><span class="punctuation">]</span> <span class="keyword">c</span><span class="literal string">"%d %d\0A\00"</span><span class="punctuation">,</span> <span class="keyword">align</span> <span class="literal number">1</span><br /><br /><span class="keyword">define</span> <span class="keyword type">void</span> <span class="name variable global">@print_A</span><span class="punctuation">(</span><span class="keyword">i64</span><span class="punctuation">)</span> <span class="keyword">local_unnamed_addr</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!7</span> <span class="punctuation">{</span><br /> <span class="name variable anonymous">%2</span> <span class="punctuation">=</span> <span class="keyword">trunc</span> <span class="keyword">i64</span> <span class="name variable anonymous">%0</span> <span class="keyword">to</span> <span class="keyword">i32</span><br /> <span class="name variable anonymous">%3</span> <span class="punctuation">=</span> <span class="keyword">lshr</span> <span class="keyword">i64</span> <span class="name variable anonymous">%0</span><span class="punctuation">,</span> <span class="literal number">32</span><br /> <span class="name variable anonymous">%4</span> <span class="punctuation">=</span> <span class="keyword">trunc</span> <span class="keyword">i64</span> <span class="name variable anonymous">%3</span> <span class="keyword">to</span> <span class="keyword">i32</span><br /> <span class="keyword">tail</span> <span class="keyword">call</span> <span class="keyword type">void</span> <span class="name variable global">@llvm.dbg.value</span><span class="punctuation">(</span><span class="keyword type">metadata</span> <span class="keyword">i32</span> <span class="name variable anonymous">%4</span><span class="punctuation">,</span> <span class="keyword">i64</span> <span class="literal number">0</span><span class="punctuation">,</span> <span class="keyword type">metadata</span> <span class="name variable anonymous">!18</span><span class="punctuation">,</span> <span class="keyword type">metadata</span> <span class="name variable anonymous">!19</span><span class="punctuation">),</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!20</span><br /> <span class="keyword">tail</span> <span class="keyword">call</span> <span class="keyword type">void</span> <span class="name variable global">@llvm.dbg.declare</span><span class="punctuation">(</span><span class="keyword type">metadata</span> <span class="name variable">%struct.A</span><span class="punctuation">*</span> <span class="keyword">undef</span><span class="punctuation">,</span> <span class="keyword type">metadata</span> <span class="name variable anonymous">!18</span><span class="punctuation">,</span> <span class="keyword type">metadata</span> <span class="name variable anonymous">!21</span><span class="punctuation">),</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!20</span><br /> <span class="name variable anonymous">%5</span> <span class="punctuation">=</span> <span class="keyword">shl</span> <span class="keyword">i32</span> <span class="name variable anonymous">%2</span><span class="punctuation">,</span> <span class="literal number">16</span><span class="punctuation">,</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!22</span><br /> <span class="name variable anonymous">%6</span> <span class="punctuation">=</span> <span class="keyword">ashr</span> <span class="keyword">exact</span> <span class="keyword">i32</span> <span class="name variable anonymous">%5</span><span class="punctuation">,</span> <span class="literal number">16</span><span class="punctuation">,</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!22</span><br /> <span class="name variable anonymous">%7</span> <span class="punctuation">=</span> <span class="keyword">tail</span> <span class="keyword">call</span> <span class="keyword">i32</span> <span class="punctuation">(</span><span class="keyword">i8</span><span class="punctuation">*,</span> <span class="punctuation">...)</span> <span class="name variable global">@printf</span><span class="punctuation">(</span><span class="keyword">i8</span><span class="punctuation">*</span> <span class="keyword">getelementptr</span> <span class="keyword">inbounds</span> <span class="punctuation">([...]</span> <span class="name variable global">@.str</span><span class="punctuation">,</span> <span class="keyword">i64</span> <span class="literal number">0</span><span class="punctuation">,</span> <span class="keyword">i64</span> <span class="literal number">0</span><span class="punctuation">),</span> <span class="keyword">i32</span> <span class="name variable anonymous">%6</span><span class="punctuation">,</span> <span class="keyword">i32</span> <span class="name variable anonymous">%4</span><span class="punctuation">),</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!23</span><br /> <span class="keyword">ret</span> <span class="keyword type">void</span><span class="punctuation">,</span> <span class="name variable">!dbg</span> <span class="name variable anonymous">!24</span><br /><span class="punctuation">}</span><br /><br /><span class="punctuation">[...]</span><br /><span class="comment">; DISubprogram defines (in our case) a C function, with its full type<br /></span><span class="name variable anonymous">!7</span> <span class="punctuation">=</span> <span class="keyword">distinct</span> <span class="name variable">!DISubprogram</span><span class="punctuation">(</span><span class="name label">name:</span> <span class="literal string">"print_A"</span><span class="punctuation">,</span> <span class="name label">scope:</span> <span class="name variable anonymous">!1</span><span class="punctuation">,</span> <span class="name label">file:</span> <span class="name variable anonymous">!1</span><span class="punctuation">,</span> <span class="name label">line:</span> <span class="literal number">6</span><span class="punctuation">,</span> <span class="name label">type:</span> <span class="name variable anonymous">!8</span><span class="punctuation">,</span> [...]<span class="punctuation">,</span> <span class="name label">variables:</span> <span class="name variable anonymous">!17</span><span class="punctuation">)</span><br /><span class="comment">; This defines the type of our subprogram<br /></span><span class="name variable anonymous">!8</span> <span class="punctuation">=</span> <span class="name variable">!DISubroutineType</span><span class="punctuation">(</span><span class="name label">types:</span> <span class="name variable anonymous">!9</span><span class="punctuation">)</span><br /><span class="comment">; We have the "original" types used for print_A, with the first one being the<br />; return type (null => void), and the other ones the arguments (in !10)<br /></span><span class="name variable anonymous">!9</span> <span class="punctuation">=</span> <span class="punctuation">!{</span><span class="keyword">null</span><span class="punctuation">,</span> <span class="name variable anonymous">!10</span><span class="punctuation">}</span><br /><span class="name variable anonymous">!10</span> <span class="punctuation">=</span> <span class="name variable">!DIDerivedType</span><span class="punctuation">(</span><span class="name label">tag:</span> <span class="error">DW_TAG_typedef</span><span class="punctuation">,</span> <span class="name label">name:</span> <span class="literal string">"A"</span><span class="punctuation">,</span> <span class="name label">file:</span> <span class="name variable anonymous">!1</span><span class="punctuation">,</span> <span class="name label">line:</span> <span class="literal number">4</span><span class="punctuation">,</span> <span class="name label">baseType:</span> <span class="name variable anonymous">!11</span><span class="punctuation">)</span><br /><span class="comment">; This defines our structure, with its various fields<br /></span><span class="name variable anonymous">!11</span> <span class="punctuation">=</span> <span class="keyword">distinct</span> <span class="name variable">!DICompositeType</span><span class="punctuation">(</span><span class="name label">tag:</span> <span class="error">DW_TAG_structure_</span><span class="keyword">type</span><span class="punctuation">,</span> <span class="name label">file:</span> <span class="name variable anonymous">!1</span><span class="punctuation">,</span> <span class="name label">line:</span> <span class="literal number">1</span><span class="punctuation">,</span> <span class="name label">size:</span> <span class="literal number">64</span><span class="punctuation">,</span> <span class="name label">elements:</span> <span class="name variable anonymous">!12</span><span class="punctuation">)</span><br /><span class="name variable anonymous">!12</span> <span class="punctuation">=</span> <span class="punctuation">!{</span><span class="name variable anonymous">!13</span><span class="punctuation">,</span> <span class="name variable anonymous">!15</span><span class="punctuation">}</span><br /><span class="comment">; We have here the size and name of the member "a". Offset is 0 (default value)<br /></span><span class="name variable anonymous">!13</span> <span class="punctuation">=</span> <span class="name variable">!DIDerivedType</span><span class="punctuation">(</span><span class="name label">tag:</span> <span class="error">DW_TAG_member</span><span class="punctuation">,</span> <span class="name label">name:</span> <span class="literal string">"a"</span><span class="punctuation">,</span> <span class="name label">scope:</span> <span class="name variable anonymous">!11</span><span class="punctuation">,</span> <span class="name label">file:</span> <span class="name variable anonymous">!1</span><span class="punctuation">,</span> <span class="name label">line:</span> <span class="literal number">2</span><span class="punctuation">,</span> <span class="name label">baseType:</span> <span class="name variable anonymous">!14</span><span class="punctuation">,</span> <span class="name label">size:</span> <span class="literal number">16</span><span class="punctuation">)</span><br /><span class="name variable anonymous">!14</span> <span class="punctuation">=</span> <span class="name variable">!DIBasicType</span><span class="punctuation">(</span><span class="name label">name:</span> <span class="literal string">"short"</span><span class="punctuation">,</span> <span class="name label">size:</span> <span class="literal number">16</span><span class="punctuation">,</span> <span class="name label">encoding:</span> <span class="error">DW_ATE_signed</span><span class="punctuation">)</span><br /><span class="comment">; We have here the size, offset and name of the member "b"<br /></span><span class="name variable anonymous">!15</span> <span class="punctuation">=</span> <span class="name variable">!DIDerivedType</span><span class="punctuation">(</span><span class="name label">tag:</span> <span class="error">DW_TAG_member</span><span class="punctuation">,</span> <span class="name label">name:</span> <span class="literal string">"b"</span><span class="punctuation">,</span> <span class="name label">scope:</span> <span class="name variable anonymous">!11</span><span class="punctuation">,</span> <span class="name label">file:</span> <span class="name variable anonymous">!1</span><span class="punctuation">,</span> <span class="name label">line:</span> <span class="literal number">3</span><span class="punctuation">,</span> <span class="name label">baseType:</span> <span class="name variable anonymous">!16</span><span class="punctuation">,</span> <span class="name label">size:</span> <span class="literal number">32</span><span class="punctuation">,</span> <span class="name label">offset:</span> <span class="literal number">32</span><span class="punctuation">)</span><br /><span class="name variable anonymous">!16</span> <span class="punctuation">=</span> <span class="name variable">!DIBasicType</span><span class="punctuation">(</span><span class="name label">name:</span> <span class="literal string">"int"</span><span class="punctuation">,</span> <span class="name label">size:</span> <span class="literal number">32</span><span class="punctuation">,</span> <span class="name label">encoding:</span> <span class="error">DW_ATE_signed</span><span class="punctuation">)</span><br /><span class="punctuation">[...]</span><br /></pre><h4>Internals</h4>DragonFFI first parses the debug information included by Clang in the LLVM IR it produces, and creates a custom type system to represent the various function types, structures, enumerations and typedefs of the parsed C file. This custom type system has been created for two reasons:<br /><ul class="simple"><li>create a type system that gathers only the necessary informations from the metadata tree (we don't need the whole debug informations)</li><li>make the public headers of the DragonFFI library free from any LLVM headers (so that the whole LLVM headers aren't needed to use the library)</li></ul>Once we've got this type system, the DragonFFI API for calling C functions is this one:<br /><br /><pre class="code cpp literal-block"><span class="name">DFFI</span> <span class="name function">FFI</span><span class="punctuation">([...]);</span><br /><span class="comment single">// This will declare puts as a function that returns int and takes a const<br /></span></pre><pre class="code cpp literal-block"><span class="comment single">// char* as an argument. We could also create this function type by hand.<br /></span><span class="name">CompilationUnit</span> <span class="name">CU</span> <span class="operator">=</span> <span class="name">FFI</span><span class="punctuation">.</span><span class="name">cdef</span><span class="punctuation">(</span><span class="literal string">"int puts(const char* s);"</span><span class="punctuation">,</span> <span class="punctuation">[...]);</span><br /><span class="name">NativeFunc</span> <span class="name">F</span> <span class="operator">=</span> <span class="name">CU</span><span class="punctuation">.</span><span class="name">getFunction</span><span class="punctuation">(</span><span class="literal string">"puts"</span><span class="punctuation">);</span><br /><span class="keyword">const</span> <span class="keyword type">char</span><span class="operator">*</span> <span class="name">s</span> <span class="operator">=</span> <span class="literal string">"hello world!"</span><span class="punctuation">;</span><br /><span class="keyword type">void</span><span class="operator">*</span> <span class="name">Args</span><span class="punctuation">[]</span> <span class="operator">=</span> <span class="punctuation">{</span><span class="operator">&</span><span class="name">s</span><span class="punctuation">};</span><br /><span class="keyword type">int</span> <span class="name">Ret</span><span class="punctuation">;</span><br /><span class="name">F</span><span class="punctuation">.</span><span class="name">call</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">Ret</span><span class="punctuation">,</span> <span class="name">Args</span><span class="punctuation">);</span><br /></pre><br />So, basically, a pointer to the returned data and an array of <tt class="docutils literal">void*</tt> is given to DragonFFI. Each <tt class="docutils literal">void*</tt> value is a pointer to the data that must be passed to the underlying function. So the last missing piece of the puzzle is the code that takes this array of <tt class="docutils literal">void*</tt> (and pointer to the returned data) and calls <tt class="docutils literal">puts</tt>, so a function like this:<br /><pre class="code cpp literal-block"><span class="keyword type"><br /></span></pre><pre class="code cpp literal-block"><span class="keyword type">void</span> <span class="name function">call_puts</span><span class="punctuation">(</span><span class="keyword type">void</span><span class="operator">*</span> <span class="name">Ret</span><span class="punctuation">,</span> <span class="keyword type">void</span><span class="operator">**</span> <span class="name">Args</span><span class="punctuation">)</span> <span class="punctuation">{</span><br /> <span class="operator">*</span><span class="punctuation">((</span><span class="keyword type">int</span><span class="operator">*</span><span class="punctuation">)</span><span class="name">Ret</span><span class="punctuation">)</span> <span class="operator">=</span> <span class="name">puts</span><span class="punctuation">((</span><span class="keyword">const</span> <span class="keyword type">char</span><span class="operator">*</span><span class="punctuation">)</span> <span class="name">Args</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">]);</span><br /><span class="punctuation">}</span><br /></pre><br />We call these "function wrappers" (how original! :)). One advantage of this signature is that it is a generic signature, which can be used in the implementation of DragonFFI. Supposing we manage to compile at run-time this function, we can then call it trivially as in the following:<br /><br /><pre class="code cpp literal-block"><span class="keyword">typedef</span> <span class="name function">void</span><span class="punctuation">(</span><span class="operator">*</span><span class="name">puts_call_ty</span><span class="punctuation">)(</span><span class="keyword type">void</span><span class="operator">*</span><span class="punctuation">,</span> <span class="keyword type">void</span><span class="operator">**</span><span class="punctuation">);</span><br /><span class="name">puts_call_ty</span> <span class="name">Wrapper</span> <span class="operator">=</span> <span class="comment multiline">/* pointer to the compiled wrapper function */;</span><br /><span class="name">Wrapper</span><span class="punctuation">(</span><span class="name">Ret</span><span class="punctuation">,</span> <span class="name">Args</span><span class="punctuation">);</span><br /></pre><pre class="code cpp literal-block"><span class="punctuation"><br /></span></pre>Generating and compiling a function like this is something Clang/LLVM is able to do. For the record, this is also what <tt class="docutils literal">libffi</tt> mainly does, by generating the necessary assembly <i>by hand</i>. We optimize the number of these wrappers in DragonFFI, by generating them for each different function type. So, the actual wrapper that would be generated for <tt class="docutils literal">puts</tt> is actually this one:<br /><br /><pre class="code cpp literal-block"><span class="keyword type">void</span> <span class="name function">__dffi_wrapper_0</span><span class="punctuation">(</span><span class="keyword type">int32_t</span><span class="punctuation">(</span> <span class="name">__attribute__</span><span class="punctuation">((</span><span class="name">cdecl</span><span class="punctuation">))</span> <span class="operator">*</span><span class="name">__FPtr</span><span class="punctuation">)(</span><span class="keyword type">char</span> <span class="operator">*</span><span class="punctuation">),</span> <span class="keyword type">int32_t</span> <span class="operator">*</span><span class="name">__Ret</span><span class="punctuation">,</span> <span class="keyword type">void</span><span class="operator">**</span> <span class="name">__Args</span><span class="punctuation">)</span> <span class="punctuation">{</span><br /> <span class="operator">*</span><span class="name">__Ret</span> <span class="operator">=</span> <span class="punctuation">(</span><span class="name">__FPtr</span><span class="punctuation">)(</span><span class="operator">*</span><span class="punctuation">((</span><span class="keyword type">char</span> <span class="operator">**</span><span class="punctuation">)</span><span class="name">__Args</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">]));</span><br /><span class="punctuation">}</span><br /></pre><pre class="code cpp literal-block"><span class="punctuation"><br /></span></pre>For now, all the necessary wrappers are generated when the <tt class="docutils literal"><span class="pre">DFFI::cdef</span></tt> or <tt class="docutils literal"><span class="pre">DFFI::compile</span></tt> APIs are used. The only exception where they are generated on-the-fly (when calling <tt class="docutils literal"><span class="pre">CompilationUnit::getFunction</span></tt>) is for variadic arguments. One possible evolution is to let the user chooses whether he wants this to happen on-the-fly or not for every declared function.<br /><h3>Issues with Clang</h3>There is one major issue with Clang that we need to hack around in order to have the <tt class="docutils literal"><span class="pre">DFFI::cdef</span></tt> functionality: unused declarations aren't emitted by Clang (even when using <tt class="docutils literal"><span class="pre">-g</span> <span class="pre">-femit-all-decls</span></tt>).<br /><br />Here is an example, produced from the following C code:<br /><br /><pre class="code c literal-block"><span class="keyword">typedef</span> <span class="keyword">struct</span> <span class="punctuation">{</span><br /> <span class="keyword type">short</span> <span class="name">a</span><span class="punctuation">;</span><br /> <span class="keyword type">int</span> <span class="name">b</span><span class="punctuation">;</span><br /><span class="punctuation">}</span> <span class="name">A</span><span class="punctuation">;</span><br /><br /><span class="keyword type">void</span> <span class="name function">print_A</span><span class="punctuation">(</span><span class="name">A</span> <span class="name">s</span><span class="punctuation">);</span><br /></pre><pre class="code sh literal-block">$ clang -S -emit-llvm -g -femit-all-decls -o - a.c <span class="punctuation">|</span>grep print_A <span class="punctuation">|</span>wc -l<br /><span class="literal number">0</span><br /></pre><br />The produced LLVM IR does not contain a function named <tt class="docutils literal">print_A</tt>! The hack we temporarily use parses the clang AST and generates temporary functions that looks like this:<br /><pre class="code cpp literal-block"><span class="keyword type"><br /></span></pre><pre class="code cpp literal-block"><span class="keyword type">void</span> <span class="name function">__dffi_force_decl_print_A</span><span class="punctuation">(</span><span class="name">A</span> <span class="name">s</span><span class="punctuation">)</span> <span class="punctuation">{</span> <span class="punctuation">}</span><br /></pre><br />This forces LLVM to generate an empty function named <tt class="docutils literal">__dffi_force_decl_print_A</tt> with the good arguments (and associated debug informations).<br /><br />This is why DragonFFI proposes another API, <tt class="docutils literal"><span class="pre">DFFI::compile</span></tt>. This API does not force declared-only functions to be present in the LLVM IR, and will only expose functions that end up naturally in the LLVM IR after optimizations.<br /><br />If someone has a better idea to handle this, please let us know! <br /><h3>Python bindings</h3>Python bindings were the first ones to have been written, simply because it's the "high level" language I know best. Python provides its own set of challenges, but we will save that for another blog post. These Python bindings are built using <a href="https://github.com/pybind/pybind11">pybind11</a>, and provides their own set of C types. Lots of example of what can be achieved can be found <a href="https://github.com/aguinet/dragonffi/tree/dffi-0.2.1/examples">here</a> and <a href="https://github.com/aguinet/dragonffi/tree/dffi-0.2.1/bindings/python/tests">here</a>.<br /><h3>Project status</h3>DragonFFI currently supports Linux, OSX and Windows OSes, running on Intel 32 and 64-bits CPUs. Travis is used for continuous integration, and every changes is validated on all these platforms before being integrated.<br /><br />The project will go from alpha to beta quality when the 0.3 version will be out (which will bring Travis and Appveyor CI integration and support for variadic functions). The project will be considered stable once these things happen:<br /><ul class="simple"><li>user and developer documentations exist!</li><li>another foreign language is supported (JS? Ruby?)</li><li>the DragonFFI main library API is considered stable</li><li>a non negligible list of tests have been added</li><li>all the things in the <tt class="docutils literal">TODO</tt> file have been done :)</li></ul><h3>Various ideas for the future</h3>Here are various interesting ideas we have for the future. We don't know yet when they will be implemented, but we think some of them could be quite nice to have.<br /><h4>Parse embedded DWARF information</h4>As the entry point of DragonFFI are DWARF informations, we could imagine parsing these debug informations from shared libraries that embed them (or provide them in a separate file). The main advantage is that all the necessary information for doing the FFI right are in one file, the header files are no longer required. The main drawback is that debug informations tend to take a lot of space (for instance, DWARF informations take 1.8Mb for <tt class="docutils literal">libarchive</tt> 3.32 compiled in release mode, for an original binary code size of 735Kb), and this brings us to the next idea.<br /><h4>Lightweight debug info?</h4>The DWARF standard allows to define lots of information, and we don't need all of them in our case. We could imagine embedding only the necessary DWARF objects, that is just the necessary types to call the exported functions of a shared library. One experiment of this is available here: <a href="https://github.com/aguinet/llvm-lightdwarf">https://github.com/aguinet/llvm-lightdwarf</a>. This is an LLVM optimisation pass that is inserted at the end of the optimisation pipeline, and parse metadata to only keep the relevant one for DragonFFI. More precisely, it only keeps the dwarf metadata related to <b>exported</b> and <b>visible</b> functions, with the associated types. It also keeps debug information of global variables, even thought these ones aren't supported yet in DragonFFI. It also does some unconventional things, like replacing every file and directory by "_", to save space. "Fun" fact, to do this, it borrows some code from the LLVM bitcode "obfuscator" included in recent Apple's clang version, that is used to anonymize some information from the LLVM bitcode that is sent with tvOS/iOS applications (see <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095588.html">http://lists.llvm.org/pipermail/llvm-dev/2016-February/095588.html</a> for more information).<br /><br />Enough talking, let's see some preliminary results (on Linux x64):<br /><ul class="simple"><li>on libarchive 3.3.2, DWARF goes from 1.8Mb to 536Kb, for an original binary code size of 735Kb</li><li>on zlib 1.2.11, DWARF goes from 162Kb to 61Kb, for an original binary code size of 99Kb</li></ul>The instructions to reproduce this are available in the README of the LLVM pass repository.<br />We can conclude that defining this "light" DWARF format could be a nice idea. One other thing that could be done is defining a new binary format, that would be thus more space-efficient, but there are drawbacks going this way:<br /><ul class="simple"><li>debug informations are well supported on every platform nowadays: tools exist to parse them, embed/extract them from binary, and so on</li><li>we already got DWARD and PDB: <a href="https://xkcd.com/927/">https://xkcd.com/927/</a></li></ul>Nevertheless, it still could be a nice experiment to try and do this, figuring out the space won and see if this is worth it!<br /><br />As a final note, these two ideas would also benefit to <tt class="docutils literal">libffi</tt>, as we could process these formats and create <tt class="docutils literal">libffi</tt> types!<br /><h4>JIT code from the final language (like Python) to native function code</h4>One advantage of embedding a full working C compiler is that we could JIT the code from the final language glue to the final C function call, and thus limit the performance impact of this glue code.<br />Indeed, when a call is issued from Python, the following things happen:<br /><ul class="simple"><li>arguments are converted from Python to C according to the function type</li><li>the function pointer and wrapper and gathered from DragonFFI</li><li>the final call is made</li></ul>All this process involves basically a loop on the types of the arguments of the called function, which contains a big switch case. This loop generates the array of <tt class="docutils literal">void*</tt> values that represents the C arguments, which is then passed to the wrapper. We could JIT a specialised version of this loop for the function type, inline the already-compiled wrapper and apply classical optimisation on top of the resulting IR, and get a straightforward conversion code specialized for the given function type, directly from Python to C.<br /><br />One idea we are exploring is combining <a href="https://github.com/jmmartinez/easy-just-in-time">easy::jit</a> (hello fellow Quarkslab teammates!) with <a href="http://www.llpe.org/">LLPE</a> to achieve this goal.<br /><h4>Reducing DragonFFI library size</h4>The DragonFFI shared library embed statically compiled versions of LLVM and Clang. The size of the final shared library is about 55Mb (stripped, under Linux x64). This is really really huge, compared for instance to the 39Kb of libffi (also stripped, Linux x64)!<br /><br />Here are some idea to try and reduce this footprint:<br /><ul class="simple"><li>compile DragonFFI, Clang and LLVM using (Thin) LTO, with visibility hidden for both Clang and LLVM. This could have the effect of removing code from Clang/LLVM that isn't used by DragonFFI.</li><li>make DragonFFI more modular: - one core module that only have the parts from CodeGen that deals with ABIs. If the types and function prototypes are defined "by hand" (without <tt class="docutils literal"><span class="pre">DFFI::cdef</span></tt>), that's more or less the only part that is needed (with LLVM obviously) - one optional module that includes the full clang compiler (to provide the <tt class="docutils literal"><span class="pre">DFFI::cdef</span></tt> and <tt class="docutils literal"><span class="pre">DFFI::compile</span></tt> APIs)</li></ul>Even with all of this, it seems to be really hard to match the 39Kb of <tt class="docutils literal">libffi</tt>, even if we remove the <tt class="docutils literal">cdef</tt>/<tt class="docutils literal">compile</tt> API from DragonFFI. As always, pick the right tool for your needs :)<br /><h3>Conclusion</h3>Writing the first working version of DragonFFI has been a fun experiment, that made me discover new parts of Clang/LLVM :) The current goal is to try and achieve a first stable version (see above), and experiment with the various cited ideas.<br /><br />It's a really long road, so feel free to come on <tt class="docutils literal">#dragonffi</tt> on FreeNode for any questions/suggestions you might have, (inclusive) or if you want to contribute! <br /><h3>Acknowledgments</h3>Thanks to Serge «sans paille» Guelton for the discussions around the Python bindings, and for helping me finding the name of the project :) (one of the most difficult task). Thanks also to him, <a href="https://twitter.com/_kamino_/">Fernand Lone-Sang</a> and <a href="https://twitter.com/wiskitki">Kévin Szkudlapski</a> for their review of this blog post!
- International Women's Day: Celebrating all the women in the LLVM Community!https://blog.llvm.org/2018/03/international-womens-day-celebrating.htmlThu, 08 Mar 2018 11:10:00 +0000https://blog.llvm.org/2018/03/international-womens-day-celebrating.html<br />Today is <a href="https://en.wikipedia.org/wiki/International_Women%27s_Day">International Women's Day</a>! To all the women in the LLVM community, thank you for all your contributions!<br /><br />The <a href="http://foundation.llvm.org/">LLVM Foundation</a> values diversity within the LLVM community and the field of compilers and tools. Our Women in Compilers and Tools program began in 2015 with a birds of a feather discussion during the US LLVM Developers' Meeting and we have been expanding it over the years.<br /><br />In 2017, we were a sponsor of the <a href="https://ghc.anitab.org/ghc-17/">Grace Hopper Conference</a>. With the help of community members Anna Zaks and David Blaikie, the LLVM Foundation had a booth at the career fair to introduce women to LLVM and encourage them to become contributors. It was very exciting to learn that many women knew of LLVM, were using it in their classes or research, using it in their career, or were interested in learning more. We hopefully encouraged more women to get involved with LLVM, compilers, and open source.<br /><br />The LLVM Foundation was also a sponsor of the <a href="https://2017.splashcon.org/track/splash-2017-PLMW">Programming Language Mentoring Workshop</a> at SPLASH 2017. Our sponsorship went towards the travel costs for many women and other minorities to attend this workshop. The workshop focused on encouraging and preparing students to enter research careers in the field of programming languages, compilers, and related fields and to provide first hand perspectives on graduate school.<br /><br />We hosted our first Women in Compilers & Tools reception before the 2017 US LLVM Developers' Meeting. Anna Zaks and Alice Chan participated in a panel discussion about the challenges and experiences that they have encountered in their careers and within the open source community. The event was attended by 60 members of the LLVM community.<br /><br />In 2018, we look forward to another year of expanding our program. The LLVM Foundation will again sponsor the Grace Hopper Conference and we are looking for LLVM community members to help out at the career booth (more details to come). We will be having two Women in Compilers and Tools events. The first will have a reception and panel discussion before the <a href="http://llvm.org/devmtg/2018-04/">2018 EuroLLVM Developers' Meeting</a>. Get your tickets <a href="https://www.eventbrite.com/e/2018-european-llvm-developers-meeting-women-in-compilers-and-tools-reception-tickets-42287427835">here</a>. The second will be before the 2018 US LLVM Developers' Meeting and details will be announced in the coming months.<br /><br />The LLVM Foundation thanks the LLVM community and its sponsors for supporting this work. If you want to participate in the discussion or receive notifications on events, please join the <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/wict">Women in Compilers and Tools mailing list</a>.<br /><br />Question for the LLVM Foundation? Email us at <a href="mailto:[email protected]">[email protected]</a>.<br /><br /><br /><br />
- Clang is now used to build Chrome for Windowshttps://blog.llvm.org/2018/03/clang-is-now-used-to-build-chrome-for.htmlMon, 05 Mar 2018 12:46:00 +0000https://blog.llvm.org/2018/03/clang-is-now-used-to-build-chrome-for.html<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;">As of Chrome 64, Chrome for Windows is compiled with Clang. We now use Clang to build Chrome for all platforms it runs on: macOS, iOS, Linux, Chrome OS, Android, and Windows. Windows is the platform with the second most Chrome users after Android <a href="http://gs.statcounter.com/browser-version-market-share">according to statcounter</a>, which made this switch particularly exciting.</div><br />Clang is the first-ever open-source C++ compiler thatâs ABI-compatible with Microsoft Visual C++ (MSVC) â meaning you can build some parts of your program (for example, system libraries) with the MSVC compiler (âcl.exeâ), other parts with Clang, and when linked together (either by MSVCâs linker, âlink.exeâ, or LLD, the LLVM projectâs linker â see below) the parts will form a working program.<br /><br />Note that Clang is not a replacement for Visual Studio, but an addition to it. We still use Microsoftâs headers and libraries to build Chrome, we still use some SDK binaries like midl.exe and mc.exe, and many Chrome/Win developers still use the Visual Studio IDE (for both development and for debugging).<br /><br />This post discusses numbers, motivation, benefits and drawbacks of using Clang instead of MSVC, how to try out Clang for Windows yourself, project history, and next steps. For more information on the technical side you can look at the <a href="https://docs.google.com/presentation/d/1oxNHaVjA9Gn_rTzX6HIpJHP7nXRua_0URXxxJ3oYRq0/edit#slide=id.p">slides of our 2015 LLVM conference talk</a>, and the slides linked from there.<br /><h3>Numbers</h3>This is what most people ask about first, so letâs talk about it first. We think the other sections are more interesting though.<br /><h4 style="text-align: left;">Build time</h4>Building Chrome locally with Clang is about 15% slower than with MSVC. (Weâve heard that Windows Defender can make Clang builds a lot slower on some machines, so if youâre seeing larger slowdowns, make sure to whitelist Clang in Windows Defender.) However, the way Clang emits debug info is more parallelizable and builds with a distributed build service (e.g. <a href="https://chromium.googlesource.com/infra/goma/client/">Goma</a>) are hence faster.<br /><h4 style="text-align: left;">Binary size</h4>Chrome installer size gets smaller for 64-bit builds and slightly larger for 32-bit builds using Clang. The same difference shows in uncompressed code size for regular builds as well (see the <a href="https://crbug.com/457078">tracking bug for Clang binary size</a> for many numbers). However, compared to MSVC builds using link-time code generation (LTCG) and <a href="https://blog.chromium.org/2016/10/making-chrome-on-windows-faster-with-pgo.html">profile-guided optimization</a> (PGO) Clang generates larger code in 64-bit for targets that use /O2 but smaller code for targets that use /Os. The installer size comparison suggests Clang's output compresses better.<br /><br />Some raw numbers for versions 64.0.3278.2 (MSVC PGO) and 64.0.3278.0 (Clang). mini_installer.exe is Chromeâs installer that users download, containing the LZMA-compressed code. chrome_child.dll is one of the two main dlls; it contains Blink and V8, and generally has many targets that are built with /O2. chrome.dll is the other main dll, containing the browser process code, mostly built with /Os.<br /><span id="docs-internal-guid-891146fc-f7de-b09a-1a30-b3298ec281f3"><br /></span><br /><div dir="ltr" style="margin-left: 0pt;"><table style="border-collapse: collapse; border: none;"><colgroup><col width="117"></col><col width="142"></col><col width="106"></col><col width="137"></col><col width="121"></col></colgroup><tbody><tr style="height: 0pt;"><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><br /></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre;">mini_installer.exe</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre;">chrome.dll</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre;">chrome_child.dll</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre;">chrome.exe</span></div></td></tr><tr style="height: 0pt;"><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">32-bit win-pgo</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">45.46 MB</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">36.47 MB</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">53.76 MB</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">1.38 MB</span></div></td></tr><tr style="height: 0pt;"><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">32-bit win-clang</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">45.65 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(+0.04%)</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">42.56 MB (+16.7%)</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">62.38 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(+16%)</span></div></td><td style="border-bottom: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">1.45 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(+5.1%)</span></div></td></tr><tr style="height: 0pt;"><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">64-bit win-pgo</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">49.4 MB</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">53.3 MB</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">65.6 MB</span></div></td><td style="border-top: solid #000000 0.5pt; padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">1.6 MB</span></div></td></tr><tr style="height: 0pt;"><td style="padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">64-bit win-clang</span></div></td><td style="padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">46.27 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(-6.33%)</span></div></td><td style="padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">50.6 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(-5.1%)</span></div></td><td style="padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">72.71 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(+10.8%)</span></div></td><td style="padding: 5pt 5pt 5pt 5pt; vertical-align: top;"><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">1.57 MB</span></div><div dir="ltr" style="line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">(-1.2%)</span></div></td></tr></tbody></table></div><h4 style="text-align: left;">Performance</h4>We conducted extensive A/B testing of performance. Performance telemetry numbers are about the same for MSVC-built and clang-built Chrome â some metrics get better, some get worse, but all of them are within 5% of each other. The official MSVC builds used LTCG and PGO, while the Clang builds currently use neither of these. This is potential for improvement that we look forward to exploring. The PGO builds took a very long time to build due to the need for collecting profiles and then building again, and as a result, the configuration was not enabled on our performance-measurement buildbots. Now that we use Clang, the perf bots again track the configuration that we ship.<br /><br />Startup performance was worse in Clang-built Chrome until we started using a <a href="https://chromium.googlesource.com/chromium/src/+/master/docs/win_order_files.md">link-order file</a> â a form of âPGO lightâ .<br /><h4 style="text-align: left;">Stability</h4>We A/B-tested stability as well and found no difference between the two build configurations.<br /><h3 style="text-align: left;">Motivation</h3>There were many motivating reasons for this project, the overarching theme being the benefits of using the same compiler across all of Chromeâs platforms, as well as the ability to change the compiler and deploy those changes to all our developers and buildbots quickly. Hereâs a non-exhaustive list of examples.<br /><ul style="text-align: left;"><li>Chrome is heavily using technology thatâs based on compiler instrumentation (ASan, CFI, <a href="https://blog.chromium.org/2012/04/fuzzing-for-security.html">ClusterFuzz</a>âuses ASan). Clang supports this instrumentation already, but we canât add it to MSVC. We previously used <a href="https://github.com/google/syzygy">after-the-fact binary instrumentation</a> to mitigate this a bit, but having the toolchain write the right bits in the first place is cleaner and faster.</li><li>Clang enables us to write compiler <a href="https://www.chromium.org/developers/coding-style/chromium-style-checker-errors">plugins</a> that add Chromium-specific warnings and to write tooling for <a href="https://chromium.googlesource.com/chromium/src/+/lkcr/docs/clang_tool_refactoring.md">large-scale refactoring</a>. <a href="https://cs.chromium.org/">Chromiumâs code search</a> can now learn to index Windows code.</li><li>Chromium is open-source, so itâs nice if itâs built with an open-source toolchain.</li><li>Chrome runs on 6+ platforms, and most developers are only familiar with 1-3 platforms. If your patch doesnât compile on a platform youâre unfamiliar with, due to a compiler error that you canât locally reproduce on your local development machine, itâll take you a while to fix. On the other hand, if all platforms use the same compiler, if it builds on your machine then itâs probably going to build on all platforms.</li><li>Using the same compiler also means that compiler-specific micro-optimizations will help on all platforms (assuming that the same -O flags are used on all platforms â not yet the case in Chrome, and only on the same ISAs â x86 vs ARM will stay different).</li><li>Using the same compiler enables <a href="https://cs.chromium.org/chromium/src/docs/win_cross.md">cross-compiling</a> â developers who feel most at home on a Linux box can now work on Windows-specific code, from their Linux box (without needing to run Wine).</li><li>We can <a href="https://ci.chromium.org/p/chromium/g/chromium.clang/console">continuously build Chrome trunk with Clang trunk</a> to find compiler regressions quickly. This allows us to update Clang every week or two. Landing a major MSVC update in Chrome usually took a year or more, with several rounds of reporting internal compiler bugs and miscompiles. The issue here isnât that MSVC is more buggy than Clang â it isnât, all software is buggy â but that we can continuously improve Clang due to Clang being open-source.</li><li>C++ receives major new revisions every few years. When C++11 was released, we were still using six different compilers, and <a href="http://chromium-cpp.appspot.com/">enabling C++11</a> was difficult. With fewer compilers, this gets much easier.</li><li>We can prioritize compiler features that are important to us. For example:</li><ul><li><a href="https://www.chromium.org/developers/testing/isolated-testing/deterministic-builds">Deterministic builds</a> were important to us before they were important for the MSVC team. For example, link.exe /incremental depends on an incrementing mtime timestamp in each object file.</li><li>We could enable warnings that fired in system headers long before <a href="https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/">MSVC added support for the system header concept</a>.</li><li>cl.exe always prints the name of the input file, so that the <a href="https://github.com/ninja-build/ninja/blob/master/src/clparser.cc#L67">build system has to filter it out for quiet builds</a>.</li></ul></ul><br />Of course, not all â or even most â of these reasons will apply to other projects.<br /><h3 style="text-align: left;">Benefits and drawbacks of using Clang instead of Visual C++</h3><div style="text-align: left;">Benefits of using Clang, if you want to try for your project:</div><div style="text-align: left;"></div><ul style="text-align: left;"><li>Clang supports 64-bit inline assembly. For example, in Chrome we built libyuv (a video format conversion library) with Clang long before we built all of Chrome with it. libyuv had highly-tuned 64-bit inline assembly with performance not reachable with intrinsics, and we could just use that code on Windows.</li><li>If your project runs on multiple platforms, you can use one compiler everywhere. Building your project with several compilers is generally considered good for code health, but in Chrome we found that Clangâs diagnostics found most problems and we were mostly battling compiler bugs (and if another compiler has a great new diagnostic, we can add that to Clang).</li><li>Likewise, if your project is Windows-only, you can get a second compilerâs opinion on your code, and Clangâs warnings might find bugs.</li><li>You can use <a href="https://clang.llvm.org/docs/AddressSanitizer.html">Address Sanitizer</a> to find memory bugs.</li><li>If you donât use LTCG and PGO, itâs possible that Clang might create faster code.</li><li>Clangâs <a href="https://clang.llvm.org/diagnostics.html">diagnostics and fix-it hints</a>.</li></ul>There are also drawbacks:<br /><ul style="text-align: left;"><li>Clang doesnât support C++/CX or #import âfoo.dllâ.</li><li>MSVC offers paid support, Clang only gives you the code and the ability to write patches yourself (although the community is very active and helpful!).</li><li>MSVC has better documentation.</li><li>Advanced debugging features such as Edit & Continue donât work when using Clang.</li></ul><h3 style="text-align: left;">How to use</h3>If you want to give Clang for Windows a try, there are two approaches:<br /><ol style="text-align: left;"><li>You could use clang-cl, a compiler driver that tries to be command-line flag compatible with cl.exe (just like Clang tries to be command-line flag compatible with gcc). The <a href="https://clang.llvm.org/docs/UsersManual.html#clang-cl">Clang user manual</a> describes how you can tell popular Windows build systems how to call clang-cl instead of cl.exe. We used this approach in Chrome to keep the Clang/Win build working alongside the MSVC build for years, with minimal maintenance cost. You can keep using link.exe, all your current compile flags, the MSVC debugger or windbg, ETW, etc. clang-cl even writes warning messages in a format thatâs compatible with cl.exe so that you can click on build error messages in Visual Studio to jump to the right file and line. Everything should just work.</li><li>Alternatively, if you have a cross-platform project and want to use gcc-style flags for your Windows build, you can pass a Windows triple (e.g. --target=x86_64-windows-msvc) to regular Clang, and it will produce MSVC-ABI-compatible output. Starting in Clang 7.0.0, due Fall 2018, Clang will also default to CodeView debug info with this triple.</li></ol>Since Clangâs output is ABI-compatible with MSVC, you can build parts of your project with clang and other parts with MSVC. You can also pass <a href="https://clang.llvm.org/docs/UsersManual.html#the-fallback-option">/fallback</a> to clang-cl to make it call cl.exe on files it canât yet compile (this should be rare; it never happens in the Chrome build).<br /><br />clang-cl accepts Microsoft language extensions needed to parse system headers but tries to emit -Wmicrosoft-foo warnings when it does so (warnings are ignored for system headers). You can choose to fix your code, or pass -Wno-microsoft-foo to Clang.<br /><br />link.exe can produce regular PDB files from the CodeView information that Clang writes.<br /><h3 style="text-align: left;">Project History</h3>We switched chrome/mac and <a href="http://blog.llvm.org/2015/01/using-clang-for-chrome-production.html">chrome/linux</a> to Clang a while ago. But on Windows, Clang was still missing support for parsing many Microsoft language extensions, and it didnât have any Microsoft C++ ABI-compatible codegen at all. In 2013, we <a href="http://blog.llvm.org/2013/09/a-path-forward-for-llvm-toolchain-on.html">spun up a team</a> to improve Clangâs Windows support, consisting half of Chrome engineers with a compiler background and half of other toolchain people. In mid-2014, Clang could <a href="http://blog.llvm.org/2014/07/clangllvm-on-windows-update.html">self-host on Windows</a>. In February 2015, we had the first fallback-free build of 64-bit Chrome, in July 2015 the first fallback-free build of 32-bit Chrome (32-bit SEH was difficult). In Oct 2015, we shipped a first clang-built Chrome to the Canary channel. Since then, weâve worked on <a href="http://https//crbug.com/457078">improving the size of Clangâs output</a>, <a href="https://crbug.com/636111">improved Clangâs debug information</a> (some of it behind -instcombine-lower-dbg-declare=0 for now), and A/B-tested stability and telemetry performance metrics.<br /><br />We use versions of Clang that are pinned to a recent upstream revision that we update every one to three weeks, without any local patches. All our work is done in upstream LLVM.<br /><br />Mid-2015, Microsoft announced that they were building on top of our work of making Clang able to parse all the Microsoft SDK headers with <a href="https://blogs.msdn.microsoft.com/vcblog/2015/05/01/bringing-clang-to-windows/">clang/c2</a>, which used the Clang frontend for parsing code, but cl.exeâs codegen to generate code. <a href="https://twitter.com/stephantlavavej/status/871861920315211776?lang=en">Development on clang/c2 was halted again</a> in mid-2017; it is conceivable that this was related to our improvements to MSVC-ABI-compatible Clang codegen quality. Weâre thankful to Microsoft for publishing documentation on the PDB file format, answering many of our questions, fixing Clang compatibility issues in their SDKs, and for giving us publicity on their blog! Again, Clang is not a replacement for MSVC, but a complement to it.<br /><br />Opera for Windows is also <a href="http://blogs.opera.com/desktop/2018/02/opera-51/">compiled with Clang</a> starting in version 51.<br /><br />Firefox is also looking at <a href="https://ehsanakhgari.org/blog/2016-01-29/building-firefox-with-clang-cl-a-status-update">using clang-cl for building Firefox for Windows</a>.<br /><h3 style="text-align: left;">Next Steps</h3>Just as clang-cl is a cl.exe-compatible interface for Clang, lld-link is a link.exe-compatible interface for lld, the LLVM linker. Our next step is to use lld-link as an alternative to link.exe for linking Chrome for Windows. This has many of the same advantages as clang-cl (open-source, easy to update, â¦). Also, using clang-cl together with lld-link allows using <a href="https://llvm.org/docs/LinkTimeOptimization.html">LLVM-bitcode-based LTO</a> (which in turn enables using <a href="https://clang.llvm.org/docs/ControlFlowIntegrity.html">CFI</a>) and <a href="http://blog.llvm.org/2018/01/improving-link-time-on-windows-with.html">using PE/COFF extensions to speed up linking</a>. A prerequisite for using lld-link was <a href="http://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.html">its ability to write PDB files</a>.<br />Weâre also considering using libc++ instead of the MSVC STL â this allows us to instrument the standard library, which is again useful for CFI and Address Sanitizer.<span style="white-space: pre;"> </span><br /><h3 style="text-align: left;">In Closing</h3>Thanks to the whole LLVM community for helping to create the first new production C++ compiler for Windows in over a decade, and the first-ever open-source C++ compiler thatâs ABI-compatible with MSVC!<br /><div><br /></div></div>
- EuroLLVM'18 developers' meeting programhttps://blog.llvm.org/2018/03/eurollvm18-developers-meeting-program.htmlThu, 01 Mar 2018 14:31:00 +0000https://blog.llvm.org/2018/03/eurollvm18-developers-meeting-program.htmlThe LLVM Foundation is excited to announce the program for the EuroLLVM'18 developers' meeting (April 16 - 17 in Bristol/UK) !<br /><br /><h2>Keynotes</h2><div><ul><li><a href="http://www.llvm.org/devmtg/2018-04/talks.html#Keynote_1">The Cerberus Memory Object Semantics for ISO and De Facto C</a> <i>P. Sewell</i></li><li><i><a href="http://llvm.org/devmtg/2018-04/talks.html#Keynote_2">LLVM x Blockchains = A new Ecosystem of Decentralized Applications</a> <i>R. Zhong</i></i></li></ul></div><h2>Tutorials</h2><ul><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Tutorial_1">Pointers, Alias & ModRef Analyses</a> <i>A. Sbirlea, N. Lopes</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Tutorial_2">Scalar Evolution - Demystified</a> <i>J. Absar</i></li></ul><h2>Talks</h2><ul><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_1">A Parallel IR in Real Life: Optimizing OpenMP</a> <i>H. Finkel, J. Doerfert, X. Tian, G. Stelle </i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_2">An Introduction to AMD Optimizing C/C++ Compiler</a> <i>A. Team</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_3">Analysis of Executable Size Reduction by LLVM passes</a> <i>V. Sinha, P. Kumar, S. Jain, U. Bora, S. Purini, R. Upadrasta</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_4">Developing Kotlin/Native infrastructure with LLVM/Clang, travel notes.</a> <i>N. Igotti</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_5">Extending LoopVectorize to Support Outer Loop Vectorization Using VPlan</a> <i>D. Caballero, S. Guggilla</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_6">Finding Iterator-related Errors with Clang Static Analyzer</a> <i>Ã. Balogh </i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_7">Finding Missed Optimizations in LLVM (and other compilers)</a> <i>G. Barany</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_8">Global code completion and architecture of clangd</a> <i>E. Liu, H. Wu, I. Biryukov, S. McCall </i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_9">Hardening the Standard Library</a> <i>M. Clow</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_10">Implementing an LLVM based Dynamic Binary Instrumentation framework</a> <i>C. Hubain, C. Tessier</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_11">LLVM Greedy Register Allocator â Improving Region Split Decisions</a> <i>M. Yatsina</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_12">MIR-Canon: Improving Code Diff Through Canonical Transformation.</a> <i>P. Lotfi</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_13">New PM: taming a custom pipeline of Falcon JIT</a> <i>F. Sergeev</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_14">Organising benchmarking LLVM-based compiler: Arm experience</a> <i>E. Astigeevich</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_15">Performance Analysis of Clang on DOE Proxy Apps</a> <i>H. Finkel, B. Homerding</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_16">Point-Free Templates</a> <i>A. Gozillon, P. Keir</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Talk_17">Protecting the code: Control Flow Enforcement Technology</a> <i>O. Simhon</i></li></ul><h2>BoFs</h2><div><ul><li><a href="http://llvm.org/devmtg/2018-04/talks.html#BoF_1">Towards implementing #pragma STDC FENV_ACCESS</a> U<i>. Weigand</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#BoF_2">Build system integration for interactive tools</a> <i>I. Biryukov, H. Wu, E. Liu, S. McCall</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#BoF_3">Clang Static Analyzer BoF</a> <i>G. Horváth</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#BoF_4">LLVM Foundation BoF</a> <i>LLVM Foundation Board of Directors</i></li></ul></div><h2>Student Research Competition</h2><div><ul><li><a href="http://llvm.org/devmtg/2018-04/talks.html#SRC_2">Compile-Time Function Call Interception to Mock Functions in C/C++</a> <i>G. Márton, Z. Porkoláb</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#SRC_3">Improved Loop Execution Modeling in the Clang Static Analyzer</a> <i>P. Szécsi </i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#SRC_4">Using LLVM in a Model Checking Workflow</a> <i>G. Sallai</i></li></ul></div><div><h2>Lightning Talks</h2><div><ul><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_1">C++ Parallel Standard Template Library support in LLVM</a> <i>M. Dvorskiy, J. Cownie, A. Kukanov</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_2">Can reviews become less of a bottleneck?</a> <i>K. Beyls</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_3">Clacc: OpenACC Support for Clang and LLVM</a> <i>J. Denny, S. Lee, J. Vetter </i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_4">DragonFFI: Foreign Function Interface and JIT using Clang/LLVM</a> <i>A. Guinet</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_5">Easy::Jit: Compiler-assisted library to enable Just-In-Time compilation for C++ codes</a> <i>J. Fernandez, S. Guelton</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_7">Flang -- Project Update</a> <i>S. Scalpone</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_9">Look-Ahead SLP: Auto-vectorization in the Presence of Commutative Operations</a> <i>V. Porpodas, R. Rocha, L. Góes</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_10">Low Cost Commercial Deployment of LLVM</a> <i>J. Bennett</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_11">Measuring the User Debugging Experience</a> <i>G. Bedwell</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_12">Measuring x86 instruction latencies with LLVM</a> <i>G. Chatelet, C. Courbet, B. De Backer, O. Sykora</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_13">OpenMP Accelerator Offloading with OpenCL using SPIR-V</a> <i>D. Schürmann, J. Lucas, B. Juurlink</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_14">Parallware, LLVM and supercomputing</a> <i>M. Arenaz</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_15">Returning data-flow to asynchronous programming through static analysis</a> <i>M. Gilbert</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_16">RFC: A new divergence analysis for LLVM</a> <i>S. Moll, T. Klössner, S. Hack</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_17">Static Performance Analysis with LLVM</a> <i>C. Courbet, O. Sykora, G. Chatelet, B. De Backer</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_18">Supporting the RISC-V Vector Extensions in LLVM</a> <i>R. Kruppe, J. Oppermann, A. Koch</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Lightning_19">Using Clang Static Analyzer to detect Critical Control Flow</a> <i>S. Cook</i></li></ul></div></div><h2>Posters</h2><div><ul><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Poster_1">Automatic Profiling for Climate Modeling</a> <i>A. Gerbes, N. Jumah, J. Kunkel</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Poster_2">Cross Translation Unit Analysis in Clang Static Analyzer: Qualitative Evaluation on C/C++ projects</a> <i>G. Horvath, P. Szecsi, Z. Gera, D. Krupp</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Poster_3">Effortless Differential Analysis of Clang Static Analyzer Changes</a> <i>G. Horváth, R. Kovács, P. Szécsi </i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Poster_4">Offloading OpenMP Target Regions to FPGA Accelerators Using LLVM</a> <i>L. Sommer, J. Oppermann, J. Korinth, A. Koch</i></li><li><a href="http://llvm.org/devmtg/2018-04/talks.html#Poster_5">Using clang as a Frontend on a Formal Verification Tool</a> <i>M. Gadelha, J. Morse, L. Cordeiro, D. Nicole</i></li></ul>If you are interested in any of this talks, you should <a href="https://www.eventbrite.com/e/2018-european-llvm-developers-meeting-bristol-tickets-42283244322" target="_blank">register</a> to attend the EuroLLVM'18. Tickets are limited !</div><div><br /></div><div>More information about the EuroLLVM'18 is available <a href="http://llvm.org/devmtg/2018-04/" target="_blank">here</a>. </div>
- LLVM accepted to 2018 Google Summer of Code!https://blog.llvm.org/2018/02/llvm-accepted-to-2018-google-summer-of.htmlWed, 14 Feb 2018 13:36:00 +0000https://blog.llvm.org/2018/02/llvm-accepted-to-2018-google-summer-of.htmlWe are excited to announce the LLVM project has been accepted to <a href="https://summerofcode.withgoogle.com/organizations/6471192286855168/">2018 Google Summer of Code</a>!<br /><br /><b>What is Google Summer of Code?</b><br /><b><br /></b>Google Summer of Code (GSoC) is a global program focused on introducing students to open source software development. Students work on a 3 month programming project with an open source organization during their break from university. There are several benefits to this program for both the students and LLVM:<br /><br /><ul><li>Inspire students to get involved with open source, compilers and LLVM</li><li>Give students exposure to real-world software development while getting paid a stipend</li><li>Allow students to do paid work related to their academic pursuits versus getting an unrelated summer job</li><li>Bring new developers into the LLVM project</li><li>Some LLVM bugs get fixed or new features get added</li></ul><br /><b>Students - Apply now! </b><br /><b><br /></b>Ok, so you can't apply right now as the official application to GSoC does not open until March 12, 2018, but you must begin discussing your project on the <a href="http://lists.llvm.org/mailman/listinfo">LLVM mailing lists</a> well before that date. There are many <a href="http://llvm.org/OpenProjects.html#gsoc18">open projects listed on our webpage</a>. Once you have selected a project, you will discuss it on the appropriate mailing list.<br /><br />If you have an idea for a project that is not listed, you can always propose it on the list as well and seek out a mentor.<br /><br /><b>Key Dates to Remember</b><br /><b><br /></b>We have listed a few key dates here, but always consult the<a href="https://developers.google.com/open-source/gsoc/timeline"> official GSoC timeline</a> to confirm.<br /><br /><ul><li>March 12 (16:00 UTC) - Applications open</li><li>March 27 (16:00 UTC) - Deadline to file your application</li><li>April 23 (16:00 UTC) - Accepted student proposals are announced</li><li>May 14 - Coding begins</li></ul><br /><b><br /></b><b>LLVM Developers - Consider being mentor!</b><br /><b><br /></b>This program is not a success without our mentors. Thank you to all that have all who have already volunteered! If you have never mentored a GSoC project but are curious, it is not too late to volunteer! You can either select an <a href="http://llvm.org/OpenProjects.html#gsoc18">open project</a> without a mentor or propose your own. Make sure to get it listed on the webpage so that students can see it as an option.<br /><br />If mentoring just isn't an option for you at this time, consider helping the project out my spreading the word about GSoC.<br /><br /><b>Questions?</b><br /><b><br /></b>If you have questions about the program for the organizers, please email <a href="mailto:[email protected]">[email protected]</a>. Project specific questions should be sent to the appropriate <a href="http://lists.llvm.org/mailman/listinfo">developer mailing list</a> instead.<br /><br />
- Improving Link Time on Windows with clang-cl and lldhttps://blog.llvm.org/2018/01/improving-link-time-on-windows-with.htmlMon, 08 Jan 2018 10:06:00 +0000https://blog.llvm.org/2018/01/improving-link-time-on-windows-with.htmlOne of our goals in bringing clang and lld to Windows has always been to improve developer experience, and what is it that developers want the most? Faster build times! Recently, our focus has been on improving link time because it's the step that's the hardest to parallelize so we can't fall back on the time honored tradition of throwing more cores at it.<br /><br />Of the various steps involved in linking, generating the debug info (which, on Windows, is a PDB file) is by far the slowest since it involves merging O(# of linker inputs) sequences of type records, most of which are duplicate anyway. For example, if two cpp files both include <span style="font-family: "courier new" , "courier" , monospace;"><string></span><span style="font-family: inherit;">, then both of those object files will have hundreds of duplicate type records that need to be de-duplicated during the link step. This means you have to compute O(M x N) hash values, even though only a small fraction of those ultimately contribute to the final PDB.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">Several strategies have been invented to deal with this over the years and try to make linking faster. Many years ago, Microsoft introduced the notion of a <i>Type Server</i> (enabled via <b>/Zi</b> compiler option in MSVC), which moves some of the work into the compiler (to take advantage of parallelism). More recently we have been given the <b>/DEBUG:FASTLINK</b> linker option which attempts to solve the problem by not merging types at all in the linker. However, each of these strategies has its own set of disadvantages, and neither can be considered perfect for all use cases.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">In this blog post, we'll first go over some technical background about CodeView so that we can understand the problem, followed by a summary of existing attempts to speed up type merging. Then, we'll describe a novel extension to the PE/COFF file format which speeds up linking by offloading part of the work required to de-duplicate types to the compiler and using a new algorithm which uniquely identifies type records even across input files, and discuss the various tradeoffs of each approach. Finally, we'll present some benchmarks and discuss how you can try this out in clang-cl and lld today.</span><br /><span style="font-family: inherit;"><br /></span><br /><h2><span style="font-family: inherit;">Background</span></h2><div><span style="font-family: inherit;">Consider a simple structure in C++, defined like this a header file:</span></div><div><span style="font-family: inherit;"><br /></span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: blue;">struct</span> <span style="color: #999999;">Node</span> {</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #999999;">Node</span> *Next = <span style="color: blue;">nullptr</span>;</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #999999;">Node</span> *Prev = <span style="color: blue;">nullptr</span>;</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: blue;">int</span> Value = 0;</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> };</span></div><div><span style="font-family: inherit;"><br /></span></div><div><span style="font-family: inherit;">Since each compilation happens independently of every other compilation, the compiler cannot assume any other translation unit will ever emit the records necessary to describe this type. As a result, to guarantee that the type makes it into the final PDB, <i>every</i> compiler instance that encounters this definition must emit type information for this type. So the record will be serialized by the compiler into a series of records that looks roughly like this:</span></div><div><span style="font-family: inherit;"><br /></span></div><div><span style="font-family: "courier new" , "courier" , monospace;">0x1004 | LF_STRUCTURE [size = 40] `Node`</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> unique name: `.?AUNode@@`</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> vtable: <none></span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> base list: <none></span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> field list: <none></span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> options: forward ref | has unique name</span></div><div><span style="font-family: "courier new" , "courier" , monospace;">0x1005 | LF_POINTER [size = 12]</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> referent = 0x1004</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> mode = pointer</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> opts = None</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> kind = ptr32</span></div><div><span style="font-family: "courier new" , "courier" , monospace;">0x1006 | LF_FIELDLIST [size = 52]</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> - LF_MEMBER</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> name = `Next`</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> Type = 0x1005</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> Offset = 0</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> attrs = public</span></div><div><div><span style="font-family: "courier new" , "courier" , monospace;"> - LF_MEMBER</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> name = `Prev`</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> Type = 0x1005</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> Offset = 4</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> attrs = public</span></div></div><div><div><span style="font-family: "courier new" , "courier" , monospace;"> - LF_MEMBER</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> name = `Value`</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> Type = 0x0074 (int)</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> Offset = 8</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> attrs = public</span></div></div><div><span style="font-family: "courier new" , "courier" , monospace;">0x1007 | LF_STRUCTURE [size = 40] `Node`</span></div><div><div><span style="font-family: "courier new" , "courier" , monospace;"> unique name: `.?AUNode@@`</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> vtable: <none></span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> base list: <none></span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> field list: 0x1006</span></div><div><span style="font-family: "courier new" , "courier" , monospace;"> options: has unique name</span></div></div><div><span style="font-family: inherit;">The values on the left correspond to the types <i>index</i> in the type sequence and depend on what types have already been encountered, while other types can the refer to them (for example, </span><span style="font-family: "courier new" , "courier" , monospace;">referent = 0x1004</span><span style="font-family: inherit;">) means that this record is a pointer to whatever the type at index 0x1004 was.</span></div><div><span style="font-family: inherit;"><br /></span></div><div>As a result of this design, another compilation unit which includes the same header file will need to emit this exact same type, with the only difference being the indices (since the other compilation may encounter other types before this one, causing the ordering to be different).</div><div><br /></div><div><div class="MsoNormal">In short, type indices only make sense within the context of a single type sequence (i.e. compiland), but since the linker needs to see across <i>all</i> object files, it has to have some way of identifying whether a type from object file A is isomorphic to a different type from object file B, even if its type indices might be different numerically from any previously seen type. </div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">This algorithm, henceforth referred to as <i>type merging</i>, is the primary consumer of CPU cycles during linking (measured in LLD, and estimated in MSVC linker by comparing /DEBUG:FULL vs /DEBUG:FASTLINK times), and as such it is the portion of the linking process which this blog post presents a new solution to.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><h2>Existing Solutions</h2></div><div><div class="MsoNormal"><span lang="EN">Itâs worthwhile to discuss some of the existing attempts to reduce the cost associated with type merging so that we can compare and contrast their various pros and cons.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN"><br /></span></div><h3><span lang="EN">Type Servers (/Zi)</span></h3></div><div><span lang="EN"></span><br /><div class="MsoNormal"><span lang="EN"><span lang="EN">The /Zi compiler option was one of the first attempts to address type merging speed, and it dates back many years. The idea behind type servers is to offload the work of de-duplication from the linking phase to the compilation phase. Most build systems already support parallel compilation, and even if they donât </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">cl.exe</span><span lang="EN"> supports it natively via the /MP compiler switch, so there is no roadblock to anyone taking advantage of parallel compilation. <o:p></o:p></span></span></div><span lang="EN"></span><br /><div class="MsoNormal"><span lang="EN"><br /></span></div><span lang="EN"></span><br /><div class="MsoNormal"><span lang="EN"><span lang="EN">To implement type servers, each compilation process communicates via IPC with a single process (<span style="font-family: "courier new" , "courier" , monospace;">mspdbsrv.exe</span>) whose job is to de-duplicate type records on the fly, and when a record is isomorphic to an existing record, the type server communicates back the previously saved index, and when it is new it sends back a new index. This allows type deduplication to happen <i>mostly</i>in parallel, but adding some overhead to each compilation (since there is contention over a global lock) in return for significantly reduced link times, since types will already have been merged.<o:p></o:p></span></span></div><span lang="EN"></span><br /><div class="MsoNormal"><span lang="EN"><br /></span></div><span lang="EN"></span><div class="MsoNormal"><span lang="EN"><span lang="EN">Type servers bring with them some disadvantages though, so we enumerate them here:<o:p></o:p></span></span></div><span lang="EN"><ol start="1" style="margin-top: 0in;" type="1"><li class="MsoNormalCxSpMiddle"><span lang="EN">Type servers add significant context switching and global lock contention to the compilation phase, reducing parallelism and degrading overall system performance while a build is in process. While some performance is reclaimed from the linker, some is sacrificed due to the use of a global system lock. Itâs still a net win, but as it is not free, it leaves open the possibility that we may be able to achieve better parallelism using a different approach.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">The type server process itself (</span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">mspdbsrv.exe</span><span lang="EN">) introduces a single point of failure. When it crashes (we see C1033 several times per day on Chrome, for example, which seems to indicate an mspdbsrv.exe crash) it could trigger a full rebuild if the type server PDB file is left in a corrupt state.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">mspdbsrv</span><span lang="EN"> is incompatible with distributed builds, which is a show-stopper for large applications that can take several hours to build on normal workstations. Type servers operate only via local IPC. While multi-processing works well for small applications, many large products have build farms that distribute compilations among tens or hundreds of physical machines. Type servers are incompatible with this scenario</span><span lang="EN">.<o:p></o:p></span></li></ol><div><h2><span lang="EN">Fastlink PDBs<o:p></o:p></span></h2><div class="MsoNormal"><span lang="EN">Fastlink PDBs are a relatively recent introduction, and the approach used by this solution is to <i>eliminate type merging entirely.</i> To support this, special metadata is set in the PDB file to indicate to the tool that this is a fastlink PDB, and when the tool (e.g. debugger) encounters this metadata, it will fetch all type information from the original object file, rather than from the PDB. As before, there are several disadvantages to this approach, enumerated here:<o:p></o:p></span></div><ol start="1" style="margin-top: 0in;" type="1"><li class="MsoNormalCxSpMiddle"><span lang="EN">The </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">pdbcopy</span><span lang="EN"> utility is almost unusable with fastlink PDBs for performance reasons.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">Since type merging doesnât happen, indexing of type information also doesnât happen (since the expensive part of building an index -- the hashing -- comes for free when you were hashing the record anyway). This leads to degradation in the debugger user experience, since waits which previously happened only at build time now happen at debug-time.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">Fastlink PDBs are not portable. The PDB references the object files by path, so if you copy the PDB and object files to a different machine (or even different path on the same machine) for archival purposes, they can no longer be debugged. This is a deal-breaker for using it on production builds<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">Symbols canât be enumerated in a Fastlink PDB. This is most obvious if you attempt to use DIA SDK on a Fastlink PDB, where it will simply refuse to do anything at all. This means that the only externally supported way of querying debug info for users is impossible against a Fastlink PDB. Beyond that, however, it also means that even Microsoftâs own tools which need to enumerate symbols cannot use any standard API for doing so. For example, WinDbg doesnât fully support Fastlink PDBs, and many workflows are broken by the use of them, even using supported Microsoft tools.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">It has several serious stability issues which make it unusable on large projects [<a href="https://developercommunity.visualstudio.com/content/problem/158451/chrome-with-1550-preview-50-and-fastlink-crashes-d.html"><span style="color: #1155cc;">ref</span></a>]. This is probably related to point 4 above, namely the fact that every tool that wants to be able to work with a Fastlink PDB needs to use different code than the SDK that has been tested and battle-hardened through years of development.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">When compiling with clang-cl and linking with /debug:fastlink the compiler has to be instructed to <a href="https://cs.chromium.org/chromium/src/build/config/compiler/BUILD.gn?type=cs&q=build/config/compiler/BUILD.gn&sq=package:chromium&l=1886"><span style="color: #1155cc;">emit additional debug information</span></a>, making .obj files about 29% larger.<o:p></o:p></span></li></ol><div><h2><span style="font-family: inherit;"><span lang="EN">Clang's Solution - The COFF </span><span lang="EN">.debug$H</span></span><span lang="EN"><span style="font-family: inherit;"> section</span><o:p></o:p></span></h2><div class="MsoNormal"><span lang="EN">This new approach tries to combine the ideas behind type servers and fastlink PDBs. Like type servers, it attempts to offload the work of de-duplication to the compilation phase so that it can be done in parallel. However, it does so using an algorithm with the property that the resulting hash can be used to identify a type record even across type streams. Specifically, <b>if two records have the same hash, they are the same record even if they are from different object files.</b> If you can take it on faith that such an algorithm exists (which will be henceforth referred to as a <i>global hash</i>), then the amount of work that the linker needs to perform is greatly reduced. And the work that it does still have to do can be done much quicker. Perhaps most importantly, <i>it produces a byte-for-byte identical PDB to when the option is not used</i>, meaning all of the issues surrounding Fastlink PDBs and compatibility are gone.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">Previously, the linker would do something that looks roughly like this:<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> HashTable<Type> HashedTypes;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> vector<Type> MergedTypes;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> for (ObjectFile &Obj : Objects) {<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> for (Type &T : Obj.types()) {<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> remapAllTypeIndices(MergedTypes, T);<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> if (!HashedTypes.try_insert(T))<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> continue;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> MergedTypes.push_back(T);<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> }<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> }<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN">The important observations here are:<o:p></o:p></span></div><ol start="1" style="margin-top: 0in;" type="1"><li class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">remapAllTypeIndices </span><span lang="EN">is called unconditionally for every type in every object file.<o:p></o:p></span></li><li class="MsoNormal"><span lang="EN">A hash of the type is computed unconditionally for every type<o:p></o:p></span></li><li class="MsoNormal"><i>At least one</i><span lang="EN"> full record comparison is done for every type. In practice it turns out to be much more, because hash buckets are computed modulo table size, so there will actually be 1 full record comparison for every probe.<o:p></o:p></span></li></ol><div class="MsoNormal"><span lang="EN">Given a global hash function as described above, the algorithm can be re-written like this:</span><span lang="EN" style="font-size: 8.0pt; line-height: 115%;"><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> HashMap<SHA1, int> HashToIndex;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> vector<Type> OrderedTypes;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> for (ObjectFile &Obj : Objects) {<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> auto Hashes = Obj.DebugHSectionHashes;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> for (int I=0; I < Obj.NumTypes; ++I) {<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> int NextIndex = OrderedTypes.size();<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> if (!HashToIndex.try_emplace(Hashes[I], NextIndex))<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> continue;<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> remapAllTypeIndices(T);<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> OrderedTypes.push_back(T);<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> }<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; line-height: 115%;"> }<span style="font-size: 10pt;"><o:p></o:p></span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">While this appears very similar, its performance characteristics are quite different.<o:p></o:p></span></div><ol start="1" style="margin-top: 0in;" type="1"><li class="MsoNormalCxSpMiddle"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">remapAllTypeIndices </span><span lang="EN">is only called when the record is actually new. Which, as we discussed earlier, is a small fraction of the time over many linker inputs.</span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"><o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">A hash of the type is <b>never</b> computed by the linker.<b> </b>It is simply there in the object file (the exception to this is mixed linker inputs, discussed earlier, but those are a small fraction of input files).<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">Full record comparisons <b>never</b> happen<i>.</i> Since we are using a strong hash function with negligible chance of false collisions, and since the hash of a record provides equality semantics across streams, the hash is as good as the record itself.<i><o:p></o:p></i></span></li></ol><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">Combining all of these points, we get an algorithm that is extremely cache friendly. Amortized over all input files, most records during type merging are cache hits (i.e. duplicate records). With this algorithm when we get a cache hit, the only two data structures that are accessed are:<o:p></o:p></span></div><ol start="1" style="margin-top: 0in;" type="1"><li class="MsoNormalCxSpMiddle"><span lang="EN">An array of contiguous hash values.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">An array of contiguous hash buckets.<o:p></o:p></span></li></ol><div class="MsoNormal"><span lang="EN">Since we never do full equality comparison (which would blow out the L1 and sometimes even L2 cache due to the average size of a type record being larger than a cache line) the algorithm here is very fast.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">Weâve deferred discussion of how to create such a hash up until now, but it is actually fairly straightforward. We use what is known as a âtree hashâ or âMerkle treeâ. The idea is to pass bytes from a type record directly to the hash function up until the point we get to a type index. Then, instead of passing the numeric value of the type index to the hash function, we pass the previously computed hash of the record that is being referenced.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">Such a hash is very fast to compute in the compiler because <i>the compiler must already hash types anyway</i>, so the incremental cost to emit this to the .debug$H section is negligible. For example, when a type is encountered in a translation unit, before you can add that type to the object fileâs </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$T</span><span lang="EN"> section, it must first be verified that the type has not already been added. And since this is happening naturally in the order in which types are encountered, all that has to be done is to save these hash values in an array indexed by type index, and subsequent hash operations will have O(1) access to all of the information needed to compute this merkle hash.<o:p></o:p></span></div><div class="MsoSubtitle"><a href="https://www.blogger.com/null" name="_ma3qfmnbo3o6"></a><span lang="EN"> </span> </div><h3><span lang="EN">Mixed Input Files and Compiler/Linker Compatibility</span></h3><div class="MsoSubtitle"><a href="https://www.blogger.com/null" name="_rmj5k0mxyuuq"></a></div><div class="MsoNormal"><span lang="EN">A linker must be prepared to deal with a mixed set of input files. For example, while a particular compiler may choose to always emit </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> sections, a linker must be prepared to link objects that for whatever reason do not have this section. To handle this, the linker can examine all inputs up front and manually compute hashes for inputs with missing </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN">sections. In practice this proves to be a small fraction and the penalty for doing this serially is negligible, although it should be noted that in theory this can also be done as a parallel pre-processing step if some use cases show that this has non-negligible cost.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">Similarly, the emission of this section in an object file has no impact on linkers which have not been taught to use it. Since it is a purely additive (and optional) inclusion into the object file, any linker which does not understand it will continue to work exactly as it does today.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN"><br /></span></div><h2><span lang="EN">The On-Disk Format</span></h2><div class="MsoNormal"><span lang="EN">Clang uses the following on-disk format for the </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN"> </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">0x0 : <Section Magic> (4 bytes)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> 0x4 : <Version> (2 bytes)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> 0x6 : <Hash Algorithm> (2 bytes)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> 0x8 : <Hash Value> (N bytes)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> 0x8 + N : <Hash Value> (N bytes)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";"> ⦠<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">Here, âSection Magicâ is an arbitrarily chosen 4-byte number whose purpose is to provide some level of certainty that what weâre seeing is a real </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section, and not some section that someone created that accidentally happened<span style="font-family: inherit;"> to be called that. Our current implementation uses the value 0x133C9C5, which represents the date of the initial prototype implementation. But this can be any reasonable value here, as long as it never changes.<o:p></o:p></span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;">âVersionâ is reserved for future use, so that the format of the section can theoretically change. <o:p></o:p></span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;"> <span lang="EN" style="line-height: 115%;">âHash Algorithmâ is a value that indicates what algorithm was used to generate the hashes that follow. As such, the value of N above is also a function of what hash algorithm is used. Currently, the only proposed value for Hash Algorithm is SHA1 = 0, which would imply N = 20 when Hash Algorithm = 0. Should it prove useful to have truncated 8-byte SHA1 hashes, we could define SHA1_8 = 1, for example.</span></span></span></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;"><span lang="EN" style="font-size: 11pt; line-height: 115%;"><br /></span></span></span></div><h2><span lang="EN">Limitations and Pitfalls</span></h2><div class="MsoNormal"><span lang="EN">The biggest limitation of this format is that it increases object file size. Experiments locally on fairly large projects show an average aggregate object file size increase of ~15% compared to /DEBUG:FULL (which, for clang-cl, actually makes .debug$H object files <i>smaller</i>than those needed to support /DEBUG:FASTLINK).<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">There is another, less obvious potential pitfall as well. The worst case scenario is when no input files have a </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section present, but this limitation is the same in principle even if only a subset of files have a </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section. Since the linker must agree on a single hash function for all object files, there is the question of what to do when not all object files agree on hash function, or when not all object files contain a </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H </span><span lang="EN">section. If the code is not written carefully, you could get into a situation where, for example, no input files contain a </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section so the linker decides to synthesize one on the fly for every input file. Since SHA1 (for example) is quite slow, this could cause a huge performance penalty.<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN">This limitation can be coded around with some care, however. For example, tree hashes can be computed up-front in parallel as a pre-processing step. Alternatively, a hash function could be chosen based on some heuristic estimate of what would likely lead to the fastest link (based on the percentage of inputs that had a </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section, for example). There are other possibilities as well. The important thing is to just be aware of this potential pitfall, and if your links become very slow, you'll know that the first thing you should check is "do all my object files have .debug$H sections?"<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN"> </span></div><div class="MsoNormal"><span lang="EN">Finally, since a hash is considered to be identical to the original record, we must consider the possibility of collisions. That said, this does not appear to be a serious concern in practice. A single PDB can have a theoretical maximum of 2<sup>32</sup> type records anyway (due to a type index being 4 bytes). The following table shows the expected number of type records needed for a collision to exist as a function of hash size.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN"></span></div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 5.0pt; mso-border-alt: solid black 1.0pt; mso-border-insideh: 1.0pt solid black; mso-border-insidev: 1.0pt solid black; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-table-layout-alt: fixed; mso-yfti-tbllook: 1536; width: 449px;"> <tbody><tr> <td style="background: #6D9EEB; border: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div class="MsoNormal" style="line-height: normal; mso-pagination: none;"><span lang="EN">Hash Size (Bytes)<o:p></o:p></span></div></td> <td style="background: #E69138; border-left: none; border: solid black 1.0pt; mso-border-left-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">Average # of records needed for a collision<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">4<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">82,137<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">6<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">21,027,121<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">8<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">5,382,943,231<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">12<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">3.53 x 10<sup>14<o:p></o:p></sup></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">16<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">2.31 x 10<sup>19</sup><o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">20<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 226.5pt;" valign="top" width="302"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">1.52 x 10<sup>24</sup><o:p></o:p></span></div></td> </tr></tbody></table></div></div><div><span lang="EN" style="line-height: 115%;"><span style="font-family: inherit;">Given that this is strictly for debug information and not generated code, itâs worth thinking about the <i>severity</i> of a collision. We feel that an 8-byte hash is probably acceptable for real world use.</span></span></div><div><span lang="EN" style="font-family: "arial" , sans-serif; line-height: 115%;"><br /></span></div><h2><span lang="EN" style="font-family: "arial" , sans-serif; line-height: 115%;">Benchmarks</span></h2><div><span style="font-family: inherit;">Here we will give some benchmarks on large real world applications (specifically, Chrome and clang). The times presented are <b>only</b> for the linker. gn args for each build of chromium are specified at the end..</span></div><div><span style="font-family: "arial" , sans-serif;"><br /></span></div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 5.0pt; mso-border-alt: solid black 1.0pt; mso-border-insideh: 1.0pt solid black; mso-border-insidev: 1.0pt solid black; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-table-layout-alt: fixed; mso-yfti-tbllook: 1536; width: 623px;"> <tbody><tr style="height: 21.0pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"> <td rowspan="2" style="background: #6D9EEB; border: solid black 1.0pt; height: 21.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 82.5pt;" valign="top" width="110"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><br /></div><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><a href="https://www.blogger.com/null"></a><a href="https://www.blogger.com/null"></a><a href="https://www.blogger.com/null"></a><a href="https://www.blogger.com/null"></a><a href="https://www.blogger.com/null"></a>Toolchain<span lang="EN"> <o:p></o:p></span></div></td> <td rowspan="2" style="background: #6D9EEB; border-left: none; border: solid black 1.0pt; height: 21.0pt; mso-border-left-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><br /></div><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">Mode<o:p></o:p></span></div></td> <td colspan="4" style="background: #FF9900; border-left: none; border: solid black 1.0pt; height: 21.0pt; mso-border-left-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 274.5pt;" valign="top" width="366"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">Target<o:p></o:p></span></div></td> </tr><tr style="height: 21.0pt; mso-yfti-irow: 1;"> <td style="background: #F9CB9C; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 21.0pt; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 75.75pt;" valign="top" width="101"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">blink_core.dll<o:p></o:p></span></div></td> <td style="background: #F9CB9C; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 21.0pt; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 69.0pt;" valign="top" width="92"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">content.dll<o:p></o:p></span></div></td> <td style="background: #F9CB9C; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 21.0pt; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 66.0pt;" valign="top" width="88"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">chrome.dll<o:p></o:p></span></div></td> <td style="background: #F9CB9C; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 21.0pt; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 63.75pt;" valign="top" width="85"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">clang.exe<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 82.5pt;" valign="top" width="110"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">MSVC<o:p></o:p></span></div></td> <td style="background: #A4C2F4; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">/DEBUG:FULL<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 75.75pt;" valign="top" width="101"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">553.11s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 69.0pt;" valign="top" width="92"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">205.45s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 66.0pt;" valign="top" width="88"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">507.17s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 63.75pt;" valign="top" width="85"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">62.45s<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 82.5pt;" valign="top" width="110"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">MSVC<o:p></o:p></span></div></td> <td style="background: #A4C2F4; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">/DEBUG:FASTLINK<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 75.75pt;" valign="top" width="101"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">116.77s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 69.0pt;" valign="top" width="92"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">56.05s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 66.0pt;" valign="top" width="88"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">67.80s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 63.75pt;" valign="top" width="85"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">29.37s<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 82.5pt;" valign="top" width="110"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">lld-link<o:p></o:p></span></div></td> <td style="background: #A4C2F4; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">/DEBUG:FULL<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 75.75pt;" valign="top" width="101"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">121.17s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 69.0pt;" valign="top" width="92"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">42.10s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 66.0pt;" valign="top" width="88"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">42.31s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 63.75pt;" valign="top" width="85"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">24.14s<o:p></o:p></span></div></td> </tr><tr> <td style="background: #A4C2F4; border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 82.5pt;" valign="top" width="110"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">lld-link<o:p></o:p></span></div></td> <td style="background: #A4C2F4; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 110.25pt;" valign="top" width="147"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">/DEBUG:GHASH<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 75.75pt;" valign="top" width="101"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">88.71s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 69.0pt;" valign="top" width="92"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">33.30s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 66.0pt;" valign="top" width="88"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">34.76s<o:p></o:p></span></div></td> <td style="background: #FCE5CD; border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 5.0pt 5.0pt 5.0pt 5.0pt; width: 63.75pt;" valign="top" width="85"><div align="center" class="MsoNormal" style="line-height: normal; mso-pagination: none; text-align: center;"><span lang="EN">17.99s<o:p></o:p></span></div></td> </tr></tbody></table><br /><div><!--[if !supportAnnotations]--> <br /><div><div class="msocomtxt" id="_com_6" language="JavaScript"><!--[if !supportAnnotations]--></div><!--[endif]--></div></div></div><div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;">The numbers here indicate a reduction in link time of up to 30% by enabling /DEBUG:GHASH in lld.<o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;"><br /></span></span></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;">It's worth mentioning that lld does not yet have support for incremental linking so we could not compare the cost of an incremental link with /DEBUG:GHASH versus MSVC. We still expect incremental linking using MSVC under optimal conditions (e.g. change whitespace in a header file) to produce much faster links than lld is currently able to do.</span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;">There are several possible avenues for further optimization though, so we will finish up by discussing them.</span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN"><span style="font-family: inherit;"><br /></span></span></div><h2><span lang="EN">Further Improvements</span></h2><div class="MsoNormal"><span lang="EN">There are several ways to improve the times further, which have yet to be explored.</span></div><div class="MsoNormal"><br /></div><ol start="1" style="margin-top: 0in;" type="1"><li class="MsoNormalCxSpMiddle"><span lang="EN">Use a smaller or faster hash. We use a 20-byte SHA1 hash. This is not a multiple of cache line size, and in any case the probability of collision is astronomically small even in the largest PDBs, considering that the theoretical limit of a PDB is just under 2^32 possible unique types (due to the 4-byte size of a type index). SHA1 is also notoriously slow. It might be interesting to try, for example, a Blake2 set to output an 8 byte hash. This should give sufficiently low probability of a collision while improving cache performance. The on-disk format is designed with this flexibility in mind, as different hash algorithms can be specified in the header.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">Hashes for compilands with missing </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> sections can be computed in parallel before linking. Currently when we encounter an object file without a </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$H</span><span lang="EN"> section, we must synthesize one in the linker. Our prototype algorithm does this serially for each input.<o:p></o:p></span></li><li class="MsoNormalCxSpMiddle"><span lang="EN">Symbol records from </span><span lang="EN" style="font-family: "courier new"; mso-fareast-font-family: "Courier New";">.debug$S </span><span lang="EN">sections can be merged in parallel. Currently in lld, we first merge type records into the TPI stream, then we iterate symbol records and remap types in each symbol record to correspond to the new type indices. If we merge types from all modules up front, the symbol records (with the exception of global symbols) can be merged in parallel since they get written to independent streams).<o:p></o:p></span></li></ol><h2>Try it out!</h2></div><div>If you're already using clang-cl and lld on Windows today, you can try this out. There are two flags needed to enable this, one for the compiler and one for the linker:</div><div><ol><li>To enable the emission of a .debug$H section by the compiler, you will need to pass the undocumented <span style="font-family: "courier new" , "courier" , monospace;">-mllvm -emit-codeview-ghash-section</span><span style="font-family: inherit;"> flag to clang-cl (this flag should go away in the future, once this is considered stable and good enough to be turned on by default).</span></li><li><span style="font-family: inherit;">To tell lld to use this information, you will need to pass the </span><span style="font-family: "courier new" , "courier" , monospace;">/DEBUG:GHASH</span><span style="font-family: inherit;"> to lld.</span></li></ol><div>Note that this feature is still considered highly experimental, so we're interested in your feedback (llvm-dev@ mailing list, direct email is ok too) and bug reports (bugs.llvm.org). </div><div><br /></div></div></span></div>
- Clang ⥠bash -- better auto completion is coming to bashhttps://blog.llvm.org/2017/09/clang-bash-better-auto-completion-is.htmlTue, 19 Sep 2017 23:37:00 +0000https://blog.llvm.org/2017/09/clang-bash-better-auto-completion-is.html<div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-01JogPSFCBM/WcKRj79NXNI/AAAAAAAANZA/X1Mr4wf_cnI57LGLoglYPn_XZWE_q-6egCLcBGAs/s1600/out.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="500" data-original-width="800" height="400" src="https://4.bp.blogspot.com/-01JogPSFCBM/WcKRj79NXNI/AAAAAAAANZA/X1Mr4wf_cnI57LGLoglYPn_XZWE_q-6egCLcBGAs/s640/out.gif" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"></span></span></div><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Compilers are complex pieces of software and have a multitude of command-line options to fine tune parameters. Clang is no exception: it has 447 command-line options. Itâs nearly impossible to memorize all these options and their correct spellings, that's where shell completion can be very handy. When you type in the first few characters of a flag and hit tab, it will autocomplete the rest for you.</span></span></div><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"><span style="font-family: "arial"; font-size: 14pt; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Background</span><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">However, such a autocompletion feature is not available yet, as there's no easy way to get a complete list of the options Clang supports. For example, bash doesnât have any autocompletion support for Clang, and despite some shells like zsh having a script for command-line autocompletion, they use hard coded lists of command-line options, and are not automatically updated when a new option is added to Clang. These shells also canât autocomplete arguments which some flags take (-std=[tab] for instance).</span></span><br /><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">This is the problem we were working to solve during this yearâs Google Summer of Code. Weâre adding a feature to Clang so that we can implement a complete, exact command-line option completion which is highly portable for any shell. To start with, we'll provide a completion script for bash which uses this feature. </span></span></div><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"><span style="font-family: "arial"; font-size: 14pt; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">Implementation</span></span></div><span id="docs-internal-guid-68af261c-84f5-10c3-00b1-6106d33aa46a"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Clang now has a new command line option called </span><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">--autocomplete</span><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">. This flag receives the incomplete user input from the shell and then queries the internal data structures of the current Clang binary, and returns a list of possible completions. With this API, we can always get an accurate list of options and values any time, on any newer versions of Clang.</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">We built an autocompletion using this in bash for the first implementation. You can find its source code </span><a href="https://github.com/llvm-mirror/clang/blob/master/utils/bash-autocomplete.sh" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">here</span></a><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">. Also, </span><a href="https://github.com/Teemperor/clang-autocomplete-qt-demo/blob/master/clangcompleter.cpp#L29" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">here</span></a><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> is the sample for Qt text entry autocompletion to give an example how to use this API from an UI application as seen below:</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;"><img alt="final.gif" height="305" src="https://lh6.googleusercontent.com/ZMCiIg-nvoKUCVI3yrIxajonOBqEL1QiievBUEFeL3zNp-E6Ua6na5u6cenXMteX4XjqH2t_ve584cTA4Hw6MNczz6UtTOr_MpnejkI61fEhbsuhmIkccA7cUgmyIvyR4dni98dX" style="-webkit-transform: rotate(0.00rad); border: none; transform: rotate(0.00rad);" width="602" /></span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">You can always complete one flag at a time. So if you want to use the API, you have to select the flag that the user is currently typing. Then just pass this flag to the --autocomplete flag in the selected clang binary. So in the case below all flags start with `-tr` are displayed with their descriptions behind them (separated from the flag with a tab character).</span><br /><div class="separator" style="clear: both; text-align: center;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><a href="https://2.bp.blogspot.com/-VRKNRM79brs/WcKM_j0JZdI/AAAAAAAANYg/0JosgCr4lo0VphdvQMqGSTXBwtqzGIOqwCLcBGAs/s1600/tr.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="64" data-original-width="496" height="82" src="https://2.bp.blogspot.com/-VRKNRM79brs/WcKM_j0JZdI/AAAAAAAANYg/0JosgCr4lo0VphdvQMqGSTXBwtqzGIOqwCLcBGAs/s640/tr.png" width="640" /></a></span></div></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">The API also supports completing the values of flags. If you have a flag for which value completion is supported, you can also provide an incomplete value behind the flag separated by a comma to get completion for this:</span><br /><div class="separator" style="clear: both; text-align: center;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><a href="https://2.bp.blogspot.com/-bu1RSxe2PjQ/WcKNLOcnCqI/AAAAAAAANYk/xu41ZdQbPKcIoR1VpjLcI_055YCWv_lsgCLcBGAs/s1600/stdlib.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="59" data-original-width="495" height="76" src="https://2.bp.blogspot.com/-bu1RSxe2PjQ/WcKNLOcnCqI/AAAAAAAANYk/xu41ZdQbPKcIoR1VpjLcI_055YCWv_lsgCLcBGAs/s640/stdlib.png" width="640" /></a></span></div></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">If you provide nothing after the comma, the list of the all possible values for this flag is displayed.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-7CZRQ3DJUMA/WcKNQ_GeYgI/AAAAAAAANYo/YsnMXn5EcUIjPrO-y5nEVj6GvuEaRZ9jACLcBGAs/s1600/meabi.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="94" data-original-width="491" height="122" src="https://4.bp.blogspot.com/-7CZRQ3DJUMA/WcKNQ_GeYgI/AAAAAAAANYo/YsnMXn5EcUIjPrO-y5nEVj6GvuEaRZ9jACLcBGAs/s640/meabi.png" width="640" /></a></div><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"></span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial"; font-size: 14pt; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;">How to get it</span></div><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">This feature is available for use now with LLVM/clang 5.0 and weâll also be adding this feature to the standard bash completion package. Make sure you have the latest clang version on your machine, and source </span><a href="https://github.com/llvm-mirror/clang/blob/master/utils/bash-autocomplete.sh" style="text-decoration-line: none;"><span style="color: #1155cc; font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">this script</span></a><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">. If want to make the change permanent, just source it from your </span><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">.bashrc</span><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> and enjoy typing your clang invocations!</span></span>
- 2017 US LLVM Developers' Meeting Programhttps://blog.llvm.org/2017/09/2017-us-llvm-developers-meeting-program.htmlMon, 11 Sep 2017 09:00:00 +0000https://blog.llvm.org/2017/09/2017-us-llvm-developers-meeting-program.htmlThe LLVM Foundation is excited to announce the selected proposals for the 2017 US LLVM Developers' Meeting!<br /><br /><b>Keynotes</b>:<br /><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#talk12">Falcon: An optimizing Java JIT </a></b> - <i>Philip Reames</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk21">Compiling Android userspace and Linux kernel with LLVM </a></b> - <i>Stephen Hines, Nick Desaulniers and Greg Hackmann</i></li></ul><br /><b>Talks:</b><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#talk1">Apple LLVM GPU Compiler: Embedded Dragons </a></b> - <i>Marcello Maggioni and Charu Chandrasekaran</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk2">Bringing link-time optimization to the embedded world: (Thin)LTO with Linker Scripts </a></b> - <i>Tobias Edler von Koch, Sergei Larin, Shankar Easwaran and Hemant Kulkarni</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk3">Advancing Clangd: Bringing persisted indexing to Clang tooling </a></b> - <i>Marc-Andre Laperle</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk4">The Further Benefits of Explicit Modularization: Modular Codegen </a></b> - <i>David Blaikie</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk5">eval() in C++ </a></b> - <i>Sean Callanan</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk7">Enabling Parallel Computing in Chapel with Clang and LLVM </a></b> - <i>Michael Ferguson</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk8">Structure-aware fuzzing for Clang and LLVM with libprotobuf-mutator </a></b> - <i>Kostya Serebryany, Vitaly Buka and Matt Morehouse</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk9">Adding IndexâWhileâBuilding and Refactoring to Clang </a></b> - <i>Alex Lorenz and Nathan Hawes</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk10">XRay in LLVM: Function Call Tracing and Analysis </a></b> - <i>Dean Michael Berris</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk11">GlobalISel: Past, Present, and Future </a></b> - <i>Quentin Colombet and Ahmed Bougacha</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk13">Dominator Trees and incremental updates that transcend time </a></b> - <i>Jakub Kuderski</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk14">Scale, Robust and Regression-Free Loop Optimizations for Scientific Fortran and Modern C++ </a></b> - <i>Tobias Grosser and Michael Kruse</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk15">Implementing Swift Generics </a></b> - <i>Douglas Gregor, Slava Pestov and John McCall</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk16">lld: A Fast, Simple, and Portable Linker </a></b> - <i>Rui Ueyama</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk17">Vectorizing Loops with VPlan â Current State and Next Steps </a></b> - <i>Ayal Zaks and Gil Rapaport</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk18">LLVM Compile-Time: Challenges. Improvements. Outlook. </a></b></li><li>- <i>Michael Zolotukhin</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk19">Challenges when building an LLVM bitcode Obfuscator </a></b> - <i>Serge Guelton, Adrien Guinet, Juan Manuel Martinez and Pierrick Brunet</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#talk20">Building Your Product Around LLVM Releases </a></b> - <i>Tom Stellard</i></li><li><a href="http://llvm.org/devmtg/2017-10/#talk6"><b>The Type Sanitizer: Free Yourself from -fno-strict-aliasing</b></a> - <i>Hal Finkel</i></li></ul><br /><i><br /></i><b>BoFs:</b><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#bof1">Storing Clang data for IDEs and static analysis </a></b> - <i>Marc-Andre Laperle</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof2">Source-based Code Coverage BoF </a></b> - <i>Eli Friedman and Vedant Kumar</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof3">Clang Static Analyzer BoF </a></b> - <i>Devin Coughlin, Artem Dergachev and Anna Zaks</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof4">Co-ordinating RISC-V development in LLVM </a></b> - <i>Alex Bradbury</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof5">Thoughts and State for Representing Parallelism with Minimal IR Extensions in LLVM </a></b> - <i>Xinmin Tian, Hal Finkel, Tb Schardl, Johannes Doerfert and Vikram Adve</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof6">BoF - Loop and Accelerator Compilation Using Integer Polyhedra </a></b> - <i>Tobias Grosser and Hal Finkel</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof7">LLDB Future Directions </a></b> - <i>Zachary Turner and David Blaikie</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#bof8">LLVM Foundation - Status and Involvement </a></b> - <i>LLVM Foundation Board of Directors</i></li></ul><br /><i><br /></i><b>Tutorials:</b><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#tutorial1">Writing Great Machine Schedulers </a></b> - <i>Javed Absar and Florian Hahn</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#tutorial2">Tutorial: Head First into GlobalISel </a></b> - <i>Daniel Sanders, Aditya Nandakumar and Justin Bogner</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#tutorial3">Welcome to the back-end: The LLVM machine representation. </a></b> - <i>Matthias Braun</i></li></ul><br /><i><br /></i><b>Lightning Talks:</b><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning1">Porting OpenVMS using LLVM </a></b> - <i>John Reagan</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning2">Porting LeakSanitizer: A Beginner's Guide </a></b> - <i>Francis Ricci</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning3">Introsort based sorting function for libc++ </a></b> - <i>Divya Shanmughan and Aditya Kumar</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning4">Code Size Optimization: Interprocedural Outlining at the IR Level </a></b> - <i>River Riddle</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning5">ThreadSanitizer APIs for external libraries </a></b> - <i>Kuba Mracek</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning6">A better shell command-line autocompletion for clang </a></b> - <i>Yuka Takahashi</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning7">A CMake toolkit for migrating C++ projects to clangâs module system. </a></b> - <i>Raphael Isemann</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning8">Debugging of optimized code: Extending the lifetime of local variables </a></b> - <i>Wolfgang Pieb</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning10">An LLVM based Loop Profiler </a></b> - <i>Shalini Jain, Kamlesh Kumar, Suresh Purini, Dibyendu Das and Ramakrishna Upadrasta</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#lightning11">Compiling cross-toolchains with CMake and runtimes build </a></b> - <i>Petr Hosek</i></li></ul><br /><br /><b>Student Research Competition:</b><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#src1">VPlan + RV: A Proposal </a></b> - <i>Simon Moll and Sebastian Hack</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#src2">Polyhedral Value & Memory Analysis </a></b> - <i>Johannes Doerfert and Sebastian Hack</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#src3">DLVM: A Compiler Framework for Deep Learning DSLs </a></b> - <i>Richard Wei, Vikram Adve and Lane Schwartz</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#src4">Leveraging LLVM to Optimize Parallel Programs </a></b> - <i>William Moses</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#src5">Exploiting and improving LLVM's data flow analysis using superoptimizer </a></b> - <i>Jubi Taneja and John Regehr</i></li></ul><br /><i><br /></i><b>Posters:</b><br /><ul><li><b><a href="http://llvm.org/devmtg/2017-10/#poster1">Venerable Variadic Vulnerabilities Vanquished </a></b> - <i>Priyam Biswas, Alessandro Di Federico, Scott A. Carr, Prabhu Rajasekaran, Stijn Volckaert, Yeoul Na, Michael Franz and Mathias Payer</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster2">Extending LLVMâs masked.gather/scatter Intrinsic to Read/write Contiguous Chunks from/to Arbitrary Locations. </a></b> - <i>Farhana Aleen, Elena Demikhovsky, Hideki Saito, and David Kreitzer</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster3">An LLVM based Loop Profiler </a></b> - <i>Shalini Jain, Kamlesh Kumar, Suresh Purini, Dibyendu Das and Ramakrishna Upadrasta</i></li><li><a href="http://llvm.org/devmtg/2017-10/#poster4"><b>Leveraging Compiler Optimizations to Reduce Runtime Fault Recovery Overhead</b></a> - <i>Fateme S. Hosseini, Pouya Fotouhi, Chengmo Yang and Guang R. Gao</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster5">Polyhedral Optimizations and transparent GPU offloading for Julia by Polly</a></b><i> - Sanjay Srivallabh Singapuram</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster6">Improving debug information in LLVM to recover optimized-out function parameters</a></b><i> - Ananth Sowda and Ivan Baev</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster7">Adding Debug Information and Merge Attribute to Merge-Functions LLVM passes</a></b><i> - Anmol Paralkar</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster8">ALLVM: LLVM All the Things!</a></b> <i>- Will Dietz and Vikram Adve</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster9">Project Sulong - Executing LLVM IR on top of a JVM</a></b><i> - Matthias Grimmer and Christian Wimmer</i></li><li><a href="http://llvm.org/devmtg/2017-10/#poster10"><b>JIT Fuzzing Solver: A LibFuzzer based constraint solver</b></a><i> - Daniel Liew, Cristian Cadar and Alastair Donaldson</i></li><li><b><a href="http://llvm.org/devmtg/2017-10/#poster11">Non-determinism in LLVM Code Generation</a></b><i> - Mandeep Singh Grang</i></li></ul><br />If you are interested in any of these talks, you should <a href="https://www.eventbrite.com/e/2017-llvm-developers-meeting-bay-area-tickets-35155516095">register</a> to attend the 2017 US LLVM Developers' Meeting! Tickets are limited, so <a href="https://www.eventbrite.com/e/2017-llvm-developers-meeting-bay-area-tickets-35155516095">register</a> now!
- LLVM on Windows now supports PDB Debug Infohttps://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.htmlFri, 18 Aug 2017 12:55:00 +0000https://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.html<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">For several years, weâve been hard at work on making clang a world class toolchain for developing software on Windows. Weâve </span><a href="http://blog.llvm.org/2013/09/a-path-forward-for-llvm-toolchain-on.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">written</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> about this </span><a href="http://blog.llvm.org/2014/07/clangllvm-on-windows-update.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">several</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> times in the past, and weâve had full ABI compatibility (minus bugs) for some time. One area that been notoriously hard to achieve compatibility on has been debug information, but over the past 2 years weâve made significant leaps. If you just want the TL;DR, then here you go: </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">If youâre using clang on Windows, you can now get PDB debug information!</span></div><b id="docs-internal-guid-c3d2d0fb-e2a7-395d-71e1-5806dc41f6bd" style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 18pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Background: CodeView vs. PDB</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CodeView is a debug information format invented by Microsoft in the mid 1980s. For various reasons, other debuggers developed an independent format called DWARF, which eventually became standardized and is now widely supported by many compilers and programming languages. CodeView, like DWARF, defines a set of records that describe mappings between source lines and code addresses, as well as types and symbols that your program uses. The debugger then uses this information to let you set breakpoints by function name, display the value of a variable, etc. But CodeView is only somewhat documented, with the </span><a href="http://ftp.openwatcom.org/devel/docs/CodeView.pdf" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">most recent official documentation</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> being at least 20 years old. While some records still have the format documented above, others have evolved, and entirely new records have been introduced that are not documented anywhere.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Itâs important to understand though that CodeView is just a collection of records. What happens when the user says â</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">show me the value of Foo</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">â? The debugger has to </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">find</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> the record that describes Foo. And now things start getting complicated. What optimizations are enabled? What version of the compiler was used? (These could be important if there are certain ABI incompatibilities between different versions of the compiler, or as a hint when trying to reconstruct a backtrace in heavily optimized code, or if the stack has been smashed). There are a billion other symbols in the program, how can we find the one named Foo without doing an exhaustive O(n) search? How can we support incremental linking so that it doesnât take a long time to re-generate debug info when only a small amount of code has actually changed? How can we save space by de-duplicating strings that are used repeatedly? Enter PDB.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">PDB (Program Database) is, as you might have guessed from the name, a database. It </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">contains</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> CodeView but it also contains many other things that allow indexing of the CodeView records in various ways. This allows for fast lookups of types and symbols by name or address, the philosophical equivalent of âtablesâ for individual input files, and various other things that are mostly invisible to you as a user but largely responsible for making the debugging experience on Windows so great. But thereâs a problem: While CodeView is at least kind-of documented, PDB is </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">completely undocumented</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. And itâs highly non-trivial.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 18pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Weâre Stuck (Or Are We?)</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Several years ago, we decided that the path forward was to abandon any hope of emitting CodeView and PDB, and instead focus on two things:</span></div><ol style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Make clang-cl emit DWARF debug information on Windows</span></div></li><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Port LLDB to Windows and teach it about the Windows ABI, which would be significantly easier than teaching Visual Studio and/or WinDbg to be able to interpret DWARF (assuming this is even possible at all, given that everything would have to be done strictly through the Visual Studio / WinDbg extensibility model)</span></div></li></ol><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In fact, I even wrote another </span><a href="http://blog.llvm.org/2015/01/lldb-is-coming-to-windows.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">blog post</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> about this very topic a little over 2 years ago. So I got it to work, and I eventually got parts of LLDB working on Windows for simple debugging scenarios.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Unfortunately, it was beginning to become clear that we really needed PDB. Our goal has always been to create as little friction as possible for developers who are embedded in the Windows ecosystem. Tools like </span><a href="https://docs.microsoft.com/en-us/windows-hardware/test/wpt/windows-performance-analyzer" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Windows Performance Analyzer</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and vTune are very powerful and standard tools in engineersâ existing repertoires. Organizations already have infrastructure in place to archive PDB files, and collect & analyze crash dumps. Debugging with PDB is extremely responsive given that the debugger does not have to index symbols upon startup, since the indices are built into the file format. And last but not least, tools such as WinDbg are already great for post-mortem debugging, and frankly many (perhaps even most) Windows developers will only give up the Visual Studio debugger when it is pried from their cold dead hands.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">I got some odd stares (to put it lightly) when I suggested that we just </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ask</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Microsoft if they would help us out. But ultimately we did, and⦠they agreed! This came in the form of some code uploaded to the </span><a href="https://github.com/Microsoft/microsoft-pdb" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Microsoft Github</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> repo which we were on our own to figure out. Although they were only able to upload a subset of their PDB code (meaning we had to do a lot of guessing and exploration, and the code didnât compile either since half of it was missing), it filled in enough blanks that we were able to do the rest.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">After about a year and a half of studying this code, hacking away, studying the code some more, hacking away some more, etc, Iâm proud to say that lld (the LLVM linker) can finally emit working PDBs. All the basics like setting breakpoints by line, or by name, or viewing variables, or searching for symbols or types, everything works (minus bugs, of course).</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">For those of you who are interested in digging into the internals of a PDB, we also have been developing a tool for expressly this purpose. Itâs called </span><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">llvm-pdbutil</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and is the spiritual counterpart to Microsoftâs own </span><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">cvdump</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> utility. It can dump the internals of a PDB, convert a PDB to yaml and vice versa, find differences between two PDBs, and much more. Brief documentation for llvm-pdbutil is </span><a href="https://llvm.org/docs/CommandGuide/llvm-pdbutil.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">here</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, and a detailed description of the PDB file format internals are </span><a href="https://llvm.org/docs/PDB/index.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">here</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, consisting of everything weâve learned over the past 2 years (still a work in progress, as I have to divide my time between writing the documentation and actually making PDBs work).</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 18pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Bring on the Bugs!</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">So this is where you come in. Weâve tested simple debugging scenarios with our PDBs, but we still consider this alpha in terms of debug info quality. Weâd love for you to try it out and report issues on our </span><a href="https://bugs.llvm.org/" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">bug tracker</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. To get you started, download the </span><a href="http://llvm.org/builds/" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">latest snapshot of clang for Windows</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Here are two simple ways to test out this new functionality:</span></div><ol style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Have clang-cl invoke lld automatically</span></div></li><ol style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: lower-alpha; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">clang-cl -fuse-ld=lld -Z7 -MTd hello.cpp</span></div></li></ol><li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Invoke clang-cl and lld separately.</span></div></li><ol style="margin-bottom: 0pt; margin-top: 0pt;"><li dir="ltr" style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: lower-alpha; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">clang-cl -c -Z7 -MTd -o hello.obj hello.cpp</span></div></li><li dir="ltr" style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: lower-alpha; text-decoration: none; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">lld-link -debug hello.obj</span></div></li></ol></ol><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We look forward to the onslaught of bug reports!</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We would like to extend a very sincere and deep thanks to Microsoft for their help in getting the code uploaded to the github repository, as we would never have gotten this far without it.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">And to leave you with something to get you even more excited for the future, it's worth reiterating that all of this is done without a dependency on any windows specific api, dll, or library. It's 100% portable. Do I hear cross-compilation?</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Zach Turner (on behalf of the the LLVM Windows Team)</span></div>
- Devirtualization in LLVM and Clanghttps://blog.llvm.org/2017/03/devirtualization-in-llvm-and-clang.htmlFri, 10 Mar 2017 13:23:00 +0000https://blog.llvm.org/2017/03/devirtualization-in-llvm-and-clang.html<span style="background-color: transparent; color: black; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-weight: normal; text-indent: 10px; white-space: normal;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"><i>This blog post is part of a series of blog posts from students who were funded by the LLVM Foundation to attend the 2016 LLVM Developers' Meeting in San Jose, CA. Please visit the LLVM Foundation's <a href="http://llvm.org/foundation" style="color: purple; text-decoration: none;">webpage</a> for more information on our Travel Grants program. </i></span></span></span><br /><i style="text-indent: 10px;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></i><i style="text-indent: 10px;"><span style="font-family: "arial" , "helvetica" , sans-serif;">This post is from Piotr Padlewski on his work that he presented at the meeting:</span></i><br /><div><br /></div><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: 11pt; white-space: pre-wrap;">This blogpost will show how C++ devirtualization is performed in current (4.0) clang and LLVM and also ongoing work on -fstrict-vtable-pointers features.</span></span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre-wrap;"><br /></span><span style="font-weight: normal; white-space: pre-wrap;"><span style="font-size: large;">Devirtualization done by the frontend</span></span></span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: 11pt; white-space: pre-wrap;"><br /></span><span style="white-space: pre-wrap;"><span style="font-family: inherit;">In order to transform a virtual call into a direct call, the frontend must be sure that there are no overrides of vfunction in the program or know the dynamic type of object. Compilation proceeds one translation unit at a time, so, barring LTO, there are only a few cases when the compiler may conclude that there are no overrides:</span></span></span><br /><ul><li><span style="font-family: "arial" , "helvetica" , sans-serif; white-space: pre-wrap;">either the class or virtual method is marked as final</span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; white-space: pre-wrap;">the class is defined in an anonymous namespace and has no deriving classes in its translation unit</span></li></ul><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span><span style="font-size: 11pt;"><span style="font-family: "arial" , "helvetica" , sans-serif;">The latter is more tricky for clang, which translates the source code in chunks on the fly (see: ASTProducer and ASTConsumer), so is not able to determine if there are any deriving classes later in the source. This could be dealt with in a couple of ways:</span></span><br /><ul><li><span style="white-space: pre-wrap;"><span style="font-family: "arial" , "helvetica" , sans-serif;">give up immediate generation</span></span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; white-space: pre-wrap;">run data flow analysis in LLVM to find all the dynamic types passed to function, which has static linkage</span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; white-space: pre-wrap;">hope that every use of the virtual function, which is necessarily in the same translation unit, will be inlined by LLVM -- static linkage increases the chances of inlining</span></li></ul><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;">Store to load propagation in LLVM</span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="text-align: justify; white-space: pre-wrap;"><br /></span></span><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">In order to devirtualize a virtual call we need:</span><br /><ul><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">value of vptr - which virtual table is pointed by it</span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">value of vtable slot - which exact virtual function it is</span></li></ul><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;"><br /></span><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">Because vtables are constant, the latter value is much easier to get when we have the value of vptr. The only thing we need is vtable definition, which can be achieved by using available_externally linkage.</span><br /><span style="text-align: justify; white-space: pre-wrap;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></span><span style="text-align: justify; white-space: pre-wrap;"><span style="font-family: "arial" , "helvetica" , sans-serif;">In order to figure out the vptr value, we have to find the store to the same location that defines it. There are 2 analysis responsible for it:</span></span><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><br /><ul><li><span style="white-space: pre-wrap;"><span style="font-family: "arial" , "helvetica" , sans-serif;">MemDep (Memory Dependence Analysis) is a simple linear algorithm that for each quered instruction iterates through all instructions above and stops when first dependency is found. Because queries might be performed for each instruction we end up with a quadratic algorithm. Of course quadratic algorithms are not welcome in compilers, so MemDep can only check certain number of instructions.</span></span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="vertical-align: baseline; white-space: pre-wrap;">Memory SSA on the other hand has constant complexity because of caching. To find out more, watch âMemory SSA in 5minutesâ (</span><a href="https://www.youtube.com/watch?v=bdxWmryoHak" style="text-decoration: none;"><span style="color: #1155cc; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">https://www.youtube.com/watch?v=bdxWmryoHak</span></a><span style="vertical-align: baseline; white-space: pre-wrap;">). MemSSA is a pretty new analysis and it doesnât have all the features MemDep has, therefore MemDep is still widely used.</span></span></li></ul></div><span style="text-align: justify; white-space: pre-wrap;"><span style="font-family: "arial" , "helvetica" , sans-serif;">The LLVM main pass that does store to load propagation is GVN - Global Value Numbering. </span></span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span><br /><div><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;"><br /></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;">Finding vptr store</span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: inherit;"><span style="font-size: 11pt; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; text-align: justify; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span></span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: inherit;"><span style="text-align: justify; vertical-align: baseline; white-space: pre-wrap;">In order to figure out the vptr value, we need to see store from constructor. To not rely on constructor's availability or inlining, we decided to use the </span><span style="font-weight: 700; text-align: justify; vertical-align: baseline; white-space: pre-wrap;">@llvm.assume intrinsic</span><span style="text-align: justify; vertical-align: baseline; white-space: pre-wrap;"> to indicate the value of vptr. Assume is akin to assert - optimizer seeing call to </span><span style="font-weight: 700; text-align: justify; vertical-align: baseline; white-space: pre-wrap;">@llvm.assume(i1 %b)</span><span style="text-align: justify; vertical-align: baseline; white-space: pre-wrap;"> can assume that %b is true after it. We can indicate vptr value by comparing it with the vtable and then call the @llvm.assume with the result of this comparison. </span></span></span><br /><h2><b style="font-weight: normal;"><span style="font-family: inherit;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> call void @_ZN1AC1Ev(%struct.A* %a) ; call ctor</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> %3 = load {...} %a ; Load vptr</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> %4 = icmp eq %3, @_ZTV1A ; compare vptr with vtable</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span id="docs-internal-guid-190e6f9f-a52c-e721-c87c-026c2cef6ffc"></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> call void @llvm.assume(i1 %4)</span></div></span></b></h2><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;"><br /></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;">Calling multiple virtual functions</span><br /><h2><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small; font-weight: 400; text-align: justify; white-space: pre-wrap;">A non-inlined virtual call will clobber the vptr. In other words, optimizer will have to assume that vfunction might change the vptr in passed object. This sounds like something that never happens because vptr is âconstâ. The truth is that it is actually weaker than C++ const member, because it changes multiple times during construction of an object (every base type constructor or destructor must set vptrs). But vptr can't be changed during a virtual call, right? Well, what about that?</span></h2><h2><b style="font-weight: normal;"><span style="font-family: inherit;"><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> A::foo() { // virtual </span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> static_assert(sizeof(A) == sizeof(Derived)); </span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">new</span><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">(</span><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">this</span><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">) Derived; </span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: inherit; font-size: small; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"><span style="white-space: pre-wrap;">This is call of placement new operator - it doesnât allocate new memory, it just creates a new object in the provided location. So, by constructing a Derived object in the place where an object of type A was living, we change the vptr to point to Derivedâs vtable. Is this code even legal? C++ Standard says yes.</span><span style="font-family: inherit;"></span></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="display: inline !important; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">However it turns out that if someone called </span><span style="background-color: transparent; color: black; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">foo</span><span style="background-color: transparent; color: black; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> 2 times (with the same object), the second call would be undefined behavior. Standard pretty much says that call or dereference of a pointer to an object whose lifetime has ended is UB, and because the standard agrees that nuking object from inside ends its lifetime, the second call is UB. Be aware that this is only because a zombie pointer is used for the second call. The pointer returned by placement new is considered alive, so performing calls on that pointer is valid. Note that we also silently used that fact with the use of assume.</span></span><br /><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;"><br /></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;">(un)clobbering vptr</span></div></span></b></h2><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="text-align: justify; vertical-align: baseline; white-space: pre-wrap;">We need to somehow say that vptr is invariant during its lifetime. We decided to introduce a new metadata for that purpose - !invariant.group. </span><span style="background-color: white; text-align: justify; vertical-align: baseline; white-space: pre-wrap;">The presence of the invariant.group metadata on the load/store tells the optimizer that every load and store to the same pointer operand within the same invariant group can be assumed to load or store the same value. With </span><span style="background-color: white; font-weight: 700; text-align: justify; vertical-align: baseline; white-space: pre-wrap;">-fstrict-vtable-pointers </span><span style="background-color: white; text-align: justify; vertical-align: baseline; white-space: pre-wrap;">Clang decorates vtable loads with invariant.group metadana coresponding to caller pointer type.</span><span style="text-align: justify; vertical-align: baseline; white-space: pre-wrap;"> </span></span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="text-align: justify; white-space: pre-wrap;"><br /></span><span style="text-align: justify; white-space: pre-wrap;">We can enhance the load of virtual function (second load) by decorating it with !invariant.load, which is equivalent of saying âload from this location is always the sameâ, which is true because vtables never changes. This way we donât rely on having the definition of vtable.</span></span><br /><h2><span style="font-family: inherit;"><b style="font-weight: normal;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-family: "arial" , "helvetica" , sans-serif; font-size: small; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Call like:</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: "courier new"; font-size: 10.5pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: "courier new"; font-size: 10.5pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">void g(A *a) {</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: "courier new"; font-size: 10.5pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> a->foo();</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: "courier new"; font-size: 10.5pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> a->foo();</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span id="docs-internal-guid-190e6f9f-a52d-5423-129c-37c542743a2b"></span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: "courier new"; font-size: 10.5pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-size: 10.5pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-family: "arial" , "helvetica" , sans-serif; font-size: small; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Will be translated to:</span></div><div dir="ltr" style="font-family: inherit; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: white; color: black; font-size: 10.5pt; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></b></span><span id="docs-internal-guid-190e6f9f-a52d-9190-f702-f45ef470fbc2" style="font-weight: normal;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">define void @function(%struct.A* %a) {</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> %1 = load {...} %a, !invariant.group !0</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> %2 = load {...} %1, !invariant.load !1</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> call void %2(%struct.A* %a)</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> %3 = load {...} %a, !invariant.group !0</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> %4 = load {...} %4, !invariant.load !1</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> call void %4(%struct.A* %a)</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> ret void</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">!0 = !{!"_ZTS1A"} ; mangled type name of A</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">!1 = !{}</span></div><div><br /></div></span><span style="font-family: inherit;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small; font-weight: 400; text-align: justify; white-space: pre-wrap;">And now by magic of GVN and MemDep:</span><b style="font-family: inherit; font-weight: normal;"><br /></b></span><span id="docs-internal-guid-190e6f9f-a52e-00ef-e518-921d8680d3b9" style="font-weight: normal;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">define void @function(%struct.A* %a) {</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> %1 = load {...} %a, !invariant.group !0</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> %2 = load {...} %1, !invariant.load !1</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> call void %2(%struct.A* %a)</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> call void %2(%struct.A* %a)</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> ret void</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div><div><span style="font-family: "courier new"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></span><span style="font-family: "arial" , "helvetica" , sans-serif;"><b style="font-weight: normal;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="background-color: transparent; color: black; font-size: small; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">With this, llvm-4.0 is be able to devirtualize function calls inside loops. </span><br /><span style="font-size: large; white-space: pre-wrap;"><br /></span><span style="font-size: large; white-space: pre-wrap;">Barriers</span></div></b></span></h2><span style="font-family: "arial" , "helvetica" , sans-serif; font-weight: 400; text-align: justify; white-space: pre-wrap;">In order to prevent the middle-end from finding load/store with the same !invariant.group metadata, that would come from construction/destruction of dead dynamic object, @llvm.invariant.group.barrier was introduced. It returns another pointer that aliases its argument but is considered different for the purposes of load/store invariant.group metadata. Optimizer wonât be able to figure out that returned pointer is the same because intrinsics donât have a definition. Barrier must be inserted in all the places where the dynamic object changes:</span><br /><ul><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">constructors</span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">destructors</span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">placement new of dynamic object</span></li></ul><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="white-space: pre-wrap;"><br /></span></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; white-space: pre-wrap;">Dealing with barriers</span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background-color: transparent; color: black; font-style: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: inherit; font-size: medium;"><br /></span></span><span style="text-align: justify; white-space: pre-wrap;">Barriers hinder some other optimizations. Some ideas how it could be fixed:</span></span><br /><ul><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">stripping invariant.group metadata and barriers just after devirtualization. Currently it is done before codegen. The problem is that most of the devirtualization comes from GVN, which also does most of the optimizations we would miss with barriers. GVN is expensive therefore it is run only once. It also might make less sense if we are in LTO mode, because that would limit the devirtualization in the link phase. </span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">teaching important passes to look through the barrier. This might be very tricky to preserve the semantics of barrier, but e.g. looking for dependency of load without invariant.group by jumping through the barrier to find a store without invariant.group, is likely to do the trick.</span></li><li><span style="font-family: "arial" , "helvetica" , sans-serif; text-align: justify; white-space: pre-wrap;">removing invariant.barrier when its argument comes from alloca and is never used etc.</span></li></ul><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre-wrap;">To find out more details about devirtualization check my talk (</span><a href="http://llvm.org/devmtg/2016-11/#talk6" style="white-space: pre-wrap;">http://llvm.org/devmtg/2016-11/#talk6</a><span style="white-space: pre-wrap;">) from LLVM Dev Meeting 2016.</span></span><br /><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: 11pt; white-space: pre-wrap;"><br /></span></span><span style="color: #434343; font-weight: 400; white-space: pre-wrap;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">About author</span></span><br /><h2><span style="font-weight: normal;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Undergraduate student at University of Warsaw, currently working on C++ static analysis in IIIT.</span></div><div><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div></span></h2></div>
- Some news about apt.llvm.orghttps://blog.llvm.org/2017/03/some-news-about-aptllvmorg.htmlMon, 06 Mar 2017 12:59:00 +0000https://blog.llvm.org/2017/03/some-news-about-aptllvmorg.html<div dir="ltr" style="text-align: left;" trbidi="on"><a href="http://apt.llvm.org/">apt.llvm.org</a> provides Debian and Ubuntu repositories for every maintained version of these distributions. LLVM, Clang, clang extra tools, compiler-rt, polly, LLDB and LLD packages are generated for the stable, stabilization and development branches.<br /><br />As it seems that we have more and more users of these packages, I would like to share an update about various recent changes.<br /><h3 style="text-align: left;">New features</h3><h4 style="text-align: left;">LLD<br /><span style="font-weight: normal;">First, the cool new stuff : lld is now proposed and built for i386/amd64 on all Debian and Ubuntu supported versions. The test suite is also executed and the <a href="http://llvm.org/reports/coverage/">coverage results</a> are great. </span></h4><h4 style="text-align: left;">4.0<br /><span style="font-weight: normal;">Then, following the branching for the 4.0 release, I created new repositories to propose this release.</span><br /><span style="font-weight: normal;">For example, for Debian stable, just add the following in <i>/etc/apt/sources.list.d/llvm.list</i></span></h4><blockquote class="tr_bq"><i><span style="font-weight: normal;">deb http://apt.llvm.org/jessie/ llvm-toolchain-jessie-4.0 main</span></i><span style="font-weight: normal;"><i><br /> deb-src http://apt.llvm.org/jessie/ llvm-toolchain-jessie main</i></span></blockquote><br /><h4 style="text-align: left;">llvm-defaults<br /><span style="font-weight: normal;">Obviously, the trunk is now 5.0. If llvm-defaults is used, clang, lldb and other meta packages will be automatically updated to this version.</span><br /><span style="font-weight: normal;">As a consequence and also because the branches are dead, 3.7 and 3.8 jobs have been disabled. Please note that both repositories are still available on apt.llvm.org and won't be removed.</span></h4><h4 style="text-align: left;">Zesty: New Ubuntu<br /><span style="font-weight: normal;">Packages for the next Ubuntu 17.04 (zesty) are also generated for 3.9, 4.0 and 5.0.</span></h4><h4 style="text-align: left;">libfuzzer<br /><span style="font-weight: normal;">It has been implemented a few months ago but not clearly communicated. <a href="http://llvm.org/docs/LibFuzzer.html">libfuzzer</a> has also its own packages: libfuzzer-X.Y-dev (example: <i>libfuzzer-3.9-dev,</i> <i>libfuzzer-4.0-dev</i> or <i>libfuzzer-5.0-dev</i>).</span></h4><br /><h3 style="text-align: left;">Changes in the infrastructure</h3><br />In order to support the load, I started to use new blades that Google (thanks again to Nick Lewycky) sponsored for an initiative that I was running for Debian and <a href="https://www.irill.org/">IRILL</a>. The 6 new blades removed all the wait time. With a new salt configuration, I automated the deployment of the slaves. In case the load increases again, we will have access to more blades.<br /><br />I also took the time to fix some long ongoing issues:<br /><ul style="text-align: left;"><li>all repositories are signed and verified that they are </li><li><i>i386</i> and <i>amd64</i> packages are now uploaded at once instead of being uploaded separately. This was causing checksum error when one of the two architectures built correctly and the second was failing (ex: test failing)</li></ul>Last but not least, the <a href="http://llvm.org/reports/coverage/">code coverage results</a> are produced in a more reliable manner.<br /><br /><br /><h3>More information about the implementation and services.</h3>As what is shipped on apt.llvm.org is exactly the same as in Debian and Ubuntu, packaging files are stored on the <a href="https://anonscm.debian.org/viewvc/pkg-llvm/llvm-toolchain/branches/">Debian subversion server.</a><br /><br />A <a href="http://llvm-jenkins.debian.net/">Jenkins instance</a> is in charge of the orchestration of the whole build infrastructure.<br /><br />The trunk packages are built twice a day for every Debian and Ubuntu packages. Branches (3.9 and 4.0 currently) are rebuilt only when the - trigger job found a change. <br /><br />In both case, the Jenkins source job will checkout the Debian SVN branches for their version, checkout/update LLVM/clang/etc repositories and repack everything to create the source tarballs and Debian files (dsc, etc).The completion of job will trigger the binaries job to start. These jobs, thanks to <a href="https://jenkins-debian-glue.org/">Debian Jenkins glue</a> will create or update Debian/Ubuntu versions.<br /><br />Then builds are done the usual way through pbuilder for both i386 and amd64. All the test suites are going to be executed. If any LLVM test is failing on i386 or amd64, the whole build will fail. If both builds and the LLVM testsuite are successful, the sync job will start and rsync packages to the LLVM server to be replicated on the CDN. If one or both builds fail, a notification is sent to the administrator.<br /><br />Some Debian static analysis (<a href="https://packages.debian.org/stretch/lintian">lintian</a>) are executed on the packages to prevent some packaging errors. From time to time, some interesting issues are found.<br /><br />In parallel, some binary builds have some special hooks like <a href="https://scan.coverity.com/projects/llvm">Coverity</a>, <a href="http://llvm.org/reports/coverage/">code coverage</a> or installation of more recent versions of gcc for Ubuntu precise.<br /><br /><h3 style="text-align: left;">Report bugs</h3><div style="text-align: left;"><span style="font-weight: normal;">Bugs can be reported on the <a href="https://bugs.llvm.org//enter_bug.cgi?product=Packaging&component=deb%20packages">bugzilla of the LLVM project</a> in the product "Packaging" and the component "deb packages".</span></div><div style="text-align: left;"><span style="font-weight: normal;"> </span> </div><h3 style="text-align: left;">Common issues</h3><div style="text-align: left;">Because packaging quickly moving projects like LLVM or clang, in some cases, this can be challenging to follow the rhythm in particular with regard to tests. For Debian unstable or the latest version of Ubuntu, the matrix is complexified by new versions of the basic pieces of the operating system like gcc/g++ or libtstdc++.<br /><br />This is also not uncommon that some tests are being ignored in the process.</div><h3 style="text-align: left;">How to help</h3><div style="text-align: left;"><br />Some <a href="https://bugs.debian.org/cgi-bin/pkgreport.cgi?include=originator%3Asylvestre;tag=newcomer">new comers bugs</a> are available. As an example:<br /><ul style="text-align: left;"><li><a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=751789">Move the compiler-rt libraries</a> into a specific packages to simplify their usage by other packages </li><li><a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=813673">Ship libc++</a> as part of llvm-toolchain packages</li><li><a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=813672">Ship openmp library</a> as part of llvm-toolchain packages</li><li><a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=827185">Full bootstrap of llvm-toolchain</a> (use a clang built during the process)</li><li>... </li></ul>Related to all this, a Google Summer of Code 2017 under the LLVM umbrella has been proposed: <a href="http://llvm.org/OpenProjects.html#apt">Integrate libc++ and OpenMP in apt.llvm.org</a><br /><br />Help is also needed to keep track of the new test failures and get them fixed upstream. For example, a few tests have been marked as <i>expected to fail</i> to avoid crashes.</div></div>
- 2016 LLVM Developers' Meeting - Experience from Johannes Doerfert, Travel Grant Recipienthttps://blog.llvm.org/2017/02/this-blog-post-is-part-of-series-of.htmlTue, 21 Feb 2017 23:26:00 +0000https://blog.llvm.org/2017/02/this-blog-post-is-part-of-series-of.html<span style="font-family: "helvetica"; font-size: 12px;"><i>This blog post is part of a series of blog posts from students who were funded by the LLVM Foundation to attend the 2016 LLVM Developers' Meeting in San Jose, CA. Please visit the LLVM Foundation's <a href="http://llvm.org/foundation">webpage</a> for more information on our Travel Grants program.</i></span><br /><span style="font-family: "helvetica"; font-size: 12px;"><i><br /></i></span><span style="font-family: "helvetica"; font-size: 12px;"><i>This post is from Johannes Doerfert:</i></span><br /><span style="font-family: "helvetica"; font-size: 12px;">2016 was my third time attending the US LLVM developers meeting and for </span><span style="font-family: "helvetica"; font-size: 12px;">the third year in a row I was impressed by the quality of the talks, the </span><span style="font-family: "helvetica"; font-size: 12px;">organization and the diversity of attendees. The hands on experiences </span><span style="font-family: "helvetica"; font-size: 12px;">that are presented, combined with innovative ideas and cutting edge </span><span style="font-family: "helvetica"; font-size: 12px;">research makes it a perfect venue for me as a PhD student. The honest </span><span style="font-family: "helvetica"; font-size: 12px;">interest in the presented topics and the lively discussions that include </span><span style="font-family: "helvetica"; font-size: 12px;">students, professors and industry people are two of the many things that </span><span style="font-family: "helvetica"; font-size: 12px;">I experienced the strongest at these developer meetings.</span><br /><span style="font-family: "helvetica"; font-size: 12px;"><br /></span><span style="font-family: "helvetica"; font-size: 12px;">For the last two years I was mainly attending as a Polly developer that </span><span style="font-family: "helvetica"; font-size: 12px;">talked about new features and possible applications of Polly. This year </span><span style="font-family: "helvetica"; font-size: 12px;">however my roles were different. First, I was attending as part of the </span><span style="font-family: "helvetica"; font-size: 12px;">organization team of the European LLVM developers meeting 2017 [0] </span><span style="font-family: "helvetica"; font-size: 12px;">together with my colleagues Tina Jung and Simon Moll. In this capacity I </span><span style="font-family: "helvetica"; font-size: 12px;">answered questions about the venue (Saarbruecken, Germany [1,2]) and the </span><span style="font-family: "helvetica"; font-size: 12px;">alterations in contrast to prior meetings. Though, more importantly, I </span><span style="font-family: "helvetica"; font-size: 12px;">advertised the meeting to core developers that usually do not attend the </span><span style="font-family: "helvetica"; font-size: 12px;">European version. Second on my agenda was the BoF on a parallel </span><span style="font-family: "helvetica"; font-size: 12px;">extension to the LLVM-IR which I organized with Simon Moll. In this BoF, </span><span style="font-family: "helvetica"; font-size: 12px;">but also during the preparation discussion on the mailing list [3], we </span><span style="font-family: "helvetica"; font-size: 12px;">tried to collect motivating examples, requirements as well as known </span><span style="font-family: "helvetica"; font-size: 12px;">challenges for a parallel extension to LLVM. These insights will be used </span><span style="font-family: "helvetica"; font-size: 12px;">to draft a proposal that can be discussed in the community.</span><br /><span style="font-family: "helvetica"; font-size: 12px;"><br /></span><span style="font-family: "helvetica"; font-size: 12px;">Finally, I attended as a 4th year PhD student who is interested in </span><span style="font-family: "helvetica"; font-size: 12px;">contributing his work to the LLVM project (not only Polly). As my c</span><span style="font-family: "helvetica"; font-size: 12px;">urrent research required a flexible polyhedral value (and iteration</span><span style="font-family: "helvetica"; font-size: 12px;">space) analysis, I used the opportunity to implement one with an</span><span style="font-family: "helvetica"; font-size: 12px;">interface similar to scalar evolution. The feedback I received on this </span><span style="font-family: "helvetica"; font-size: 12px;">topic was strictly positive. I will soon post a first version of this </span><span style="font-family: "helvetica"; font-size: 12px;">standalone analysis and start a public discussion. Since I hope to </span><span style="font-family: "helvetica"; font-size: 12px;">finish my studies at some (not too distant) point in time, I seized the </span><span style="font-family: "helvetica"; font-size: 12px;">opportunity to inquire about potential options for the time after my </span><span style="font-family: "helvetica"; font-size: 12px;">PhD.</span><br /><br style="font-family: Helvetica; font-size: 12px;" /><span style="font-family: "helvetica"; font-size: 12px;">As a final note I would like to thank the LLVM Foundation for their </span><span style="font-family: "helvetica"; font-size: 12px;">student travel grant that allowed me to attend the meeting in the first </span><span style="font-family: "helvetica"; font-size: 12px;">place.</span><br /><br style="font-family: Helvetica; font-size: 12px;" /><br style="font-family: Helvetica; font-size: 12px;" /><span style="font-family: "helvetica"; font-size: 12px;">[0] </span><a href="http://llvm.org/devmtg/2017-03/" style="font-family: Helvetica; font-size: 12px;">http://llvm.org/devmtg/2017-03/</a><br /><span style="font-family: "helvetica"; font-size: 12px;">[1] </span><a href="http://sic.saarland/" style="font-family: Helvetica; font-size: 12px;">http://sic.saarland/</a><br /><span style="font-family: "helvetica"; font-size: 12px;">[2] </span><a href="https://en.wikipedia.org/wiki/Saarbr%C3%BCcken" style="font-family: Helvetica; font-size: 12px;">https://en.wikipedia.org/wiki/Saarbr%C3%BCcken</a><br /><span style="font-family: "helvetica"; font-size: 12px;">[3] </span><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-October/106051.html" style="font-family: Helvetica; font-size: 12px;">http://lists.llvm.org/pipermail/llvm-dev/2016-October/106051.html</a>
- LLVM's New Versioning Schemehttps://blog.llvm.org/2016/12/llvms-new-versioning-scheme.htmlWed, 14 Dec 2016 13:25:00 +0000https://blog.llvm.org/2016/12/llvms-new-versioning-scheme.htmlHistorically, LLVM's major releases always added "0.1" to the version number, producing major versions like 3.8, 3.9, and 4.0 (expected by March 2017). With our next release though, we're changing this. The LLVM version number will now increase by "1.0" with every major release, which means that the first major release after LLVM 4.0 will be LLVM 5.0 (expected September 2017).<br />We believe that this approach will provide a simpler and more standard approach to versioning.<br /><a name='more'></a>LLVMâs version number (also shared by many of its sub-projects, such as Clang, LLD, etc.) consists of three parts: <i>major</i>.<i>minor</i>.<i>patch</i>. The community produces a new release every six months, with "patch" releases (also known as "dot" or "stable" releases) containing bug fixes in between.<br />Until now, the six-monthly releases would cause the <i>minor</i> component of the version to be incremented. Every five years, after <i>minor</i> reached 9, a more major release would occur, including some breaking changes: <a href="http://lists.llvm.org/pipermail/llvm-announce/2007-May/000023.html">2.0</a> introduced the bitcode format, <a href="http://lists.llvm.org/pipermail/llvm-announce/2011-December/000039.html">3.0</a> a <a href="http://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.html">type system rewrite</a>.<br />During <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101044.html">the discussions</a> about what to call the release after 3.9, it was pointed out that since our releases are time-based rather than feature-based, the distinction between major and minor releases seems arbitrary. Further, every release is also API breaking, so by the principles of <a href="http://semver.org/">semantic versioning</a>, we should be incrementing the major version number.<br />We decided that going forward, <b>every release on the six-month cycle will be a major release</b>. Patch releases will increment the <i>patch</i> component as before (producing versions like 5.0.1), and the <i>minor</i> component will stay at zero since no minor releases will be made.<br /><h3>Bitcode Compatibility</h3>Before LLVM 4.0.0, the <a href="http://llvm.org/docs/DeveloperPolicy.html">Developer Policy</a> specified that bitcode produced by LLVM would be readable by the next versions up to and including the next major release. The new version of the Developer Policy instead specifies that LLVM will currently load any bitcode produced by version 3.0 or later. When developers decide to drop support for some old bitcode feature, the policy will be updated.<br /><h3>API Compatibility</h3>Nothing has changed. As before, patch releases are API and ABI compatible with the main releases, and the C API is "<a href="http://llvm.org/docs/DeveloperPolicy.html#c-api-changes">best effort</a>" for stability, but besides that, LLVMâs API changes between releases. <br /><h3>What About the Minor Version?</h3>Since the <i>minor</i> version is expected to always be zero, why not drop it and just use <i>major</i>.<i>patch</i> as the version number?<br />Dropping the minor component from the middle of the version string would introduce ambiguity: whether to interpret <i>x</i>.<i>y</i> as <i>major</i>.<i>minor</i> or <i>major</i>.<i>patch</i> would then depend on the value of <i>x</i>.<br />The version numbers are also exposed through various APIs, such as LLVM's <span style="font-family: monospace;">llvm-config.h</span> and Clang's <span style="font-family: monospace;">__clang_minor__</span> preprocessor macro. Removing the <i>minor</i> component from these APIs would break a lot of existing code.<br />Going forward, since the <i>minor</i> number will be zero and patch releases are compatible, I expect we will generally refer to versions simply by their <i>major</i> number and treat the rest of the version string as details (just as Chromium 55 might really be 55.0.2883.76). Future versions of LLVM and Clang can generally be referred to simply as "LLVM 4" or "Clang 5".
- Announcing the next LLVM Foundation Board of Directorshttps://blog.llvm.org/2016-09-12-announcing-next-llvm-foundation-board.htmlMon, 12 Sep 2016 09:55:00 +0000https://blog.llvm.org/2016-09-12-announcing-next-llvm-foundation-board.html<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The LLVM Foundation is pleased to announce its new Board of Directors:</span></div><b id="docs-internal-guid-6038a77a-1083-f85c-21ca-6c75ed972326" style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chandler Carruth</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Hal Finkel</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Arnaud de Grandmaison</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">David Kipping</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Anton Korobeynikov</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Tanya Lattner</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chris Lattner</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">John Regehr</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Three new members and five continuing members were elected to the eight person board. The new board consists of individuals from corporations and from the academic and scientific communities. They also represent various geographical groups of the LLVM community. All board members are dedicated and passionate about the programs of the LLVM Foundation and growing and supporting the LLVM community. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">When voting on new board members, we took into consideration all contributions (past and present) and current involvement in the LLVM community. We also tried to create a balanced board of individuals from a wide range of backgrounds and locations to provide a voice to as many groups within the LLVM community. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We want to thank everyone who applied as we had many strong applications. As the programs of the LLVM Foundation grow we will be relying on volunteers to help us reach success. Please join our <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-foundation">mailing list</a> to be informed of volunteer opportunities.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">About the board of directors (listed alphabetically by last name):</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chandler Carruth</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> has been an active contributor to LLVM since 2007. Over the years, he has has worked on LLVMâs memory model and atomics, Clangâs C++ support, GCC-compatible driver, initial profile-aware code layout optimization pass, pass manager, IPO infrastructure, and much more. He is the current code owner of inlining and SSA formation.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In addition to his numerous technical contributions, Chandler has led Googleâs LLVM efforts since 2010 and shepherded a number of new efforts that have positively and significantly impacted the LLVM project. These new efforts include things such as adding C++ modules to Clang, adding address and other sanitizers to Clang/LLVM, making Clang compatible with MSVC and available to the Windows C++ developer community, and much more.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chandler works at Google Inc. as a technical lead for their C++ developer platform and has served on the LLVM Foundation board of directors for the last 2 years.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Hal Finkel </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">has been an active contributor to the LLVM project since 2011. He is the code owner for the PowerPC target, alias-analysis infrastructure, loop re-roller and the basic-block vectorizer. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In addition to his numerous technical contributions, Hal has chaired the LLVM in HPC workshop, which is held in conjunction with Super Computing (SC), for the last 3 years. This workshop provides a venue for the presentation of peer-reviewed HPC-related researching LLVM from both industry and academia. He has also been involved in organizing an LLVM-themed BoF session at SC and LLVM socials in Austin.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Hal is Lead for Compiler Technology and Programming Languages at Argonne National Laboratoryâs Leadership Computing Facility. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Arnaud de Grandmaison </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">has been hacking on LLVM projects since 2008. In addition to his open source contributions, he has worked for many years on private out-of-tree LLVM-based projects at Parrot, DiBcom, or ARM. He has also been a leader in the European LLVM community by organizing the EuroLLVM Developersâ meeting, Paris socials, and chaired or participated in numerous program committees for the LLVM Developersâ Meetings and other LLVM related conferences.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Arnaud has attended numerous LLVM Developersâ meetings and volunteered as moderator or presented as well. He also moderates several LLVM mailing lists. Arnaud is also very involved in community wide discussions and decisions such as re-licensing and code of conduct.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Arnaud is a Principal Engineer at ARM.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">David Kipping </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">has been involved with the LLVM project since 2010. He has been a key organizer and supporter of many LLVM community events such as the US and European LLVM Developersâ Meetings. He has served on many of the program committees for these events. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">David has worked hard to advance the adoption of LLVM at Qualcomm and other companies. One such example of his efforts is the LLVM track he created at the 2011 Linux Collaboration summit. He has over 30 years experience in open source and developer tools including working on C++ at Borland. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">David has served on the board of directors for the last 2 years and has held the officer position of treasurer. The treasurer is a time demanding position in that he supports the day to day operation of the foundation, balancing the books, and generates monthly treasurer reports. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">David is Director of Product Management at Qualcomm and has served on the LLVM Foundation board of directors for the last 2 years</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Anton Korobeynikov </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">has been an active contributor to the LLVM project since 2006. Over the years, he has numerous technical contributions to areas including Windows support, ELF features, debug info, exception handling, and backends such as ARM and x86. He was the original author of the MSP430 and original System Z backend. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In addition to his technical contributions, Anton has maintained LLVMâs participation in Google Summer of Code by managing applications, deadlines, and overall organization. He also supports the LLVM infrastructure and has been on numerous program committees for the LLVM Developersâ Meetings (both US and EuroLLVM). </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Anton is currently an associate professor at the Saint Petersburg State University and has served on the LLVM Foundation board of directors for the last 2 years. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Tanya Lattner </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">has been involved in the LLVM project for over 14 years. She began as a graduate student who wrote her master's thesis using LLVM, and continued on using and extending LLVM technologies at various jobs during her career as a compiler engineer. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Tanya has been organizing the US LLVM Developersâ meeting since 2008 and attended every developer meeting. She was the LLVM release manager for 3 years, moderates the LLVM mailing lists, and helps administer the LLVM infrastructure servers, mailing lists, bugzilla, etc. Tanya has also been on the program committee for the US LLVM Developersâ meeting (4 years) and the EuroLLVM Developersâ Meeting (1 year). </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">With the support of the initial board of directors, Tanya created the LLVM Foundation, defined its charitable and education mission, and worked to get 501(c)(3) status. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Tanya is the Chief Operating Officer and has served as the President of the LLVM Foundation board for the last 2 years.</span></div><br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chris Lattner </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">is well known as the founder for the LLVM project and has a lengthy history of technical contributions to the project over the years. He drove much of the early implementation, architecture, and design of LLVM and Clang.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chris has attended every LLVM Developersâ meeting, and presented at the majority. He helped drive the conception and incorporation of the LLVM Foundation, and has served as Secretary of the board for the last 2 years. Chris also grants commit access to the LLVM Project, moderates mailing lists, moderates and edits the LLVM blog, and drives important non-technical discussions and policy decisions related to the LLVM project. </span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Chris manages the Developer Tools department at Apple Inc and has served on the LLVM Foundation board of directors for the last 2 years.</span></div><b style="font-weight: normal;"><br /></b><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">John Regehr </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">has been involved in LLVM for a number of years. As a professor of computer science at the University of Utah, his research specializes in compiler correctness and undefined behavior. He is well known within the LLVM community for the hundreds of bug reports his group has reported to LLVM/Clang.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">John was a project lead for IOC, a Clang based integer overflow checker that eventually became the basis for the integer parts of UBSan. He was also the primary developer of C-Reduce which utilizes Clang as a library and is often used as a test case reducer for compiler issues.</span></div><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In addition to his technical contributions, John has served on several LLVM-related program committees. He also has a widely read blog about LLVM and other compiler-related issues (</span><a href="http://blog.regehr.org/" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Embedded in Academia</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">).</span></div>
- LLVM Weekly - #130, Jun 27th 2016https://blog.llvm.org/2016/06/llvm-weekly-130-jun-27th-2016.htmlMon, 27 Jun 2016 08:00:00 +0000https://blog.llvm.org/2016/06/llvm-weekly-130-jun-27th-2016.htmlWelcome to the one hundred and thirtieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org/">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org/">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:[email protected]">[email protected]</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.<br />If you're reading this on blog.llvm.org then do note this is LAST TIME it will be cross-posted there directly. There is a great effort underway to increase the content on the LLVM blog, and unfortunately LLVM Weekly has the effect of drowning out this content. As ever, you can head to <a href="http://llvmweekly.org/">http://llvmweekly.org</a>, subscribe to get it by email, or subscribe to the <a href="http://llvmweekly.org/rss.xml">RSS feed</a>.<br />The canonical home for this issue <a href="http://llvmweekly.org/issue/130">can be found here at llvmweekly.org</a>. <br /><a name='more'></a> <h3>News and articles from around the web</h3>After recently being taken down due to excessive resource usage, the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101500.html">LLVM apt repositories are now back</a>.<br />A detailed <a href="http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html">introduction to ThinLTO</a> has been published on the LLVM blog. This covers the background, design, current status, and usage information for ThinLTO.<br />A post on Reddit gives a summary of <a href="https://www.reddit.com/r/cpp/comments/4pmlpz/">notable language features voted into the C++17 working draft at the Oulu meeting</a>.<br /><h3>On the mailing lists</h3><ul><li>Sanjoy Das has written an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101522.html">strong GC references in LLVM</a>. The motivating case for this proposal is supporting a precise, relocating garbage collector.<br /> </li><li>LLVM version 3.8.1-final <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101458.html">has been tagged</a>.<br /> </li><li>The Google Summer of Code mid-terms have snuck up on us already. The participating students have posted to the mailing lists with a summary of their work so far:<br /> <ul><li><a href="http://lists.llvm.org/pipermail/cfe-dev/2016-June/049547.html">Finding and reporting bugs caused by copy and paste</a></li><li><a href="http://lists.llvm.org/pipermail/cfe-dev/2016-June/049563.html">Enabling LLVM's self-hosted modules builds using libstdc++</a></li><li><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101237.html">Capture tracking improvements</a></li><li><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101370.html">Improvement of vectorization process in Polly</a></li><li><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101414.html">Better alias analysis by default</a></li><li><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101057.html">Interprocedural register allocation</a></li><li><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101314.html">Polly as an analysis pass</a></li><li><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101419.html">Enabling polyhedral optimisations in Julia</a></li></ul></li><li>Vivek Pandya wrote the mailing list seeking <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101319.html">advice on adding a new calling convention for interprocedural register allocation</a>. Matthias Braun <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101338.html">summarised some follow-up discussion</a>.<br /> </li></ul><h3>LLVM commits</h3><ul><li>The new representation for control-flow integrity and virtual call metadata has landed. The commit message further details the problems this change addresses. <a href="http://reviews.llvm.org/rL273729">r273729</a>.<br /> </li><li>The <code>llvm.type.checked.load</code> intrinsic was added. It loads a function pointer from a virtual table pointer using type metadata. <a href="http://reviews.llvm.org/rL273576">r273576</a>.<br /> </li><li>As part of the work on CFL-AA, interprocedural function summaries were added. These avoid recomputation for many properties of a function. <a href="http://reviews.llvm.org/rL273219">r273219</a>, <a href="http://reviews.llvm.org/rL273596">r273596</a>.<br /> </li><li>MemorySSA gained new APIs for PHI creation and MemoryAccess creation. <a href="http://reviews.llvm.org/rL273295">r273295</a>.<br /> </li><li>Metadata attachments are now allowed for declarations. <a href="http://reviews.llvm.org/rL273336">r273336</a>.<br /> </li><li>A new runtimes directory was added to the LLVM tree. <a href="http://reviews.llvm.org/rL273620">r273620</a>.<br /> </li><li>LLVM's dynamic loader gained basic support for COFF ARM. <a href="http://reviews.llvm.org/rL273682">r273682</a>.<br /> </li></ul><h3>Clang commits</h3><ul><li><code>constexpr if</code> support has been added to Clang. <a href="http://reviews.llvm.org/rL273602">r273602</a>.<br /> </li><li>clang-tidy has a new <code>modernize-use-emplace</code> check that will replace calls of <code>push_back</code> to <code>emplace_back</code>. <a href="http://reviews.llvm.org/rL273275">r273275</a>.<br /> </li><li>The CMake build system for Clang gained a <code>ENABLE_X86_RELAX_RELOCATIONS</code> option. <a href="http://reviews.llvm.org/rL273224">r273224</a>.<br /> </li></ul><h3>Other project commits</h3><ul><li>Basic support for versioned symbols was added to LLD. <a href="http://reviews.llvm.org/rL273143">r273143</a>.<br /> </li><li>LLD now handles both single and double dashes for all options. <a href="http://reviews.llvm.org/rL273256">r273256</a>.<br /> </li></ul>
- ThinLTO: Scalable and Incremental LTOhttps://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.htmlTue, 21 Jun 2016 06:01:00 +0000https://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;">ThinLTO was first introduced at <a href="http://llvm.org/devmtg/2015-04/slides/ThinLTO_EuroLLVM2015.pdf">EuroLLVM in 2015</a>, with results shown from a prototype implementation within clang and LLVM. Since then, the design was reviewed through several RFCs, it has been implemented in LLVM (for gold and libLTO), and tuning is ongoing. Results already show good performance for a number of benchmarks, with compile time close to a non-LTO build.</div><br /><div style="text-align: left;">This blog post covers the background, design, current status and usage information.</div><br /><div style="text-align: left;">This post was written by Teresa Johnson, Mehdi Amini and David Li.<br /><br /><a name='more'></a></div><h3>LTO Background and Motivation</h3><div style="text-align: left;">LTO (Link Time Optimization) is a method for achieving better runtime performance through whole-program analysis and cross-module optimization. During the compile phase, clang will emit LLVM bitcode instead of an object file. The linker recognizes these bitcode files and invokes LLVM during the link to generate the final objects that will constitute the executable. The LLVM implementation loads all input bitcode files and merges them together to produce a single Module. The interprocedural analyses (IPA) as well as the interprocedural optimizations (IPO) are performed serially on this monolithic Module.</div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/--p7jPdTVaxI/V19BygsO0aI/AAAAAAAAMhg/aJSiVLqd30AFDXPyQqZkQFaKPohsfNHwgCKgB/s1600/Screen%2BShot%2B2016-06-13%2Bat%2B4.28.25%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="292" src="https://4.bp.blogspot.com/--p7jPdTVaxI/V19BygsO0aI/AAAAAAAAMhg/aJSiVLqd30AFDXPyQqZkQFaKPohsfNHwgCKgB/s640/Screen%2BShot%2B2016-06-13%2Bat%2B4.28.25%2BPM.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><br /><div style="text-align: left;">What this means in practice is that LTO often requires a large amount of memory (to hold all IR at once) and is very slow. And with debug information enabled via -g, the size of the IR and the resulting memory requirements are significantly larger. Even without debug information, this is prohibitive for very large applications, or when compiling on memory-constrained machines. It also makes incremental builds less effective, as everything from the LTO step on must be re-executed when any input source changes.</div><h3 style="text-align: left;">ThinLTO Design</h3><div style="text-align: left;">ThinLTO is a new approach that is designed to scale like a non-LTO build, while retaining most of the performance achievement of full LTO.</div><div style="text-align: left;">In ThinLTO, the serial step is very thin and fast. This is because instead of loading the bitcode and merging a single monolithic module to perform these analyses, it utilizes compact summaries of each module for global analyses in the serial link step, as well as an index of function locations for later cross module importing. The function importing and other IPO transformations are performed later when the modules are optimized in fully parallel backends.</div><br /><div style="text-align: left;">The key transformation enabled by ThinLTO global analyses is function importing, in which only those functions likely to be inlined are imported into each module. This minimizes the memory overhead in each ThinLTO backend, while maximizing the most impactful cross module optimization opportunities. The IPO transformations are therefore performed on each module extended with its imported functions.</div><br /><div style="text-align: left;">The ThinLTO process is divided into 3 phases:</div><div style="text-align: left;"><ol style="text-align: left;"><li>Compile: Generate IR as with full LTO mode, but extended with module summaries </li><li>Thin Link: Thin linker plugin layer to combine summaries and perform global analyses </li><li>ThinLTO backend: Parallel backends with summary-based importing and optimizations </li></ol></div><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-n15XLWlQoJE/V18v5zSXCGI/AAAAAAAAMgc/5utJmweTI8QoqCbfruf-LHLHyY7ij-UVgCKgB/s1600/Screen%2BShot%2B2016-06-13%2Bat%2B3.12.16%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="274" src="https://1.bp.blogspot.com/-n15XLWlQoJE/V18v5zSXCGI/AAAAAAAAMgc/5utJmweTI8QoqCbfruf-LHLHyY7ij-UVgCKgB/s640/Screen%2BShot%2B2016-06-13%2Bat%2B3.12.16%2BPM.png" width="640" /></a></div><br /><div style="text-align: left;">By default, linkers that support ThinLTO (see below) are set up to launch the ThinLTO backends in threads. So the distinction between the second and third phases is transparent to the user.</div><br /><div style="text-align: left;">The key enabler for this process are the summaries emitted during phase 1. These summaries are emitted using the bitcode format, but designed so that they can be separately loaded without involving an LLVMContext or any other expensive construction. Each global variable and function has an entry in the module summary. An entry contains metadata that abstracts the symbol it is describing. For example, a function is abstracted with its linkage type, the number of instructions it contains, and optional profiling information (PGO). Additionally, every reference (address taken, direct call) to another global is recorded. This information enables building a complete reference graph during the Thin Link phase, and subsequent fast analyses using the global summary information.</div><h3 style="text-align: left;">Current Status</h3><div style="text-align: left;">ThinLTO is currently supported in both the gold plugin as well as in ld64 starting with <a href="https://developer.apple.com/xcode/">Xcode 8</a>. Additionally, support is currently being added to the lld linker. The 3.9 release of clang will have ThinLTO accessible using the -flto=thin command line option.</div><br /><div style="text-align: left;">While tuning is still in progress, ThinLTO already performs well compared to LTO, in many cases matching the performance improvement. In a few cases ThinLTO even outperforms full LTO, most likely because the higher scalability of ThinLTO allows using a more aggressive backend optimization pipeline (similar to that of a non-LTO build).</div><br /><div style="text-align: left;">The following results were collected for the C/C++ SPEC cpu2006 benchmarks on an 8-core 2.6GHz Intel Xeon E5-2689. Each benchmark was run in isolation three times and results are shown for the average of the three runs.</div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://lh5.googleusercontent.com/FBz172vtE5q1NtGldLhWM11Q_S0CxXO8gTtEUMFTHEWhq5H6vO9ouh8HxMo_46rAaONS_WCz4G1zgUli_6sm6EeQJaMOg8lxfc3L7WQNhLMKyb9tvpi1qEPVMsJ4u3_1zL0v-mBk" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="453" src="https://lh5.googleusercontent.com/FBz172vtE5q1NtGldLhWM11Q_S0CxXO8gTtEUMFTHEWhq5H6vO9ouh8HxMo_46rAaONS_WCz4G1zgUli_6sm6EeQJaMOg8lxfc3L7WQNhLMKyb9tvpi1qEPVMsJ4u3_1zL0v-mBk" width="640" /></a><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div><br /><br /><div style="text-align: left;">Critically, due to the scalable design of ThinLTO, this performance is achieved with a build time that stays within a non-LTO build scale. The following build times were collected on a 20 core 2.8GHz Intel Xeon CPU E5-2680 v2, running Linux and using the gold linker. The results are for an end-to-end build of clang (ninja clang) from a clean build directory, so it includes all the compile steps and links of intermediate binaries such as llvm-tblgen and clang-tblgen.</div><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-iLPTCAEC8yU/V1jubF7sl9I/AAAAAAAAMfQ/sRVEnIRxebc80PorKWB5lqRGD6G1OlGDACKgB/s1600/BuildTime.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="394" src="https://4.bp.blogspot.com/-iLPTCAEC8yU/V1jubF7sl9I/AAAAAAAAMfQ/sRVEnIRxebc80PorKWB5lqRGD6G1OlGDACKgB/s640/BuildTime.png" width="640" /></a></div><br />Release build shows how ThinLTO build time is very comparable to a non-LTO build. Adding -gline-tables-only adds a very small overhead, and ThinLTO is again similar to the regular non-LTO build. However with full debug information, ThinLTO is still somewhat slower than a non-LTO build due to the additional overhead during importing. Ongoing improvements to debug metadata representation and handling are expected to continue to reduce this overhead. In all cases, full LTO is actually significantly slower.<br /><br /><div style="text-align: left;">On the memory consumption side, the improvements are significant. Over the last two years, FullLTO was significantly improved, as shown on the chart below, but our measurement shows that ThinLTO keeps a large advantage.</div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-22OhulY_7AI/V185N9fAJyI/AAAAAAAAMhE/nBEjhKGbeAcpv_VDj18q_24vwiOQPUMtgCKgB/s1600/Screen%2BShot%2B2016-06-13%2Bat%2B3.52.10%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="406" src="https://1.bp.blogspot.com/-22OhulY_7AI/V185N9fAJyI/AAAAAAAAMhE/nBEjhKGbeAcpv_VDj18q_24vwiOQPUMtgCKgB/s640/Screen%2BShot%2B2016-06-13%2Bat%2B3.52.10%2BPM.png" width="640" /></a></div><h3 style="text-align: left;">Usage Information</h3><div style="text-align: left;">To utilize ThinLTO, simply add the -flto=thin option to compile and link. E.g.</div> % clang -flto=thin -O2 file1.c file2.c -c<br /> % clang -flto=thin -O2 file1.o file2.o -o a.out<br /><br /><div style="text-align: left;">As mentioned earlier, by default the linkers will launch the ThinLTO backend threads in parallel, passing the resulting native object files back to the linker for the final native link. As such, the usage model the same as non- LTO. Similar to regular LTO, for Linux this requires using the <a href="http://llvm.org/docs/GoldPlugin.html">gold linker configured with plugins enabled</a> or ld64 starting with <a href="https://developer.apple.com/xcode/">Xcode 8</a>.</div><h3 style="text-align: left;">Distributed Build Support</h3><div style="text-align: left;">To take advantage of a distributed build system, the parallel ThinLTO backends can each be launched as a separate process. To support this, the gold plugin provides a thinlto_index_only option that causes the link to exit after creating the combined index and performing global analysis.</div><br /><div style="text-align: left;">Additionally, in this mode:</div><ul style="text-align: left;"><li>Instead of using a monolithic combined index, a separate individual index file is written per backend containing the necessary portions of the combined index for recording the imports and any other global summary based optimization decisions that should be acted on in the backend. </li><li>A plain text listing of the bitcode files each module will import from is optionally emitted to aid in distributed build file staging (thinlto-emit-imports-files plugin option). </li></ul><br /><div style="text-align: left;">The backends can be launched by invoking clang on the bitcode and providing its index via an option. Finally, the resulting native objects are linked to generate the final binary. For example:</div><br /> % clang -flto=thin -O2 file1.c file2.c -c<br /> % clang -flto=thin -O2 file1.o file2.o -Wl,-plugin-opt,-thinlto-index-only<br /> % clang -O2 -o file1.native.o -x ir file1.o -c -fthinlto-index=./file1.o.thinlto.bc<br /> % clang -O2 -o file2.native.o -x ir file2.o -c -fthinlto-index=./file2.o.thinlto.bc<br /> % clang file1.native.o file2.native.o -o a.out<br /><br /><h3 style="text-align: left;">Incremental ThinLTO Support</h3><div style="text-align: left;">With full LTO, only the initial compile steps can be performed incrementally. If any input has changed, the expensive serial IPA/IPO step must be redone.</div><br /><div style="text-align: left;">With ThinLTO, the serial Thin Link step must be redone if any input has changed, however, as noted earlier this is small and fast, and does not involve loading any module. And any particular ThinLTO backend must be redone iff:</div><br /><ol style="text-align: left;"><li>The corresponding (primary) moduleâs bitcode changed </li><li>The list of imports into or exports from the module changed </li><li>The bitcode for any module being imported from has changed </li><li>Any global analysis result affecting either the primary module or anything it imports has changed. </li></ol><br /><div style="text-align: left;">For single machine builds, where the threads are launched by the linker, incremental builds can be achieved by caching the module after applying the global summary based optimizations such as importing, using a hash of the information listed above as the key. This caching is already supported in libLTOâs ThinLTO handling, which is used by ld64. To enable it, the link step needs to be passed an extra flag: <i>-Wl,-cache_path_lto,/path/to/cache</i></div><br /><div style="text-align: left;">For distributed builds, the above information in items 2-4 are all serialized into the individual index files. So the build system can compare the contents of the input bitcode files (the primary moduleâs bitcode and any it imports from) along with the combined index against those from an earlier build to decide if a particular ThinLTO backend must be redone. To make this process more efficient, the content of the bitcode file is hashed when emitted during the compile phase, and the result is stored in the bitcode file itself so that the cache can be queried during the Thin Link step without reading the IR.<br /><br />The chart below illustrates the full build time of clang in three different situations:<br /><ol style="text-align: left;"><li>The full link following a clean build.</li><li>The developer fixes the implementation of <i>DenseMap::grow()</i>. This is a widely used header in the project, which forces to rebuild a large number of files.</li><li>The developer fixes the implementation of <i>visitCallInst()</i> in <i>InstCombineCalls.cpp</i>. This an implementation file and incremental build should be fast.</li></ol><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-1AXpVE8BMtA/V1866_hMEpI/AAAAAAAAMhQ/oBNi7TXF8BcRZD93OUMGJmFa0oFxg3BwwCKgB/s1600/Screen%2BShot%2B2016-06-13%2Bat%2B3.59.16%2BPM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="358" src="https://1.bp.blogspot.com/-1AXpVE8BMtA/V1866_hMEpI/AAAAAAAAMhQ/oBNi7TXF8BcRZD93OUMGJmFa0oFxg3BwwCKgB/s640/Screen%2BShot%2B2016-06-13%2Bat%2B3.59.16%2BPM.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div style="text-align: left;">These results illustrate how full LTO is not friendly with incremental build, and show how ThinLTO is providing an incremental link-time very close to a non-LTO build.</div></div></div>
- LLVM Weekly - #129, Jun 20th 2016https://blog.llvm.org/2016/06/llvm-weekly-129-jun-20th-2016.htmlMon, 20 Jun 2016 04:23:00 +0000https://blog.llvm.org/2016/06/llvm-weekly-129-jun-20th-2016.html<p>Welcome to the one hundred and twenty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/129">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Last week was WWDC, which featured talks on <a href="https://developer.apple.com/videos/play/wwdc2016/405/">what's new in LLVM</a> (<a href="http://devstreaming.apple.com/videos/wwdc/2016/405i2ilotov3bazyei1/405/405_whats_new_in_llvm.pdf">slides</a>) and <a href="https://developer.apple.com/videos/play/wwdc2016/402/">what's new in Swift</a> (<a href="http://devstreaming.apple.com/videos/wwdc/2016/402h429l9d0hy98c9m6/402/402_whats_new_in_swift.pdf">slides</a>). Note that the embedded video player suggests you need Safari or the WWDC app to stream the video, but you can find a downloadable version under the "resources" tab.</p><h3>On the mailing lists</h3><ul><li><p>Jason Henline has announced the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101028.html">LLVM parallel-libs subproject</a> which will "host the development of libraries which are aimed at enabling parallelism in code and which are also closely tied to compiler technology.Examples of libraries suitable for hosting within the <code>parallel-libs</code> subproject are runtime libraries and parallel math libraries. The initial candidates for inclusion in this subproject are StreamExecutor and libomptarget which would live in the <code>streamexecutor</code>and <code>libomptarget</code> subdirectories of <code>parallel-libs</code>, respectively."</p></li><li><p>One of the most active threads this week was about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101044.html">whether the release following 3.9 should be 4.0</a>. Much of the discussion was around whether the move from 3.9 to 4.0 should come with a large change breaking IR compatibility. Chris Lattner suggests a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101270.html">sliding window of IR compatibility may be better</a>.</p></li><li><p>TB Schardl has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101162.html">upstreaming the CSI framework</a> ("Comprehensive Static Instrumentation"). The <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101196.html">code</a> is now up for review. This framework makes it easy to implement dynamic analysis tools, often without needing compiler changes.</p></li><li><p>Ashutosh Nema has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101123.html">strided memory access vectorisation</a>.</p></li><li><p>In response to a question on the mailing list, Hubert Tong has given a <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-June/049480.html">brain dump on the status of work on concepts support in Clang</a> including opportunities for getting involved.</p></li><li><p>PaweÅ Bylica has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101125.html">asked for advice on dealing with LLVM as a project dependency</a>. In particular, is it worth investigating CMake's ExternalProject module? Chris Bieneman has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101131.html">shared some advice</a>.</p></li><li><p>Michael Kuperstein has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/101136.html">allowing the loop vectorizer to choose vector widths that generate illegal types</a>. The feedback appears to be possible so far.</p></li></ul><h3>LLVM commits</h3><ul><li><p>FileCheck learnt the <code>--check-prefixes</code> option as a shorthand for multiple <code>--check-prefix</code> options. <a href="http://reviews.llvm.org/rL272670">r272670</a>.</p></li><li><p>A <code>local_unnamed_addr</code> attribute was introduced. This can be used by the code generator and LTO to allow the linker to decide whether the global needs to be in the symbol table. <a href="http://reviews.llvm.org/rL272709">r272709</a>.</p></li><li><p>The ScalarReplAggregates pass has been removed as it has been superseded by SROA by a long time. <a href="http://reviews.llvm.org/rL272737">r272737</a>.</p></li><li><p>LLVM's C API gained support for string attributes. <a href="http://reviews.llvm.org/rL272811">r272811</a>.</p></li><li><p>Assembly parsing and lexing has seem some cleanups. <a href="http://reviews.llvm.org/rL273007">r273007</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A new loop distribution pragma was added. Loop distribution is a transformation which attempts to break a loop in to multiple loops with each taking part of the loop body. <a href="http://reviews.llvm.org/rL272656">r272656</a>.</p></li><li><p>The nodebug attribute can now be applied to local variables. <a href="http://reviews.llvm.org/rL272859">r272859</a>.</p></li><li><p>The validity check for MIPS CPU/ABI pairings is now performed at initialisation time and a much clearer message is printed. <a href="http://reviews.llvm.org/rL272645">r272645</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A complete implementation of the C++ Filesystem TS has been checked in. <a href="http://reviews.llvm.org/rL273034">r273034</a>.</p></li><li><p>LLD's ARM port gained initial support for Thumb with ARMv7a. <a href="http://reviews.llvm.org/rL272881">r272881</a>.</p></li></ul>
- Using LNT to Track Performancehttps://blog.llvm.org/2016/06/using-lnt-to-track-performance.htmlWed, 15 Jun 2016 23:19:00 +0000https://blog.llvm.org/2016/06/using-lnt-to-track-performance.html<span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">In the past year, LNT has grown a number of new features that makes performance tracking and understanding the root causes of performance deltas a lot easier. In this post, Iâm showing how weâre using these features.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">LNT contains 2 big pieces of functionality:</span><br /><ol><li><span style="font-family: inherit;">A server,<br />a. to which you can submit correctness and performance measurement data, by sending it a json-file in the correct format,<br />b. that analyzes which performance changes are significant and which ones aren't,<br />c. that has a webui to show results and analyses in a number of different ways.</span></li><li><span style="font-family: inherit;">A command line tool to run tests and benchmarks, such as LLVMâs test-suite, SPEC2000 and SPEC2006 benchmarks.</span></li></ol><span style="font-family: inherit;">This post focuses on using the server. None of the features Iâll show are LLVM-specific, or even specific to ahead-of-time code generators, so you should be able to use LNT in the same way for all your code performance tracking needs. At the end, Iâll give pointers to the documentation needed to setup an LNT server and how to construct the json file format with benchmarking and profiling data to be submitted to the server.</span><br /><span style="font-family: inherit;">The features highlighted focus on tracking the performance of code, not on other aspects LNT can track and analyze.</span><br /><span style="font-family: inherit;">We have 2 main uses cases in tracking performance:</span><br /><ul><li><span style="font-family: inherit;">Post-commit detection of performance regressions and improvements.</span></li><li><span style="font-family: inherit;">Pre-commit analysis of the impact of a patch on performance.</span></li></ul><span style="font-family: inherit;">I'll focus on the post-commit detection use case.</span><br /><h2><span style="font-family: inherit;">Post-commit performance tracking</span></h2><h4>Step 1. Get an overview of the "Daily Report" page</h4><div><div>Assuming your server runs at http://yourlntserver:8000, this page is located at http://yourlntserver:8000/db_default/v4/nts/daily_report</div><div>The page gives a summary of the significant changes it found today.</div><div>An example of the kind of view you can get on that page is the following</div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-lNSURt-I4tc/V2F48OowcSI/AAAAAAAAFg8/EYJXuOe9tZ4_ljn2fzbEjcdTArs0BAeDACLcB/s1600/lnt_daily_report.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://4.bp.blogspot.com/-lNSURt-I4tc/V2F48OowcSI/AAAAAAAAFg8/EYJXuOe9tZ4_ljn2fzbEjcdTArs0BAeDACLcB/s640/lnt_daily_report.png" width="640" /></a></div><div class="separator" style="clear: both;">In the above screenshot, you can see that there were performance differences on 3 different programs, bigfib, fasta and ffbench. The improvement on ffbench only shows up on a machine named âmachine3â, whereas the performance regression on the other 2 programs shows up on multiple machines.</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">The table shows how performance evolved over the past 7 days, one column for each day. The sparkline on the right shows graphically how performance has evolved over those days. When the program was run multiple times to get multiple sample points, these show as separate dots that are vertically aligned (because they happened on the same date). The background color in the sparkline represents a hash of the program binary. If the color is the same on multiple days, the binaries were identical on those days.</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">Letâs look first at the ffbench program. The background color in the sparkline is the same for the last 2 days, so the binary for this program didnât change in those 2 days. Conclusion: the reported performance variation of -8.23% is caused by noise on the machine, not due to a change in code. The vertically spread out dots also indicate that this program has been noisy consistently over the past 7 days.</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">Letâs now look at the bigfib. The background color in the sparkline has changed since its previous run, so letâs investigate further. By clicking on one of the machine names in the table, we go to a chart showing the long-term evolution of the performance of this program on that machine.</div><h4>Step 2. The long-term performance evolution chart</h4><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-S53qGJAhZiI/V2F58jQ0NVI/AAAAAAAAFhI/XuxqfUnh0rshfgqD1Gcn1SEynH22ZOEKACLcB/s1600/longterm-perf-evolution-chart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="280" src="https://1.bp.blogspot.com/-S53qGJAhZiI/V2F58jQ0NVI/AAAAAAAAFhI/XuxqfUnh0rshfgqD1Gcn1SEynH22ZOEKACLcB/s640/longterm-perf-evolution-chart.png" width="640" /></a></div><div class="separator" style="clear: both;">This view shows how performance has evolved for this program since we started measuring it. When you click on one of the dots, which each represent a single execution of the program, you get a pop-up with information such as revision, date at which this was run etc.</div><div class="separator" style="clear: both;">When you click on the number after âRun:â in that pop-up, itâll bring you to the run page.</div><h4 style="clear: both;">Step 3. The Run page</h4><div><div>The run page gives an overview of a full âRunâ on a given machine. Exactly what a Run contains depends a bit on how you organize the data, but typically it consists of many programs being run a few times on 1 machine, representing the quality of the code generated by a specific revision of the compiler on one machine, for one optimization level.</div><div>This run page shows a lot of information, including performance changes seen since the previous run:</div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-2CaZGoSAmL4/V2F7Fftk8XI/AAAAAAAAFhU/gnTa49e6lt0ckVLkj49zP20in0VvXd5HACLcB/s1600/run-over-run%2Bchanges.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="128" src="https://1.bp.blogspot.com/-2CaZGoSAmL4/V2F7Fftk8XI/AAAAAAAAFhU/gnTa49e6lt0ckVLkj49zP20in0VvXd5HACLcB/s640/run-over-run%2Bchanges.png" width="640" /></a></div><div>When hovering with the mouse over entries, a âProfileâ button will show, that when clicked, shows profiles of both the previous run and the current run.</div><h4>Step 4. The Profile page</h4><div><div>At the top, the page gives you an overview of differences of recorded performance events between the current and previous run.</div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-1KaKjIGohZw/V2F9WxfRdII/AAAAAAAAFhg/d1ePCRy_uL4T6rVQnZPk316H8iuxutQ0wCLcB/s1600/PerformanceCounters.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="64" src="https://2.bp.blogspot.com/-1KaKjIGohZw/V2F9WxfRdII/AAAAAAAAFhg/d1ePCRy_uL4T6rVQnZPk316H8iuxutQ0wCLcB/s640/PerformanceCounters.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: left;">After selecting which function you want to compare, this page shows you the annotated assembly:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-k5mJCSu02Og/V2F90A9uiSI/AAAAAAAAFho/epjri2UOIPMYQILotrAX34gllJWoSBMSwCLcB/s1600/profile_view.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="306" src="https://1.bp.blogspot.com/-k5mJCSu02Og/V2F90A9uiSI/AAAAAAAAFho/epjri2UOIPMYQILotrAX34gllJWoSBMSwCLcB/s640/profile_view.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div><br /></div><div><div>While itâs clear that there are differences between the disassembly, itâs often much easier to understand the differences by reconstructing the control flow graph to get a per-basic-block view of differences. By clicking on the âView:â drop-down box and selecting the assembly language you see, you can get a CFG view. I find showing absolute values rather than relative values helps to understand performance differences better, so I also chose âAbsolute numbersâ in the drop down box on the far right:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-intetvmwToI/V2F-WH08lII/AAAAAAAAFh0/1rNkIiUEtOAtQ1QeWVaSXkXExXjK-8rqACLcB/s1600/profile_view_cfg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://4.bp.blogspot.com/-intetvmwToI/V2F-WH08lII/AAAAAAAAFh0/1rNkIiUEtOAtQ1QeWVaSXkXExXjK-8rqACLcB/s640/profile_view_cfg.png" width="640" /></a></div><div class="separator" style="clear: both;">There is obviously a single hot basic block, and there are differences in instructions in the 2 versions. The number in the red side-bar shows that the number of cycles spent in this basic block has increased from 431M to 716M. In just a few clicks, I managed to drill down to the key codegen change that caused the performance difference!</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">We combine the above workflow with the llvmbisect tool available at <a href="http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmbisect/">http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmbisect/</a> to also quickly find the commit introducing the performance difference. We find that using both the above LNT workflow and the llvmbisect tool are vital to be able to act quickly on performance deltas.</div><h2>Pointers on setting up your own LNT server for tracking performance</h2><div><div>Setting up an LNT server is as simple as running the half a dozen commands documented at <a href="http://lnt.llvm.org/quickstart.html">http://lnt.llvm.org/quickstart.html</a> under "Installation" and "Viewing Results". The "Running tests" section is specific to LLVM tests, the rest is generic to performance tracking of general software.</div><div><br /></div><div>The documentation for the json file format to submit results to the LNT server is here: <a href="http://lnt.llvm.org/importing_data.html">http://lnt.llvm.org/importing_data.html</a>.</div><div>The documentation for how to also add profile information, is at <a href="http://lnt.llvm.org/profiles.html">http://lnt.llvm.org/profiles.html</a>.</div></div><div><br /></div></div><div><br /></div>
- LLVM Weekly - #128, June 13th 2016https://blog.llvm.org/2016/06/llvm-weekly-128-june-13th-2016.htmlMon, 13 Jun 2016 05:08:00 +0000https://blog.llvm.org/2016/06/llvm-weekly-128-june-13th-2016.html<p>Welcome to the one hundred and twenty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/128">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LDC, a compiler for the D programming language with an LLVM backends has a <a href="http://forum.dlang.org/post/[email protected]">major release with 1.0.0</a>. The big news with this release is that the frontend is now completely written in D. Congratulations to everyone involved in this release. See <a href="http://dlang.org/">the D website</a> for more information about the D programming language.</p><p>The minor release LLVM 3.8.1-rc1 <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100787.html">has been tagged</a>.</p><h3>On the mailing lists</h3><ul><li><p>Gor Nishanov has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100838.html">adding support for coroutines to LLVM IR</a>.</p></li><li><p>Hans Wennborg has shared the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100913.html">release plan for the 3.9 release</a>. This plan would see the release branch created on the 18th of July and the final shipping on the 22nd of August. Hans wonders whether, as with 2.9 and 1.9 the base version number will be incremented (making release 4.0). He'd also like to make LLVM's current release cadence "official" on the website and publicly list people who are currently committed to testing releases.</p></li><li><p>Chris Bieneman is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100859.html">proposing some changes to the LLVM directory structure</a>. Specifically, adding a 'runtimes' subdirectory and removing the 'projects' subdirectory. Chris has helpfully <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100904.html">summarised some of the key feedback</a> and proposed how to move forwards.</p></li><li><p>Sebastian Pop is trying to get a feel for <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100942.html">how many LLVM developers are attending HPCA/PPoPP/CGO in February 2017</a> in order to estimate potential numbers for an LLVM gathering.</p></li><li><p>In answer to a question, Krzysztof Parzyszek explains <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100885.html">how to use glue values</a>.</p></li><li><p>Philip Reames provides a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100781.html">handy explanation</a> of what is means for allocations to "escape", be "captured" or be "thread local".</p></li><li><p>Simon Brand is seeking feedback on how to <a href="http://lists.llvm.org/pipermail/lldb-dev/2016-June/010453.html">enhance LLDB to better support HSA applications</a>.</p></li><li><p>Simon Cook describes how he has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100899.html">set up pseudo-registers representing register locations on a very register-poor architecture</a>.</p></li><li><p>Vikram TV has shared a proposal on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100789.html">adding a pass that calculates loop cost based on cache data</a>. The prototype patch analyses references to determine which would be in the same cache line. This knowledge can then be used to calculate a more accurate loop cost and. A drawback of the current implementation is it uses a static cache line size.</p></li><li><p>Sean Silva has kicked off a thread about the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100792.html">intended behaviour of the CGSCC pass manager</a>. This manages passes over strongly connected components of the callgraph.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Some of the work from the GSoC project on interprocedural register allocation has started to land. A RegUsageInfoCollector analysis was added that collects the list of clobbered registers for a MachineFunction. A new transformation pass was committed which scans the body of a function to find calls and updates the register mask with the one saved by RegUsageInfoCollector. <a href="http://reviews.llvm.org/rL272403">r272403</a>, <a href="http://reviews.llvm.org/rL272414">r272414</a>.</p></li><li><p>Chapter 2 of the tutorial on building a JIT with ORC has been fleshed out with a rough draft of the text. <a href="http://reviews.llvm.org/rL271885">r271885</a>.</p></li><li><p>The host CPU detection code for x86 has seen a large refactoring. <a href="http://reviews.llvm.org/rL271921">r271921</a>.</p></li><li><p>More documentation has been added about LLVM's CodeView support. <a href="http://reviews.llvm.org/rL272057">r272057</a>.</p></li><li><p>llvm-symbolizer will now be searched for in the same directory as the LLVM or Clang tool being executed. This increases the chance of being able to print pretty backtraces for systems where LLVM tools aren't installed in the $PATH. <a href="http://reviews.llvm.org/rL272232">r272232</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang analyzer gained a checker for correct usage of the MPI API in C and C++. <a href="http://reviews.llvm.org/rL271907">r271907</a>.</p></li><li><p>Documentation was added on avoiding static initializers when using profiling. <a href="http://reviews.llvm.org/rL272067">r272067</a>, <a href="http://reviews.llvm.org/rL272214">r272214</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A hardened allocator, 'scudo' was added to compiler-rt. It attempts to mitigate some common heap-based vulnerabilities. <a href="http://reviews.llvm.org/rL271968">r271968</a>.</p></li><li><p>Initial support for ARM has landed in LLD. This is just enough to link a hello world on ARM Linux. <a href="http://reviews.llvm.org/rL271993">r271993</a>.</p></li><li><p>Initial support for AddressSanitizer on Win64 was added. <a href="http://reviews.llvm.org/rL271915">r271915</a>.</p></li></ul>
- LLVM Weekly - #127, June 6th 2016https://blog.llvm.org/2016/06/llvm-weekly-127-june-6th-2016.htmlMon, 06 Jun 2016 08:02:00 +0000https://blog.llvm.org/2016/06/llvm-weekly-127-june-6th-2016.html<p>Welcome to the one hundred and twenty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/127">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Graham Markall at Embecosm has been comparing the code size of <a href="http://www.embecosm.com/2016/05/26/risc-v-compiler-performance-part-1-code-size-comparisons/">RISC-V binaries produced by the GCC and LLVM ports</a>, as well as compared to ARM. GCC is currently ahead, though it is worth noting the LLVM port has seen much less attention.</p><p>Matthias Reisinger is a Google Summer of Code student working on enabling polyhedral optimisations for the Julia programming language. He's written a blog post detailing his <a href="http://www.mreisinger.com/?p=43">initial steps and immediate future plans</a>. Hopefully we'll see more posts over the summer.</p><p>Loïc Hamot has been working on a <a href="http://forum.dlang.org/post/[email protected]">C++ to D converter</a>, implemented using Clang.</p><p>The MSVC team have blogged about the <a href="https://blogs.msdn.microsoft.com/vcblog/2016/06/03/clang-3-8-in-the-may-release-of-clang-with-microsoft-codegen/">latest release of Clang with Microsoft CodeGen</a>, based on Clang 3.8.</p><p>There is going to be a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100647.html">clang-tidy code dojo</a> in Warsaw on Tuesday the 7th of June.</p><h3>On the mailing lists</h3><ul><li><p>Renato Golin has kicked off a discussion on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100310.html">moving LLVM's repository hosting to GitHub</a>. Chris Lattner <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100314.html">came out in favour</a>, specifically motivated by GitHub's community aspects. Renato has very helpfully <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100507.html">summarised the discussion</a>.</p></li><li><p>Peter Smith has shared his <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100598.html">initial port of LLD to ARM</a> along with his planned roadmap. The currently submitted patch is just enough to link a hello world executable on ARM Linux.</p></li><li><p>The apt repo hosted at llvm.org has been <a href="http://lists.llvm.org/pipermail/llvm-foundation/2016-May/000020.html">temporarily turned off</a> as it is resulting in excessive I/O and network activity. Some commenters ask about setting up an Ubuntu PPA or using the OpenSUSE build service.</p></li><li><p>David Blaikie has written a GDB pretty printer script for some common LLVM types and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100365.html">described how to use it</a>.</p></li><li><p>Michael LeMay has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100346.html">RFC on using segmentation to harden SafeStack</a>.</p></li><li><p>Rui Ueyama has been investigating <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100700.html">using sendfile to copy file contents in LLD</a> and shares his results. He concludes the performance improvement is too modest to be worth the change.</p></li><li><p>If you're interested in register allocation, then <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100523.html">delve in to this thread on LLVM's PBQP allocator and copy propagation</a>.</p></li><li><p>Daniel Dunbar is <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-May/049135.html">suggesting some changes to the lit default output</a>.</p></li><li><p>Steven Wu shares a follow-up RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100643.html">embedded bitcode</a>.</p></li><li><p>There's a useful discussion in <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100470.html">this thread on lowering loops to use a hardware loop instruction</a>.</p></li><li><p>Peter Collingbourne <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100462.html">proposes renaming and slightly redesigning the bitset metadata</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM gained support for 'SJLJ' (setjmp/longjmp) exception handling on x86 targets. <a href="http://reviews.llvm.org/rL271244">r271244</a>.</p></li><li><p>LLVM now requires CMake 3.4.3 to build <a href="http://reviews.llvm.org/rL271325">r271325</a>.</p></li><li><p>Support was added for attaching metadata to global variables. <a href="http://reviews.llvm.org/rL271348">r271348</a>.</p></li><li><p>The AArch64 backend switched to use SubtargetFeatures rather than testing for specific CPUs. <a href="http://reviews.llvm.org/rL271555">r271555</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The release notes have been updated to explain the current level of OpenMP support (full support of non-offloading features of OpenMP 4.5). <a href="http://reviews.llvm.org/rL271263">r271263</a>.</p></li><li><p>Clang's source-based code coverage has been documented. <a href="http://reviews.llvm.org/rL271454">r271454</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>An <code>-fno-exceptions</code> libc++abi library variant was defined, to match the <code>-fno-exceptions</code> libc++ build. <a href="http://reviews.llvm.org/rL271267">r271267</a>.</p></li><li><p>LLDB's compact unwind printing tool gained support for ARMv7's compact unwind format. <a href="http://reviews.llvm.org/rL271744">r271744</a>.</p></li></ul>
- LLVM Weekly - #126, May 30th 2016https://blog.llvm.org/2016/05/llvm-weekly-126-may-30th-2016.htmlMon, 30 May 2016 12:07:00 +0000https://blog.llvm.org/2016/05/llvm-weekly-126-may-30th-2016.html<p>Welcome to the one hundred and twenty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/126">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <p>I've been moving house this weekend, so do accept my apologies if you find this issue to be a little less thorough than usual.</p><h3>News and articles from around the web</h3><p>Pyston, the LLVM-based Python compiler has <a href="https://blog.pyston.org/2016/05/25/pyston-0-5-released/">released version 0.5</a>. The main changes are a switch to reference counting and NumPy compatibility.</p><p>I don't want to become "C++ weekly", but I think this audience appreciates a fun use of C++ features. <a href="https://woboq.com/blog/verdigris-qt-without-moc.html">Verdigris</a> is a header-only library that allows you to use Qt5 without the moc preprocessor.</p><p>The call for papers for the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100107.html">3rd workshop on the LLVM compiler infrastructure in HPC</a> has been published. The deadline for paper submission is September 1st. The workshop will take place on November 14th in Salt Lake City, and is held in conjunction with SC16.</p><h3>On the mailing lists</h3><ul><li><p>Vivek Pandya, a GSoC student working on interprocedural register allocation has shared <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100227.html">a weekly status report</a>.</p></li><li><p>Rafael EspÃndola has proposed <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100190.html">creating a bitcode symbol table</a>.</p></li><li><p>There's been <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100169.html">some</a> <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100170.html">updates</a> on the progress of open-sourcing PGI's Fortran frontend.</p></li><li><p>Elena Lepilkina has proposed some <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100024.html">enhancement to FileCheck</a>. Some questions were raised about how useful the proposed extensions will be. Sergey Yakoushkin provided more background on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100162.html">how these features are used</a> in a commercial codebase. As Elena notes, these features don't need to all be upstreamed at once (or at all), and are mostly independent.</p></li><li><p>Lang Hames has posted a heads-up about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100061.html">upcoming breaking API changes for ORC and MCJIT</a>.</p></li><li><p>Sean Silva has kicked off a discussion on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100021.html">the state of IRPGO</a>. You might ask what is IRPGO? This is profile-guided optimisation performed through instrumentation at the LLVM IR level, as opposed to FEPGO where instrumentation is added by the frontend (e.g. Clang), prior to lowering to IR. Sean would like to make IRPGO the default on all platforms other than Apple at the moment (who may require a longer deprecation period). A number of followup comments discuss possibilities for ensuring all platforms can move forward together, and ensuring a sensible flag exists to choose between frontend or middle-end PGO.</p></li><li><p>What exactly is a register pressure set? Both <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100004.html">Quentin Colombet</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/100019.html">Andrew Trick</a> have answers for us.</p></li></ul><h3>LLVM commits</h3><ul><li><p>New optimisations covering checked arithmetic were added. <a href="http://reviews.llvm.org/rL271152">r271152</a>, <a href="http://reviews.llvm.org/rL271153">r271153</a>.</p></li><li><p>Advanced unrolling analysis is now enabled by default. <a href="http://reviews.llvm.org/rL270478">r270478</a>.</p></li><li><p>The initial version of a new chapter to the 'Kaleidoscope' tutorial has been committed. This describes how to build a JIT using ORC. <a href="http://reviews.llvm.org/rL270487">r270487</a>, <a href="http://reviews.llvm.org/rL271054">r271054</a>.</p></li><li><p>LLVM's stack colouring analysis data flow analysis has been rewritten in order to increase the number of stack variables that can be overlapped. <a href="http://reviews.llvm.org/rL270559">r270559</a>.</p></li><li><p>Parts of EfficiencySanitizer are starting to land, notably instrumentation for its working set tool. <a href="http://reviews.llvm.org/rL270640">r270640</a>.</p></li><li><p>SelectionDAG learned how to expand multiplication for larger integer types where there isn't a standard runtime call to handle it. <a href="http://reviews.llvm.org/rL270720">r270720</a>.</p></li><li><p>LLVM will now report more accurate loop locations in optimisation remarks by reading the starting location from llvm.loop metadata. <a href="http://reviews.llvm.org/rL270771">r270771</a>.</p></li><li><p>Symbolic expressions are now supported in assembly directives, matching the behaviour of the GNU assembler. <a href="http://reviews.llvm.org/r271102">r271102</a>.</p></li><li><p>Symbols used by plugins can now be auto-exported on Windows, which improves support for plugins in Windows. See the commit message for a full description. <a href="http://reviews.llvm.org/rL270839">r270839</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Software floating point for Sparc has been exposed in Clang through <code>-msoft-float</code>. <a href="http://reviews.llvm.org/rL270538">r270538</a>.</p></li><li><p>Clang now supports the <code>-finline-functions</code> argument to enable inlining separately from the standard <code>-O</code> flags. <a href="http://reviews.llvm.org/rL270609">r270609</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>SectionPiece in LLD is now 8-bytes smaller on 64-bit platforms. This improves the time to link Clang with debug info by 2%. <a href="http://reviews.llvm.org/rL270717">r270717</a>.</p></li><li><p>LLD has replaced a use of binary search with a hash table lookup, resulting in a 4% speedup when linking Clang with debug info. <a href="http://reviews.llvm.org/rL270999">r270999</a>.</p></li><li><p>LLDB now supports AArch64 compact unwind tables, as used on iOS, tvos and watchos. <a href="http://reviews.llvm.org/rL270658">r270658</a>.</p></li></ul>
- LLVM Weekly - #125, May 23rd 2016https://blog.llvm.org/2016/05/llvm-weekly-125-may-23rd-2016.htmlMon, 23 May 2016 03:57:00 +0000https://blog.llvm.org/2016/05/llvm-weekly-125-may-23rd-2016.html<p>Welcome to the one hundred and twenty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/125">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Stephen Kelly has written a blog post about <a href="https://steveire.wordpress.com/2016/05/18/generating-python-bindings-with-clang/">using Clang through the cindex API to automatically generate Python bindings</a>. He also makes use of <a href="https://www.riverbankcomputing.com/software/sip/intro">SIP</a>.</p><p>Krister Walfridsson has written a wonderfully clear post on <a href="http://kristerw.blogspot.co.uk/2016/05/type-based-aliasing-in-c.html">C's type-based aliasing rules</a>.</p><p>This week I discovered the <a href="http://swiftweekly.github.io/">Swift Weekly Brief newsletter</a>. Its author, Jesse Squires does a wonderful job of summarising mailing list traffic, recent commits, and discussions on swift-evolution proposals. If you have an interest in Swift development or language design in general I highly recommend it.</p><p>Are you interested in <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099807.html">writing for the LLVM blog</a>? Or volunteering to help recruit content authors? If so, get in touch with Tanya.</p><p>The next Cambridge LLVM Social will be held <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099870.html">at 7.30pm on May 25th at the Cambridge Blue</a>.</p><h3>On the mailing lists</h3><ul><li><p>Elena Demikhovsky is interested in <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099724.html">extending scalar evolution (SCEV) analysis to include floating point support</a>. This kicked off a pretty interesting discussion. Sanjoy Das highlighted what he sees as the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099743.html">most important issues to discuss</a>. A number of follow-ups discussed whether enough code uses floating point values as an induction variable to be worth optimising. There was also the question of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099819.html">should vectorisation be pursued at any cost?</a>. Even if a loop can be made vectorisable through loop-versioning with run-time checks, is it worth the code size? Is the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099814.html">cost of maintaining the compiler code</a> worthwhile? Hideki Saito posted a useful <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099928.html">summary of the discussion so far</a>.</p></li><li><p>Chandler Carruth is looking for feedback on the idea of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099715.html">supporting horizontal operations on vector types such as sum directly in LLVM IR</a>. Everyone who has responsed so far is in favour.</p></li><li><p>Jia Chen, GSoC student with LLVM, has noted the CFL-AA pass seems to be mostly working now and would <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099742.html">appreciate reports from people trying it out on their codebases</a>.So far, Geoff Berry <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099900.html">reports</a> no correctness issues but seemingly very limited changes in the generated code for SPEC and the LLVM test-suite.</p></li><li><p>Adam Nemet is seeking feedback on the idea of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099873.html">adding optimisation remarks to indicate where non-temporal stores may be profitable</a>.</p></li><li><p>Quentin Colombet has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099752.html">summarised recent discussion on policies to help release management</a> and detailed the automatic hooks he hopes to explore next for updating bugs when referenced in a commit message. The following discussion looked at how these hooks may be implemented and what level of rigidity would be most beneficial to the community.</p></li><li><p>Dean Michael Berris is looking for a way of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099759.html">defining a default implementation for a pseudo-instruction</a>. No answers yet, but hopefully that will change soon!</p></li><li><p>Galina Kistanova is doing some cleanup work on zorg (the buildbot-based testing infrastructure of the LLVM project) and is interested whether <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099739.html">anyone uses these seemingly stale modules</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>llc will now report all errors in the input file rather than just exiting after the first. <a href="http://reviews.llvm.org/rL269655">r269655</a>.</p></li><li><p>The SPARC backend gained support for soft floating point. <a href="http://reviews.llvm.org/rL269892">r269892</a>.</p></li><li><p><code>Reloc::Default</code> no longer exists. Instead, <code>Optional<Reloc></code> is used. <a href="http://reviews.llvm.org/rL269988">r269988</a>.</p></li><li><p>An initial implementation of a "guard widening" pass has been committed. This will combine multiple guards to reduce the number of checks at runtime. <a href="http://reviews.llvm.org/rL269997">r269997</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>clang-include-fixer gained a basic Vim integration. <a href="http://reviews.llvm.org/rL269927">r269927</a>.</p></li><li><p>The intrinsics headers now have feature guards enabled in Microsoft mode to combat the compile-time regression discussed last week due to their increased size. <a href="http://reviews.llvm.org/rL269675">r269675</a>.</p></li><li><p>avxintrin.h gained many new Doxygen comments. <a href="http://reviews.llvm.org/rL269718">r269718</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lld now lets you specify a subset of passes to run in LTO. <a href="http://reviews.llvm.org/rL269605">r269605</a>.</p></li><li><p>LLDB has replaced uses of its own Mutex class with <code>std::mutex</code>. <a href="http://reviews.llvm.org/rL269877">r269877</a>, <a href="http://reviews.llvm.org/rL270024">r270024</a>.</p></li></ul>
- LLVM Weekly - #124, May 16th 2016https://blog.llvm.org/2016/05/llvm-weekly-124-may-16th-2016.htmlMon, 16 May 2016 04:26:00 +0000https://blog.llvm.org/2016/05/llvm-weekly-124-may-16th-2016.html<p>Welcome to the one hundred and twenty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/124">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The main news this week is the announcement of <a href="http://www.scala-native.org/">Scala-native</a>, an ahead-of-time compiler for Scala using LLVM. Jos Dirkens has written a <a href="http://www.smartjava.org/content/getting-started-scala-native">getting started guide</a> if you want to compile it and try it out. There's also more information in the <a href="https://github.com/densh/talks/blob/master/2016-05-11-scala-goes-native.pdf">slides from the announcement talk</a>.</p><h3>On the mailing lists</h3><ul><li><p>More of the students taking part in Google Summer of Code with LLVM-related projects have introduced themselves and their plans. Vivek Pandya will be working on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099492.html">interprocedural register allocation</a>. Scott Egerton will be working on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099704.html">capture tracking improvements</a>. Jie Chen will be working on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099573.html">better alias analysis, specifically improving cfl-aa</a>. Matthias Reisinger will be working on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099471.html">enabling polyhedral optimisations in Julia</a>, and Zhengyan Liu has plans for <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099600.html">SAFECode memory hardening</a>.</p></li><li><p>Renato Golin kicked off a discussion about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099541.html">whether LLVM's release process could be better aligned with downstream users</a>. This thread covered a broad range of topics and triggered a lot of discussion, but luckily there's no need to summarise it as Renato has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099706.html">done the job for us</a>.</p></li><li><p>Nicolai Hähnle notes that currently libLLVM.so <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099398.html">contains about 1.7MB in its .data.rel.ro section</a>, of which about 1.3MB comes from the MCInstrDesc tables created by tablegen representing a massive number of pointers to be relocated. He suggests reducing this by using offsets instead. Reducing the relocations will both reduce binary size and increase the portion of the binary that can be mapped as shared. So far, responses to the thread are supportive of the idea.</p></li><li><p>James Knight has written a detailed post on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099490.html">how it's not really possible to write an LL/SC loop guaranteed to make forward progress in LLVM IR right now</a>. There are restrictions on what you can do between a load-linked and a store-conditional instruction that the code generator may not meet.</p></li><li><p>A public <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-foundation">llvm-foundation</a> mailing list has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099574.html">announced</a>, which to facilitate discussions related to the Foundation.</p></li><li><p>As well as the long, technically detailed and precise threads each week it's nice to highlight cases where a simple question has a simple answer. How do you register a pass as being opt-in based on a command-line flag? <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099470.html">Answer</a>: have it run every time, but return immediately if the desired command line flag isn't present.</p></li><li><p>Sanjoy Das has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099693.html">adding a callee-saved register verifier</a>. As is clarified later in the thread, the intention is to ensure that code not generated by LLVM (e.g. output from another JIT or hand-written assembly) properly adheres to the calling convention and doesn't clobber registers it shouldn't. The proposed pass would simply add code to check that the test values written to the callee-saved registers aren't modified.</p></li><li><p>In response to questions about pass ordering, Mehdi Amini has written a helpful description of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099477.html">what exactly happens when you do opt -mymodulepass0 -myfunctionpass -mymodulepass1</a>.</p></li><li><p>Konstantin Vladimirov wonders <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099494.html">if there's an option to force the register allocator to use as many architectural registers as possible to reduce dependencies</a>. The short answer is there isn't currently, but it would be interesting to investigate.</p></li><li><p>Diana Picus has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099594.html">modifying llc so it no longer exits after the first error</a>. Generally people are in favour, and the patch should hopefully land soon (it had to be temporarily backed out after exposing some test cases failures in lldb).</p></li><li><p>Nico Weber has noted that now with AVX512, <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-May/048837.html">Clang's intrinsics headers are huge</a>. This can cause compile time issues, for instance Nico reports building all of the v8 JS engine is 6% faster after removing the avx512 includes. The thread participants haven't yet decided on the best way forward to fix this, beyond the potential immediate step of adding include guards so AVX512 intrinsic headers aren't included when not compiling for AVX512 platforms.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The outdated guide on cross-compiling LLVM has been brought up to date. <a href="http://reviews.llvm.org/rL269054">r269054</a>.</p></li><li><p>The WebAssembly backend gained preliminary fast instruction selection (fast-isel) support. <a href="http://reviews.llvm.org/rL269083">r269083</a>, <a href="http://reviews.llvm.org/rL269203">r269203</a>, <a href="http://reviews.llvm.org/rL269273">r269273</a>.</p></li><li><p>Loop unrolling (other than in the case of explicit pragmas) is now disabled at <code>-Os</code> in LLVM. You may recall last week it was enabled for <code>-Os</code> in Clang, but with different thresholds. <a href="http://reviews.llvm.org/rL269124">r269124</a>.</p></li><li><p>A new cost-tracking system has been implemented for the loop unroller. <a href="http://reviews.llvm.org/rL269388">r269388</a>.</p></li><li><p>LLVM's Sparc backend has seen the addition of more LEON-specific features, e.g. signed and unsigned multiply-accumulate. <a href="http://reviews.llvm.org/rL268908">r268908</a>.</p></li><li><p>llc's <code>-run-pass</code> option will now work with any pass known to the pass registry. Previously it would silently do nothing if you specify indirectly added analysis passes or passes not present in the optimisation pipeline. <a href="http://reviews.llvm.org/rL269003">r269003</a>.</p></li><li><p>WebAssembly register stackification and coloring are now run very late in the optimisation pipeline. The commit message suggests it's useful to think of these passes as domain-specific liveness-based compression rather than a conventional optimisation. <a href="http://reviews.llvm.org/rL269012">r269012</a>.</p></li><li><p>When declaring global in textual LLVM IR, you must now assign them with e.g. <code>@0 = global i32 42</code>. <a href="http://reviews.llvm.org/rL269096">r269096</a>.</p></li><li><p>The internal assembler is now enabled by default for 32-bit MIPS targets. <a href="http://reviews.llvm.org/rL269560">r269560</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang now supports <code>__float128</code>. <a href="http://reviews.llvm.org/rL268898">r268898</a>.</p></li><li><p>Clang gained a new warning that triggers when casting away calling conventions from a function. <a href="http://reviews.llvm.org/rL269116">r269116</a>.</p></li><li><p>The recently developed include-fixer tools now has documentation. <a href="http://reviews.llvm.org/rL269167">r269167</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>compiler-rt's CMake build system can now build builtins without a full toolchain, allowing you to bootstrap a cross-compiler. <a href="http://reviews.llvm.org/rL268977">r268977</a>.</p></li><li><p>LLD will now sort relocations to optimise dynamic linker performance. <a href="http://reviews.llvm.org/rL269066">r269066</a>.</p></li></ul>
- LLVM Weekly - #123, May 9th 2016https://blog.llvm.org/2016/05/llvm-weekly-123-may-9th-2016.htmlMon, 09 May 2016 01:28:00 +0000https://blog.llvm.org/2016/05/llvm-weekly-123-may-9th-2016.html<p>Welcome to the one hundred and twenty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>If you're in London tomorrow you may be interested in the <a href="http://oshug.org/event/nmiopen">NMI Open Source Conference</a>. You can register until midday today. I'll be giving a brief talk on <a href="http://www.lowrisc.org/">lowRISC</a>. While on the subject of conferences, if you are interested in diversity and inclusion in computing education, you may want to check out the <a href="http://casinclude.org.uk/events/diversity-conference-2016/">CAS #include diversity conference</a> in Manchester on the 11th June.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/123">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>Fabien Giesen has written a brief article explaining <a href="https://gist.github.com/rygorous/e0f055bfb74e3d5f0af20690759de5a7">why compilers exploit undefined signed overflow</a>.</p><p>The Google Open Source blog has a <a href="http://google-opensource.blogspot.co.uk/2016/05/xray-function-call-tracing-system.html">short piece</a> on the XRay function call tracing system that was proposed for upstreaming last week on the LLVM mailing list.</p><h3>On the mailing lists</h3><ul><li><p>By far the most active thread on the mailing list this week was the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099120.html">resumption of discussion on adding an LLVM Code of Conduct</a>. The draft text can be found <a href="http://reviews.llvm.org/D13741">here</a>. As well as a number of messages offering a "+1" to the current text, concerns were raised by some about the implications of "violations of this code outside these spaces may affect a person's ability to participate within them", and about how the committee enforcing the CoC will be selected.</p></li><li><p>Amos Robinson wrote to the mailing list with <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099034.html">an optimisation missed by LLVM's current Global Value Numbering pass</a>. Rather excitingly, Daniel Berlin <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099035.html">reports</a> he's working on a <a href="https://github.com/dberlin/llvm-gvn-rewrite/branches">new GVN implementation</a>.</p></li><li><p>Chandler Carruth has written an update on the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099121.html">state of work to move to the new pass manager</a>. He notes the major missing piece at the moment is the ability to communicate invalidation information between two parts of the pass manager.</p></li><li><p>Jonas Hahnfield has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/098980.html">automatically generating non-temporal loads and stores</a>. Some respondents are very strongly against this, suggesting it's something better left for the programmer to specify.</p></li><li><p>Some of the students taking part in Google Summer of Code this year with LLVM-related projects have been introducing themselves on the mailing list. Utpal Bora will be working on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099373.html">implementing Polly as an analysis pass in LLVM</a>. Bianca-Cristina Cristescu will be working in <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-May/048671.html">enabling LLVM's self-hosted modules builds using libstdc++</a>, and Roman Gareev will be <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/098943.html">improving the vectorisation process in Polly</a>.</p></li><li><p>Chris Bieneman notes he recently introduced a new option in LLVM's CMake buildsystem that may be of particular interest to package maintainers. <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/098993.html">LLVM_DISTRIBUTION_COMPONENTS</a> allows you to specify which components of LLVM you want to install.</p></li><li><p>Peter Collingbourne has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099095.html">extending ThinLTO to allow a bitcode module to embed another bitcode module containing summary information for CFI and whole-program devirtualisation</a>.</p></li><li><p>Adam Nemet is interested in feedback on the idea of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099082.html">filtering optimisation remarks by the hotness of the code region</a>.</p></li><li><p>Justin Bogner has given a heads-up to out-of-tree backend maintainers that he <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/099216.html">intends to change the API of SelectionDAGISel::Select</a> so the function directly replaces nodes rather than returning the desired replacement.</p></li><li><p>Quentin Colombet has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-May/098952.html">how LLVM contributors can better help release management</a>. There's a lot of support for this direction, with most comments discussing ways of better tagging commit messages (post-commit in phabricator/bugzilla, or through getting committers to write commit messages in a certain format).</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM's CppBackend has been removed. As the commit message says, this backend has bit-rotted to the extent that it's not useful for its original purpose and doesn't generate code that compiles. <a href="http://reviews.llvm.org/rL268631">r268631</a>.</p></li><li><p>The AVR backend has seen a large amount of code merged in to LLVM. <a href="http://reviews.llvm.org/rL268722">r268722</a>.</p></li><li><p>The MIPS backend has seen some large changes to how relocations are handled. These are now represented using MipsMCExpr instead of MCSymbolRefExpr. As someone who has done quite a lot of (out-of-tree) LLVM backend work, I've always found it odd how some architectures have globally visible enum members in include/llvm/MC/MCExpr.h. <a href="http://reviews.llvm.org/rL268379">r268379</a>.</p></li><li><p>LLVM builds should hopefully now be deterministic by default, as <code>LLVM_ENABLE_TIMESTAMPS</code> is now opt-in rather than opt-out. In fact, a follow-up patch removed the option altogether. <a href="http://reviews.llvm.org/rL268441">r268441</a>, <a href="http://reviews.llvm.org/rL268670">r268670</a>.</p></li><li><p>The AARch64 backend learned to combine adjustments to the stack pointer for callee-save stack memory and local stack memory. <a href="http://reviews.llvm.org/rL268746">r268746</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang now supports <code>-malign-double</code> for x86. This matches the default behaviour on x86-64, where i64 and f64 types are aligned to 8-bytes instead of 4. <a href="http://reviews.llvm.org/rL268473">r268473</a>.</p></li><li><p>Loop unrolling is no longer completely disabled for <code>-Os</code>. <a href="http://reviews.llvm.org/rL268509">r268509</a>.</p></li><li><p>Clang's release notes (reflecting the state of current trunk) have been updated to say more about the state of C++1z support. <a href="http://reviews.llvm.org/rL268663">r268663</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx will now build a libc++experimental.a static library to hold symbols from the experimental C++ Technical Specifications (e.g. filesystem). This library provides no ABI compatibility. <a href="http://reviews.llvm.org/rL268443">r268443</a>, <a href="http://reviews.llvm.org/rL268456">r268456</a>.</p></li><li><p>All usage of pthreads in libcxx has been refactored in to the <code>__threading_support</code> header, with the intention of making it easier to retarget libcxx to platform that don't support pthreads. <a href="http://reviews.llvm.org/rL268374">r268374</a>.</p></li><li><p>libcxx gained support for the <a href="https://isocpp.org/files/papers/N3916.pdf">polymorphic memory resources</a> C++ TS. <a href="http://reviews.llvm.org/rL268829">r268829</a>.</p></li></ul>
- LLVM Weekly - #122, May 2nd 2016https://blog.llvm.org/2016/05/llvm-weekly-122-may-2nd-2016.htmlMon, 02 May 2016 08:31:00 +0000https://blog.llvm.org/2016/05/llvm-weekly-122-may-2nd-2016.html<p>Welcome to the one hundred and twenty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/122">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>GCC 6.1 <a href="https://gcc.gnu.org/ml/gcc-announce/2016/msg00000.html">has been released</a>. Perhaps the most apparent user-visible change is that the C++ frontend now defaults to C++14.</p><p>The Rust compiler has <a href="http://blog.rust-lang.org/2016/04/19/MIR.html">introduced a new intermediate representation</a>, MIR, used for optimisations prior to lowering to LLVM IR.</p><p>Tanya Lattner has <a href="http://blog.llvm.org/2016/04/llvm-foundation-2016-announcements.html">written about the LLVM Foundation's plans for 2016</a>. The LLVM Foundation has established 3 main programs: Educational Outreach, Grants and Scholarships, and Women in Compilers and Tools.</p><h3>On the mailing lists</h3><ul><li><p>Dean Michael Berris has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098901.html">RFC on upstraming Google's 'XRay' function call tracing system</a>. For more information, you can read <a href="https://storage.googleapis.com/xray-downloads/whitepaper/XRayAFunctionCallTracingSystem.pdf">the XRay whitepaper</a>.</p></li><li><p>Sanjoy Das has suggested <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098853.html">generalising the AssumptionCache to AxiomAche</a>. He proposes maintaining separate lists of guards and assumptions within the AxiomCache.</p></li><li><p>There's been some more activity in response to Phil Tomson's question about instruction scheduling. Christof Douma followed up <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098763.html">with some advice</a>.</p></li><li><p>Chris Bieneman has suggested <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098780.html">raising the CMake minimum version to 3.4.3</a>. Renato Golin <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098811.html">flagged up some concerns</a>, with Chandler Carruth <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098814.html">offering a counterpoint</a>.</p></li><li><p>Discussion has continued on the proposal to introduce a new LLVM sub-project for parallelism runtime and support libraries. This is probably best summarised by reading <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098734.html">Hal Finkel's thoughts on the way forward</a>, <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098820.html">C Bergström's concerns</a>, and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098822.html">Jason Henline's proposed charter for the subproject</a>.</p></li><li><p>Peter Collingbourne has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html">RFC on redesigning the LLD symbol table</a> in order to improve memory locality.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM now supports indirect call promotion based on value-profile information. This will promote indirect calls to a direct call guarded by a precondition. <a href="http://reviews.llvm.org/rL267815">r267815</a>.</p></li><li><p>The LLVM documentation has been extended with a CMake primer covering the basics of the CMake scripting language. <a href="http://reviews.llvm.org/rL268906">r268096</a>.</p></li><li><p>The PDB dumper has been refactored into a library. <a href="http://reviews.llvm.org/rL267431">r267431</a>.</p></li><li><p>The MinLatency attributed has been removed from SchedMachineModel. <a href="http://reviews.llvm.org/rL267502">r267502</a>.</p></li><li><p>CodeGenPrepare will now use branch weight metadata to decide if a select should be turned into a branch. <a href="http://reviews.llvm.org/rL267572">r267572</a>.</p></li><li><p>Support for <code>llvm.loop.distribute.enable</code> metadata was added. This indicates a loop should be split in to multiple loops. <a href="http://reviews.llvm.org/rL267672">r267672</a>.</p></li><li><p>The SystemZ backend now supports the Swift calling convention. <a href="http://reviews.llvm.org/rL267823">r267823</a>.</p></li><li><p>libFuzzer's documentation has been expanded and improved. <a href="http://reviews.llvm.org/rL267892">r267892</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>clang-tidy gained a new checker for redundant expressions on both sides of a binary operator. <a href="http://reviews.llvm.org/rL267574">r267574</a>.</p></li><li><p>A new clang-tidy check will warn for use of functions like <code>atoi</code> and <code>atol</code> that don't report conversion errors. <a href="http://reviews.llvm.org/rL268100">r268100</a>.</p></li><li><p>The <code>nodebug</code> attribute on a global or static variable will now suppress all debug info for that variable. <a href="http://reviews.llvm.org/rL267746">r267746</a>.</p></li><li><p>A number of OpenMP features gained codegen support, such as the map clause and target data directive. <a href="http://reviews.llvm.org/rL267808">r267808</a>, <a href="http://reviews.llvm.org/rL267811">r267811</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLD now supports an <code>-O0</code> option to produce output as quickly as possible. Currently this disables section merging at the cost of a potentially much larger output. <a href="http://reviews.llvm.org/rL268056">r268056</a>.</p></li><li><p>The symbol table in LLD's ELF linker has been redesigned with the intent of improving memory locality. The new design produces measurable speedups for the binaries tested in the commit message. <a href="http://reviews.llvm.org/rL268178">r268178</a>.</p></li><li><p>LLD's linkerscript support expanded to encompass comparison operators. <a href="http://reviews.llvm.org/rL267832">r267832</a>.</p></li><li><p>LLD performance on large executables has been improved by skipping scanRelocs on sections that are never mapped to memory at runtime (e.g. debug sections). <a href="http://reviews.llvm.org/rL267917">r267917</a>.</p></li></ul>
- LLVM Foundation 2016 Announcementshttps://blog.llvm.org/2016/04/llvm-foundation-2016-announcements.htmlWed, 27 Apr 2016 08:48:00 +0000https://blog.llvm.org/2016/04/llvm-foundation-2016-announcements.html<div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">With 2016 upon us, the <a href="http://llvm.org/foundation">LLVM Foundation</a> would like to announce our plans for the year. If you are not familiar with the LLVM Foundation, we are a 501(c)(3) nonprofit that supports the LLVM Project and its community. We are best known for our LLVM Developersâ Meetings, but we are introducing several new programs this year. </div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">The LLVM Foundation originally grew out of the need to have a legal entity to plan and support the annual LLVM Developersâ Meeting and LLVM infrastructure. However, as the Foundation was created we saw a need for help in other areas related to the LLVM project, compilers, and tools. The LLVM Foundation has established 3 main programs: Educational Outreach, Grants & Scholarships, and Women in Compilers & Tools.</div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;"><b>Educational Outreach </b></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">The LLVM Foundation plans to expand its educational materials and events related to the LLVM Project and compiler technology and tools. </div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">First, the LLVM Foundation is excited to announce the 2016 Bay Area LLVM Developersâ Meeting will be held November 3-4 in San Jose, CA. This year will be the 10th anniversary of the developer meeting which brings together developers of LLVM, Clang, and related projects. For this yearâs meeting, we are increasing our registration cap to 400 in order to allow more community members to attend.</div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">We also are investigating how we can support or be involved in other conferences in the field of compilers and tools. This may include things such as LLVM workshops or tutorials by sponsoring presenters, or providing instructional materials. We plan to work with other conference organizers to determine how the LLVM Foundation can be helpful and develop a plan going forward.</div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">However, we want to do more for the community and have brainstormed some ideas for the coming year. We plan to create some instructional videos for those just beginning with LLVM. These will be short 5-10 minute videos that introduce developers to the project and get them started. Documentation is always important, but we find that many are turning to videos as a way to learn. </div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;"><b>Grants & Scholarships</b></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">We are creating a grants and scholarships program to cover student presenter travel expenses to the LLVM Developersâ Meetings. However, we also hope to expand this program to include student presenter travel to other conferences where the student is presenting their LLVM related work. Details on this program will be published once they have been finalized. </div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;"><b>Women in Compilers & Tools</b></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">Grace Hopper invented the first compiler and yet women are severely underrepresented in the field of compilers and tools. At the 2015 Bay Area LLVM Developersâ Meeting, we held a BoF on this topic and brainstormed ideas about what can be done. One idea was to increase LLVM awareness at technical conferences that have strong female participation. One such conference is the Grace Hopper Conference (GHC). The LLVM Foundation has submitted a proposal to present about LLVM and how to get involved with the LLVM open source community. We hope our submission is accepted, but if not, we are exploring other ways we can increase our visibility at GHC. Many of the other ideas from this BoF are being considered and actionable plans are in progress.</div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /><b></b></div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">In addition, to these 3 programs, we will continue to support the LLVM Projectâs infrastructure. The <a href="http://llvm.org/">llvm.org</a> server will move to a new machine to increase performance and reliability. </div><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px; min-height: 13px;"><br /></div><br /><div style="-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Helvetica; font-size: 11px;">We hope that you are excited about the work the LLVM Foundation will be doing in 2016. Our 2016 Plans & Budget may be viewed <a href="http://llvm.org/foundation/documents/other/2016-LLVMFoundation-Outlook-Budget.pdf">here</a>. You may also contact our COO & President, Tanya Lattner (<a href="mailto:[email protected]">[email protected]</a>) or the LLVM Foundation Board of Directors (<a href="mailto:[email protected]">[email protected]</a>).</div><div><br /></div>
- LLVM Weekly - #121, Apr 25th 2016https://blog.llvm.org/2016/04/llvm-weekly-121-apr-25th-2016.htmlMon, 25 Apr 2016 04:20:00 +0000https://blog.llvm.org/2016/04/llvm-weekly-121-apr-25th-2016.html<p>Welcome to the one hundred and twenty-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/121">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Congratulations to the eight students who have <a href="https://summerofcode.withgoogle.com/organizations/5450930363301888/#projects">been selected for LLVM projects on Google Summer of Code this year</a>. There's about a month before they start coding. The time between now and then is the 'community bonding period', so please do make them feel welcome.</p><p>The preliminary release schedule for LLVM/Clang 3.8.1 has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098637.html">been published</a>. This would have a deadline of May 25th for requesting changes to be merged and would see the final release on June 15th.</p><h3>On the mailing lists</h3><ul><li><p>A series of RFCs have been posted around the idea of <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098355.html">adding an EfficiencySanitizer tool</a>. Like the existing sanitizer tools, this would rely on compiler-based dynamic instrumentation in order to detect problems in user code. The goal is to collect userful information with overhead less than 5x, ideally closer to 3x. Separate threads have been started to discuss an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098658.html">EfficiencySanitizer cache fragmentation tool</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098491.html">a working set tool</a>.</p></li><li><p>Sanjoy Patel has proposed <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098642.html">removing the llvm.expect intrinsic</a>, in favour of using metadata to represent the same information. There isn't currently <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098657.html">full agreement on this</a>.</p></li><li><p>Richard Trieu is seeking feedback on <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-April/048508.html">which floating point to boolean conversions should trigger warnings</a>.</p></li><li><p>How do you add fixup information to a MachineInstruction? Tim Northover <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098511.html">has the answer</a>.</p></li><li><p>Elena Lepilkina has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098372.html">RFC on adding support for custom metrics and test parameterisation to LNT</a>. The feedback so far seems positive.</p></li><li><p>Phil Tomson is looking for <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098535.html">advice on instruction scheduling in LLVM</a>. As he notes in his email, it's part of LLVM that's seen a lot of changes over the past 8 years or so. I'm certainly interested in the answer here.</p></li></ul><h3>LLVM commits</h3><ul><li><p>An implementation of optimisation bisection support has landed. This helps to track down bugs by allowing optimisations to be selectively disabled at compile-time to identify the one introducing a miscompile. <a href="http://reviews.llvm.org/rL267022">r267022</a>.</p></li><li><p>The AArch64 and ARM thread pointer intrinsics have been merged to make a target-independent <code>llvm.thread.pointer</code> intrinsic. <a href="http://reviews.llvm.org/rL266818">r266818</a>.</p></li><li><p>The llvm.load.relative intrinsic has been added. <a href="http://reviews.llvm.org/rL267233">r267233</a>.</p></li><li><p>There have been more changes to DebugInfo which will require a bitcode upgrade. A script to perform this upgrade is linked in the commit message. <a href="http://reviews.llvm.org/rL267296">r27296</a>.</p></li><li><p>The ORC JIT API improved its support for RPC, including support for calling functions with return values. <a href="http://reviews.llvm.org/rL266581">r266581</a>.</p></li><li><p>The patchable-function function attribution has been introduced, indicating that the function should be easily patchable at runtime. <a href="http://reviews.llvm.org/rL266715">r266715</a>.</p></li><li><p>The IntrReadArgMem intrinsic property has been split in to IntrReadMem and IntrArgMemOnly. <a href="http://reviews.llvm.org/rL267021">r267021</a>.</p></li><li><p>The MachineCombiner gained the ability to combine AArch64 fmul and fadd in to an fmadd. <a href="http://reviews.llvm.org/rL267328">r267328</a>.</p></li><li><p>Scheduling itineraries were added for Sparc, specifically for the LEON processors. <a href="http://reviews.llvm.org/rL267121">r267121</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A prototype of an include fixing tool was created. The indexer remains to be written. <a href="http://reviews.llvm.org/rL266870">r266870</a>.</p></li><li><p>A new warning has been added, which will trigger if the compiler tries to make an implicit instantiation of a template but cannot find the template definition. <a href="http://reviews.llvm.org/rL266719">r266719</a>.</p></li><li><p>Initial driver flags for EfficiencySanitizer were added. <a href="http://reviews.llvm.org/rL267059">r267059</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The initial EfficiencySanitizer base runtime library was added to compiler-rt. It doesn't do much of anything yet. <a href="http://reviews.llvm.org/rL267060">r267060</a>.</p></li><li><p>LLD learned to support the linkerscript ALIGN command. <a href="http://reviews.llvm.org/rL267145">r267145</a>.</p></li><li><p>LLDB can now parse EABI attributes for an ELF input. <a href="http://reviews.llvm.org/rL267291">r267291</a>.</p></li></ul>
- LLVM Weekly - #120, Apr 18th 2016https://blog.llvm.org/2016/04/llvm-weekly-120-apr-18th-2016.htmlMon, 18 Apr 2016 06:05:00 +0000https://blog.llvm.org/2016/04/llvm-weekly-120-apr-18th-2016.html<p>Welcome to the one hundred and twentieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/120">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>This week has seen not one, but two articles about LLVM and profile-guided optimisation. Dig in John Engelen's article about <a href="https://johanengelen.github.io/ldc/2016/04/13/PGO-in-LDC-virtual-calls.html">optimising D's virtual function calls with PGO</a>, then read Geoffroy Couprie's article about <a href="https://unhandledexpression.com/2016/04/14/using-llvm-pgo-in-rust/">PGO with Rust</a>.</p><p>The next Cambridge (UK) social <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098248.html">will be at 7.30pm on April 20th</a>, at the Cambridge Blue.</p><p>Alex Denisov has written a blog post <a href="http://lowlevelbits.org/llvm-based-mutation-testing-system/">around the idea of building a mutation testing system using LLVM</a>.</p><h3>On the mailing lists</h3><ul><li><p>James Knight is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098218.html">requesting a way to test changes before committing them</a>. Renato Golin had a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098219.html">thorough response</a>.</p></li><li><p>Eric Fiselier has shared an <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-April/048411.html">RFC on packaging the proposed libc++ filesystem library</a>.</p></li><li><p>Teresa Johnson has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098272.html">RFC on the ThinLTO distributed backend interface</a>.</p></li><li><p>Jeroen Dobbelaere is wondering if there's <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098303.html">any interest in an LLVM social in Leuven, Belgium</a>.</p></li><li><p>Mingwha Wang asks if there's any support for <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098227.html">outlining in LLVM</a>. You'll want to <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098229.html">look at CodeExtractor</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>AtomicExpandPass learned to lower various atomic operations to <code>__atomic_*</code> library calls. The eventual aim is to move all atomic lowering from Clang to LLVM. <a href="http://reviews.llvm.org/rL266115">r266115</a>.</p></li><li><p>Targets can now define an inlining threshold multiplier, to e.g. increase the likelihood of inlining on platforms where calls are very expensive. <a href="http://reviews.llvm.org/rL266405">r266405</a>.</p></li><li><p>The ownership between DICompileUnit and DISubprogram has been reversed. This may break tests for your out-of-tree backend, but the commit has a link to a Python script to update your testcases. <a href="http://reviews.llvm.org/rL266446">r266446</a>.</p></li><li><p>llvm-readobj learned to print a histogram of an input ELF file's .gnu.hash . <a href="http://reviews.llvm.org/rL265967">r265967</a>.</p></li><li><p>More target-specific support for the Swift calling convention (on ARM, AARch64, and X86) has landed. Also, a callee save register is used for the swiftself parameter. <a href="http://reviews.llvm.org/rL265997">r265997</a>, <a href="http://reviews.llvm.org/rL266251">r266251</a>.</p></li><li><p>A new <code>allocsize</code> attribute has been introduced. This indicates the given function is an allocation function. <a href="http://reviews.llvm.org/rL266032">r266032</a>.</p></li><li><p>analyzeSiblingValues has been replaced with a new lower-complexity implementation in order to reduce compile times. <a href="http://reviews.llvm.org/rL266162">r266162</a>.</p></li><li><p>The AMDGPU backend gained a skeleton GlobalISel implementation. <a href="http://reviews.llvm.org/rL266356">r266356</a>.</p></li><li><p>Every use of getGlobalContext other than the C API has been removed. <a href="http://reviews.llvm.org/rL266379">r266379</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained support for the GCC ifunc attribute. <a href="http://reviews.llvm.org/rL265917">r265917</a>.</p></li><li><p>The <code>__unaligned</code> type qualifier was implemented for MSVC compatibility. <a href="http://reviews.llvm.org/rL266415">r266415</a>.</p></li><li><p>Support for C++ core guideline Type.6: always initialize a member variable was completed in clang-tidy. <a href="http://reviews.llvm.org/rL266191">r266191</a>.</p></li><li><p>A new clang-tidy checker for suspicious sizeof expressions was added. <a href="http://reviews.llvm.org/rL266451">r266451</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The way relocations are applied in the new ELF linker has been reworked. <a href="http://reviews.llvm.org/rL266158">r266158</a>.</p></li><li><p>ELF LLD now supports parallel codegen for LTO using splitCodeGen. <a href="http://reviews.llvm.org/rL266484">r266484</a>.</p></li><li><p>Support for Linux on SystemZ in LLDB landed. <a href="http://reviews.llvm.org/rL266308">r266308</a>.</p></li></ul>
- LLVM Weekly - #119, Apr 11th 2016https://blog.llvm.org/2016/04/llvm-weekly-119-apr-11th-2016.htmlMon, 11 Apr 2016 06:03:00 +0000https://blog.llvm.org/2016/04/llvm-weekly-119-apr-11th-2016.html<p>Welcome to the one hundred and nineteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/119">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Last week the slides from the <a href="http://llvm.org/devmtg/2016-03/">recent EuroLLVM 2016 Developers' Meeting</a> made it online. This week this has been followed by <a href="https://www.youtube.com/playlist?list=PL_R5A0lGi1ADuZKWUJOVOgXr2dRW06e55">videos of the talks from the conference</a>.</p><p>John Regehr has written about <a href="http://blog.regehr.org/archives/1384">efficient integer overflow checking in LLVM</a>, looking at cases where LLVM can and cannot remove unnecessary overflow checks, and how this might be improved.</p><p>Version 0.13 of Pocl, the portable OpenCL implementation <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/097953.html">has been released</a>. This release works with LLVM/Clang 3.8 and 3.7, and adds initial OpenCL 2.0 support and improved HSA support.</p><p>Serge Guelton at QuarksLab has written up a really useful guide to <a href="http://blog.quarkslab.com/implementing-a-custom-directive-handler-in-clang.html">implementing a custom directive handler in Clang</a>.</p><p>Microsoft's Visual C++ team are <a href="https://blogs.msdn.microsoft.com/vcblog/2016/04/06/clangc2-we-need-your-advice/">looking for feedback on Clang/C2</a> (Clang with Microsoft CodeGen).</p><h3>On the mailing lists</h3><ul><li><p>James Molloy has posted an RFC on adding support for <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/097936.html">constant folding calls to math.h functions on long doubles</a>. Currently these functions aren't constant-folded as the internal APFloat class doesn't implement them and long double operations aren't portable. Solutions include adding support to APFloat, linking against libMPFR to provide compile-time evaluation, or recognising when the long double format of the host and target are the same, so the host math library can be called. From the responses so far, there seems to be some push-back on adding the libMPFR dependency.</p></li><li><p>Sanjoy Das has an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098034.html">adding a patchable-prologue attribute</a>. This would be used to indicate that the function's prologue is compiled so as to provide support for easy hot-patching.</p></li><li><p>Ulrich Weigand has shared a patch for <a href="http://lists.llvm.org/pipermail/lldb-dev/2016-April/010067.html">supporting LLDB on Linux on SystemZ</a>. The patchset contains many big-endian fixes, and may be of interest to others looking at porting LLDB.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The Swift calling convention as well as support for the 'swifterror' argument has been added. <a href="http://reviews.llvm.org/rL265433">r265433</a>, <a href="http://reviews.llvm.org/rL265480">r265480</a>.</p></li><li><p>Work on GlobalISel continues with many commits related to the assignment of virtual registers to register banks. <a href="http://reviews.llvm.org/rL265445">r265445</a>, <a href="http://reviews.llvm.org/rL265440">r265440</a>.</p></li><li><p>LLVM will no longer perform inter-procedural optimisation over functions that can be "de-refined". <a href="http://reviews.llvm.org/rL265762">r265762</a>.</p></li><li><p>The substitutions supported by lit are now documented. <a href="http://reviews.llvm.org/rL265314">r265314</a>.</p></li><li><p>Unrolled loops now execute the remainder in an epilogue rather than the prologue. This should produce slightly improved code. <a href="http://reviews.llvm.org/rL265388">r265388</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained necessary support for the Swift calling convention. <a href="http://reviews.llvm.org/rL265324">r265324</a>.</p></li><li><p>New flags <code>-fno-jump-tables</code> and <code>-fjump-tables</code> can be used to disable/enable support for jump tables when lowering switch statements. <a href="http://reviews.llvm.org/rL265425">r265425</a>.</p></li><li><p>TargetOptions is now passed through all the TargetInfo constructors. This will allow target information to be modified based on the ABI selected. <a href="http://reviews.llvm.org/rL265640">r265640</a>.</p></li><li><p>A large number of intrinsics from emmintrin.h now have Doxygen docs. <a href="http://reviews.llvm.org/rL265844">r265844</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>clang-tidy gained a new check to flag initializers of globals that access extern objects, leading to potential order-of-initialization issues. <a href="http://reviews.llvm.org/rL265774">r265774</a>.</p></li><li><p>LLD's ELF linker gained new options <code>--start-lib</code>, <code>--end-lib</code>, <code>--no-gnu-unique</code>, <code>--strip-debug</code>. <a href="http://reviews.llvm.org/rL265710">r265710</a>, <a href="http://reviews.llvm.org/rL265717">r265717</a>, <a href="http://reviews.llvm.org/rL265722">r265722</a>.</p></li></ul>
- LLVM Weekly - #118, Apr 4th 2016https://blog.llvm.org/2016/04/llvm-weekly-118-apr-4th-2016.htmlMon, 04 Apr 2016 04:22:00 +0000https://blog.llvm.org/2016/04/llvm-weekly-118-apr-4th-2016.html<p>Welcome to the one hundred and eighteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/118">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Almost all slides from the recent EuroLLVM conference are <a href="http://llvm.org/devmtg/2016-03/">now available online</a> for your enjoyment.</p><p>Some readers my be interested in a new paper about the 'LifeJacket' tool for <a href="http://arxiv.org/abs/1603.09290">verifying precise floating-point optimisations in LLVM</a>.</p><p>Christian Neumüller has written a <a href="https://github.com/oberon00/synth">new tool for syntax highlighting and cross-referencing C and C++ source</a> using libclang.</p><h3>On the mailing lists</h3><ul><li><p>Chandler Carruth suggests that just like commits that break codegen are immediately reverted, <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097849.html">commits that introduce large, especially super-linear compile time regressions should be reverted</a>. There's a lot of agreement in the general principle in replies, though some point out that much of the slowdown across the past few LLVM and Clang versions is due to a large number of small changes.</p></li><li><p>James Molloy is interested in discussing <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/097877.html">how LLVM could learn the size of a particular std::vector</a> and omit unnecessary checks etc.</p></li><li><p>Nick Johnson has a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097755.html">couple of questions about IfConversion in LLVM</a>. They haven't been answered yet, but I know I'd be interested in the answer.</p></li><li><p>Russell Wallace has kicked off a very useful thread about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097675.html">generating calls to existing functions from the JIT</a>.</p></li><li><p>Zachary Turner is interested in <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097756.html">people's feelings on requiring a minimum of MSVC 2015 to compile LLVM and Clang</a>. The general feeling so far is that it's too early for this, as typically the policy is to support the last two major MSVC releases.</p></li><li><p>Hans Wennborg has kindly highlighted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097844.html">recent API change to TargetFrameLowering::eliminateCallFramePseudoInstr</a> that will be of interest to maintainers of out-of-tree backends.</p></li><li><p>Matt Masten has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097862.html">vectorizing loops with calls to math functions using SVML</a> (Intel's short vector math library).</p></li><li><p>Eric Christopher has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097773.html">migrating debug type information generation from the backends to the frontend</a>.</p></li><li><p>Ke Bai's <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097355.html">memory scope proposal</a> hasn't really seen any responses up to now. Philip Reames does <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097726.html">share some feedback</a>, but notes it's unlikely this proposal could realistically be merged in to LLVM unless there is more interest. If this is an area that interests you, then please do have a good read of Ke's proposal.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The Lanai backend has landed. <a href="http://reviews.llvm.org/rL264578">r264578</a>.</p></li><li><p>A new <code>llvm.experimental.guard</code> intrinsic has been added. As described in the accompanying documentation, along with deoptimization operand bundles this allows frontends to express guards or checks on optimistic assumptions made during compilation. <a href="http://reviews.llvm.org/rL264976">r264976</a>.</p></li><li><p>Support for a number of new Altivec instructions has been added. Amazingly, this includes BCD (Binary Coded Decimal) instructions. <a href="http://reviews.llvm.org/rL264568">r264568</a>.</p></li><li><p>The concept of MachineFunctionProperties has been introduced, with the first property being AllVRegsAllocated. This allows passes to declare that they require a particular property, in this case requiring that they be run after regalloc. <a href="http://reviews.llvm.org/rL264593">r264593</a>.</p></li><li><p>On X86, push will now be used in preference to mov at all optimisation levels (before it was only enabled for <code>-Os</code>). <a href="http://reviews.llvm.org/rL264966">r264966</a>.</p></li><li><p>LLVM's support library can now compute SHA1 hashes. This is used to implement a 'build-id'. <a href="http://reviews.llvm.org/rL265094">r265094</a>, <a href="http://reviews.llvm.org/rL265095">r265095</a>.</p></li><li><p>When metadata is only referenced in a single function, it will now be emitted just in that function block. The aim of this is to improve the potential of lazy-loading. <a href="http://reviews.llvm.org/rL265226">r265226</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The Lanai backend is now supported in the Clang driver. <a href="http://reviews.llvm.org/rL264655">r264655</a>.</p></li><li><p>libTooling gained a handy formatAndApplyAllReplacements function. <a href="http://reviews.llvm.org/rL264745">r264745</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Parts of LLD are starting to use the new Error handling. <a href="http://reviews.llvm.org/rL264910">r264910</a>, <a href="http://reviews.llvm.org/rL264921">r264921</a>, <a href="http://reviews.llvm.org/rL264924">r264924</a>, and more.</p></li><li><p>Infrastructure was added to LLD for generating thunks (as required on platforms like MIPS when calling PIC code from non-PIC). <a href="http://reviews.llvm.org/rL265059">r265059</a>.</p></li></ul>
- My Little LLVM: Undefined Behavior is Magic!https://blog.llvm.org/2016/04/undefined-behavior-is-magic.htmlFri, 01 Apr 2016 00:00:00 +0000https://blog.llvm.org/2016/04/undefined-behavior-is-magic.html<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><div class="separator" style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-uilL1GOdl0E/WrVbVxsAxHI/AAAAAAAAAoU/oDi-ww1rx8I-xlHhmFHtUiLK_FgCUVajQCLcBGAs/s1600/DragonPony.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="961" data-original-width="1600" height="384" src="https://2.bp.blogspot.com/-uilL1GOdl0E/WrVbVxsAxHI/AAAAAAAAAoU/oDi-ww1rx8I-xlHhmFHtUiLK_FgCUVajQCLcBGAs/s640/DragonPony.png" width="640" /></a></div><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Thereâs been <a href="https://www.google.com/#q=%22undefined+behavior%22+%22should+just%22+OR+%22just+work%22+site:news.ycombinator.com">lots of discussion online</a> (<a href="http://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_2015_submission_29.pdf">and</a> <a href="https://gcc.gnu.org/ml/gcc/2016-02/msg00381.html">then</a> <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">quite</a> <a href="http://blog.regehr.org/archives/761">some</a> <a href="https://groups.google.com/forum/m/#!msg/boring-crypto/48qa1kWignU/o8GGp2K1DAAJ">more</a>) </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">about compilers abusing undefined behavior. As a response the LLVM compiler infrastructure is rebranding and adopting a motto to make undefined behavior friendlier and less prone to </span><a href="https://youtu.be/H6g15JroPow?t=1m32s" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">corruption</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The re-branding puts to rest a long-standing issue with LLVMâs âdragonâ logo </span><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"><a href="http://scifi.stackexchange.com/questions/34088/differences-between-dragon-drake-wyrm-and-wyvern" style="text-decoration: none;">actually being a wyvern</a></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> with an <a href="https://twitter.com/siracusa/status/659741883166547968" target="_blank">upside-down head</a>, a special form of undefined behavior in its own right. The logo is now </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">clearly</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> a pegasus pony.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Another great side-effect of this rebranding is increased security by auto-magically closing all vulnerabilities used by the hacker who goes by the pseudonym â</span><a href="https://www.google.com/search?q=pinkie%20pie%20hacker" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">Pinkie Pie</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">â.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">These new features are enabled with the </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">-rainbow</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> clang option, in honor of Rainbow Dashâs unary name.</span><br /><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br /><a name='more'></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><span style="font-family: "arial"; font-size: 21.333333333333332px; white-space: pre-wrap;">A Few Examples</span><br /><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">C++âs memory model specifies that data races are undefined behavior. It is well established that </span><a href="http://wg21.link/n4455" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">no sane compiler would optimize atomics</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, LLVM will therefore supplement the Standardâs </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">happens-before relationship</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> with an LLVM-specific </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">happens-to-work relationship</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. On most architectures this will be implemented with micro-pause primitives such as x86âs </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">rep rep rep nop</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> instruction.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Shifts by bit-width or larger will now return a normally-distributed random number. This also obsoletes </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">rand()</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">std::random_shuffle</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">bool</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> now obeys the rules of </span><a href="https://en.wikipedia.org/wiki/Truthiness" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">truthiness</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> to avoid that annoying âbut what if itâs </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">not</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> zero or one?â interview question. Further, incrementing a </span><span style="background-color: transparent; color: black; font-family: "courier new" , "courier" , monospace; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">bool</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> with </span><span style="background-color: transparent; color: black; font-family: "courier new" , "courier" , monospace; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">++</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> now does the right thing.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Atomic integer arithmetic is already specified to be twoâs complement. Regular arithmetic will therefore now also be atomic. Except when </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">volatile</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, but not when </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">volatile</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> atomic.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html#899" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">NaNs</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> will now compare equal, subnormals are free to self-classify as normal / zero / other, negative zero simply wonât be a thing, IEEE-754 has been upgraded to PONY-754, floats will still </span><a href="http://en.cppreference.com/w/cpp/types/numeric_limits/float_round_style" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">round with style</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, and generating a signaling NaN is now guaranteed to </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">not</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> be quiet by being equivalent to </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">putchar('\a')</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. While weâre at it none of </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">math.h</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> will set </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">errno</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> anymore. This has nothing to do with undefined behavior but seriously, </span><span style="background-color: transparent; color: black; font-size: 14.6667px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">errno</span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">?</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Type-punning isnât a thing anymore. Weâre renaming it to type-pony-ing, but it doesnât do anything surprising besides throw parties. </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">AND WHO DOESNâT LIKE PARTIESâ½ EVEN SECURITY PEOPLE DO!</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.6667px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> ð</span></div><b style="font-weight: normal;"><br /></b><br /><h2 dir="ltr" style="line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 21.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A Word From Our Sponsors</span></h2><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The sanitizersâespecially </span><a href="http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">undefined behavior sanitizer</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, </span><a href="http://clang.llvm.org/docs/AddressSanitizer.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">address sanitizer</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and </span><a href="http://clang.llvm.org/docs/ThreadSanitizer.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">thread sanitizer</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">âare great tools when dealing with undefined behavior. Use them on your tests, combine them with </span><a href="http://llvm.org/docs/LibFuzzer.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">fuzzers</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, try them as cupcake topping! Be warned: their runtimes arenât designed to be secure and you shouldnât ship them in production code!</span></div><b style="font-weight: normal;"><br /></b><br /><h2 dir="ltr" style="line-height: 1.38; margin-bottom: 6pt; margin-top: 18pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 21.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Cutie Marks</span></h2><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">To address the </span><a href="https://twitter.com/horse_clang" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">horse</span></a><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> in the room: weâve left the new LLVM logoâs cutie mark as </span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: italic; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">implementation-defined</span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Different instances of the logo can use their own cutie mark to illustrate their proclivities, but must clearly document them.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><i><span style="font-size: xx-small;">Posted by <a href="https://twitter.com/jfbastien">JF Bastien</a> and <a href="https://twitter.com/Bigcheesegs">Michael Spencer</a>.</span></i></span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: "arial"; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><i><span style="font-size: xx-small;"><br /></span></i></span></div>
- LLVM Weekly - #117, Mar 28th 2016https://blog.llvm.org/2016/03/llvm-weekly-117-mar-28th-2016.htmlMon, 28 Mar 2016 06:22:00 +0000https://blog.llvm.org/2016/03/llvm-weekly-117-mar-28th-2016.html<p>Welcome to the one hundred and seventeenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/117">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Google Summer of Code applications are now closed. Applicants and interested third-parties can look forward to finding out which projects were selected <a href="https://summerofcode.withgoogle.com/how-it-works/">on April 22nd</a>.</p><p>Ramkumar Ramachandra has written a blog post giving a <a href="http://artagnon.com/inside-a-register-allocator/">whirlwind tour of the internals of LLVM's fast register allocator</a> (FastRegAlloc.cpp).</p><p>Alex Denisov has blogged about <a href="http://lowlevelbits.org/system-under-test-llvm/">the various test suites used within the LLVM project</a>.</p><p>Version 1.13 of the TTA-based Co-design Environment (TCE) has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097139.html">been released</a>. This adds support for LLVM 3.8.</p><h3>On the mailing lists</h3><ul><li><p>Last week, Jia Chen's thread about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096851.html">pointer analysis in LLVM</a> had yet to receive replies. It's now received some extensive discussion. Daniel Berlin argues there is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097152.html">lower hanging fruit than improving AA</a>. It does seem there's <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097372.html">interest in getting in getting cfl-aa turned on by default</a>, which will require some careful bug fixing.</p></li><li><p>The issue of LLD and fatal errors has again surfaced on the mailing list. The more productive line of discussion focused around what should be expected of LLD when given maliciously corrupted inputs. Rui Ueyama is suggesting <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097445.html">adding a verifier pass</a> which could be optionally enabled or disabled.</p></li><li><p>Andrew Kaylor has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097617.html">RFC on adding new support to help triage optimisation-related failures</a>. Optimisation passes are assigned numbers which can be used to help bisect a failure. Michael Gottesman reports <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097637.html">a similar approach used in Swift</a>.</p></li><li><p>Samuel F Antao has <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-March/048087.html">summarised recent discussion on unified offloading support in Clang</a>.</p></li><li><p>Duncan P. N. Exon Smith has proposed an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097419.html">RFC on lazy-loading of debug info metadata</a>.</p></li><li><p>What does it mean for a platform to support a type but not support a particular operation? Krzysztof Parzyszek is kind enough to provide a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097489.html">clear and straight-forward answer</a>.</p></li><li><p>Applications for Google Summer of Code have closed, but the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/097380.html">list of new project ideas</a> from Philip Reames is a good starting point for anybody looking for a way to get stuck in to making impactful contributions to LLVM.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new utility, <code>update_test_checks.py</code> was added to update opt or llc test cases with new FileCheck patterns. <a href="http://reviews.llvm.org/rL264357">r264357</a>.</p></li><li><p>Non-power-of-2 loop unroll count pragmas are now supported. <a href="http://reviews.llvm.org/rL264407">r264407</a>.</p></li><li><p>The NVPTX backend gained a new address space inference pass. <a href="http://reviews.llvm.org/rL263916">r263916</a>.</p></li><li><p>Instances of Error are now convertible to <code>std::error_code</code>. Conversions are also available between <code>Expected<T></code> and <code>ErrorOr<T></code>. <a href="http://reviews.llvm.org/rL264221">r264221</a>, <a href="http://reviews.llvm.org/rL264238">r264238</a>.</p></li><li><p>Hexagon gained supported for run-time stack overflow checking. <a href="http://reviews.llvm.org/rL264328">r264328</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang now supports lambda capture of <code>*this</code> by value. <a href="http://reviews.llvm.org/rL263921">r263921</a>.</p></li><li><p>The bitreverse builtins are now documented. <a href="http://reviews.llvm.org/rL264203">r264203</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB will fix inputted expressions with 'trivial' mistakes automatically. <a href="http://reviews.llvm.org/rL264379">r264379</a>.</p></li><li><p>ThreadSanitizer debugging support was added to LLDB. <a href="http://reviews.llvm.org/rL264162">r264162</a>.</p></li><li><p>Polly gained documentation to describe how it fits in to the LLVM pass pipeline. <a href="http://reviews.llvm.org/rL264446">r264446</a>.</p></li><li><p>LLDB has been updated to handle the UTF-16 APIs on Windows. <a href="http://reviews.llvm.org/rL264074">r264074</a>.</p></li></ul>
- LLVM Weekly - #116, Mar 21st 2016https://blog.llvm.org/2016/03/llvm-weekly-116-mar-21st-2016.htmlMon, 21 Mar 2016 05:06:00 +0000https://blog.llvm.org/2016/03/llvm-weekly-116-mar-21st-2016.html<p>Welcome to the one hundred and sixteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/116">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>If you're a student and would like to get paid to work on an LLVM-related project over the summer then do consider <a href="https://summerofcode.withgoogle.com/organizations/5450930363301888/">applying for Google Summer of Code with LLVM</a>. More details about Summer of Code are available <a href="https://summerofcode.withgoogle.com/how-it-works/">here</a>. The deadline for applications is this Friday, March 25th at 1900 GMT. I'd also encourage you to look at <a href="http://www.lowrisc.org/docs/gsoc-2016-ideas/">lowRISC's project ideas</a> if you have an interest in open source hardware.</p><p>Stephen Kelly has written about his <a href="https://steveire.wordpress.com/2016/03/19/aaargh-aaa-right-good-and-hygenic/">new Clang-based tool for porting a C++ codebase to use almost-always-auto</a>. As was pointed out on Twitter, Ryan Stortz from Trail of Bits has a tools that removes auto and does <a href="https://github.com/trailofbits/clang-tidy-audit">roughly the opposite</a>.</p><p>Honza HubiÄka has written up his experiments of <a href="http://hubicka.blogspot.co.uk/2016/03/building-libreoffice-with-gcc-6-and-lto.html">building LibreOffice with GCC6 and LTO</a>. This includes a comparison to a build using LLVM and Clang.</p><p>Nick Clifton has shared an update for February and March <a href="https://gcc.gnu.org/ml/gcc/2016-03/msg00164.html">on the GNU toolchain</a> that may be of interest.</p><p>The developer of the Capstone disassembly framework and the Unicorn multi-architecture simulator is running a funding campaign for the <a href="http://www.keystone-engine.org/">Keystone multi-architecture assembler framework</a>. Like Capstone, this will build on LLVM but also <a href="http://www.keystone-engine.org/docs/beyond_llvm.html">aims to go beyond it</a>.</p><h3>On the mailing lists</h3><ul><li><p>Ehsan Amiri has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096901.html">RFC on a change in the InstCombine canonical form</a>. In the ensuing discussion, the question of the current state of the typeless pointer work was raised <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096928.html">and answered</a>.</p></li><li><p>Sean Silva has shared some <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096879.html">recent performance observations about LLD with --build-id</a>. Adding support for this option has added a measurable slowdown which should be considered when reviewing comparisons with other linkers from before it was added.</p></li><li><p>I normally prefer to link to mailing list threads where there has already been some discussion or attempts at answers, but I think this one is worth some more eyeballs. Jia Chen is interested in <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096851.html">the tradeoffs in LLVM using more sophisticated pointer analyses</a>. There are no responses at the time of writing, but it seems an interesting question.</p></li><li><p>Huw Davies has proposed a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096762.html">new IR attribute, incoming-stack-align</a>. This is needed for Wine which may require functions to have an ABI stack alignment different to the host's alignment.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new Error support class has been added to support structured error handling. See the associated updates to the LLVM programmer's manual for more info. <a href="http://reviews.llvm.org/rL263609">r263609</a>.</p></li><li><p>New documentation was committed for advanced CMake build configurations. <a href="http://reviews.llvm.org/rL263834">r263834</a>.</p></li><li><p>Support was added for MIPS32R6 compact branches. <a href="http://reviews.llvm.org/rL263444">r263444</a>.</p></li><li><p>The MemCpyOptimizer will now attempt to reorder instructions in order to create an optimisable sequence. <a href="http://reviews.llvm.org/rL263503">r263503</a>.</p></li><li><p>llvm-readobj learnt to print sections and relocations in the GNU style. <a href="http://reviews.llvm.org/rL263561">r263561</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Attributes have been added for the <code>preserve_mostcc</code> and <code>preserve_allcc</code> calling conventions. <a href="http://reviews.llvm.org/rL263647">r263647</a>.</p></li><li><p>clang-format will handle some cases of automatic semicolon insertion in JavaScript. <a href="http://reviews.llvm.org/rL263470">r263470</a>.</p></li><li><p>Clang learned to convert some Objective-C message sends to runtime calls. <a href="http://reviews.llvm.org/rL263607">r263607</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>AddressSanitizer is now supported on mips/mips64 Android. <a href="http://reviews.llvm.org/rL263261">r263261</a>.</p></li><li><p>The documentation on the LLD linker has added a few numbers to give an idea of the sort of inputs it needs to handle. e.g. Chrome with debug info contains roughly 13M relocations, 6.3M symbols, 1.8M sections and 17k files. <a href="http://reviews.llvm.org/rL263466">r263466</a>.</p></li></ul>
- LLVM Weekly - #115, Mar 14th 2016https://blog.llvm.org/2016/03/llvm-weekly-115-mar-14th-2016.htmlMon, 14 Mar 2016 04:56:00 +0000https://blog.llvm.org/2016/03/llvm-weekly-115-mar-14th-2016.html<p>Welcome to the one hundred and fifteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/115">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <p>We have an LLVM-related research position currently being <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096751.html">advertised here at the University of Cambridge Computer Lab</a>. If you'd like an informal chat about what it's like working in this group or on this project please don't hesitate to get in touch with me.</p><h3>News and articles from around the web</h3><p>LLVM and Clang 3.8 have now been released. Check out the <a href="http://llvm.org/releases/3.8.0/docs/ReleaseNotes.html">LLVM</a> and <a href="http://llvm.org/releases/3.8.0/tools/clang/docs/ReleaseNotes.html">Clang</a> release notes for a run-down of the new features.</p><p>It's GDC this week and if you're attending you may be interested that there's an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096446.html">LLVM meetup scheduled for Thursday</a>.</p><p>Felix Angell has a detailed blog post introducing <a href="https://blog.felixangell.com/an-introduction-to-llvm-in-go/">generating LLVM IR from Go</a>.</p><h3>On the mailing lists</h3><ul><li><p>Jason Henline has posted a very detailed RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096576.html">creating a new parallel runtime library</a>. StreamExecutor wraps both the CUDA and OpenCL runtimes and is used internally at Google.</p></li><li><p>Ed Maste has shared an update on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096449.html">linking the FreeBSD base system using LLD</a>. With a few workarounds, the full amd64 FreeBSD system is now buildable.</p></li><li><p>Vedant Kumar has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096643.html">RFC on removing redundant profile counter updates</a>.</p></li><li><p>Sean Silva is seeking to <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096529.html">formalize the 'revert for more design review policy'</a>. Overall, the comments seem to be positive.</p></li><li><p>With EuroLLVM coming up this week, people have been advertising their birds of a feather sessions. e.g. the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096667.html">LLVM on PowerPC and SystemZ</a> session and the session on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096638.html">surviving downstream</a>.</p></li><li><p>Rafael EspÃndola reports that compilation with LLVM and Clang has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096488.html">getting slower over time</a>. Hal Finkel has some good input on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096491.html">potential areas for improvement</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Loop invariant code motion learnt the ability the exploit the fact a memory location is known to be thread-local. <a href="http://reviews.llvm.org/rL263072">r263072</a>.</p></li><li><p>A new <code>llvm.experimental.deoptimize</code> intrinsic has been added. <a href="http://reviews.llvm.org/rL263281">r26328</a>.</p></li><li><p>A ThinLTOCodeGenerator was added in order to provide a proof-of-concept implementation. <a href="http://reviews.llvm.org/rL262977">r262977</a>.</p></li><li><p>The Sparc backend gained support for co-processor condition branching and conditional traps. <a href="http://reviews.llvm.org/rL263044">r263044</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained support for the <code>[[nodiscard]]</code> attribute. <a href="http://reviews.llvm.org/rL262872">r262872</a>.</p></li><li><p>New AST matchers were added for addrLabelExpr, atomicExpr, binaryCondtionalOperator, designatedINitExpr, designatedInitExpr, designatorCountIs, hasSyntacticForm, implicitValueINitExpr, labelDecl, opaqueValueExpr, parenListExpr, predefinedExpr, requiresZeroInitialization, and stmtExpr. <a href="http://reviews.llvm.org/rL263027">r263027</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Error and warning messages in LLD are now more consistent. <a href="http://reviews.llvm.org/rL263125">r263125</a>.</p></li><li><p>Documentation on the new ELF and COFF LLD linkers has been updated. <a href="http://reviews.llvm.org/rL263336">r263336</a>.</p></li></ul>
- LLVM Weekly - #114, Mar 7th 2016https://blog.llvm.org/2016/03/llvm-weekly-114-mar-7th-2016.htmlMon, 07 Mar 2016 04:40:00 +0000https://blog.llvm.org/2016/03/llvm-weekly-114-mar-7th-2016.html<p>Welcome to the one hundred and fourteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/114">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/096138.html">accepted</a> as a mentoring organisation in Google Summer of Code 2016. See <a href="https://summerofcode.withgoogle.com/how-it-works/">here</a> for more about what that means. If you're a student who would like to get paid to work on LLVM over the summer, you should definitely consider applying. Also take a look at the full list of <a href="https://summerofcode.withgoogle.com/organizations/">organisations in GSoC 2016</a>. If you have an interest in open source hardware, in my (biased) opinion you should definitely look at <a href="http://www.lowrisc.org/docs/gsoc-2016-ideas/">lowRISC's listed project ideas</a>.</p><p>LLVM and Clang 3.8 'final' <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096319.html">has been tagged</a>. A release should be imminent.</p><p>There was a big C++ committee meeting last week. You can find summaries <a href="https://www.reddit.com/r/cpp/comments/48zp05/what_we_added_to_the_c17_working_draft/">here</a> and <a href="http://usingstdcpp.org/2016/03/05/trip-report-c-meeting-at-jacksonville/">here</a>. If you were hoping for modules, concepts, UFCS, ranges, or coroutines in C++17 I'm afraid you're in for disappointment. Many new features will be available in C++ Technical Specifications though.</p><p>llvmlite 0.9.0 has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096199.html">released</a>. llvmlite is a light-weight Python binding for LLVM. If you're wondering how to get started with llvmlite, then check out this recent blog post from Ian Bertolacci on <a href="https://ian-bertolacci.github.io/llvm/llvmlite/python/compilers/programming/2016/03/06/LLVMLite_fibonacci.html">writing fibonacci in LLVM with llvmlite</a>.</p><p>Andi McClure has written a really interesting blog post about <a href="http://msm.runhello.com/p/1003">writing software without a compiler</a>. In this case, generating LLVM IR from LuaJIT.</p><h3>On the mailing lists</h3><ul><li><p>John McCall has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096250.html">implementing the Swift calling convention in LLVM and Clang</a>. Feedback is generally positive and there's an interesting discussion on the handling of Swift's errors in the calling convention.</p></li><li><p>Roel Jordans has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096205.html">posted some thoughts and questions in preparation for the EuroLLVM birds of a feather sessions on compilers in education</a>.</p></li><li><p>Peter Collingbourne has shared a new RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/096146.html">adding a new ABI for virtual calls</a>, termed the 'relative ABI'. He'd also like to change how virtual calls are represented in the IR.</p></li><li><p>Grigori Fursin from Dividiti <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096370.html">shared some recent work on crowdtuning compiler optimisation heuristics</a>.</p></li><li><p><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096351.html">What is the current status of garbage collection with statepoints in LLVM?</a>. <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096360.html">Philip Reames</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096361.html">Sanjoy Das</a> have the answer!</p></li><li><p>Xinmin Tian has shared a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096291.html">proposal for function vectorisation and loop vectorisation with function calls</a>.</p></li><li><p>Akira Hatanaka is interested in comments to his <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-March/096233.html">RFC on more precise lifetime.end metadata</a>. In the given example, three local variables have non-overlapping lifetimes and could potentially use the same stack slot, but this isn't currently done.</p></li></ul><h3>LLVM commits</h3><ul><li><p>MemorySSA has gained an initial update API. <a href="http://reviews.llvm.org/rL262362">r262362</a>.</p></li><li><p>TableGen can now check at compile time that a scheduling model is complete. <a href="http://reviews.llvm.org/rL262384">r262384</a>.</p></li><li><p>New comments in PassBuilder give a description of what trade-offs are expected for each optimisation level. <a href="http://reviews.llvm.org/rL262196">r262196</a>.</p></li><li><p>LoopLoadElimination is now enabled by default. <a href="http://reviews.llvm.org/rL262250">r262250</a>.</p></li><li><p>A new patch adding infrastructure for profile-guided optimisation enhancements in the inline has landed. <a href="http://reviews.llvm.org/rL262636">r262636</a>.</p></li><li><p>Experimental ValueTracking code which tried to infer more precise known bits using implied dominating conditions has been removed. Experiments didn't find it to be profitable enough, but it may still be useful to people wanting to experiment out of tree. <a href="http://reviews.llvm.org/rL262646">r262646</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang's C API gained an option to demote fatal errors to non-fatal errors. This is likely to be useful for clients like IDEs. <a href="http://reviews.llvm.org/rL262318">r262318</a>.</p></li><li><p>clang-cl gained initial support for precompiled headers. <a href="http://reviews.llvm.org/rL262420">r262420</a>.</p></li><li><p>An <code>-fembed-bitcode</code> driver option has been introduced. <a href="http://reviews.llvm.org/rL262282">r262282</a>.</p></li><li><p>Semantic analysis for the swiftcall calling convention has landed. <a href="http://reviews.llvm.org/rL262587">r262587</a>.</p></li><li><p>Clang's TargetInfo will now store an actual DataLayout instance rather than a string. <a href="http://reviews.llvm.org/rL262737">r262737</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB can now read line tables from Microsoft's PDB debug info files. <a href="http://reviews.llvm.org/rL262528">r262528</a>.</p></li><li><p>The LLVM test-suite gained the ability to hash generated binaries and to skip tests if the hash didn't change since a previous run. <a href="http://reviews.llvm.org/rL262307">r262307</a>.</p></li><li><p>LLVM's OpenMP runtime now supports the new OpenMP 4.5 doacross loop nest and taskloop features. <a href="http://reviews.llvm.org/rL262532">r262532</a>, <a href="http://reviews.llvm.org/rL262535">r262535</a>.</p></li></ul>
- LLVM Weekly - #113, Feb 29th 2016https://blog.llvm.org/2016/02/llvm-weekly-113-feb-29th-2016.htmlMon, 29 Feb 2016 06:58:00 +0000https://blog.llvm.org/2016/02/llvm-weekly-113-feb-29th-2016.html<p>Welcome to the one hundred and thirteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or @llvmweekly or @asbradbury on Twitter.</p><h3>News and articles from around the web</h3><p>LLVM and Clang 3.8RC3 <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095756.html">has been tagged</a>.</p><p>EuroLLVM 2016 is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095832.html">less than a month away</a>. If you want to attend, be sure to <a href="http://www.llvm.org/devmtg/2016-03/#registration">register</a>.</p><p>The Red Hat blog has a <a href="http://developerblog.redhat.com/2016/02/23/upcoming-features-in-gcc-6/">summary of new features in the upcoming GCC 6 release</a>.</p><p>The Meeting C++ blog has a <a href="http://meetingcpp.com/index.php/br/items/current-proposals-for-c17.html">helpful summary of a subset of the proposals for the next C++ committee meeting</a>.</p><h3>On the mailing lists</h3><ul><li><p>Chandler Carruth has suggested <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095809.html">moving the LLVM test-suite repository to Github</a>. In response to some concerns, Chris Lattner points out that using GitHub in this case <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095942.html">doesn't mean abandoning the current development workflow</a>, it just means it can be augmented with GitHub-style pull requests for those who prefer it. Chandler <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095943.html">summarised the thread</a> and provided a list of next steps.</p></li><li><p>Sanjoy Das <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095833.html">pointed out a potential soundness issue with the <code>available_externally</code> linkage type</a>. This triggered a very long discussion. James Knight pointed out the same issue <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095935.html">could happen with normal functions in a shared library</a>. There was some back and forth between Hal Finkel and Chandler Carruth <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/096025.html">on the best approach to addressing this problem</a>.</p></li><li><p>Philip Reames asks whether <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095964.html">a PHI depending on another PHI in the same basic block is valid</a>. It's currently accepted by the verifier but arguably shouldn't be. So far, nobody has argued that it should be valid.</p></li><li><p>Matthias Braun kicked off a discussion on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095947.html">better defining the semantics of reserved and unallocatable registers</a>. After more discussion, he followed up with a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095999.html">revised definition</a>.</p></li><li><p>David Li has posted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/096077.html">proposal for supporting in-process merging of profile data</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The Sparc backend now contains definitions for all registers and instructions defined in the Sparc v8 manual. <a href="http://reviews.llvm.org/rL262133">r262133</a>.</p></li><li><p>LLVM gained a basic LoopPassManager, though it currently only contains dummy passes. <a href="http://reviews.llvm.org/rL261831">r261831</a>.</p></li><li><p>A number of TargetInstrInfo predicates now take a reference to a MachineInstr rather than a pointer. <a href="http://reviews.llvm.org/rL261605">r261605</a>.</p></li><li><p>The WebAssembly backend gained redzone support for the userspace stack. <a href="http://reviews.llvm.org/rL261662">r261662</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Whole-program vtable optimisation is now available in Clang using the <code>-fwhole-program-vtables</code> flag. <a href="http://reviews.llvm.org/rL261767">r261767</a>.</p></li><li><p>Clang gained <code>__builtin_canonicalize</code> which returns the platform-specific canonical encoding of a floating point number. <a href="http://reviews.llvm.org/rL262122">r262122</a>.</p></li><li><p>A hasAnyName matcher was added. <a href="http://reviews.llvm.org/rL261574">r261574</a>.</p></li><li><p>The pointer arithmetic checker has been improved to report fewer false positives. <a href="http://reviews.llvm.org/rL261632">r261632</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The new ELF linker gained support for identical code folding (ICF). This reduces the size of an LLD binary by 3.6% and of a Clang binary by 2.7%. As described in the commit message, this is not a "safe" version of ICF as implemented in GNU gold, so will cause issues if the input relies on two distinct functions always having distinct addresses. <a href="http://reviews.llvm.org/rL261912">r261912</a>.</p></li><li><p>Polly's tree now contains an <code>update_check.py</code> script that may be useful to other LLVM devs. It updates a FileCheck-based lit test by updating the <code>CHECK:</code> lines with the actual output of the <code>RUN:</code> command. <a href="http://reviews.llvm.org/rL261899">r261899</a>.</p></li><li><p>LLDB gained a new set of plugins to help debug Java programs, specifically Java code JIT-ed by the Android runtime. <a href="http://reviews.llvm.org/rL262015">r262015</a>.</p></li><li><p>The new OpenMP 4.5 affinity API is now supported in LLVM's openmp implementation. <a href="http://reviews.llvm.org/rL261915">r261915</a>.</p></li><li><p>The new ELF linker gained support for the <code>-r</code> command-line option, which produces relocatable output (partial linking). <a href="http://reviews.llvm.org/rL261838">r261838</a>.</p></li><li><p>The CMake/lit runner for SPEC in the LLVM test-suite can now run the C CPU2006 floating point benchmarks (but not the Fortran ones). <a href="http://reviews.llvm.org/rL261816">r261816</a>.</p></li><li><p>The old ELF linker has been deleted from LLD. <a href="http://reviews.llvm.org/rL262158">r262158</a>.</p></li></ul>
- LLVM Weekly - #112, Feb 22nd 2016https://blog.llvm.org/2016/02/llvm-weekly-112-feb-22nd-2016.htmlMon, 22 Feb 2016 03:29:00 +0000https://blog.llvm.org/2016/02/llvm-weekly-112-feb-22nd-2016.html<p>Welcome to the one hundred and twelfth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/112">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Filip Pizlo has written a <a href="https://webkit.org/blog/5852/introducing-the-b3-jit-compiler/">fantastic article</a> introducing the new B3 JIT compiler for WebKit's JavaScriptCore. This intends to replace LLVM as the optimising backend to their fourth-tier JIT. The article describes in detail their reasons for moving away from LLVM (mainly compile-time) and the design trade-offs made, such as in reducing memory allocations and minimising pointer-chasing in the IR. This reminds me of the trade-offs Mike Pall made in the <a href="http://wiki.luajit.org/SSA-IR-2.0">LuaJIT 2.0 IR</a>. Philip Reames also shared <a href="http://www.philipreames.com/Blog/2016/02/15/quick-thoughts-on-webkits-b3/">some initial thoughts on B3</a>. I know some people have expressed disappointment about WebKit moving away from LLVM, but if you'll allow me to insert just a little bit of editorial I'd argue B3 is a very positive development for LLVM and the wider compiler community. B3 explores a different set of design trade-offs to those chosen for LLVM, and these sort of changes are probably easiest to explore in a fresh codebase.Thanks to this write-up (and hopefully future B3/AIR documentation), we can learn from the B3 developers' experiences and consider if some of their choices will make sense for LLVM. It's also good to remember that LLVM isn't the only feasible route for code generation and optimisation, and we shouldn't treat LLVM's design choices as the one-true way to do things. Impressively, B3 was developed to its current state in only <a href="https://news.ycombinator.com/item?id=11104604">6 months of developer-time</a>.</p><p>Version 0.17.0 of LDC, the LLVM-based compiler for the D programming language has <a href="http://forum.dlang.org/thread/[email protected]">been released</a>. You can view a <a href="https://github.com/ldc-developers/ldc/releases/tag/v0.17.0">detailed changelog here</a>.</p><p>GCC6 will feature a whole bunch of new warnings, and <a href="https://gnu.wildebeest.org/blog/mjw/2016/02/15/looking-forward-to-gcc6-many-new-warnings/">this blog post</a> details many of them.</p><p>The schedule for <a href="http://www.llvm.org/devmtg/2016-03/">EuroLLVM 2016</a> has now been posted. This will be held March 17th-18th in Barcelona.</p><h3>On the mailing lists</h3><ul><li><p>Bob Wilson proposes that format-security warnings in Clang <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-February/047367.html">default to error</a>. Nico Weber posted a handy <a href="http://lists.llvm.org/pipermail/cfe-dev/2016-February/047438.html">summary of the thread</a>.</p></li><li><p>Sanjoy Das has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095523.html">RFC on adding guard intrinsics to LLVM</a>. These would be used in a similar way to the Check opcode in WebKit's new B3 compiler.</p></li><li><p>Alina Sbirlea proposes adding <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095557.html">bitcode tests to the LLVM test-suite</a>. Hal Finkel suggests going further and just <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095562.html">pulling Halide in to the LLVM test-suite</a> as a front-end example that should provide greater test coverage.</p></li><li><p>Andrew Trick shared some <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095463.html">thoughts on LLVM in light of the WebKit B3 announcement</a>. "Even when LLVM's compile time problems are largely solved, and I believe they can be, there will always be systemic compile time and memory overhead from design decisions that achieve generality, flexibility, and layering. These are software engineering tradeoffs."</p></li></ul><h3>LLVM commits</h3><ul><li><p>The PPCLoopDataPrefetch pass has been moved to Transforms/Scalar/LoopDataPrefetch in preparation for it becoming a target-agnostic pass. <a href="http://reviews.llvm.org/rL261265">r261265</a>.</p></li><li><p>The cmpxchg LLVM instruction now allows pointer type operands. <a href="http://reviews.llvm.org/rL261281">r261281</a>.</p></li><li><p>The X86 backend gained support for a new stack symbol ordering optimisation. This is primarily intended to reduce code size, and produces small but measurable improvements across some SPEC CPU 2000 benchmarks. <a href="http://reviews.llvm.org/rL260917">r260917</a>.</p></li><li><p>The LLVM C API has been extended to allow it to be used to manipulate the datalayout. <a href="http://reviews.llvm.org/rL260936">r260936</a>.</p></li><li><p>Some major work on the LazyCallGraph has been checked in. <a href="http://reviews.llvm.org/rL261040">r261040</a>.</p></li><li><p>The AMDGPU backend gained a basic disassembler. <a href="http://reviews.llvm.org/rL261185">r261185</a>.</p></li><li><p>The PostOrderFuctionAttrs pass has been ported to the new pass manager. As described in the commit message, this actually represents a major milestone. <a href="http://reviews.llvm.org/rL261203">r261203</a>.</p></li><li><p>The Hexagon backend gained support for thread-local storage. <a href="http://reviews.llvm.org/rL261218">r261218</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A nullPointerConstant AST matcher was added. <a href="http://reviews.llvm.org/rL261008">r261008</a>.</p></li><li><p>Clang gained a <code>-Wcomma</code> warning, which will warn for most uses of the builtin comma operator. <a href="http://reviews.llvm.org/rL261278">r261278</a></p></li></ul><h3>Other project commits</h3><ul><li><p>LLD has sprouted a release notes document. <a href="http://reviews.llvm.org/rL260960">r260960</a>.</p></li><li><p>The LLVM test-suite's CMake build system saw a number of fixes for SPEC. <a href="http://reviews.llvm.org/rL261470">r261470</a>.</p></li></ul>
- LLVM Weekly - #111, Feb 15th 2016https://blog.llvm.org/2016/02/llvm-weekly-111-feb-15th-2016.htmlMon, 15 Feb 2016 03:58:00 +0000https://blog.llvm.org/2016/02/llvm-weekly-111-feb-15th-2016.html<p>Welcome to the one hundred and eleventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/111">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>There has been a <a href="http://cilkplus.github.io/">new release of the CilkPlus compiler</a>. This includes an update to the latest LLVM and Clang trunk. CilkPlus implements the Cilk Plus language extensions for data and task parallelism in Clang.</p><p>There's been some more papers appearing from the C++ standards committee. P0225R0, or as you may prefer to call it "<a href="https://isocpp.org/files/papers/p0225r0.html">Why I want Concepts, and why I want them sooner rather than later</a>" is worth a read. There's also been a few <a href="https://isocpp.org/blog/2016/02/new-papers">other recently published papers</a> on iterator facades, the filesystem technical specification, and unified function call syntax.</p><h3>On the mailing lists</h3><ul><li><p>Jacques Pienaar has proposed <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095118.html">upstreaming the 'Lanai' backend</a>. This is for a CPU design used internally at Google, and the posting of these patches did attract some <a href="http://www.theregister.co.uk/2016/02/09/google_processor/">attention in the press</a>. A good chunk of the ensuing discussion focused on what the bar should be for accepting a new backend upstream. There seem to ultimately be far more people for the upstreaming than against it, but some concern was raised about the ability for others to test the generated code without access to hardware or even simulators.</p></li><li><p>Natanael Ramos recently worked with LLVM for his bachelor thesis, and as a result <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095083.html">wrote and submitted a tutorial for writing a new LLVM register allocator</a>. This can also be found <a href="https://github.com/nael8r/How-To-Write-An-LLVM-Register-Allocator/blob/master/HowToWriteAnLLVMRegisterAllocator.rst">on github</a>.</p></li><li><p>Nolan has been working on an <a href="https://github.com/beholdnec/llvm-m6502">experimental 6502 backend</a>, and sought some help with a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095379.html">memory operand folding problem</a>. He later followed up to the list <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095436.html">with his solution</a>, and David Chisnall added some <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095439.html">extra thoughts on potential approaches to targeting 6502 or similar architectures</a>.</p></li><li><p>Hans Wennborg is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095376.html">looking for help in expanding the release notes for the 3.8 release</a>.</p></li><li><p>Vaivaswatha Nagaraj has been working on a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095115.html">control structure analysis</a> capable of detecting control structures in the CFG and is seeking feedback on his code.</p></li><li><p>Lang Hames has followed up to his RFC on error handling in LLVM libraries with a detailed post <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095324.html">summarising his thoughts and responding some some feedback</a>.</p></li><li><p>Sadly, CMake's current Ninja generator <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095266.html">is non-deterministic</a>. The good news is there is <a href="https://public.kitware.com/Bug/view.php?id=15968">already a fix in upstream CMake</a>.</p></li><li><p>Peter Collingbourne prototyped <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095306.html">a change to reduce DWARF emitter memory consumption</a>. Early results are very positive.</p></li><li><p>Philip Reames proposes <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095290.html">removing the inaccessiblememonly attribute from the 3.8 branch</a>, on the grounds that the major motivating patch was reverted, there has been no further development, and including it in a release may pose a backwards-compatibility concern. There appears to be agreement so far in the responses.</p></li><li><p>LLVM will be applying for inclusion in the Google Summer of Code this year. If you have a project listed on the 'open projects' page, <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/095087.html">please review and update it if necessary</a>, or suggest new projects.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The WholeProgramDevirt pass has been added. This implements whole program optimization of virtual calls where the list of callees is known to be fixed. <a href="http://reviews.llvm.org/rL260312">r260312</a>.</p></li><li><p>The AVR backend upstreaming continues with the addition of the AVR tablegen instruction definitions. <a href="http://reviews.llvm.org/rL60363">r260363</a>.</p></li><li><p>There's been a bunch of other work on the new global instruction selection mechanism this week, but the commits I'd pick out are the addition of support for translating Add instructions and for lowering returns. It is currently being tests with the AArch64 backend. <a href="http://reviews.llvm.org/rL260549">r260549</a>, <a href="http://reviews.llvm.org/rL260562">r260562</a>, <a href="http://reviews.llvm.org/rL260600">r260600</a>.</p></li><li><p>The AArch64 backend gained support (including a scheduling model) for the Qualcomm Kryo CPU. <a href="http://reviews.llvm.org/rL260686">r260686</a>.</p></li><li><p>LoopUnrollAnalyzer has been abstracted out from LoopUnrollPass, and gained unit tests for its functionality. <a href="http://reviews.llvm.org/rL260169">r260169</a>.</p></li><li><p>llvm-config gained preliminary Windows support. <a href="http://reviews.llvm.org/rL260263">r260263</a>.</p></li><li><p>The details of the convergent attribute have been clarified in the language reference. The convergent attribute will now be removed on functions which provably don't converge or invoke any convergent functions. <a href="http://reviews.llvm.org/rL260318">r260316</a>, <a href="http://reviews.llvm.org/rL260319">r260319</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>It is now possible to perform a 3-stage Clang build using CMake. It is suggested in the commit message this may be useful for detecting non-determinism in the compiler by verifying stage2 and stage3 are identical. <a href="http://reviews.llvm.org/rL260261">r260261</a>.</p></li><li><p>ARMv8.2-A can be targeted using appropriate Clang options. <a href="http://reviews.llvm.org/rL260533">r260533</a>.</p></li><li><p>Clang's CMake build system learned the <code>CLANG_DEFAULT_CXX_STDLIB</code> to set the default C++ standard library. <a href="http://reviews.llvm.org/rL260662">r260662</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The new LLD ELF linker gained initial link-time optimisation support. <a href="http://reviews.llvm.org/rL260726">r260726</a>.</p></li><li><p>LLDB has seen some more updates for Python 3 support, though not yet enough for a clean testsuite run. <a href="http://reviews.llvm.org/rL260721">r260721</a>.</p></li></ul>
- LLVM Weekly - #110, Feb 8th 2016https://blog.llvm.org/2016/02/llvm-weekly-110-feb-8th-2016.htmlMon, 08 Feb 2016 08:44:00 +0000https://blog.llvm.org/2016/02/llvm-weekly-110-feb-8th-2016.html<p>Welcome to the one hundred and tenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/110">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Slides from the LLVM devroom at FOSDEM last weekend are <a href="http://llvm.org/devmtg/2016-01/">now available online</a>. Unfortunately there was an issue with the recording of the talks so videos will not be available.</p><p>JavaScriptCore's <a href="https://trac.webkit.org/wiki/FTLJIT">FTL JIT</a> is moving away from using LLVM as its backend, towards <a href="https://webkit.org/docs/b3/">B3 (Bare Bones Backend)</a>. This includes its own <a href="https://webkit.org/docs/b3/intermediate-representation.html">SSA IR</a>, optimisations, and instruction selection backend.</p><p>Source tarballs and binaries are <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094987.html">now available</a> for LLVM and Clang 3.8-RC2.</p><p>The Zurich LLVM Social <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094759.html">is coming up this Thursday</a>, February 11th at 7pm.</p><p>Jeremy Bennett has written up a <a href="http://www.embecosm.com/2016/02/05/how-similar-are-gcc-and-llvm-the-user-perspective/">comparison of the Clang and GCC command-line flags</a>. The headline summary is that 397 work in both GCC and LLVM, 433 are LLVM-only and 598 are GCC-only.</p><p><a href="https://github.com/alepez/vim-llvmcov">vim-llvmcov</a> has been released. It is a vim plugin to show code coverage using the llvm-cov tool.</p><h3>On the mailing lists</h3><ul><li><p>Mehdi Amini has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094869.html">RFC on floating point environment and rounding mode handling in LLVM</a>. The work started all the way back in 2014 and has a whole bunch of patches up for review. Chandler Carruth has responded with a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094916.html">detail description of his concerns about the current design</a>, and his proposed alternative seems to be getting a lot of positive feedback.</p></li><li><p>Morten Brodersen has recently upgraded a number of applications from the old JIT to the new MCJIT under LLVM 3.7.1 but has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094908.html">found significant performance regressions</a>. Some other respondents have seen similar issues, either in compilation time or in reduced code quality in the generated code. Some of the thread participants will be providing specific examples so they can be investigated. It's possible the issue is something as simple as a different default somewhere. Benoit Belley noted <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094946.html">they saw regressions due to their frontend's use of allocas in 3.7</a>.</p></li><li><p>Lang Hames kicked off a long discussion about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094804.html">error handling in LLVM libraries</a>. Lang has implemented a new scheme and is seeking feedback on it. There's a lot of discussion that unfortunately I haven't had time to summarise properly. If error handling design interests you, do get stuck in.</p></li><li><p>Adrian McCarthy has written up details on the <a href="http://lists.llvm.org/pipermail/lldb-dev/2016-February/009533.html">recent addition of minidump support to LLDB</a>. Minidumps are the Windows equivalent of a core file.</p></li><li><p>Juan Wajnerman is looking at adding support for multithreading to the Crystal language, and has a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094736.html">question about thread local variables</a>. LLVM won't re-load the thread local address, which causes issues when a thread local variable is read in a coroutine running on one thread which is then suspended and continued on a different thread. This is apparently a known issue, covered by <a href="https://llvm.org/bugs/show_bug.cgi?id=19177">PR19177</a>.</p></li><li><p>Steven Wu has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094851.html">RFC on embedding bitcode in object files</a>. The intent is to upstream support that already exists in Apple's fork. Understandably some of the respondents asked how this relates to the .llvmbc section that the Thin-LTO work is introducing. Steven indicates it's pretty much the same, but for Mach-O rather than ELF and that he hopes to unify them during the upstreaming.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM now has a memory SSA form. This isn't yet used by anything in-tree, but should form a very useful basis for a variety of analyses and transformations. This patch has been baking for a long time, first being submitted for initial feedback in April last year. <a href="http://reviews.llvm.org/rL259595">r259595</a>.</p></li><li><p>A new loop versioning loop-invariant code motion (LICM) pass was introduced. This enables more opportunities for LICM by creating a new version of the loop guarded by runtime checks to test for potential aliases that can't be determined not to exist at compile-time. <a href="http://reviews.llvm.org/rL259986">r259986</a>.</p></li><li><p>LazyValueInfo gained an intersect operation on lattice values, which can be used to exploit multiple sources of facts at once. The intent is to make greater use of it, but already it is able to remove a half range-check when performing jump-threading. <a href="http://reviews.llvm.org/rL259461">r259461</a>.</p></li><li><p>The SmallSet and SmallPtrSet templates will now error out if created with a size greater than 32. <a href="http://reviews.llvm.org/rL259419">r259419</a>.</p></li><li><p>The ability to emit errors from the backend for unsupported features has been refactored, so BPF, WebAssembly, and AMDGPU backends can all share the same implementation. <a href="http://reviews.llvm.org/rL259498">r259498</a>.</p></li><li><p>A simple pass using LoopVersioning has been added, primarily for testing. The new pass will fully disambiguate all may-aliasing memory accesses no matter how many runtime checks are required. <a href="http://reviews.llvm.org/rL259610">r259610</a>.</p></li><li><p>The way bitsets are used to encode type information has now been documented. <a href="http://reviews.llvm.org/rL259619">r259619</a>.</p></li><li><p>You can now use the flag <code>-DLLVM_ENABLE_LTO</code> with CMake to build LLVM with link-time optimisation. <a href="http://reviews.llvm.org/rL259766">r259766</a>.</p></li><li><p>TableGen's AsmOperandClass gained the <code>IsOptional</code> field. Setting this to 1 means the operand is optional and the AsmParser will not emit an error if the operand isn't present. <a href="http://reviews.llvm.org/rL259913">r259913</a>.</p></li><li><p>There is now a scheduling model for the Exynos-M1. <a href="http://reviews.llvm.org/rL259958">r259958</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang now has builtins for the bitreverse intrinsic. <a href="http://reviews.llvm.org/rL259671">r259671</a>.</p></li><li><p>The option names for profile-guided optimisations with the cc1 driver have been modified. <a href="http://reviews.llvm.org/rL259811">r259811</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>AddressSanitizer now supports iOS. <a href="http://reviews.llvm.org/rL259451">r259451</a>.</p></li><li><p>The current policy for using the new ELF LLD as a library has been documented. <a href="http://reviews.llvm.org/rL259606">r259606</a>.</p></li><li><p>Polly's new Sphinx documentation gained a guide on using Polly with Clang. <a href="http://reviews.llvm.org/rL259767">r259767</a>.</p></li></ul>
- LLVM Weekly - #109, Feb 1st 2016https://blog.llvm.org/2016/02/llvm-weekly-109-feb-1st-2016.htmlMon, 01 Feb 2016 06:24:00 +0000https://blog.llvm.org/2016/02/llvm-weekly-109-feb-1st-2016.html<p>Welcome to the one hundred and ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/109">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The GNU Tools Cauldron 2016 has been <a href="https://gcc.gnu.org/ml/gcc/2015-12/msg00160.html">announced</a> for the 9th-11th of September 2016, in Hebden Bridge, UK.</p><p>The Sulong project has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094713.html">announced</a>. It is an LLVM IR interpreter using the Truffle framework and Graal on the JVM to support JIT compilation.</p><p>Ehsan Akhgari has posted an <a href="https://ehsanakhgari.org/blog/2016-01-29/building-firefox-with-clang-cl-a-status-update">updated on building Firefox with clang-cl</a>. It is now possible to build a complete Firefox with Clang without using the MSVC fallback once.</p><p>I've mentioned it down below in the list of notable commits, but it's worth calling out here too: the old autoconf build-system has now been <a href="http://reviews.llvm.org/rL258861">removed</a> from LLVM. 3.8 will be the last release to include it. Time to switch to CMake if you haven't already.</p><p>John Regehr gave a talk about undefined behaviour in LLVM at the Paris LLVM meetup, and you can find the slides <a href="http://www.cs.utah.edu/~regehr/llvm-ub.pdf">here</a>.</p><h3>On the mailing lists</h3><ul><li><p>James Knight has written to the list to get feedback on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094576.html">approaches to cleaning up Clang's handling of atomics</a>. There seems to be widespread support for the cleanup. James followed up again to <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094702.html">slightly revise his plan</a>.</p></li><li><p>Matt Arsenault proposes that <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094593.html">all libcalls be canonicalized to intrinsics</a>. All responses so far are in favour.</p></li><li><p>Ke Bai has shared a proposal on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094640.html">representing multiple memory scopes in LLVM IR</a>. There hasn't been any feedback yet.</p></li><li><p>Dmitree Kuvaiskii asks if anyone has implemented <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094620.html">a pass utilizing Intel's new MPX memory protection</a>. The answer appears to be no, and in addition <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094627.html">David</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094638.html">Kostya</a> are sceptical about how worthwhile it would be.</p></li><li><p>Peter Collingbourne has proposed a new optimisation, <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094600.html">virtual constant propagation</a>. The original motivation was to reduce the overhead added by enabling control-flow integrity in certain Chromium benchmarks. Constants will be devirtualized at LTO time.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The autoconf build system for LLVM has been removed. <a href="http://reviews.llvm.org/rL258861">r258861</a>.</p></li><li><p>The WebAssembly backend gained support for unaligned loads and stores. <a href="http://reviews.llvm.org/rL258779">r258779</a>.</p></li><li><p>LLVM's MCAsmSreamer will now always use .p2align rather than .align, because .align's behaviour can differ between targets. <a href="http://reviews.llvm.org/rL258750">r258750</a>.</p></li><li><p>Intrinsic IDs are now looked up by binary search rather than the previous more complex mechanism. This improves the compile time of Function.cpp. <a href="http://reviews.llvm.org/rL258774">r258774</a>.</p></li><li><p>TargetSelectionDAGInfo has been renamed to SelectionDAGTargetInfo and now lives in CodeGen rather than Target. <a href="http://reviews.llvm.org/rL258939">r258939</a>.</p></li><li><p>A LoopSimplifyCFG pass was added to canonicalise loops before running through passes such as LoopRotate and LoopUnroll. <a href="http://reviews.llvm.org/rL259256">r259256</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The clang-cl driver will now warn for unknown arguments rather than erroring, to match the behaviour of MSVC. <a href="http://reviews.llvm.org/rL258720">r258720</a>.</p></li><li><p>The old autoconf build system was removed from Clang. <a href="http://reviews.llvm.org/rL258862">r258862</a>.</p></li><li><p>The 'sancov' (SanitizerCoverage) tool gained some documentation. <a href="http://reviews.llvm.org/rL259000">r259000</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx gained an implementation of <code>ostream_joiner</code>. <a href="http://reviews.llvm.org/rL259014">r259014</a>, <a href="http://reviews.llvm.org/rL259015">r259015</a>.</p></li><li><p>lld gained a new error function which won't cause process exit. The hope is this can be used to provide a gradual path towards lld-as-a-library. <a href="http://reviews.llvm.org/rL259069">r259069</a>.</p></li><li><p>The lit runner for the LLVM test suite can now be passed <code>--param=profile=perf</code> which will cause each test to be run under <code>perf record</code>. <a href="http://reviews.llvm.org/rL259051">r259051</a>.</p></li></ul>
- LLVM Weekly - #108, Jan 25th 2016https://blog.llvm.org/2016/01/llvm-weekly-108-jan-25th-2016.htmlMon, 25 Jan 2016 04:48:00 +0000https://blog.llvm.org/2016/01/llvm-weekly-108-jan-25th-2016.html<p>Welcome to the one hundred and eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/108">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM 3.8 RC1 <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094433.html">has been released</a>. Now is the time to test it out with your favourite projects and report any issues.</p><p>The deadline for the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094371.html">EuroLLVM call for papers</a> is today.</p><p>Version 1.6 of the Rust programming language <a href="http://blog.rust-lang.org/2016/01/21/Rust-1.6.html">was released</a> las week. Rust uses LLVM for its code generation.</p><p>The LLVM Social in Paris <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094370.html">will be held this week</a> on Wednesday.</p><h3>On the mailing lists</h3><ul><li><p>Quentin Colombet has posted an RFC <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094426.html">asking for views on adding a kind of MachineModulePass</a>. Questions include who would be interested and why. John Criswell's <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094444.html">response</a> includes some interesting use-cases.</p></li><li><p>Eduard-Mihai Burtescu has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094204.html">making byval argument passing work with opaque pointers</a>.</p></li><li><p>Quentin Colombet has posted an RFC seeking opinions on the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094411.html">contract between LLVM IR and the backends for instruction selection</a>. In particular, should backends be able to perform instruction selection on any valid LLVM IR. Several people have fed back that in practical terms, a backend doesn't need to be able to select any instruction as long as it provides IR to IR transformations that can perform necessary modifications prior to instruction selection.</p></li><li><p>Jonas Wagner is looking for feedback on how to support <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094192.html">self-modifying branches in LLVM</a>. The thread contained some interesting discussion about the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094340.html">cost of well-predicted branches</a>. It would certainly seem worthwhile to delve deeper to see how much of the overhead is due to limitations in LLVM's basic block at-a-time instruction scheduler.</p></li><li><p>Philip Reames has written to the list to warn users of the RewriteStatePointsForGC <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094411.html">that there are currently issues expressing arbitrary exceptional control flow</a>. The thread discusses some potential solutions to the current issues.</p></li><li><p>Ed Maste has been working to use libunwind in FreeBSD's base system, and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094202.html">queries its stack usage</a>. LLVM's libunwind allows for 120 saved registers on all architectures, while in contrast the GCC unwinder has a target-dependent maximum (it's 18 on x86-64).</p></li></ul><h3>LLVM commits</h3><ul><li><p><code>llvm::SplitModule</code> gained a new flag which can be used to cause it to attempt to split the module without globalizing local objects. <a href="http://reviews.llvm.org/rL258083">r258083</a>.</p></li><li><p>The WebAssembly backend will now rematerialize constants with multiple uses rather than holding them live in registers, as there is no code size saving in using registers in for constants in most cases in the WebAssembly encoding. <a href="http://reviews.llvm.org/rL258142">r258142</a>.</p></li><li><p>Some small patches from the global instruction selection effort have started to land, such as the introduction of a generic machine opcode for ADD (<code>G_ADD</code>) and the all-important CMake support for building it. <a href="http://reviews.llvm.org/rL258333">r258333</a>, <a href="http://reviews.llvm.org/rL258344">r258344</a>.</p></li><li><p><code>getCacheLineSize</code> was added to TargetTransformInfo. It's currently only used by PPCLoopDataPrefetch. <a href="http://reviews.llvm.org/rL258419">r258419</a>.</p></li><li><p>LoopIdiomRecognize improved in its ability to recognise memsets. <a href="http://reviews.llvm.org/rL258620">r258620</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A number of new AST matchers were added. <a href="http://reviews.llvm.org/rL258042">r258042</a>, <a href="http://reviews.llvm.org/rL258072">r258072</a>, and more.</p></li><li><p>The LeakSanitizer documentation has been updated with a usage example. <a href="http://reviews.llvm.org/rL258476">r258476</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The new ELF linker gained initial support for MIPS local GOT (global offset table) entries. <a href="http://reviews.llvm.org/rL2583888">r2583888</a>.</p></li><li><p>The LLVM test suite now contains a ClangAnalyzer subdirectory containing tests for the static analyzer. <a href="http://reviews.llvm.org/rL258336">r258336</a>.</p></li></ul>
- LLVM Weekly - #107, Jan 18th 2016https://blog.llvm.org/2016/01/llvm-weekly-107-jan-18th-2016.htmlMon, 18 Jan 2016 05:32:00 +0000https://blog.llvm.org/2016/01/llvm-weekly-107-jan-18th-2016.html<p>Welcome to the one hundred and seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/107">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <p>I have a very exciting piece of non-LLVM news to share this week. On Saturday I proposed to my partner Carrie Anne, and I'm delighted to report that <a href="https://twitter.com/MissPhilbin/status/688452374260744192">she said yes</a>. You may well question if this piece of personal news has any relevance to you, and in response I'd like to highlight just how important Carrie Anne is to this weekly newsletter. For over two years now, I've given up 2-3+ hours of my time every week without fail on evenings and weekends, time we could really be spending together as a couple. Without Carrie Anne's understanding and support LLVM Weekly couldn't exist. 2016 is going to be a very exciting year.</p><h3>News and articles from around the web</h3><p>Registration is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094106.html">now open</a> for EuroLLVM 2016. The conference will be held in Barcelona on March 17th-18th. The call for papers closes on January 25th.</p><p>Registration is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093960.html">open</a> for the Clang/LLVM development sprint to be held on the weekend of Feb 6th/7th at Bloomberg's London and New York offices.</p><p>The next Cambridge LLVM social will be held <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093918.html">on Wednesday 20th January at 7.30pm</a>, and will be colocated with the FreeBSD social.</p><h3>On the mailing lists</h3><ul><li><p>Rui Ueyama has run <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094132.html">benchmarks for every LLD commit</a>. He observes the linker in general is getting slightly slower over time as it gains more functionality, but that no commit seems to increase link time without a justifiable reason.</p></li><li><p>Chris Bieneman has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html">RFC on removing autoconf from the trunk</a>. The proposal is to remove it from the repository on January 26th. There don't seem to be any objections to this timeline so far.</p></li><li><p>Krzystof Parzyszek has shared a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093891.html">description of the recently committed register data-flow framework</a>.</p></li><li><p>Discussion has been ongoing in the thread about global instruction selection, particularly surrounding the semantics of bitcasts on big-endian systems. James Molloy has <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093977.html">posted to clarify the current behaviour</a>.</p></li><li><p>JF Bastien has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093912.html">RFC on supporting non-temporal fencing in LLVM IR</a>.</p></li><li><p>Quentin Colombet is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094049.html">seeking feedback on the best way to map LLVM IR values to MachineInstr values</a> as part of his GlobalISel work.</p></li><li><p>The branch for LLVM 3.8 <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093932.html">has now been created</a>. The first release candidate should some soon.</p></li><li><p>John McCall has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094012.html">enforcing pointer type alignment in Clang</a>. The RFC proposes the following "It is not undefined behavior to create a pointer that is less aligned than its pointee type. Instead, it is only undefined behavior to access memory through a pointer that is less aligned than its pointee type."</p></li><li><p>Philip Reames has posted a note for anyone using RewriteStatepointsForGC. There's been a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094041.html">recent change in the handling of vectors of pointers</a>.</p></li><li><p>Derek Schuff has followed up to the previous discussion about allowing virtual registers after register allocation with <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093952.html">some more thoughts after some offline discussions</a>.</p></li><li><p>Hans de Goede is working on a backend for TGSI (Tungsten Graphics Shader Infrastruture, as used by Gallium) and has a <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093829.html">number of questions</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The ORC JIT API now supports remote JITing over an RPC interface to a separate process. The LLI tool has been updated to use this interface. <a href="http://reviews.llvm.org/rL257305">r257305</a>, <a href="http://reviews.llvm.org/rL257343">r257343</a>.</p></li><li><p>The Hexagon backend gained a target-independent SSA-based data flow framework for representing data flow between physical registers and passes using this to implement register liveness analysis, dead code elimination, and copy propagation. <a href="http://reviews.llvm.org/rL257447">r257447</a>, <a href="http://reviews.llvm.org/rL257480">r257480</a>, <a href="http://reviews.llvm.org/rL257485">r257485</a>, <a href="http://reviews.llvm.org/rL257490">r257490</a>.</p></li><li><p>The documentation on committing code reviewed on Phabricator to trunk has been improved. <a href="http://reviews.llvm.org/rL257764">r257764</a>.</p></li><li><p>WebAssembly gained a prototype instruction encoder and disassembler based on a temporary binary format. <a href="http://reviews.llvm.org/rL257440">r257440</a>.</p></li><li><p>LLVM's MathExtras gained a SaturatingMultiplyAdd helper. <a href="http://reviews.llvm.org/rL257352">r257352</a>.</p></li><li><p>llvm-readobj has much-expanded support for dumping CodeView debug info. <a href="http://reviews.llvm.org/rL257658">r257658</a>.</p></li><li><p>The code that finds code sequences implementing bswap or bitreverse and emits the appropriate intrinsic has been rewritten. <a href="http://reviews.llvm.org/rL257875">r257875</a>.</p></li><li><p>The AMDGPU backend gained a new machine scheduler for the Southern Islands architecture. <a href="http://reviews.llvm.org/rL257609">r257609</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A Python implementation of scan-build has been added. <a href="http://reviews.llvm.org/rL257533">r257533</a>.</p></li><li><p>The 'interrupt' attribute is now supported on x86. <a href="http://reviews.llvm.org/rL257867">r257867</a>.</p></li><li><p>Clang learned to respond to the <code>-fsanitize-stats</code> flag. It can currently only be used with control-flow integrity and allows statistics to be dumped. <a href="http://reviews.llvm.org/rL257971">r257971</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The compiler-rt CMake buildsystem gained experimental support for tvOS and watchOS. <a href="http://reviews.llvm.org/rL257544">r257544</a>.</p></li><li><p>Initial support was added for PPC and the new ELF linker. <a href="http://reviews.llvm.org/rL257374">r257374</a>.</p></li><li><p>The CMake and Lit runners in the LLVM test-suite can now support the integer C and C++ tests from SPEC CPU2006. <a href="http://reviews.llvm.org/rL257370">r257370</a>.</p></li></ul>
- LLVM Weekly - #106, Jan 11th 2016https://blog.llvm.org/2016/01/llvm-weekly-106-jan-11th-2016.htmlMon, 11 Jan 2016 05:15:00 +0000https://blog.llvm.org/2016/01/llvm-weekly-106-jan-11th-2016.html<p>Welcome to the one hundred and sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/106">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <p>Many readers may be interested that last week was the 3rd RISC-V Workshop. You can find slides from the two <a href="http://www.lowrisc.org">lowRISC</a> talks <a href="https://speakerdeck.com/asb/lowrisc-plans-for-risc-v-in-2016">here</a> and <a href="http://riscv.org/workshop-jan2016/Wed1115%20untether_wsong83.pdf">here</a>. You may also want to read my <a href="http://www.lowrisc.org/blog/2016/01/third-risc-v-workshop-day-one/">liveblog of the event</a>.</p><h3>News and articles from around the web</h3><p>The BSD Now podcast recently <a href="http://www.jupiterbroadcasting.com/92191/the-bsd-black-box-bsd-now-122/">interviewed Alex Rosenberg</a> about his work on LLVM/Clang and FreeBSD.</p><p>The folks at QuarksLab have shared a <a href="http://blog.quarkslab.com/clang-hardening-cheat-sheet.html">Clang hardening cheat sheet</a>.</p><p>LLDB 3.8 will <a href="https://groups.google.com/forum/m/#!topic/golang-nuts/pzpNcarQcvo">feature initial Go debugging support</a>.</p><p>The next Paris LLVM Social will be held <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093610.html">on January 27th</a> and includes a talk from John Regehr.</p><p>The next Zurich LLVM Social <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093589.html">will be taking place on January 14th</a>.</p><h3>On the mailing lists</h3><ul><li><p>One long discussion on the lists this week was regarding the design of the new LLD ELF and COFF linkers. Rui Ueyama <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093712.html">notes that they are currently designed as commands instead of libraries</a>. e.g. exit() on failure is considered appropriate. Chandler Carruth argues strongly that <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093760.html">supporting a library interface is important for any project under the LLVM umbrella</a>. There ultimately seems to be agreement that the ability to use the linker as a library is important for some use cases, but also that the person doing the work (Rui) should be able to go about development in the way that makes most sense to him. He intends to focus first on reaching feature parity with the GNU linker, and then look at issues such as the library interface.</p></li><li><p>There's been some discussion in the thread on the new global instruction selection implementation about the <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093739.html">semantics of inttoptr and ptrtoint</a>. Specifically whether the currently specified semantics are appropriate for architectures where converting between integers and pointers is not a no-op. It looks like <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093802.html">Philip Reames, David Chisnall, and others</a> should share an RFC on this issue in the following weeks.</p></li><li><p>Matthew Arsenault asks about <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093662.html">TargetTransformInfo getOperationCost</a>. Hal Finkel <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093670.html">points out</a> the problems Matt is seeing are likely down to there being two cost models. One used for vectorization, and one used for inlining and unrolling.</p></li><li><p>James Byerly has an <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093692.html">interesting question about constraint solving and unspillable register classes</a>. He is targetting a custom, seemingly micro-coded architecture and hasn't received any responses so far.</p></li><li><p>Steve King has shared some thoughts on <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093626.html">adding ISD::OPAQUE to complement ISD::BITCAST</a>.</p></li><li><p>What is the current status of LLDB on Windows? Zachary Turner has <a href="http://lists.llvm.org/pipermail/lldb-dev/2016-January/009248.html">written a summary</a>.</p></li><li><p>Both <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093706.html">Xilinx</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093684.html">Microsoft Research Cambridge</a> are advertising intern positions on LLVM-related projects.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM gained the <code>-print-funcs</code> option which can be used to filter IR printing to only certain functions. <a href="http://reviews.llvm.org/rL256952">r256952</a>.</p></li><li><p>The LLVM ADT library gained a new sum type abstraction for pointer-like types and an abstraction for embedding an integer within a pointer-like type. <a href="http://reviews.llvm.org/rL257282">r257282</a>, <a href="http://reviews.llvm.org/rL257284">r257284</a>.</p></li><li><p>LLVM now recognises the Samsung Exynos M1 core. <a href="http://reviews.llvm.org/rL256828">r256828</a>.</p></li><li><p>InstCombine learned to expose more constants when comparing getelementptrs (GEPs) by detecting when both GEPs could be expressed as GEPs with the same base pointer. <a href="http://reviews.llvm.org/rL257064">r257064</a>.</p></li><li><p>SelectionDAGBuilder will set NoUnsignedWrap for an inbounds getelementptr and for load/store offsets. <a href="http://reviews.llvm.org/rL256890">r256890</a>.</p></li><li><p>AArch64 MachineCombine will now allow fadd and fmul instructions to be reassociated. <a href="http://reviews.llvm.org/rL257024">r257024</a>.</p></li><li><p>Macro emission in DWARFv4 is now supported. <a href="http://reviews.llvm.org/rL257060">r257060</a>.</p></li><li><p>llvm-symbolizer gained the <code>-print-source-context-lines</code> option to print source code around the line. <a href="http://reviews.llvm.org/rL257326">r257326</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang's CMake build system can now perform a multi-stage bootstrap build with profile-guided optimisation. <a href="http://reviews.llvm.org/rL256873">r256873</a>.</p></li><li><p>Clang's command line frontend learned to handle a whole bunch of <code>-fno-builtin-*</code> arguments. <a href="http://reviews.llvm.org/rL256937">r256937</a>.</p></li><li><p>The new ELF LLD linker will now be used for th AMDGPU target. <a href="http://reviews.llvm.org/rL257175">r257175</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The performance of string table construction in the LLD ELF linker has been improved. This improves link time of lld by 12% from 3.50 seconds to 3.08 seconds. <a href="http://reviews.llvm.org/rL257017">r257017</a>.</p></li><li><p>The LLD ELF linker gained support for the AMDGPU target. <a href="http://reviews.llvm.org/rL257023">r257023</a>.</p></li></ul>
- LLVM Weekly - #105, Jan 4th 2016https://blog.llvm.org/2016/01/llvm-weekly-105-jan-4th-2016.htmlMon, 04 Jan 2016 06:07:00 +0000https://blog.llvm.org/2016/01/llvm-weekly-105-jan-4th-2016.html<p>Welcome to the one hundred and fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>Happy new year! This issue marks the second anniversary of LLVM Weekly. It's rather short as the past week has been very quiet, with most LLVM developers seemingly taking a break over the holidays. My colleague Wei Song and myself will be presenting about <a href="http://www.lowrisc.org">lowRISC</a> at the <a href="http://riscv.org/workshop-jan2016.html">3rd RISC-V workshop</a> on Wednesday this week. Do say hi if you're going to be there.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/105">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Sanjoy Das has written a blog post about <a href="http://www.playingwithpointers.com/problem-with-undef.html">issues with LLVM's undef value</a>. Interestingly, he provides an example where undef can actually inhibit optimisations.</p><h3>On the mailing lists</h3><ul><li><p>Devin Coughlin provided a really useful and detailed <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046653.html">guide to how you might implement a lifetime checker in the Clang static analyzer</a>.</p></li><li><p>There's been some questions raised about <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093544.html">what happened to the LLVM/Clang 3.7.1 release</a>. Everything is ready to go, it's just waiting for the release manager to push the button.</p></li><li><p>Rahman Lavaee Mashhadi has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093537.html">experimenting with disabling function alignment</a>. He observes this results in a segfault on some programs, which David Chisnall points out <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093545.html">is because of the C++ ABI using low-bits on pointers</a>.</p></li><li><p>Dan Liew has posted some <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093540.html">feedback on the Arcanist/Phabricator work-flow</a>. This has resulted in a new patch up for review <a href="http://reviews.llvm.org/D15801">improving the LLVM Phabricator documentation</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The <code>-align-all-loops</code> and <code>-align-all-functions</code> arguments have been introduced to force function or loop alignments for testing purposes. <a href="http://reviews.llvm.org/rL256571">r256571</a>.</p></li><li><p>The x86 backend has added intrinsics for reading and writing to the flags register. <a href="http://reviews.llvm.org/rL256685">r256685</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Various Clang classes have been converted to use the TrailingObjects helper. <a href="http://reviews.llvm.org/rL256658">r256658</a>, <a href="http://reviews.llvm.org/rL256659">r256659</a>, and more.</p></li><li><p><code>__readeflags</code> and <code>__writeeflags</code> intrinsics are exposed in Clang. <a href="http://reviews.llvm.org/rL256686">r256686</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>In libcxx, undefined behaviour in <code><list></code> has been fixed for builtin pointer types and support added for the next ABI version. <a href="http://reviews.llvm.org/rL256652">r256652</a>.</p></li></ul>
- LLVM Weekly - #104, Dec 28th 2015https://blog.llvm.org/2015/12/llvm-weekly-104-dec-28th-2015.htmlMon, 28 Dec 2015 07:50:00 +0000https://blog.llvm.org/2015/12/llvm-weekly-104-dec-28th-2015.html<p>Welcome to the one hundred and fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/104">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The <a href="http://llvm.org/devmtg/2016-01/">schedule for the LLVM devroom at FOSDEM</a> has been published. This will be on January 30th 2016 in Brussels at <a href="https://fosdem.org/2016/">FOSDEM</a>.</p><p>Andy Finnell spent some time over the Christmas vacation porting the LLVM Kaleidoscope tutorial to Erlang and has kindly <a href="http://losingfight.com/blog/2015/12/24/christmas-and-compilers/">shared the fruits of his labours</a>.</p><p>Richard Pennington has written another blog post about ELLCC, this time about <a href="http://ellcc.org/blog/?p=26435">using it to cross-compile the Linux kernel for the Raspberry Pi</a>.</p><p>Tim Jones (lecturer at the University of Cambridge Computer Laboratory) has written about the <a href="http://www-dyn.cl.cam.ac.uk/~tmj32/wordpress/alias-analysis-in-helix/">alias analysis used in the HELIX compiler</a>. There's nothing LLVM-specific here, indeed it was implemented using ILDJIT but should be of general interest to compiler developers.</p><h3>On the mailing lists</h3><ul><li><p>Keno Fischer has posted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093535.html">proposal for multi-location debug info support in LLVM IR</a>. This would allow, for instance, modelling when a variable is available either on the stack or in a register.</p></li><li><p>Adam Nemet is proposing to <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093514.html">extend the PowerPC software prefetching pass to work on other targets</a>, specifically AArch64.</p></li><li><p>Russel Wallace asks for <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093486.html">advice on finding all pointers to functions</a>, and had a number of suggestions in response.</p></li><li><p>For a while now, Galina Kistanova has been posting <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093503.html">statistics from the LLVM buildbots</a>. This includes the number of commits for each project, the number of failed builds, and average build time. I haven't linked to it before, so felt I should rectify that.</p></li></ul><h3>LLVM commits</h3><ul><li><p>An initial implementation of an LLVMCodeView library has landed. This implements support for emitting debug info in the CodeView format. <a href="http://reviews.llvm.org/rL256385">r256385</a>.</p></li><li><p>lit has gained support for a per-test timeout which can be set using <code>--timeout=</code>. <a href="http://reviews.llvm.org/rL256471">r256471</a>.</p></li><li><p>All uses of edge wights in BranchProbabilityInfo have been replaced with probabilities. <a href="http://reviews.llvm.org/rL256263">r256263</a>.</p></li><li><p>The LLVM project documentation on patch reviews via Phabricator now has advice on choosing reviewers. <a href="http://reviews.llvm.org/rL256265">r256265</a>.</p></li><li><p>The gc.statepoint intrinsic's return type is now a token type rather than i32. <a href="http://reviews.llvm.org/rL256443">r256443</a>.</p></li></ul><h3>Clang commits</h3><ul> <li><p>ASTtemplateKWAndArgsInfo and ASTTemplateArgumentListInfo have been converted to use the TrailingObjects header. This abstracts away <code>reinterpret_cast</code>, pointer arithmetic, and size calculations needed for the case where a class has some other objects appended to the end of it. <a href="http://reviews.llvm.org/rL256359">r256359</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>Development of LLD's new ELF linker is continuing, with support for new relocations on x86, x86-64, and MIPS. <a href="http://reviews.llvm.org/rL256143">r256143</a>, <a href="http://reviews.llvm.org/rL256144">r256144</a>, <a href="http://reviews.llvm.org/rL256172">r256172</a>, <a href="http://reviews.llvm.org/rL256416">r256416</a>.</p></li></ul>
- LLVM Weekly - #103, Dec 21st 2015https://blog.llvm.org/2015/12/llvm-weekly-103-dec-21st-2015.htmlMon, 21 Dec 2015 11:42:00 +0000https://blog.llvm.org/2015/12/llvm-weekly-103-dec-21st-2015.html<p>Welcome to the one hundred and third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/103">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <p>Regular readers will know about lowRISC, a not-for-profit project a group of us founded aiming to produce a complete open-source System-on-Chip in volume. We've just hit a new milestone with the <a href="http://www.lowrisc.org/blog/2015/12/untethered-lowrisc-release/">untethering of the base SoC</a>. If you're interested in contributing, the blog post contains a number of potential starting points.</p><h3>News and articles from around the web</h3><p>The 6th EuroLLVM conference will be held on March 17th-18th in Barcelona, Spain. The <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093291.html">call for papers</a> is now open and will remain open until January 25th 2016. EuroLLVM CFP </p><p>Chandler Carruth's keynote, "Understanding compiler optimizations" from the Meeting C++ 2015 conference is <a href="https://www.youtube.com/watch?v=FnGCDLhaxKU">now online</a>.</p><p>Richard Pennington has blogged about <a href="http://ellcc.org/blog/?p=26397">bootstrapping LLVM and Clang using pre-compiled ELLCC binaries</a>.</p><p>Bloomberg is going to be holding a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093412.html">weekend Clang and LLVM hackathon</a> in NYC and in London on February 6th and 7th. The event will be open to everyone in the community and Bloomberg will provide space, power, food, beverages, and internet access.They're looking for experienced Clang and LLVM developers to help as mentors.</p><h3>On the mailing lists</h3><ul><li><p>Marshall Clow proposes <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046575.html">dropping support in libc++ for GCC versions prior to 4.7</a>. Eric Fiselier suggests that actually GCC 4.7 and 4.8 have a rather large number of test failures and <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046584.html">4.9 would be a more sensible requirement</a>.</p></li><li><p>Dmitry Polukhin has proposed an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093414.html">RFC on supporting GCC's ifunc attribute</a>. He proposes three potential approaches and feedback so far prefers the second.</p></li><li><p>Easwaran Raman has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093388.html">hotness thresholds in profile-guided optimisation</a>. The proposal attempts to define a way of determining hot blocks that works both for programs with few hot-spots and a long tail of frequently executed blocks.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM IR now supports floating point atomic loads and stores. <a href="http://reviews.llvm.org/rL255737">r255737</a>.</p></li><li><p>New attributes have been introduced: <code>InaccessibleMemOnly</code> (a function may only access memory that is not accessible by the module being compiled) and <code>InaccessibleMemOrArgMemOnly</code> (a function may only access memory that is either not accessible by the module being compiled or is pointed to by its pointer arguments). <a href="http://reviews.llvm.org/rL255778">r255778</a>.</p></li><li><p>The PowerPC backend gained support for soft float operations on ppc32. <a href="http://reviews.llvm.org/rL255516">r255516</a>.</p></li><li><p>The <code>terminatepad</code> instruction has been removed from LLVM IR. <a href="http://reviews.llvm.org/rL255522">r255522</a>.</p></li><li><p>IR call instructions can now take a fast-math flags marker which indicates fast-math flags may allow otherwise unsafe optimisations. <a href="http://reviews.llvm.org/rL255555">r255555</a>.</p></li><li><p>LLVM gained a C++11 ThreadPool in its internal library. It is intended to be used for ThinLTO. <a href="http://reviews.llvm.org/rL255593">r255593</a>.</p></li><li><p>The default set of passes has been adjusted. mem2reg will not be run immediately after globalopt and more scalar optimization passes have been added to the LTO pipeline. <a href="http://reviews.llvm.org/rL255634">r255634</a>.</p></li><li><p>The llvm-profdata tool now supports specifying a weight when merging profile data. This can be used to give more relative importance to one of multiple profile runs. <a href="http://reviews.llvm.org/rL255659">r255659</a>.</p></li><li><p>For CMake builds, a <code>compile_commands.json</code> file will now be generated which tells tools like YouCompleteMe and <code>clang_complete</code> how to build each source file. <a href="http://reviews.llvm.org/rL255789">r255789</a>.</p></li><li><p>The Hexagon VLIW packetizer saw a large update (though unfortunately the changes aren't summarised in the commit message). <a href="http://reviews.llvm.org/rL255807">r255807</a>.</p></li><li><p>A number of LLVM's C APIs have been depreciated: LLVMParseBitcode, LLVMParseBitcodeInContext, LLVMGetBitcodeModuleInContext and LLVMGetBitcodeModule. These have been replaced with new versions of the functions which don't record a diagnostic. <a href="http://reviews.llvm.org/rL256065">r256065</a>.</p></li><li><p>The AVR backend (which is being imported incrementally) gained AVR.td and AVRRegisterInfo.td. <a href="http://reviews.llvm.org/rL256120">r256120</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A new checker has been introduced to detect excess padding in classes and structs. <a href="http://reviews.llvm.org/rL255545">r255545</a>.</p></li><li><p>A new control-flow integrity mode was introduced, cross-DSO CFI allows control flow to be protected across shared objects. It is currently marked experimental. <a href="http://reviews.llvm.org/rL255694">r255694</a>.</p></li><li><p>Clang's CMake build system now supports generating profile data for Clang. <a href="http://reviews.llvm.org/rL255740">r255740</a>, <a href="http://reviews.llvm.org/rL256069">r256069</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>It is now possible to suppress reports from UndefinedBehaviourSanitizer for certain files, functions, or modules at runtime. <a href="http://reviews.llvm.org/rL256018">r256018</a>.</p></li><li><p>The llvm test-suite's CMake+Lit runner gained support for SPEC2000 and SPEC CPU95. <a href="http://reviews.llvm.org/rL255876">r255876</a>, <a href="http://reviews.llvm.org/rL255878">r255878</a>.</p></li></ul>
- LLVM Weekly - #102, Dec 14th 2015https://blog.llvm.org/2015/12/llvm-weekly-102-dec-14th-2015.htmlMon, 14 Dec 2015 04:43:00 +0000https://blog.llvm.org/2015/12/llvm-weekly-102-dec-14th-2015.html<p>Welcome to the one hundred and second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/102">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Version 1.5 of the Rust programming language <a href="http://blog.rust-lang.org/2015/12/10/Rust-1.5.html">has been released</a>. Rust of course uses LLVM as its backend.</p><p>George Balatsouras has written a blog post on <a href="http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html">compiling a project using autotools to LLVM bitcode</a>.</p><h3>On the mailing lists</h3><ul><li><p>Derek Schuff kicked off a discussion about whether <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093172.html">virtual registers should be allowed after register allocation for targets with infinite virtual register sets</a>. For targets such as WebAssembly and NVPTX, it of course doesn't make sense to have a fixed size register file. A number of people raised concerns that using virtual registers after register allocation seems like a hack that could result in difficult corner cases, or suggested that supporting infinite (or at least growable) physical register sets might be an interesting alternative. Matthias Braun gave a really good <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093215.html">summary of the issues</a>.</p></li><li><p>Discussion has continued on adding an HasInaccessibleState attribute. Vaivaswatha Nagaraj summarised the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093108.html">key points of the discussion so far</a> while Joseph Tremoulet <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093139.html">shared some thoughts based on his experience on the Microsoft Phoenix compiler</a>.</p></li><li><p>Alexander Riccio is interested in feedback on his <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046384.html">proposal to integrate more static analysis tests</a>. He's looking to import code published by NIST.</p></li><li><p>Philip Reames has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093237.html">extending atomic loads and stores to floating point and vector types</a>. Feedback appears to be positive.</p></li><li><p>Hans Wennborg has proposed a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093273.html">schedule for the 3.8 release</a>. Under this proposal, 3.8 would be branched on the 13th of January 2016 with a final release targeted for 18th February.</p></li><li><p>Craig Topper has provided a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093239.html">useful description of how patterns are ordered by TableGen</a>.</p></li><li><p>David Li has posted an update detailing <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093170.html">remaining steps for size reduction of profile-guided optimisation</a>.</p></li><li><p>When writing your own backend, how should you handle checking the range of immediates for your assembly parser? Alex Bradbury <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093093.html">explains how</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new minimum spanning tree based method of instrumenting code for profile-guided optimisation was added. This guarantees the minimum number of CFG edges are instrumented. <a href="http://reviews.llvm.org/rL255132">r255132</a>.</p></li><li><p>MatchBSwap in InstCombine will now also detect bit reversals. <a href="http://reviews.llvm.org/rL255334">r255334</a>.</p></li><li><p>Sample-based profile-guided optimisation memory usage has been reduced by 10x by changing from using a DenseMap for sample records to a std::map. <a href="http://reviews.llvm.org/rL255389">r255389</a>.</p></li><li><p>An <code>Instruction::getFunction</code> method was added. It's perhaps surprising this didn't exist before. <a href="http://reviews.llvm.org/rL254975">r254975</a>.</p></li><li><p>FP16 vector instructions defined in ARMv8.2-A are now supported. <a href="http://reviews.llvm.org/rL255010">r255010</a>.</p></li><li><p>The EarlyCSE (common subexpression elimination) pass learned to perform value forwarding for unordered atomics. <a href="http://reviews.llvm.org/rL255054">r255054</a>.</p></li><li><p>Debug info in LLVM IR can now refer to macros. <a href="http://reviews.llvm.org/rL255245">r255245</a>.</p></li><li><p>LLVM's developer policy has been updated to detail the currently accepted C API stability policy and other guidelines. <a href="http://reviews.llvm.org/rL255300">r255300</a>.</p></li><li><p>A massive rework of funclet-oriented exception handling (needed for Windows exceptions) has landed. <a href="http://reviews.llvm.org/rL255422">r255422</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained an option to use the new ThinLTO pipeline. <a href="http://reviews.llvm.org/rL254927">r254927</a>.</p></li><li><p>Hexagon will use the integrated assembler by default. <a href="http://reviews.llvm.org/rL255127">r255127</a>.</p></li><li><p>dllexport and dllimport attributes are now exposed through the libclang API. <a href="http://reviews.llvm.org/rL255273">r255273</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>ThreadSanitizer gained initial support for PPC64. <a href="http://reviews.llvm.org/rL255057">r255057</a>.</p></li></ul>
- LLVM Weekly - #101, Dec 7th 2015https://blog.llvm.org/2015/12/llvm-weekly-101-dec-7th-2015.htmlMon, 07 Dec 2015 03:52:00 +0000https://blog.llvm.org/2015/12/llvm-weekly-101-dec-7th-2015.html<p>Welcome to the one hundred and first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/101">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The implementation of the Swift programming language is <a href="https://swift.org/blog/welcome/">now open source</a>. Rather than being a simple code dump, development will now occur out in the open with <a href="https://swift.org/contributing/">external contributions encouraged</a>. If you haven't already, now might be a good time to watch Joseph Groff and Chris Lattner's <a href="https://www.youtube.com/watch?v=Ntj8ab-5cvE">talk on the Swift Intermediate Language</a>.</p><p>Rui Ueyama <a href="http://blog.llvm.org/2015/11/new-elf-linker-from-llvm-project.html">wrote about the new LLD ELF linker</a> on the official LLVM blog.</p><p>The Visual C++ team have released <a href="http://blogs.msdn.com/b/vcblog/archive/2015/12/04/introducing-clang-with-microsoft-codegen-in-vs-2015-update-1.aspx">Clang with Microsoft CodeGen</a>. This uses the Clang parser along with the code generator and optimizer from Visual C++. The majority of the Clang and LLVM changes will be contributed back upstream.</p><p>Alex Denisov wrote about <a href="http://lowlevelbits.org/how-to-use-llvm-api-with-swift/">using the LLVM API with Swift</a>.</p><p>If you haven't already submitted your talk proposal for the LLVM devroom at FOSDEM, you've now got a little more time. <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/092897.html">Get your submission in by this Friday</a>.</p><h3>On the mailing lists</h3><ul><li><p>Swift team members have started discussions about upstreaming their changes to <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093006.html">LLVM</a>, <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-December/046335.html">Clang</a>, and <a href="http://lists.llvm.org/pipermail/lldb-dev/2015-December/009010.html">LLDB</a>. The Clang changes include the addition of an 'API notes' feature which has seen some interest from other developers. This can be used to associate certain attributes with functions from system headers through an external YAML file, which is of course much more pragmatic than expecting system headers on all supported platforms to be updated.</p></li><li><p>Vaivaswatha Nagaraj observes that <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/092919.html">malloc and realloc don't have the doesNotAccessMemory/onlyReadsMemory attributes set</a>, and that this makes GlobalsAA much less effective. As was pointed out in the ensuing discussion, these attributes wouldn't be correct for malloc and realloc but it would perhaps make sense to add a new attribute. Vaivaswatha <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093008.html">penned an RFC on an HasInaccessibleState attribute</a>. This has generated a lot of discussion and alternate proposals but no conclusion yet.</p></li><li><p>Christof Douma has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093021.html">RFC on adding execute only support to the ARM code generator</a>. This means the compiler will not generate data accesses in to the code section.</p></li><li><p>Oliver Stannard has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/093022.html">RFC on supporting position-independent code on ARM for small embedded systems</a>. In read-only position independence (ROPI), code and read-only data is accessed PC-relative with the offsets known at static link time. In read-write position independence (RWPI), read-write data is accessed relative to the static base register (R9).</p></li><li><p>This week's bikeshedding thread is on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/092876.html">the naming convention for LLVM intrinsics</a>. The proposal is to standardise on using <code>.</code> as a separator. There are some suggestions that <code>_</code> be allowed in words.</p></li><li><p>How can you recompile functions at different optimisation levels? Lang Hames <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-December/092945.html">provides a sample doing this using the Orc API</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>llc and opt gained an option to run all passes twice. This is intended to help show up bugs that occur when using the same pass manager to compile multiple modules. <a href="http://reviews.llvm.org/rL254774">r254774</a>.</p></li><li><p>An initial prototype for llvm-dwp has been committed. This will eventually be a tool for building a DWARF package file out of a number of .dwo split debug files. <a href="http://reviews.llvm.org/rL254355">r254355</a>.</p></li><li><p>All weight-based interfaces in MachineBasicBlock have now been replaced with probability-based interfaces. <a href="http://reviews.llvm.org/rL254377">r254377</a>.</p></li><li><p>LLVM's STLExtras gained a range-based version of <code>std::any_of</code> and <code>std::find</code>. <a href="http://reviews.llvm.org/rL254391">r254391</a>, <a href="http://reviews.llvm.org/rL254390">r254390</a>.</p></li><li><p><code>llvm.get.dynamic.area.offset.{i32,264}</code> intrinsics have been added. These can be used to get the address of the most recent dynamic alloca. <a href="http://reviews.llvm.org/rL254404">r254404</a>.</p></li><li><p>The X86 backend gained a new pass to reduce code size by removing redundant address recalculations for LEA. <a href="http://reviews.llvm.org/rL254712">r254712</a>.</p></li><li><p>The WebAssembly backend now has initial support for varargs. <a href="http://reviews.llvm.org/rL254799">r254799</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Design docs have been added for forward-edge CFI for indirect calls. <a href="http://reviews.llvm.org/rL254464">r254464</a>.</p></li><li><p>The <code>pass_object_size</code> attribute was added to Clang. This intended to be used to work around cases where <code>__builtin_object_size</code> doesn't function. <a href="http://reviews.llvm.org/rL254554">r254554</a>.</p></li><li><p>Documentation was added for UndefinedBehaviorSanitizer. <a href="http://reviews.llvm.org/rL254733">r254733</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLD now supports the <code>R_MIPS_HI16/LO16</code> relocations. <a href="http://reviews.llvm.org/rL254461">r254461</a>.</p></li><li><p>libomp can now make use of libhwloc on Unix to discover topology of the host system. <a href="http://reviews.llvm.org/rL254320">r254320</a>.</p></li></ul>
- New ELF Linker from the LLVM Projecthttps://blog.llvm.org/2015/11/new-elf-linker-from-llvm-project.htmlMon, 30 Nov 2015 07:26:00 +0000https://blog.llvm.org/2015/11/new-elf-linker-from-llvm-project.htmlWe have been working hard for a few months now to rewrite the ELF support in lld, the LLVM linker. We are happy to announce that it has reached a significant milestone: it is now able to bootstrap LLVM, Clang, and itself and pass all tests on x86-64 Linux and FreeBSD with the speed expected of an LLVM project.<br /><br />ELF is the standard file format for executables on Unix-like systems, such as Linux and BSDs. GNU ld and GNU gold are commonly used linkers for such systems today. In many use cases, the linker is a black box for which only speed matters. Depending on program size, linking a program takes from tens of milliseconds to more than a minute. We designed the new linker so that it runs as fast as possible. Although no serious benchmarking or optimization has been conducted yet, it is consistently observed that the new lld links the LLVM/Clang/lld executables in about half the time of GNU gold. Generated executables are roughly the same size. lld is not at feature parity with gold yet, so it is too early to make a conclusion, but we are working hard to maintain or improve lldâs speed while adding more features.<br /><br />lld is command-line compatible with GNU ld so that it can be used as a drop-in replacement. This does not necessarily mean that we are implementing all the features of the GNU linkers in the same way as they did. Some features are no longer relevant for modern Unix-like systems and can be removed. Some other features can be implemented in more efficient ways than those in the traditional linkers. Writing a new linker from scratch is a rare occasion. We take advantage of this opportunity to simplify the linker while keeping compatibility with the existing linkers for normal use.<br /><br />The new ELF linker is a relatively small program which currently consists of about 7000 lines of C++ code. It is based on the same design as the PE/COFF (Windows) support in lld, so the design document for the PE/COFF support is directly applicable to the ELF support.<br /><br />The older ELF support still exists in lld repository in parallel with the new one. Please be careful to not confuse the two. They are separated at the top directory and do not share code. You can run the new linker with ld.lld command or by passing -fuse-ld=lld to Clang when linking.<br /><br />We are still working on implementing remaining functionality such as improved linker script support or improved support for architectures beyond x86_64. If you are interested in the new linker, <a href="http://lld.llvm.org/getting_started.html">try it out for yourself</a>.
- LLVM Weekly - #100, Nov 30th 2015https://blog.llvm.org/2015/11/llvm-weekly-100-nov-30th-2015.htmlMon, 30 Nov 2015 04:41:00 +0000https://blog.llvm.org/2015/11/llvm-weekly-100-nov-30th-2015.html<p>Welcome to the one hundredth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>Eagle-eyed readers will note we've now reached issue 100, marking 100 weeks of uninterrupted service and of course meaning there's just 28 weeks to go until an important numerical milestone.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/100">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>There is going to be an LLVM Devroom at FOSDEM next year and the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092826.html">call for proposals</a> closes on December 1st. Get your submissions in!</p><p>Most slides from the recent LLVM in HPC workshop have <a href="http://llvm-hpc2-workshop.github.io/">now been posted</a>.</p><p>Jeff Trull has posted a great <a href="http://jefftrull.github.io/c++/clang/llvm/fuzzing/sanitizers/2015/11/27/fuzzing-with-sanitizers.html">blog post on fuzzing C++ code with AFL and libFuzzer</a>.</p><h3>On the mailing lists</h3><ul><li><p>The upcoming removal of the autoconf build system came up on the mailing list again. Chris Bieneman explains <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092841.html">the policy on blocking vs non-blocking bugs for this</a>. If you think you're likely to be affected, now is a very good time to kick the tires on CMake.</p></li><li><p>Geoffrey Romer is <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-November/046239.html">interested in adding the ability to customise the behaviour of std::hash</a> and is looking for feedback.</p></li><li><p>Is it possible to use a static base register on ARM rather than PC-relative addressing? Oliver Stannard <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092812.html">has a patch for this</a> which should be upstreamed soon.</p></li><li><p>Rail Shafigulin is looking for information on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092729.html">how slots are assigned for packets in Hexagon</a>. As usual, Krzystof Parzyszek provides some useful answers.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A number of patches related to ARMv8.2-A have landed. Public documentation doesn't seem to have been released for this architecture revision, but the patches indicate some of the new features including: persistent memory instruction and FP16 instructions. You can see the patches still in review <a href="http://reviews.llvm.org/differential/?authors=olista01">here</a>. <a href="http://reviews.llvm.org/rL254156">r254156</a>, <a href="http://reviews.llvm.org/rL254198">r254198</a>.</p></li><li><p>A series of helper functions from SelectionDAGNodes have been exposed (isNullConstant, isNullFPConstant, isAllOnesConstant, isOneConstant). These helpers can help simplify code in your target's ISelLowering. <a href="http://reviews.llvm.org/rL254085">r254085</a>.</p></li><li><p>The WebAssembly backend's block placement algorithm has been improved. <a href="http://reviews.llvm.org/rL253876">r253876</a>.</p></li><li><p>Tests generated from <code>utils/update_llc_test_checks.py</code> are now marked as autogenerated. <a href="http://reviews.llvm.org/rL253917">r253917</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>DataRecursiveASTVisitor has been removed, and RecursiveASTVisitor can be used in its place. This resulted in the removal of 2912 lines of code. <a href="http://reviews.llvm.org/rL253948">r253948</a>.</p></li><li><p>Sparc and SparcV9 default to using an external assembler again. <a href="http://reviews.llvm.org/rL254199">r254199</a></p></li><li><p>Functions with the interrupt attribute are now supported for mips32r2+. <a href="http://reviews.llvm.org/rL254205">r254205</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A single DataFlowSanitizer or ThreadSanitizer-instrumented binary can now run on both 39-bit virtual address space and 42-bit virtual address space AArch64 platforms. <a href="http://reviews.llvm.org/rL254151">r254151</a>, <a href="http://reviews.llvm.org/rL254197">r254197</a>.</p></li><li><p>lldb gained a <code>swig_bot.py</code> for generating bindings. <a href="http://reviews.llvm.org/rL254022">r254022</a>.</p></li></ul>
- LLVM Weekly - #99, Nov 23rd 2015https://blog.llvm.org/2015/11/llvm-weekly-99-nov-23rd-2015.htmlMon, 23 Nov 2015 06:20:00 +0000https://blog.llvm.org/2015/11/llvm-weekly-99-nov-23rd-2015.html<p>Welcome to the ninety-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/99">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM/Clang 3.7.1-rc2 <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092684.html">has been tagged</a>. As always, help testing is appreciated.</p><p>Clasp 0.4 <a href="https://drmeister.wordpress.com/2015/11/20/clasp-0-4-joining-common-lisp-and-cxx/">has been released</a>. Clasp is a new Common Lisp implementation that uses LLVM as a compiler backend and aims to offer seamless C++ interoperation.</p><h3>On the mailing lists</h3><ul><li><p>Quentin Colombet has shared a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092566.html">plan for moving forwards with global instruction selection</a>, as proposed in his <a href="https://www.youtube.com/watch?v=F6GGbYtae3g">Dev Meeting talk</a>. There's a lot of enthusiasm for this work, though some questions about how in practical terms the development should proceed and be tested. There is also hope that this new work will <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092616.html">allow the distinction between integers and pointers to be preserved through to MachineInstructions</a>. This is useful both <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092612.html">for GC</a> and for <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092609.html">architectures where pointers aren't integers</a>.</p></li><li><p>Eric Christopher has shared a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092623.html">summary of discussions from the recent Birds of a Feather discussion on the LLVM C API</a>. This includes proposed policy for stability guarantees and extending the APIs.</p></li><li><p>Ed Maste has been experimenting with <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092572.html">linking the FreeBSD base system with lld</a>. With a few extra patches he's managed to link the whole FreeBSD userland.</p></li><li><p>Artem Dergachev has shared some <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-November/046136.html">minutes from a call about summary-based inter-procedural analysis</a> for Clang's static analyser.</p></li><li><p>Steve King is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092611.html">concerned about recent code size regressions with Os</a>. The issue was <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092675.html">bisected</a> to recent changes to the heuristic for merging conditional stores. James Molloy, who authored the patch in question suggests <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092679.html">more investigation is necessary</a>.</p></li><li><p>Rail Shafigulin is working on a custom VLIW architecture and has had a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092665.html">number</a> <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092467.html">of</a> <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092531.html">questions</a> <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092518.html">about</a> <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092480.html">the</a> DFAPacketizer. Krzysztof Parzyszek has provided useful answers each time - well worth a read of these threads if you're doing any work with VLIW or want to learn more about DFAPacketizer.</p></li><li><p>Nick Johnson pointed out an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092526.html">interesting potential bug in the LiveVariables pass</a>. There haven't been any responses yet, but he has followed up with a <a href="http://reviews.llvm.org/D14875">patch to fix the issue</a>.</p></li><li><p>Amjad Aboud has posted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092551.html">detailed RFC on ensuring LLVM debug info supports all lexically scoped entities</a>. He includes a simple example which shows where block-local typedefs or class definitions can lead to problems.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Initial support for value profiling landed. <a href="http://reviews.llvm.org/rL253484">r253484</a>.</p></li><li><p>It is now possible to use the <code>-force-attribute</code> command-line option for specifying a function attribute for a particular function (e.g. norecurse, noinline etc). This should be very useful for testing. <a href="http://reviews.llvm.org/rL253550">r253550</a>.</p></li><li><p>The WebAssembly backend gained initial prototype passes for register coloring (on its virtual registers) and register stackifying. <a href="http://reviews.llvm.org/rL253217">r253217</a>, <a href="http://reviews.llvm.org/rL253465">r253465</a>.</p></li><li><p>The built-in assembler now treats fatal errors as non-fatal in order to report all errors in a file rather than just the first one encountered. <a href="http://reviews.llvm.org/rL253328">r253328</a>.</p></li><li><p>As <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092238.html">discussed on the mailing list last week</a>, lane masks are now always precise. <a href="http://reviews.llvm.org/rL253279">r253279</a>.</p></li><li><p>Support for prelinking has been dropped. See the commit message for a full rationale. <a href="http://reviews.llvm.org/rL253280">r253280</a>.</p></li><li><p>llvm-lto can now be used to emit assembly rather than object code. <a href="http://reviews.llvm.org/rL253622">r253622</a>, <a href="http://reviews.llvm.org/rL253624">r253624</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang should now be usable for CUDA compilation out of the box. <a href="http://reviews.llvm.org/rL253389">r253389</a>.</p></li><li><p>When giving the <code>-mcpu/-march</code> options to Clang targeting ARM, you can now specify <code>+feature</code>. <a href="http://reviews.llvm.org/rL253471">r253471</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Compiler-rt gained support for value profiling. <a href="http://reviews.llvm.org/rL253483">r253483</a>.</p></li><li><p>The 'new ELF linker' is now the default ELF linker in lld. <a href="http://reviews.llvm.org/rL253318">r253318</a>.</p></li><li><p>The LLVM test suite gained support for running SPEC2000int and SPEC2006int+fp with PGO and reference inputs. <a href="http://reviews.llvm.org/rL253362">r253362</a>.</p></li></ul>
- LLVM Weekly - #98, Nov 16th 2015https://blog.llvm.org/2015/11/llvm-weekly-98-nov-16th-2015.htmlMon, 16 Nov 2015 04:18:00 +0000https://blog.llvm.org/2015/11/llvm-weekly-98-nov-16th-2015.html<p>Welcome to the ninety-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This week's issue comes to you from Vienna where I'm just about to head home from a short break (so apologies if it's a little later than usual and perhaps a little less detailed). I'll admit that nobody has actually written in to beg that LLVM Weekly share travel tips, but I will say that Vienna is a beautiful city that's provided lots to do over the past few days. If you're visiting, I can strongly recommend <a href="http://www.salmbraeu.com/home/">Salm Bräu</a> for good beer and food.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/98">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>All of the <a href="https://www.youtube.com/playlist?list=PL_R5A0lGi1AA4Lv2bBFSwhgDaHvvpVU21">LLVM Dev Meeting Videos</a> are now up, and will stay up. This includes <a href="https://www.youtube.com/watch?v=Ntj8ab-5cvE">Chris Lattner and Joseph Groff's talk on Swift's IR</a>. You can also find most of the slides <a href="http://llvm.org/devmtg/2015-10/slides/">here</a>. The folks at Quarkslab have also <a href="http://blog.quarkslab.com/llvm_dev_meeting.html">posted a trip report</a>.</p><p>The big news this week is that code derived from NVIDIA's PGI Fortran compiler <a href="https://www.llnl.gov/news/nnsa-national-labs-team-nvidia-develop-open-source-fortran-compiler-technology">is to be open-sourced and a production-grade Fortran front-end to LLVM produced</a>. This project is a collaboration between the US NNSA (National Nuclear Security Administration), NVIDIA, and the Lawrence Livermore, Sandia, and Los Alamos national laboratories. Hal Finkel has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092404.html">shared a little more on the LLVM mailing list</a>. With a source code release not due for about another year, where does this leave the existing <a href="https://github.com/llvm-flang/flang">Flang</a> efforts? The hope is that <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092422.html">parts of Flang will be merged with the PGI release</a>. Douglas Miles from the PGI team has also <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092438.html">shared a mini-FAQ</a>. Fortran announcement </p><p>Bjarne Stroustrup has shared a <a href="https://isocpp.org/blog/2015/11/kona-standards-meeting-trip-report">detailed trip report</a> from the last C++ Standards Meeting.</p><p>This post over at the Include Security Blog <a href="http://blog.includesecurity.com/2015/11/LLVM-SafeStack-buffer-overflowprotection.html">delves in to some details of support for the SafeStack buffer overflow protection in LLVM</a>.</p><p>At the official LLVM blog, a new post gives a very useful guide on <a href="http://blog.llvm.org/2015/11/reduce-your-testcases-with-bugpoint-and.html">how to reduce your testcases using bugpoint and custom scripts</a>. As the post notes, bugpoint is a very powerful tool but can be difficult to use.</p><h3>On the mailing lists</h3><ul><li><p>Do you maintain an out-of-tree target? Does your out-of-tree target have a huge number of subregisters and depends on imprecise lanemasks being available? If so, <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092238.html">Matthias Braun wants to hear from you</a>. Speak up now if the proposed change may affect you.</p></li><li><p>Geoff Berry is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092376.html">proposing some more work on devirtualization</a>. In particular, he wants to propagate <code>llvm.assume</code> across function calls. He also asks what else is required to enable Clang's <code>-fstrict-vtable-pointers</code> by default, which <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092384.html">Piotr Padlewski and Richard Smith provide detailed responses to</a>.</p></li><li><p>Cong Hou has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092379.html">adding a vector reduction add instruction</a> to LLVM IR. There hasn't been much feedback yet, but David Li <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092398.html">questions whether the effect could be modelled with simpler instructions/intrinsics</a>.</p></li><li><p>Ben Langmuir has posted an <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-November/045999.html">RFC on whether modules specified in a module map file should shadow implicitly discovered modules</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM's autoconf-based build system is now officially deprecated, with the CMake build system being preferred. <a href="http://reviews.llvm.org/rL252520">r252520</a>.</p></li><li><p>Do you want to compile CUDA code with Clang and LLVM? There's now some <a href="http://llvm.org/docs/CompileCudaWithLLVM.html">handy documentation describing how to do so</a>. See also <a href="https://www.youtube.com/watch?v=JHfb8z-iSYk">Jingyue's talk</a> from the recent LLVM Dev Meeting. <a href="http://reviews.llvm.org/rL252660">r252660</a>.</p></li><li><p>A simple MachineInstruction SSA pass for PowerPC has been added. The implementation is short and straight-forward, so worth a read if you want to do some MI-level peephole optimisations for your target. <a href="http://reviews.llvm.org/rL252651">r252651</a>.</p></li><li><p>Basic support for AArch64's address tagging has been added. In AArch64, the top 8 bits of an address can be used to store extra metadata with these bits being masked out before going through address translation. <a href="http://reviews.llvm.org/rL252573">r252573</a>.</p></li><li><p>The Hexagon backend now supports assembly parsing. <a href="http://reviews.llvm.org/rL252443">r252443</a>.</p></li><li><p>The CMake build system gained a new LLVMExternalProjectUtils module. As an example, this is used with the LLVM test suite which can be set up to be rebuilt whenever the in-tree clang or lld change. This could also be used with compiler-rt or libcxx. <a href="http://reviews.llvm.org/rL252747">r252747</a>.</p></li><li><p>An 'empty token' is now defined (written as <code>token empty</code>) for when using tokens in LLVM IR. <a href="http://reviews.llvm.org/rL252811">r252811</a>.</p></li><li><p>LibFuzzer gained a new experimental search heuristic, drill. As the comment in FuzzerLoop.cpp explains, this will 1) read+shuffle+execute+minimize the corpus, 2) choose a random unit, 3) reset the coverage, 4) start fuzzing as if the chosen unit was the only element of the corpus, 5) reset the coverage again when done, 6) merge the newly created corpus into the original one. <a href="http://reviews.llvm.org/rL252838">r252838</a>.</p></li><li><p>A BITREVERSE SelectionDAG node and a set of <code>llvm.bitreverse.*</code> intrinsics have been introduced. The intention is that backends should no longer have to reimplement similar code to match instruction patterns to their own ISA's bitreverse instruction. See also the patch to the ARM backend that replaces ARMISD::RBIT with ISD::BITREVERSE. <a href="http://reviews.llvm.org/rL252878">r252878</a>, <a href="http://reviews.llvm.org/rL253047">r253047</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Support for <code>__attribute__(internal_linkage)</code> was added. This is much like C's static keyword, but applies to C++ class methods. <a href="http://reviews.llvm.org/rL252648">r252648</a>.</p></li><li><p>Clang now supports GCC's <code>__auto_type</code> extension, with a few minor enhancements. <a href="http://reviews.llvm.org/rL252690">r252690</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>libcxx gained initial support for building with mustl libc. Primarily this is a new CMake option, necessary as Musl doesn't provide a macro to indicate its presense. <a href="http://reviews.llvm.org/rL252457">r252457</a>).</p></li></ul>
- Reduce Your Testcases with Bugpoint and Custom Scriptshttps://blog.llvm.org/2015/11/reduce-your-testcases-with-bugpoint-and.htmlThu, 12 Nov 2015 20:18:00 +0000https://blog.llvm.org/2015/11/reduce-your-testcases-with-bugpoint-and.html<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;"><div style="text-align: left;">LLVM provides many useful command line tools to handle bitcode: <i>opt</i> is the most widely known and is used to run individual passes on an IR module, and <i>llc</i> invokes the backend to generate an assembly or object file from an IR module. Less known but very powerful is <i>bugpoint</i>, the automatic test case reduction tool, that should be part of every developer's toolbox.</div><div style="text-align: left;"><br /></div><div style="text-align: left;">The <i>bugpoint</i> tool helps to reduce an input IR file while preserving some interesting behavior, usually a compiler crash or a miscompile. Multiple strategies are involved in the reduction of the test case (shuffling instructions, modifying the control flow, etc.), but because it is oblivious to the LLVM passes and the individual backend specificities, "it may appear to do stupid things or miss obvious simplifications", as stated in the <a href="http://llvm.org/docs/CommandGuide/bugpoint.html#description">official description</a>. The <a href="http://llvm.org/docs/Bugpoint.html">documentation</a> gives some insights on the strategies that can be involved by <i>bugpoint</i>, but the details are beyond the scope of this post.<br /><br />Read on to learn how you can use the power of bugpoint to solve some non-obvious problems.<br /><br /><a name='more'></a></div><h2 style="text-align: left;">Bugpoint Interface Considered Harmful</h2>Bugpoint is a powerful tool to reduce your test case, but its interface can lead to frustration (as stated in the documentation: "<i>bugpoint can be a remarkably useful tool, but it sometimes works in non-obvious ways</i>"). One of the main issue seems to be that <i>bugpoint</i> is ironically too advanced! It operates under three modes and switches automatically among them to solve different kind of problem: crash, miscompilation, or code generation (see <a href="http://llvm.org/docs/Bugpoint.html">the documentation</a> for more information on these modes). However it is not always obvious to know beforehand which mode will be activated and which strategy <i>bugpoint</i> is actually using.</div><br />I found that for most of my uses, I don't want the <i>advanced</i> <i>bugpoint</i> features that deal with pass ordering for example, and I don't need <i>bugpoint</i> to detect which mode to operate and switch automatically. For most of my usage, the `compile-custom` option is perfectly adequate: similar to<br />`git bisect`, it allows you to provide a script to <i>bugpoint</i>. This script is a black box for <i>bugpoint</i>, it needs to accept a single argument (the bitcode file to process) and needs to return 0 if the bitcode does not exhibit the behavior you're interested in, or a non zero value in the other case. <i>Bugpoint</i> will apply multiple strategies in order to reduce the test case, and will call your custom script after each transformation to validate if the behavior you're looking for is still exhibited. The invocation for <i>bugpoint</i> is the following:<br /><br /><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">$ ./bin/bugpoint -compile-custom -compile-command=./check.sh -opt-command=./bin/opt my_test_case.ll</div><br />The important part is the two options <i>-compile-custom</i> and <i>-compile-command=path_to_script.sh</i> that indicate to <i>bugpoint</i> that it should use your own script to process the file. The other important part is the <i>-opt-command</i> option that should point to the correct <i>opt</i> that will be used to reduce the test case. Indeed by default <i>bugpoint</i> will search in the path for <i>opt</i> and may use an old system one that won't be able to process your IR properly, leading to some curious error message:<br /><br /><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">*** Debugging code generator crash!</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Checking for crash with only these blocks: diamond .preheader .lr.ph .end: error: Invalid type for value</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">simplifycfg failed!</div><div><br /></div>Considering such a script `check.sh`, running it with your original test case this way:<br /><br /><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">$ ./check.sh my_test_case.ll && echo "NON-INTERESTING" || echo "INTERESTING"</div><br />should display <span style="background-color: black; color: whitesmoke; font-family: "monaco"; font-size: 12px;">INTERESTING</span> before you try to use it with bugpoint, or you may very well be surprised. In fact <i>bugpoint</i> considers the script as a compile command. If you start with an <span style="background-color: black; color: whitesmoke; font-family: "monaco"; font-size: 12px;">NON-INTERESTING</span> test case and feed it to <i>bugpoint</i>, it will assume that the code compiles correctly, and will try to assemble it, link it, and execute it to get a reference result. This is where <i>bugpoint</i> behavior can be confusing when it automatically switches mode, leaving the user with a confusing trace. A correct invocation should lead to a trace such as:<br /><br /><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">./bin/bugpoint -compile-custom -compile-command=./check.sh -opt-command=./bin/opt slp.ll </div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Read input file : 'slp.ll'</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">*** All input ok</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Initializing execution environment: Found command in: ./check.sh</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Running the code generator to test for a crash: </div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Error running tool:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> ./check.sh bugpoint-test-program-1aa0e1d.bc</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">*** Debugging code generator crash!</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Checking to see if we can delete global inits: <crash></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">*** Able to remove all global initializers!</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Checking for crash with only these blocks: .lr.ph6.preheader .preheader .lr.ph.preheader .lr.ph .backedge ._crit_edge.loopexit... <11 total>: <crash></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Checking for crash with only these blocks: .preheader .backedge .lr.ph6.preheader: </div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Checking for crash with only these blocks: .lr.ph ._crit_edge: </div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">...</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">...</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Checking instruction: store i8 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @cle, i64 0, i64 15), align 1, !tbaa !2</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">*** Attempting to perform final cleanups: <crash></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">Emitted bitcode to 'bugpoint-reduced-simplified.bc'</div><div><br /></div>In practice the ability to write a custom script is very powerful, I will go over a few use cases I recently used <i>bugpoint</i> with.<br /><h2 style="text-align: left;">Search For a String in the Output</h2>I recently submitted a patch (http://reviews.llvm.org/D14364) for a case where the loop vectorizer didn't kick-in on a quite simple test case. After fixing the underlying issue I needed to submit a test with my patch. The original IR was a few hundred lines. Since I believe it is good practice to reduce test cases as much as possible, bugpoint is often my best friend. In this case the analysis result indicates "Memory dependences are safe with run-time checks" on the output after my patch.<br /><br />Having compiled `opt` with and without my patch and copied each version in `/tmp/` I wrote this shell script:<br /><br /><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"><br /></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">#!/bin/bash</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #c33720; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">/tmp/opt.original </span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-loop-accesses</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-analyze</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> | </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">grep</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">"</span>Memory dependences are safe<span style="color: #ce7924;">"</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;">res_original<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">=</span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$?</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">/tmp/opt.patched <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-loop-accesses</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-analyze</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$1</span> | <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">grep</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">"</span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">Memory dependences are safe</span><span style="color: #ce7924;">"</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;">res_patched<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">=</span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$?</span></div><div style="background-color: black; color: #d53bd3; font-family: Monaco; font-size: 12px; line-height: normal;">[[<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>$res_original<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">==</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">&&</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>$res_patched<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">==</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>]]<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> && </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">exit</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">1</span></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">exit<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span></div><br />It first runs the bitcode supplied as argument to the script (the $1 above) through <i>opt</i> and uses <i>grep</i> to check for the presence of the expected string in the output. When <i>grep</i> exits, <i>$?</i> contains with 1 if the string is <b>not</b> present in the output. The reduced test case is valid if the original <i>opt</i> didn't produce the expected analysis but the new <i>opt</i> did.<br /><h2>Reduce While a Transformation Makes Effects</h2>In another case (http://reviews.llvm.org/D13996), I patched the SLP vectorizer and I wanted to reduce the test case so that it didn't vectorize before my changes but vectorizes after:<br /><br /><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">#!/bin/bash</div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">set<span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-e</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">/tmp/opt.original <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-slp-vectorizer</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-S</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">></span> /tmp/original.ll <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$1</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">/tmp/opt.patched <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-slp-vectorizer</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-S</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">></span> /tmp/patched.ll <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$1</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">diff /tmp/original.ll /tmp/patched.ll && <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">exit</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924;">exit</span> <span style="color: #c33720;">1</span></div><br />The use of a custom script offers flexibility and allows to run any complex logic to decide if a reduction is valid or not. I used it in the past to reduce crashes on a specific assertion and avoiding the reduction leading to a different crash, or to reduce for tracking instruction count regressions or any other metric.<br /><h2>Just Use FileCheck</h2><div>LLVM comes with a <a href="http://llvm.org/docs/CommandGuide/FileCheck.html">Flexible pattern matching file verifier</a> (FileCheck) that the tests are using intensively. You can annotate your original test case and write a script that reduce it for your patch. Let's take an example from the public LLVM repository with commit r252051<i> "</i>[SimplifyCFG] Merge conditional stores<i>".</i> The associated test in the validation is test/Transforms/SimplifyCFG/merge-cond-stores.ll ; and it already contains all the check we need, let's try to reduce it. For this purpose you'll need to process one function at a time, or bugpoint may not produce what you expect: because the check will fail for one function, bugpoint can do any transformation to another function and the test would still be considered "interesting". Let's extract the function test_diamond_simple from the original file:</div><div><br /></div><div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">$ ./bin/llvm-extract -func=test_diamond_simple test/Transforms/SimplifyCFG/merge-cond-stores.ll -S > /tmp/my_test_case.ll</div></div><div><br /></div><div>Then checkout and compile <i>opt</i> for revision r252050 and r252051, and copy them in /tmp/opt.r252050 and /tmp/opt.r252051. The check.sh script is then based on the <i>CHECK</i> line in the original test case:</div><div><br /></div><div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">#!/bin/bash</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;"># Process the test before the patch and check with FileCheck,<br /># this is expected to fail.</div><div style="background-color: black; line-height: normal;"><span style="color: whitesmoke; font-family: "monaco";"><span style="font-size: 12px;">/tmp/opt.r252050 </span></span><span style="color: #d53bd3; font-family: "monaco"; font-size: 12px;">-simplifycfg</span> <span style="color: #d53bd3; font-family: "monaco"; font-size: 12px;">-instcombine</span> <span style="color: #d53bd3; font-family: "monaco"; font-size: 12px;">-phi-node-folding-threshold</span><span style="color: #ce7924; font-family: "monaco"; font-size: 12px;">=</span><span style="color: #c33720; font-family: "monaco"; font-size: 12px;">2</span> <span style="color: #d53bd3; font-family: "monaco"; font-size: 12px;">-S</span> <span style="color: #ce7924; font-family: "monaco"; font-size: 12px;"><</span> <span style="color: #d53bd3; font-family: "monaco";"><span style="font-size: 12px;">$1 | ./bin/FileCheck merge-cons-stores.ll</span></span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;">original<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">=</span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$?</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;"># Process the test after the patch and check with FileCheck,<br /># this is expected to succeed.</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">/tmp/opt.r252051 <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-simplifycfg</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-instcombine</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-phi-node-folding-threshold</span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">=</span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">2</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">-S</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;"><</span> <span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$1 | </span><span style="color: #d53bd3;">./bin/FileCheck merge-cons-stores.ll</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;">patched<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">=</span><span style="color: #d53bd3; font-variant-ligatures: no-common-ligatures;">$?</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;"># The test is interesting if FileCheck failed before and<br /># succeed after the patch.</div><div style="background-color: black; color: #d53bd3; font-family: Monaco; font-size: 12px; line-height: normal;">[[<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>$original<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">!=</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">&&</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>$patched<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">==</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>]]<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> && </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">exit</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">1</span></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">exit<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div></div><div><br /></div><div>I intentionally selected a very well written test to show you both the power of bugpoint and its limitation. If you look at the function we just extracted in <i>my_test_case.ll</i> for instance:</div><div><br /></div><div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; CHECK-LABEL: @test_diamond_simple</div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; This should get if-converted.</div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; CHECK: store</div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; CHECK-NOT: store</div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; CHECK: ret</div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">define</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>@test_diamond_simple<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">* </span>%p<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">* </span>%q<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%a<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%b<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">) {</span></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">entry:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x1</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">icmp</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">eq</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%a</span>, <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>i1<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%no1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%yes1</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">yes1:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">store</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span>* <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%p</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">label</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%fallthrough</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">no1:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z1</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">add</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%a</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">label</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%fallthrough</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">fallthrough:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z2</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">phi</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> [ <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z1</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%no1</span> ], [ <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%yes1</span> ]</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x2</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">icmp</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">eq</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span>, <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>i1<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x2</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%no2</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%yes2</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">yes2:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">store</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">1</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span>* <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%p</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%end</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">no2:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z3</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">sub</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z2</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%end</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;"><br /></span></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">end:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"> <span style="color: #34bbc7;">%z4</span> = <span style="color: #ce7924;">phi</span> <span style="color: #34bd26;">i32</span> [ <span style="color: #34bbc7;">%z3</span>, <span style="color: #34bbc7;">%no2</span> ], [ <span style="color: #c33720;">3</span>, <span style="color: #34bbc7;">%yes2</span> ]</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">ret</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z4</span></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;"></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">}</div></div><div><br /></div><div>The transformation introduced in this patch allows to merge the stores in the true branches <span style="background-color: black; color: #ce7924; font-family: "monaco"; font-size: 12px;">yes1</span> and <span style="background-color: black; color: #ce7924; font-family: "monaco"; font-size: 12px;">yes2</span>:</div><div><br /></div><div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">declare<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">void</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">@f</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">()</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">define</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>@test_diamond_simple<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">* </span>%p<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">* </span>%q<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%a<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%b<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">) {</span></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">entry:</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x1</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">icmp</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">eq</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%a</span>, <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z1</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">add</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%a</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z2</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">select</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i1</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x1</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z1</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x2</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">icmp</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">eq</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span>, <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z3</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">sub</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z2</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z4</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">select</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i1</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x2</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z3</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">3</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%0</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">or</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%a</span>, <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%1</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">icmp</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">eq</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%0</span>, <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>i1<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%3</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%2</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; <label>:2 ; preds = %entry</div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%simplifycfg.merge<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> = </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">select</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%x2<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%z2<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">1</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">store</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%simplifycfg.merge<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">* </span>%p<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">align</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">4</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%3</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: #5330e1; font-family: Monaco; font-size: 12px; line-height: normal;">; <label>:3 ; preds = %entry, %2</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">ret</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%z4</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">}</div></div><div><br /></div><div>The original code seems pretty minimal, the variable and block names are explicit, it is easy to follow and you probably wouldn't think about reducing it. For the exercise, let's have a look at what bugpoint can do for us here:</div><div><br /></div><div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">define</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">void</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>@test_diamond_simple<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">* </span>%p<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%b<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">) {</span></div><div style="background-color: black; color: #ce7924; font-family: Monaco; font-size: 12px; line-height: normal;">entry:</div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i1</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">undef</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">label</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%fallthrough<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">label</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%yes1</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">yes1:</span> <span style="color: #5330e1; font-variant-ligatures: no-common-ligatures;">; preds = %entry</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">store</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span>* <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%p</span></div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">label</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>%fallthrough</div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">fallthrough:</span> <span style="color: #5330e1; font-variant-ligatures: no-common-ligatures;">; preds = %yes1, %entry</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x2</span> = <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">icmp</span> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">eq</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%b</span>, <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">0</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>i1<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%x2</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%end</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;">, </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%yes2</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><br /></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">yes2:</span> <span style="color: #5330e1; font-variant-ligatures: no-common-ligatures;">; preds = %fallthrough</span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;"> <span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">store</span> <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span> <span style="color: #c33720; font-variant-ligatures: no-common-ligatures;">1</span>, <span style="color: #34bd26; font-variant-ligatures: no-common-ligatures;">i32</span>* <span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%p</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">br</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>label<span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;">%end</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: #34bbc7; font-variant-ligatures: no-common-ligatures;"><br /></span></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal; min-height: 16px;"><span style="color: #ce7924;">yes2:</span> <span style="color: #5330e1;">; preds = %yes2, %fallthrough</span></div><div style="background-color: black; color: #34bd26; font-family: Monaco; font-size: 12px; line-height: normal;"><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ce7924; font-variant-ligatures: no-common-ligatures;">ret</span><span style="color: whitesmoke; font-variant-ligatures: no-common-ligatures;"> </span>void</div><div style="background-color: black; color: #34bbc7; font-family: Monaco; font-size: 12px; line-height: normal;"></div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">}</div></div><div><br /></div><div>Bugpoint figured out that the <i>no</i> branches were useless for this test and removed them. The drawback is that bugpoint also has a tendency to introduce <i>undef</i> or <i>unreachable </i>here and there, which can make the test more fragile and harder to understand. </div><h2 style="text-align: left;">Not There Yet: Manual Cleanup</h2><div>At the end of the reduction, the test is small but probably not ready to be submitted with your patch "as is". Some cleanup is probably still needed: for instance bugpoint won't convert invoke into calls, remove metadata, tbaa informations, personality function, etc. We also saw before that bugpoint can modify your test in unexpected way, adding <i>undef</i> or <i>unreachable</i>. Also you probably want to rename the variables to end up with a readable test case.</div><div><br /></div><div>Fortunately, having the <i>check.sh</i> script at hand is helpful in this process, since you can just manually modify your test and run continuously the same command:</div><div><br /></div><div><div style="background-color: black; color: whitesmoke; font-family: Monaco; font-size: 12px; line-height: normal;">$ ./check.sh my_test_case.ll && echo "NON-INTERESTING" || echo "INTERESTING"</div></div><div><br /></div><div>While the result is <span style="background-color: black; color: whitesmoke; font-family: "monaco"; font-size: 12px;">INTERESTING</span> you know you keep having a valid test and you can continue to proceed with your cleanup.</div><div><br /></div><div>Keep in mind that bugpoint can do far more, but hopefully this subset will be helpful to the ones that are still struggling with its command line options.<br /><br />Finally, I'm grateful to Manman Ren for her review of this post.</div></div>
- LLVM Weekly - #97, Nov 9th 2015https://blog.llvm.org/2015/11/llvm-weekly-97-nov-9th-2015.htmlMon, 09 Nov 2015 08:28:00 +0000https://blog.llvm.org/2015/11/llvm-weekly-97-nov-9th-2015.html<p>Welcome to the ninety-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/97">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>A number of slide decks have started appearing from last week's LLVM Dev Meeting. The first set of videos made a brief appearance <a href="https://www.youtube.com/playlist?list=PL_R5A0lGi1AA4Lv2bBFSwhgDaHvvpVU21">here</a> but apparently they weren't ready for distribution and have been taken down again. In the mean time, you might be interested in the slides for: <a href="http://llvm.org/devmtg/2015-10/slides/RobinsonEdwards-LivingDownstreamWithoutDrowning.pdf">Living downstream without drowning</a>, <a href="http://llvm.org/devmtg/2015-10/slides/Beyls-AutomatedPerformanceTrackingOfLlvmGeneratedCode.pdf">Automated performance tracking of LLVM-generated code</a>, <a href="http://llvm.org/devmtg/2015-10/slides/Blaikie-OpaquePointerTypes.pdf">opaque pointer types</a>, and <a href="http://llvm.org/devmtg/2015-10/slides/Blaikie-DebugInfoOnADiet.pdf">debug info on a diet</a>.</p><p>Pyston 0.4 has <a href="http://blog.pyston.org/2015/11/03/102/">been released</a>. It now features a baseline JIT in addition to the LLVM JIT.</p><p>The LLVM-based ELLCC cross-compilation tool chain has had a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091899.html">new release, version 0.1.18</a>. This release has been tested for building the Linux kernel.</p><p>There is going to be an LLVM devroom at FOSDEM 2016. Check <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091906.html">here for the call for papers and participation</a>. The deadline for receiving submissions is December 1st.</p><h3>On the mailing lists</h3><ul><li><p>As loyal LLVM Weekly readers will know, for a long time now there's been a movement to replace autoconf in the LLVM build system with CMake. It's now at the point where Chris Bieneman suggests we should consider <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092150.html">deprecating autoconf</a>. His proposal suggests it is marked deprecated for the 3.8 release and removed after 3.8 branches from the main development tree. This proposal is getting a lot of positive feedback.</p></li><li><p>After a discussion about the spotty use of the <code>DEBUG_TYPE</code> in passes to prefix debug messages, Daniel Berlin makes the suggestion <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091933.html">that a new <code>DEBUG_MSG</code> macro be introduced</a> which will always include the <code>DEBUG_TYPE</code>. Although there are a number of responses indicating how useful they find it when debug messages are prefixed with their source, there doesn't seem to yet be a consensus on whether it's worth replacing all <code>DEBUG(dbgs() << ..)</code> with something like this.</p></li><li><p>George Burgess is <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-November/045935.html">seeking feedback for his proposal on performing nullability analysis in Clang</a>.</p></li><li><p>Richard Diamond has written a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091968.html">proposal on introducing an llvm.blackbox intrinsic</a> with the purpose of explicitly preventing certain optimisations. So far, there's some confusion about exactly what this intrinsic would do, and whether there's an alternative way to achieve the same aims.</p></li><li><p>James Molloy <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092094.html">proposes adding a new norecurse attribute</a>. With no major exceptions, this has actually already been committed. See the commit summary below for more information.</p></li><li><p>David Blaikie is planning to implement an llvm-dwp tool to support building a DWARF package file out of a number of .dwo split debug files. He is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/092035.html">seeking feedback</a> on his plan.</p></li><li><p>Chris Bieneman has been improving support with the CMake build system for bootstrapping a cross-compiler toolchain and has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-November/091916.html">run in to issues involving compiler-rt and bootstrapping builtins</a>. There seems to be some support for the third of the proposed options, splitting the builtins and runtime libraries.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new optimisation was added to SimplifyCFG to merge conditional stores. The commit message notes it has little impact on the standard LLVM test suite, but it apparently causes many changes in a third party suite. <a href="http://reviews.llvm.org/rL252051">r252051</a>.</p></li><li><p>Implicit conversions between ilist iterators and pointers are now disabled. All in-tree code has been updated to use explicit conversions, but out-of-tree developers may need to either revert this patch for now or update their code. <a href="http://reviews.llvm.org/rL252380">r252380</a>.</p></li><li><p>The LoopLoadElimination pass was introduced, which can discover store-to-load forwarding opportunities. <a href="http://reviews.llvm.org/rL251972">r251972</a>, <a href="http://reviews.llvm.org/rL252017">r252017</a>.</p></li><li><p>Work on operand bundles continues with the addition of a <code>data_operand</code> abstraction. <a href="http://reviews.llvm.org/rL252077">r252077</a>.</p></li><li><p>LLVM gained portable helper macros for packed struct definitions. <a href="http://reviews.llvm.org/rL252099">r252099</a>.</p></li><li><p>DebugInfo has been modified so that a reference to a subprogram is stored in function-level metadata rather than subprograms containing a metadata reference to the function they describe. A script to update out-of-tree textual IR is <a href="http://reviews.llvm.org/D14265">attached here</a>. <a href="http://reviews.llvm.org/rL252219">r252219</a>, <a href="http://reviews.llvm.org/rL252268">r252268</a>.</p></li><li><p>The <code>norecurse</code> attribute has been introduced. This indicates the function will never recurse into itself, either directly or indirectly, and can be used to demote global variables to locals. <a href="http://reviews.llvm.org/rL252282">r252282</a>.</p></li><li><p>The <code>notail</code> marker for call instructions was added, which prevents tail or musttail markers being added by the optimizer. <a href="http://reviews.llvm.org/rL252368">r252368</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The idea of 'module file extensions' has been introduced. These add additional information to a module file that can be queried when it's read, allowing tools built on Clang to stash their own data in module files. See <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-October/045740.html">the original mailing list RFC</a> for more details. <a href="http://reviews.llvm.org/rL251955">r251955</a>.</p></li><li><p>Clang now supports the <code>__make_integer_seq</code> template. <code>__make_integer_seq<std::integer_sequence, int, 90000></code> takes 0.25 seconds while <code>std::make_integer_sequence<int, 90000></code> takes so long the patch author didn't wait for it to finish. <a href="http://reviews.llvm.org/rL252036">r252036</a>.</p></li><li><p>The newly-introduced VforkChecker will look for unsafe code in a vforked process. <a href="http://reviews.llvm.org/rL252285">r252285</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB gained an initial Go expression parser. <a href="http://reviews.llvm.org/rL251820">r251820</a>.</p></li><li><p>compiler-rt now supports 32-bit mingw-w64. <a href="http://reviews.llvm.org/rL251928">r251928</a>.</p></li><li><p>Some initial documentation has been written on <a href="http://lldb.llvm.org/adding-language-support.html">adding programming language support to LLDB</a>. <a href="http://reviews.llvm.org/rL251831">r251831</a>.</p></li><li><p>LLDB should now be able to directly launch processors on the iOS simulator. <a href="http://reviews.llvm.org/rL252112">r252112</a>.</p></li></ul>
- LLVM Weekly - #95, Oct 26th 2015https://blog.llvm.org/2015/10/llvm-weekly-95-oct-26th-2015.htmlMon, 26 Oct 2015 08:34:00 +0000https://blog.llvm.org/2015/10/llvm-weekly-95-oct-26th-2015.html<p>Welcome to the ninety-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/95">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The C++ Standardization Committee just finished up their most recent meeting, and STL (Stephan T. Lavavej) has <a href="https://www.reddit.com/r/cpp/comments/3q4agc/c17_progress_update_oct_2015/">provided a useful summary</a>. Herb Sutter has also <a href="http://herbsutter.com/2015/10/25/2568/">posted a trip report</a>.</p><p>The HHVM team have posted an <a href="http://hhvm.com/blog/10205/llvm-code-generation-in-hhvm">update on the status of LLVM code generation in HHVM</a>. They managed to get LLVM to equal the performance of their custom backend, but are not going to deploy the LLVM backend to production for now. They're no longer actively working on the LLVM backend, but hope to ensure it doesn't regress.</p><p>Hal Finkel is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091612.html">proposing an LLVM social in Austin on the evening of November 15th</a>. There should be a high density of LLVM users due to the <a href="http://llvm-hpc2-workshop.github.io/">LLVM in HPC workshop</a>.</p><h3>On the mailing lists</h3><ul><li><p>The biggest discussion this week in the LLVM community is the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091536.html">proposed change to the Apache license</a>. One motivation is that some companies feel blocked from contributing due to the wording in the patent section of the LLVM developer policy, though see the linked message for a full summary. Concerns were raised about the fact that Apache 2 is incompatible with the GPLv2 and that <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091642.html">license complexity may put off contributors, such as the FreeBSD community</a>.</p></li><li><p>Robert Cox has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091687.html">RFC on adding the ability for LLVM to produce an inlining report</a>. This report would give details on where inlining has taken place and why. Initial feedback is positive.</p></li><li><p>More information for birds of a feather sessions at the upcoming LLVM dev meeting has gone out. Kristof Beyls is running one on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091736.html">performance tracking and benchmarking infrastructure</a>, John Criswell on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091552.html">sophisticated program analysis on LLVM IR</a>, and Paul Robinson on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091546.html">living downstream without drowning</a>.</p></li><li><p>Gaël Jobin has a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091685.html">fantastic answer</a> to a question about handling intrinsics in your backend.</p></li><li><p>Louis Brandy is a Facebook employee who is <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-October/045706.html">starting to work on enabling Clang module support for their C++ codebase</a>. He's interested in experiences from anyone on incrementally adding module maps to a large codebase.</p></li><li><p>A lot of work has been done to extend Clang's static analyzer to support interprocedural analysis. This thread <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-October/045665.html">discusses the current state and path forward</a>. It's not giving the improvement expected (in terms of detected bugs-per-second) and the thread discusses thoughts on why.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The <code>TargetLowerBase::LibCall</code> LegalizeAction has been introduced. This allows backends to control whether they prefer expansion or conversion to a libcall. <a href="http://reviews.llvm.org/rL250826">r250826</a>.</p></li><li><p>The Hexagon backend continues to accumulate sophisticated target-specific optimisations. HexagonBitSimplify continues a number of transformations to perform simplifications, redundant code elimination etc. <a href="http://reviews.llvm.org/rL250868">r250868</a>.</p></li><li><p>The new AliasAnalysis infrastructure gained an optional 'external' AA wrapper pass, to allow users to merge in external AA results. The unit test included in the patch gives a good example of how to use this. <a href="http://reviews.llvm.org/rL250894">r250894</a>.</p></li><li><p>CodeGenPrepare can now transform select instructions into branches and sink expensive operands. <a href="http://reviews.llvm.org/rL250743">r250743</a>.</p></li><li><p>Loop rotation can now use profile data in making decisions during MachineBlockPlacement. <a href="http://reviews.llvm.org/rL250754">r250754</a>.</p></li><li><p>ValueTracking now has a <code>isKnownNonEqual</code> predicate. <a href="http://reviews.llvm.org/rL251012">r251012</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Basic (currently parsing and basic semantic analysis) support for the anticipated C++1z coroutine feature was added. <a href="http://reviews.llvm.org/rL250980">r250980</a>, <a href="http://reviews.llvm.org/rL250985">r250985</a>, <a href="http://reviews.llvm.org/rL250993">r250993</a>.</p></li><li><p><code>-fvisibility=internal</code> is now aliased to <code>-fvisibility=hidden</code>, as LLVM doesn't currently support internal visibility. <a href="http://reviews.llvm.org/rL250954">r250954</a>.</p></li><li><p>Clang's static analyzer learnt to associate hashes with found issues. This hash aims to be resilient to code changes, so should be useful for suppressing false positives. <a href="http://reviews.llvm.org/rL251011">r251011</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lld gained support for lazy relocations on x86-64. <a href="http://reviews.llvm.org/rL250808">r250808</a>.</p></li><li><p>The new LLD ELF linker now supports the <code>--gc-sections</code> parameter. This increases the time to link Clang by 8% bus reduces the size of the output binary by 4%. <a href="http://reviews.llvm.org/rL251043">r251043</a>.</p></li><li><p>LLDB gained a REPL. <a href="http://reviews.llvm.org/rL250753">r250753</a>, <a href="http://reviews.llvm.org/rL250773">r250773</a>.</p></li><li><p>DWARF parsing in LLDB can now be multi-threaded, which can drastically incrase the speed of loading debug info. <a href="http://reviews.llvm.org/rL251106">r251106</a>.</p></li></ul>
- LLVM Weekly - #94, Oct 19th 2015https://blog.llvm.org/2015/10/llvm-weekly-94-oct-19th-2015.htmlMon, 19 Oct 2015 03:53:00 +0000https://blog.llvm.org/2015/10/llvm-weekly-94-oct-19th-2015.html<p>Welcome to the ninety-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or @llvmweekly or @asbradbury on Twitter.</p><p>A good time was had by all at <a href="http://openrisc.io/orconf/">ORConf</a> last week at CERN. We had over 100 open source hardware enthusiasts join us in Geneva. You can find my <a href="https://speakerdeck.com/asb/an-update-on-the-lowrisc-open-source-system-on-chip">slides updating on lowRISC here</a>. Videos should appear on youtube in the next week or so.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/94">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>A <a href="https://github.com/dotnet/llilc/blob/master/Documentation/llilc-at-six-months.md">six month retrospective of LLILC</a>, the project to produce an open source LLVM-based compiler for .NET, has been posted. It describes work still to be done for garbage collection and exception handling, code size and code quality, and JIT throughput.</p><p>The <a href="http://devmtg15.llvm.org/">schedule for the 2015 LLVM Developers' Meeting</a> is now available.</p><p>The new ELF linker in LLD is <a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151005/304675.html">looking pretty fast</a>. Right now it can link Clang in about half the time of binutils gold. However, the resulting binary is larger. It will be interesting to see how the performance compares when both are at feature parity, but this is looking promising.</p><h3>On the mailing lists</h3><ul><li><p>Chandler Carruth, on behalf of the board of the LLVM Foundation has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091218.html">RFC on introducing an LLVM Community Code of Conduct</a>. The proposal is based on the Django code of conduct and generated masses of discussion. A couple of days later, Chandler posted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091408.html">second draft</a> incorporated feedback and answering many of the questions raised. The response appears to be good so far. I'll just highlight one of the questions and answers: "Q: Is this trying to change how the community behaves?" "A: I think the resounding answer is no, this is very much meant to formalize the existing extremely polite and respectful behavior that the LLVM community has had for many years."</p></li><li><p>There is going to be a birds of a feather section about the future of LLVM's C APIs at the upcoming LLVM developers' meeting, and Justin Bogner has helpfully shared <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-October/045610.html">some notes in preparation for this</a>.</p></li><li><p>Philip Reames has shared some <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091457.html">suggested topics for the managed languages birds of a feather meeting at the upcoming LLVM devmeeting</a>. Joe Ranieri <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091492.html">suggests some additional topics</a>.</p></li><li><p>Chris Matthews has shared an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091454.html">adding background workers to LNT</a>.</p></li><li><p>Diego Novillo is going to be hosting a birds of a feather on profile-guided optimisations at the upcoming dev meeting and <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091478.html">has shared a preliminary list of topics for discussion</a>.</p></li><li><p>Sanjoy Das has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091434.html">updated us on his work with operand bundles and gc transition arguments</a>, and is seeking input and opinions on his suggested ways forward.</p></li><li><p>Zachary Turner has <a href="http://lists.llvm.org/pipermail/lldb-dev/2015-October/008538.html">written about his efforts to support Python 3 with LLDB</a>.</p></li><li><p>Evgenii Stepanov has posted an <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-October/045580.html">RFC on adding an internal linkage attribute</a>. The message explains why setting <code>always_inline</code> and hidden symbol visibility is not enough.</p></li><li><p>Arch Robison initiated a discussion on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091395.html">extending the SLP vectorizer to work with tuples in Julia</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Hexagon gained a new pass to merge adjacent stores. <a href="http://reviews.llvm.org/rL250542">r250542</a>.</p></li><li><p>Hexagon gained skeleton support for the 'HVX' extension instructions. <a href="http://reviews.llvm.org/rL250600">r250600</a>.</p></li><li><p>The loop vectorizer will now shrink integer operations into the smallest type possible. <a href="http://reviews.llvm.org/rL250032">r250032</a>.</p></li><li><p>Documentation has been added for binary sample profile encoding. <a href="http://reviews.llvm.org/rL250309">r250309</a>.</p></li><li><p>RewriteStatpointsForGC is starting to make use of operand bundles. <a href="http://reviews.llvm.org/rL250489">r250489</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained support for the <code>-fdebug-prefix-map=</code> option as in GCC. <a href="http://reviews.llvm.org/rL250094">r250094</a>.</p></li><li><p>The PS4 toolchain definition has been added to Clang. <a href="http://reviews.llvm.org/rL250262">r250262</a>.</p></li><li><p>Clang now understands <code>-flto=thin</code>. <a href="http://reviews.llvm.org/rL250398">r250398</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The libc++ testing guide has been updated. <a href="http://reviews.llvm.org/rL250323">r250323</a>.</p></li><li><p>LLD got even faster at linking clang. <a href="http://reviews.llvm.org/rL250315">r250315</a>.</p></li><li><p>LLDB gained preliminary NetBSD support. <a href="http://reviews.llvm.org/rL250146">r250146</a>.</p></li></ul>
- LLVM Weekly - #93, Oct 12th 2015https://blog.llvm.org/2015/10/llvm-weekly-93-oct-12th-2015.htmlMon, 12 Oct 2015 11:14:00 +0000https://blog.llvm.org/2015/10/llvm-weekly-93-oct-12th-2015.html<p>Welcome to the ninety-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>Apologies that this week's issue comes rather late in the day, my laptop gave up the ghost over the weekend while I was travelling leaving me with no way to write it. Now I'm back, I've managed to dust off an old desktop from my closet to write this issue (and to keep my unbroken streak). LLVM Weekly has been sent out every Monday since it started on the first Monday of January 2014. This weekend I was talking about <a href="http://www.lowrisc.org">lowRISC</a> at <a href="http://openrisc.io/orconf/">ORConf 2015</a>. You can find my slides <a href="https://speakerdeck.com/asb/an-update-on-the-lowrisc-open-source-system-on-chip">here</a>. There was a wide array of talks on open source hardware, including many on lowRISC and RISC-V. The videos should hopefully be posted in the next week or so.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/93">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The LLVM project has hit 250,000 commits. The commit that managed to hit this milestone was <a href="http://reviews.llvm.org/rL250000">this one-liner</a>.</p><p>A <a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Introduction%20to%20type%20and%20resource%20safety.pdf">new paper</a> by Bjarne Stroustrup, Herb Sutter, and Gabriel Dos Reis gives more details on their plans for memory safety in C++.</p><p>Videos from CppCon2015 are <a href="https://www.youtube.com/playlist?list=PLHTh1InhhwT75gykhs7pqcR_uSiG601oh">being posted to Youtube</a>.</p><h3>On the mailing lists</h3><ul><li><p>Ed Maste is taking a look at the feasibility of using the new LLD ELF linker for FreeBSD, and has shared <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091072.html">his initial findings</a>.</p></li><li><p>When is addrspacecast needed? Both <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091062.html">David Chisnall</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091063.html">Mats Petersson</a> have good answers.</p></li><li><p>Vedant Kumar has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091169.html">cleaning up the way optional Function data is stored</a>.</p></li><li><p>Dehao Chen has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091162.html">update on the AutoFDO project</a>, which allows the use of a perf.data profile for profile-guided optimisation. Clang built with <code>-fprofile-sample-use</code> is about 10% faster than Clang built with <code>-O3</code>.</p></li><li><p>Larisse Voufo has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091178.html">shared</a> a proposal for optimizing const C++ objects in LLVM.</p></li><li><p>Chris Matthews has announced <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/091140.html">the open-sourcing of an llvm bisect tool</a>, for bisecting bugs using prebuilt LLVM and Clang revisions.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The Hexagon architecture gained an early if-conversion pass. <a href="http://reviews.llvm.org/rL249423">r249423</a>.</p></li><li><p>ThinLTO has started to land, in particular support for function summary index bitcode sections and files. <a href="http://reviews.llvm.org/rL249270">r249270</a>.</p></li><li><p>Codegen for ARM's memcpy intrinsic has been modified to make better use of LDM/STM. <a href="http://reviews.llvm.org/rL249322">r249322</a>.</p></li><li><p>The llvm.eh.exceptioncode intrinsic was added. <a href="http://reviews.llvm.org/rL249492">r249492</a>.</p></li><li><p>It is now possible to turn off MMX support without disabling SSE. <a href="http://reviews.llvm.org/rL249731">r249731</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The policy for adding new style options to clang-format has been documented. <a href="http://reviews.llvm.org/rL249289">r249289</a>.</p></li><li><p>The libclang bindings have been extended with accessors for C++ function attributes (pure virtual, virtual, or const). <a href="http://reviews.llvm.org/rL250008">r250008</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>GoLanguageRuntime was introduced to LLDB, which supports finding the runtime type for Go interfaces. <a href="http://reviews.llvm.org/rL249456">r249456</a>, <a href="http://reviews.llvm.org/rL249459">r249459</a>.</p></li><li><p>The new LLD ELF linker now supports the <code>--as-needed</code> option. <a href="http://reviews.llvm.org/rL249998">r249998</a>.</p></li><li><p>LLDB for MIPS is now able to emulate microMIPS instructions. <a href="http://reviews.llvm.org/rL249381">r249381</a>.</p></li><li><p>liblldb is working towards being able to work under both Python 2.x and 3.x. <a href="http://reviews.llvm.org/rL249886">r249886</a>.</p></li></ul>
- LLVM Weekly - #92, Oct 5th 2015https://blog.llvm.org/2015/10/llvm-weekly-92-oct-5th-2015.htmlMon, 05 Oct 2015 05:32:00 +0000https://blog.llvm.org/2015/10/llvm-weekly-92-oct-5th-2015.html<p>Welcome to the ninety-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/92">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Most of the presentation materials from CppCon2015 are <a href="https://github.com/CppCon/CppCon2015">now online</a>. Talks that may be of particular interest include <a href="https://github.com/CppCon/CppCon2015/blob/master/Presentations/Beyond%20Sanitizers/Beyond%20Sanitizers%20-%20Kostya%20Serebryany%20-%20CppCon%202015.pdf">Kostya Serebryany on fuzzing with libFuzzer</a>, <a href="https://github.com/CppCon/CppCon2015/blob/master/Lightning%20Talks%20and%20Lunch%20Sessions/C++%20devirtualization%20in%20clang/C++%20devirtualization%20in%20clang%20-%20Piotr%20Padlewski%20-%20CppCon%202015.pdf">Piotr Padlewski on C++ devirtualization in Clang</a>, and <a href="https://github.com/CppCon/CppCon2015/blob/master/Presentations/C++%20on%20the%20Web/C++%20on%20the%20Web%20-%20JF%20Bastien%20-%20CppCon%202015.pdf">JF Bastien talking about C++ on the web</a>.</p><p>Rafael EspÃndola wrote in to share an impressive milestone for the new LLD ELF linker. It can now link itself and all of LLVM and Clang (though not all tests pass, and you must use <code>LLVM_ENABLE_THREADS=OFF</code>). Things will of course get really interesting once LLD matures if it can compete with Gold in terms of speed.</p><p>The next Paris LLVM social will <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090813.html">take place on October 15th</a>. Calixte Denizet will be talking about Scilab's usage of LLVM.</p><h3>On the mailing lists</h3><ul><li><p>David Li has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090860.html">update on efforts to reduce the overhead of profile-guided optimisation size overhead</a>. He's produced an initial implementation of one of the proposals, which reduces the size of a release clang binary with coverage mapping from 986MB to 569MB.</p></li><li><p>It's a new month, so time for a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/090958.html">new update on CMake's ability to replace autoconf in LLVM</a>. As Chris says, we're getting very close now.</p></li><li><p>Tom Stellard has posted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/090992.html">proposed release schedule for LLVM/Clang 3.7.x</a> point releases. The deadline to propose patches for 3.7.1 is November 2nd and November 30th for 3.7.2. Tom is also asking that people nominate patches using Phabricator rather than email.</p></li><li><p>Renato has kicked off a discussion on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-October/090945.html">buildbot noise</a> with a good summary of the issues and potential ways forward.</p></li><li><p>Chris Matthews is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090840.html">looking for feedback on how people are using orders in LNT</a>, so as to better understand how to improve things. As he explains, the 'Order' is the SVN revision of the compiler.</p></li><li><p>Jeroen Ketema is asking if anyone has any <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090826.html">objections to a change to ARM's NEON vld and vst intrinsics</a>. The change would allow an address space to be associated with the pointer these intrinsics take.</p></li><li><p>Jonas Paulsson is curious about <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090845.html">how to control selection of two-address vs three-address instruction forms</a>. Several responses suggest just allowing three-address forms to be selected and have a late pass that converts to the two-address form where possible. Jonas has an interesting followup questions as to whether the register allocator will produce the maximum number of opportunities for this conversion.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A scheduler for the MIPS P5600 processor landed. <a href="http://reviews.llvm.org/rL248725">r248725</a>.</p></li><li><p>Align metadata for the load instruction was introduced. <a href="http://reviews.llvm.org/rL248721">r248721</a>.</p></li><li><p>Support for windows exception handling continues with support in AsmPrinter for 'funclets'. <a href="http://reviews.llvm.org/rL248824">r248824</a>.</p></li><li><p>Support landed for the HHVM JIT calling convention. <a href="http://reviews.llvm.org/rL248832">r248832</a>.</p></li></ul><h3>Clang commits</h3><ul><li>clang-format's <code>#include</code> sorting functionality has been extended. <a href="http://reviews.llvm.org/rL248782">r248782</a>.</li></ul><h3>Other project commits</h3><ul><li><p>The new ELF linker gained initial support for MIPS. <a href="http://reviews.llvm.org/rL248779">r248779</a>.</p></li><li><p>Some basic linker script support was added to the new ELF linker, enough to parse Linux's libc.so. <a href="http://reviews.llvm.org/rL248918">r248918</a>.</p></li><li><p>.ARM.exidx and .ARM.extab unwind information is now supported by lldb. <a href="http://reviews.llvm.org/rL248903">r248903</a>.</p></li></ul>
- LLVM Weekly - #91, Sep 28th 2015https://blog.llvm.org/2015/09/llvm-weekly-91-sep-28th-2015.htmlMon, 28 Sep 2015 04:16:00 +0000https://blog.llvm.org/2015/09/llvm-weekly-91-sep-28th-2015.html<p>Welcome to the ninety-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/91">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Some slides and videos from cppcon have started to appear. See the <a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Stroustrup%20-%20CppCon%202015%20keynote.pdf">slides from Bjarne Stroustrup's keynote</a> (which focus on the <a href="https://github.com/isocpp/CppCoreGuidelines">Core Guidelines</a> project), as well as Herb Sutter's slides on <a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Sutter%20-%20CppCon%202015%20day%202%20plenary%20.pdf">supporting ownership annotations in C++</a> (this will be familiar to anyone who has used Rust). Videos are starting to appear <a href="https://www.youtube.com/playlist?list=PLHTh1InhhwT75gykhs7pqcR_uSiG601oh">on the CppCon Youtube channel</a>.</p><p>A Microsoft blog says something about <a href="http://blogs.msdn.com/b/vcblog/archive/2015/09/25/rejuvenating-the-microsoft-c-c-compiler.aspx">their plans to rejuvenate MSVC</a>. "We will continue to invest in improving our compiler with a goal towards making it fully standards compliant".</p><h3>On the mailing lists</h3><ul><li><p>Jason Kim has posted a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090731.html">summary of a recent in-person meeting about ThreadSanitizer, Android, and AARch64</a>.</p></li><li><p>Chris Matthews is planning to work on improving performance change tracking in LNT, and has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090616.html">RFC on his plans</a>.</p></li><li><p>The discussion/debate in the 'trouble with triples' thread has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090665.html">rumbled on</a>. There's been a <em>lot</em> of in-depth discussion, which I'm afraid I don't have the time to study and try to summarise fairly. Do dive in if this topic is important to you. Otherwise, I hope we'll see a summary/RFC once a way forward is found.</p></li><li><p>Jia-Ju Bai is looking for <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090671.html">a way to extract basic loop information from LLVM IR</a>. There's a good range of suggested starting points: <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090672.html">LoopInfoWrapperPass</a>, <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090673.html">ScalarEvolution</a>, <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090717.html">InductiveRangeCheckElimination</a>, and <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090720.html">Polly</a>.</p></li><li><p>Wolfgang Pieb is interested in <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090610.html">extending the liveness of the 'this' pointer for a better debugging experience</a>. His question is whether there's a better way of doing this than creating a new 'fake use' intrinsic. Kevin Smith suggests always storing the 'this' pointer in memory, but Wolfgang <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090644.html">is concerned about the overhead of this approach</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The AArch64 machine reassociation code has been refactored to be target-independent. <a href="http://reviews.llvm.org/rL248164">r248164</a>.</p></li><li><p>LLVM's SafeStack now supports Android. <a href="http://reviews.llvm.org/rL248405">r248405</a>.</p></li><li><p>A new target hook has been added for optimizing register copies. <a href="http://reviews.llvm.org/rL248478">r248478</a>.</p></li><li><p>Operand bundles are now supported for CallInst and InvokeInst. Initial support was also added to LLVM bitcode. <a href="http://reviews.llvm.org/rL248527">r248527</a>, <a href="http://reviews.llvm.org/rL248551">r248551</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The iOS/OSX localizability checks have been improved. <a href="http://reviews.llvm.org/rL248350">r248350</a>.</p></li><li><p>Some more PS4 toolchain code landed. <a href="http://reviews.llvm.org/rL248546">r248546</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The new ELF linker should now be able to create binaries for FreeBSD. <a href="http://reviews.llvm.org/rL248554">r248554</a>.</p></li><li><p>The new ELF linker gained initial AArch64 support. <a href="http://reviews.llvm.org/rL248641">r248641</a>.</p></li></ul>
- LLVM Weekly - #90, Sep 21st 2015https://blog.llvm.org/2015/09/llvm-weekly-90-sep-21st-2015.htmlMon, 21 Sep 2015 05:10:00 +0000https://blog.llvm.org/2015/09/llvm-weekly-90-sep-21st-2015.html<p>Welcome to the ninetieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/90">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The ISO C++ committee have started putting together a set of <a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md">C++ Core Guidelines</a>. The document describes itself as a set of guidelines for using C++ well, with the intention that adherence to the rules could be checked by an analysis tool. Bjarne Stroustrup and Herb Sutter are acting as editors for this project.</p><p>A reddit user has posted a <a href="https://www.reddit.com/r/gamedev/comments/3lh0ba/using_clang_to_generate_c_reflection_data/">detailed description of how they use libclang to generate reflection data for C++</a>.</p><p>Andrew Chambers has written a blog post about his use of <a href="http://achacompilers.blogspot.co.uk/2015/09/calling-conventions-are-hard-fuzz-them.html">fuzzing to look for ABI bugs</a>.</p><p>This <a href="http://www.kdab.com/use-static-analysis-improve-performance/">short and sweet blog post</a> introduces the <a href="https://quickgit.kde.org/?p=scratch%2Fsmartins%2Fclazy.git">clazy static checker</a>, a simple checker for some common suboptimal uses of Qt types. There are plenty of ideas in the comments for further analyses that might be useful.</p><h3>On the mailing lists</h3><ul><li><p>The discussion on 'the trouble with triples' <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090432.html">has resumed</a>. Both <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090437.html">Daniel Sanders</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090439.html">Renato Golin</a> give examples of the kind of problems they're dealing with (yet again, naming things proves to be one of the great challenges in CS).</p></li><li><p>Escha has been looking at <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090371.html">optimising passes using 'side-data'</a>. This might mean e.g. making use of a spare bit in Value to indicate liveness. The question is whether this is something we should be looking to do in LLVM. Daniel Berlin comments that optimising these kinds of cases <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090467.html">would be useful in the GVN rewrite</a>. Chris Lattner follows up with a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090499.html">sketch of how manipulation of a marker bit might be exposed</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Assert builds will now produce human-readable numbers to identify dumped SelectionDAG nodes. "0x7fcbd9700160: ch = EntryToken" becomes "t0: ch = EntryToken". <a href="http://reviews.llvm.org/rL248010">r248010</a>.</p></li><li><p>Basic support for reading GCC AutoFDO profiles has landed. <a href="http://reviews.llvm.org/rL247874">r247874</a>.</p></li><li><p>The llvm-mc-fuzzer tool has been documented. <a href="http://reviews.llvm.org/rL247979">r247979</a>.</p></li><li><p>The llvm.invariant.group.barrier intrinsic was born. <a href="http://reviews.llvm.org/rL247711">r247711</a>.</p></li><li><p>The LLVM default target triple can now be set to the empty string at configure time. <a href="http://reviews.llvm.org/rL24675http://reviews.llvm.org/rL247775">r247775</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>AST matcher functions have been renamed to match the AST node names directly. This is a breaking change. <a href="http://reviews.llvm.org/rL27885">r247885</a>, <a href="http://reviews.llvm.org/rL247887">r247887</a>.</p></li><li><p>The static analyzer gained a new Objective-C checker. DynamicTypeChecker will check for cases where the dynamic and static type of an object are unrelated. <a href="http://reviews.llvm.org/rL248002">r248002</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The LLD COFF linker has gained some extra parallelisation. Self-link time has now improved from 1022ms to 654ms. <a href="http://reviews.llvm.org/rL248038">r248038</a>, <a href="http://reviews.llvm.org/rL248078">r248078</a>.</p></li><li><p>Support code was added to LLDB for recognising and printing Go types. <a href="http://reviews.llvm.org/rL247629">r247629</a>.</p></li><li><p>MemorySanitizer has been enabled for AArch64. <a href="http://reviews.llvm.org/rL247809">r247809</a>.</p></li></ul>
- LLVM Weekly - #89, Sep 14th 2015https://blog.llvm.org/2015/09/llvm-weekly-89-sep-14th-2015.htmlMon, 14 Sep 2015 08:03:00 +0000https://blog.llvm.org/2015/09/llvm-weekly-89-sep-14th-2015.html<p>Welcome to the eighty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/89">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>I didn't spot any new LLVM-related articles or news this week. As a reminder, I always welcome tips either via email or Twitter. Seeing as there's nothing new, now seems a good time to point you towards either Stephen Diehl's tutorial on <a href="http://www.stephendiehl.com/llvm/">implementing a JIT compiled language with Haskell and LLVM</a> or Adrian Sampson's <a href="http://adriansampson.net/blog/llvm.html">'LLVM for grad students'</a>.</p><h3>On the mailing lists</h3><ul><li><p>James Knight is proposing to <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090300.html">deprecate and remove the old SelectionDAG scheduler</a>, given that machine schedulers are now the preferred approach. He notes that a number of in-tree targets still use the SelectionDAG scheduler. It seems there is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090309.html">support for this plan</a>.</p></li><li><p>Jauhien is curious about the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090120.html">availability of a C API for the ORC JIT</a>, with the motivating use case here being to provide a binding for Rust. The <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090155.html">main concern</a> is that the ORC API is not yet stable, meaning it's not feasible to provide stable C bindings. The proposal is they live in llvm/include/llvm-c/unstable.</p></li><li><p>Joseph Tremoulet has a whole bunch of questions about addrspacecast semantics, and Chandler Carruth has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090180.html">a whole bunch of answers</a>.</p></li><li><p>David Chisnall has a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090240.html">useful response</a> to a question about implementing LLVM intrinsics with multiple return values. As he points out, this is usually done by returning a struct.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A major modification of LLVM'a alias analysis manager has landed in order to port it to the new pass manager. See the commit message for full details. <a href="http://reviews.llvm.org/rL247167">r247167</a>.</p></li><li><p>The scalar replacement of aggregates (SROA) pass has been ported to the new pass manager. In the commit message, Chandler comments he hopes this serves as a good example of porting a transformation pass with non-trivial state to the new pass manager. <a href="http://reviews.llvm.org/rL247501">r247501</a>.</p></li><li><p>The GlobalsModRef alias analysis pass is now enabled by default. <a href="http://reviews.llvm.org/rL247264">r247264</a>.</p></li><li><p>Emacs users, rest your aching pinky fingers for a moment and rejoice. A range of improvements for the Emacs LLVM IR mode have landed. <a href="http://reviews.llvm.org/rL247281">r247281</a>.</p></li><li><p>The AArch64 backend can now select STNP, the non-temporal store instruction (this hints that the value need not be kept in cache). <a href="http://reviews.llvm.org/rL247231">r247231</a>.</p></li><li><p>Shrink wrapping optimisations are enabled on PPC64. <a href="http://reviews.llvm.org/rL247237">r247237</a>.</p></li><li><p>A whole bunch of StringRef functions have been sprinkled with the <code>ALWAYS_INLINE</code> attribute so as to reduce the overhead of string operations even on debug LLVM builds. Chandler has also been making other changes to improve the performance of check-llvm with a debug build. <a href="http://reviews.llvm.org/rL247253">r247253</a>.</p></li><li><p>The LLVM performance tips document has been extended to detail the use of allocas and when to specify alignment. <a href="http://reviews.llvm.org/rL247301">r247301</a>.</p></li><li><p>The <code>hasLoadLinkedStoreConditional</code> TargetLoweringInformation callback has now been split in to <code>bool shouldExpandAtomicCmpXchgInIR(inst)</code> and <code>AtomicExpansionKind shouldExpandAtomicLoadInIR(inst)</code>. <a href="http://reviews.llvm.org/rL247429">r247429</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A new control-flow integrity variant has been introduced, indirect function call chacking (enabled with <code>-fsanitize=cfi-icall</code>). This checks the dynamic type of the called function matches the static type used at the call. <a href="http://reviews.llvm.org/rL247238">r247238</a>.</p></li><li><p>A new <code>-analyzer-config</code> option is available to modify the size of function that the inliner considers as large. <a href="http://reviews.llvm.org/rL247463">r247463</a>.</p></li><li><p>Clang will now try much harder to preserve alignment information during IR-generation. <a href="http://reviews.llvm.org/rL246985">r246985</a>.</p></li><li><p>The <code>__builtin_nontemporal_store</code> and <code>__builtin_nontemporal_load</code> builtins have been introduced. <a href="http://reviews.llvm.org/rL247104">r247104</a>, <a href="http://reviews.llvm.org/rL247374">r247374</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx gained implementations of Boyer-Moore and Boyer-Moore-Horspool searchers (for the language fundamentals technical specification). <a href="http://reviews.llvm.org/rL247036">r247036</a>.</p></li><li><p>A trivial dynamic program linked with the new ELF lld now works with musl's dynamic linker. <a href="http://reviews.llvm.org/rL247290">r247290</a>.</p></li><li><p>LLD's COFF linker learned to merge cyclic graphs, which means self-linking now produces a 27.7MB rather than a 29.0MB executable. MSVC manages to produce a 27.1MB executable, so there is still room for improvement. <a href="http://reviews.llvm.org/rL247387">r247387</a>.</p></li></ul>
- LLVM Weekly - #88, Sep 7th 2015https://blog.llvm.org/2015/09/llvm-weekly-88-sep-7th-2015.htmlMon, 07 Sep 2015 10:57:00 +0000https://blog.llvm.org/2015/09/llvm-weekly-88-sep-7th-2015.html<p>Welcome to the eighty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/88">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The biggest news from the past week is of course the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/089935.html">release of LLVM and Clang 3.7</a>. See the <a href="http://llvm.org/releases/3.7.0/docs/ReleaseNotes.html">LLVM release notes</a> and the <a href="http://llvm.org/releases/3.7.0/tools/clang/docs/ReleaseNotes.html">Clang release notes</a> for more details.</p><p>Slides from the 2015 GNU Tools Cauldron are <a href="https://gcc.gnu.org/wiki/cauldron2015#Slides_and_Notes">now available online</a>.</p><p>Version 1.12 of TCE, the TTA-based co-design environment <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090050.html">has been released</a>.</p><h3>On the mailing lists</h3><ul><li><p>David Li has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090039.html">RFC on reducing the size overhead for profile-guided optimisation</a>. He observes that right now, Clang's PGO instrumentation increases binary size by 4.6X compared to 2.8X or GCC.</p></li><li><p>The Hip-Hop Virtual Machine team (a JITting virtual machine for PHP and Hack) have been looking at <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090030.html">utilising LLVM as a backend</a>. As part of this work, they've generated a number of patches that they're now looking to upstream. Sanjoy and Philip (Azul) have volunteered to help review the patches. With active work on Java (Azul), MSIL/C# (Microsoft), Python (Dropbox) and now PHP/Hack (Facebook) there seems to be a growing number of teams looking at improving LLVM when used for optimising higher-level languages.</p></li><li><p>Dylan McKay has been maintaining and developing an AVR backend for LLVM out of tree, and is now <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/090038.html">interested in merging it upstream</a>.</p></li><li><p>Steve King is <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089867.html">proposing a new LoopExitValues pass</a> which aims to remove recomputations of loop exit values. This <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/089992.html">follow-up message</a> perhaps makes it clearer what the pass does.</p></li><li><p>Teresa Johnson continues to work on ThinLTO and has now <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/089925.html">shared a revamped ThinLTO file format document</a>. She's also created this <a href="https://sites.google.com/site/llvmthinlto/">handy website</a> to track the current RFCs and patches for ThinLTO.</p></li><li><p>John Regehr has <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-September/089904.html">shared some results from Souper</a> that point to areas where computeKnownBits could be improved.</p></li><li><p>I missed this last week, but Ben Craig has been <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-August/044817.html">looking at ways to improve the speed of Clang's static analyzer</a>. Ted Kremenek gives some <a href="http://lists.llvm.org/pipermail/cfe-dev/2015-August/044825.html">useful general guidance</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The LLVM plugin for the gold linker now supports parallel LTO code generation. <a href="http://reviews.llvm.org/rL246584">r246584</a>.</p></li><li><p>The 'unpredictable' metadata annotation is now supported. This can be used to signal that a branch or switch is unpredictable. <a href="http://reviews.llvm.org/rL246888">r246888</a>.</p></li><li><p>A tool built on libFuzzer to fuzz llvm-as has been added. <a href="http://reviews.llvm.org/rL246458">r246458</a>.</p></li><li><p>The FunctionAttrs pass learned to infer nonnull attributes on returns. <a href="http://reviews.llvm.org/rL246476">r246476</a>.</p></li><li><p>Work on Windows exception handling continues with the addition of the cleanupendpad instruction and the llvm.eh.exceptionpointer intrinsic. <a href="http://reviews.llvm.org/rL246751">r246751</a>, <a href="http://reviews.llvm.org/rL246752">r246752</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Basic support for the WebAssembly target landed in Clang. Basic codegen is supported, but not yet assembling or linking. <a href="http://reviews.llvm.org/rL246814">r246814</a>.</p></li><li><p>Clang will now warn when you reference object members from a handler of a constructor/destructor function-try-block. <a href="http://reviews.llvm.org/rL246548">r246548</a>.</p></li><li><p>Clang learnt the <code>__builtin_unpredictable</code> builtin, which will generate the newly added unpredictable metadata. <a href="http://reviews.llvm.org/rL246699">r246699</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The new ELF lld linker gained basic archive file support. <a href="http://reviews.llvm.org/rL246886">r246886</a>.</p></li><li><p>Language plugins in LLDB can now provide data formatters. <a href="http://reviews.llvm.org/rL246568">r246568</a>.</p></li></ul>
- LLVM 3.7 Releasehttps://blog.llvm.org/2015/09/llvm-37-release.htmlTue, 01 Sep 2015 14:15:00 +0000https://blog.llvm.org/2015/09/llvm-37-release.html<p>It is my pleasure to announce that LLVM 3.7.0 is now available!</p> <p>Get it here: <a href="http://llvm.org/releases/">http://llvm.org/releases/</a></p> <p>This release contains the work of the LLVM community over the past six months: full OpenMP 3.1 support (behind a flag), the On Request Compilation (ORC) JIT API, a new backend for Berkeley Packet Filter (BPF), Control Flow Integrity checking, as well as improved optimizations, new Clang warnings, many bug fixes, and more.</p> <p>For details on what's new, see the release notes [<a href="http://llvm.org/releases/3.7.0/docs/ReleaseNotes.html">LLVM</a>, <a href="http://llvm.org/releases/3.7.0/tools/clang/docs/ReleaseNotes.html">Clang</a>].</p> <p>Many thanks to everyone who helped with testing, fixing, and getting the release into a good state!</p> <p>Special thanks to the volunteer release builders and testers, without whom this release would not be possible: Dimitry Andric, Sebastian DreÃler, Renato Golin, Pavel Labath, Sylvestre Ledru, Ed Maste, Ben Pope, Daniel Sanders, and Nikola SmiljaniÄ!</p> <p>If you have any questions or comments about this release, please contact the community on the mailing lists. Onwards to 3.8!</p>
- LLVM Weekly - #87, Aug 31st 2015https://blog.llvm.org/2015/08/llvm-weekly-87-aug-31st-2015.htmlMon, 31 Aug 2015 05:03:00 +0000https://blog.llvm.org/2015/08/llvm-weekly-87-aug-31st-2015.html<p>Welcome to the eighty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>It's a bank holiday weekend here in the UK, so apologies that you're reading this a few hours later than usual. As a quick reminder, if you're able to be in Geneva for the 9th-11th October then you should definitely <a href="http://www.lowrisc.org/blog/2015/08/lowrisc-at-orconf-2015/">come along to ORConf</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/87">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>At the time of writing, LLVM 3.7.0 has not yet seen its official release, <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089761.html">but it has been tagged</a>. The final release should be out within the next day or so. Congratulations to everyone involved.</p><p>The deadline for submissions to the LLVM in HPC workshop has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089572.html">extended to Friday, September 4th</a>.</p><p>Save the date! The next Cambridge LLVM Social will be <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089650.html">on Wednesday 30th September</a>.</p><h3>On the mailing lists</h3><ul><li><p>Jingyue Wu has shared a <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089845.html">design doc on NVPTX memory space inference</a> and on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089574.html">straight-line scalar optimisations</a>.</p></li><li><p>An RFC from Swaroop Sridhar on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089706.html">extending alloca to allow the specification of the address space of the allocation</a> has resulted in a lot of discussion and is well worth a read for those interested in the intricacies of supporting GC in LLVM. Or particular interest is this <a href="https://docs.google.com/document/d/1H5am1PyY8n8hc1hIAisDQMgbZDmMgnjU8wdN25YqMbQ/edit">design doc from Philip Reames</a> on the interaction of stack-based allocation and GC in LLVM. See also this summary from Joseph Tremoulet of <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089843.html">his understanding of how LLILC is hoping to use address spaces</a>.</p></li><li><p>There's been some discussion on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089652.html">flaky buildbots</a>. Renato <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089657.html">details his concerns with simply ignoring these bots</a>. Some of the issues with the bots in question <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089753.html">may be due to the use of incremental builds</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The 'kaleidoscope' tutorial has seen a major update. Now, rather than introducing MCJIT it describes how to use ORC, building a custom JIT called KaleidoscopeJIT. <a href="http://reviews.llvm.org/rL246002">r246002</a>.</p></li><li><p>WebAssembly backend implementation work has been continuing over the past few weeks. The individual commits tend to be small and focused (as good commits should be). I mainly wanted to include a mention to highlight how work is ongoing. e.g. this recent commit added support for emitting simple call s-expressions. <a href="http://reviews.llvm.org/rL245986">r245986</a>.</p></li><li><p>The documentation on statepoints now has more to say about base pointers and related assumptions and optimisations. <a href="http://reviews.llvm.org/rL246103">r246103</a>.</p></li><li><p>Constant propagation is enabled for more single precisions math functions, such as acosf, powf, logf. <a href="http://reviews.llvm.org/rL246194">r246194</a>.</p></li><li><p>The function <code>llvm::splitCodeGen</code> has been introduced in order to support the implementation of parallel LTO code generation. It uses SplitModule to split the module in to linkable partitions that are distributed among threads to be codegenned. <a href="http://reviews.llvm.org/rL246236">r246236</a>.</p></li><li><p>There's been another change to DebugInfo. DISubprogram definitions must now be marked as distinct. The commit message includes a suggested script for updating IR. <a href="http://reviews.llvm.org/rL246327">r246327</a>.</p></li><li><p>Chandler has been doing some refactoring of the ARM target parsing code with the hope of making it more efficient. He's reduced the cases where the code is called, which has a noticeable effect on some LLVM timings (e.g. check-llvm with non-optimized builds is 15 seconds faster). <a href="http://reviews.llvm.org/rL246370">r246370</a>, <a href="http://reviews.llvm.org/rL246378">r246378</a>.</p></li></ul><h3>Clang commits</h3><ul><li>A NullabilityChecker has been introduced, which is designed to catch a number of nullability-related issues. <a href="http://reviews.llvm.org/rL246105">r246105</a>.</li></ul><h3>Other project commits</h3><ul><li><p>ThreadSanitizer is now enabled for AArch64 with 42-bit virtual addressing on Linux. <a href="http://reviews.llvm.org/rL246330">r246330</a>.</p></li><li><p>libcxx now contains release goals for 3.8 in its TODO.txt. This includes the Filesystem TS and the asynchronous I/O TS. <a href="http://reviews.llvm.org/rL245864">r245864</a>.</p></li><li><p>LLD's ELF linker gained a basic AMDGPU ReaderWriter that enables it to emit binaries that can be consumed by the HSA runtime. <a href="http://reviews.llvm.org/rL246155">r246155</a>.</p></li><li><p>LLD's COFF linker gained support for parallel LTO code generation. <a href="http://reviews.llvm.org/rL246342">r246342</a>.</p></li><li><p>LLDB now supports hardware watchpoints on ARM. <a href="http://reviews.llvm.org/rL245961">r245961</a>.</p></li><li><p>The concept of 'language plugins' was introduced to LLDB. These will provide language-specific data formatters or expression evaluation. <a href="http://reviews.llvm.org/rL246212">r246212</a>.</p></li></ul>
- LLVM Weekly - #86, Aug 24th 2015https://blog.llvm.org/2015/08/llvm-weekly-86-aug-24th-2015.htmlMon, 24 Aug 2015 02:56:00 +0000https://blog.llvm.org/2015/08/llvm-weekly-86-aug-24th-2015.html<p>Welcome to the eighty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/86">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The LLVM Foundation <a href="http://blog.llvm.org/2015/08/llvm-foundation-granted-501c3-nonprofit.html">has been granted 501(c)(3) non-profit status</a>. This means contributions are tax-deductible for US tax payers.</p><p>LLVM 3.7-rc3 <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089468.html">has been tagged</a>. This is the final release candidate and 3.7.0 final is expected very shortly.</p><p>The paper <a href="http://soarlab.org/2015/08/ase2015-ddr/">Fast and Precise Symbolic Analysis of Concurrency Bugs in Device Drivers</a> makes use of Clang and LLVM as part of its verification flow.</p><p>Good news everyone! The deadline for submissions for the 2015 LLVM Developers' meeting has been <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089376.html">extended</a> to August the 25th.</p><h3>On the mailing lists</h3><ul><li><p>Edward Jones and Simon Cook at Embecosm have been developing an <a href="https://github.com/embecosm/aap-llvm">LLVM backend for AAP</a>, a 16-bit architecture which aims to be representative of common deeply embedded microprocessors. They're <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089304.html">looking for feedback</a> on upstreaming it. The architecture reference can be found <a href="http://www.embecosm.com/appnotes/ean13/ean13.html">here</a>.</p></li><li><p>Alex Lorenz has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089527.html">update on the status of Machine IR serialization</a>. There's also the beginnings of a <a href="http://llvm.org/docs/MIRLangRef.html">reference manual</a> for it, which covers the syntax and how to use it in tests.</p></li><li><p>'deadal nix' has posted an RFC on supporting <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089430.html">load and store for large aggregates</a>. The author gives more detail <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089460.html">here</a>.</p></li><li><p>Lang Hames proposes <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089384.html">two changes to the llvm.memcpy and llvm.memmove intrinsics</a>. It seems that based on feedback, the plans is to <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089461.html">add alignment information via metadata</a>.</p></li><li><p>Evgenii Stepanav has an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089466.html">RFC on a minor fix to codegen for AlwaysInline functions</a>. Right now, if an alwaysinline function is only called from dead code it may not be inlined.</p></li><li><p>Rong Xu has shared some <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089425.html">interesting numbers</a> on his investigations regarding front-end vs middle-end instrumentation of binaries.</p></li><li><p>Renato Golin <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089309.html">raises concerns about the introduction of 'hacks' in to LLVM</a>. In this particular instance, it's a patch for TheadSanitizer on AArch64 Android. He elaborated on his concerns <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089377.html">here</a> and <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089381.html">here</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>TransformUtils gained the module splitter, which splits a module into linkable partitions and is intended to be used for parallel LTO code generation. <a href="http://reviews.llvm.org/rL245662">r245662</a>.</p></li><li><p>MergeFunctions is now closer to being deterministic. <a href="http://reviews.llvm.org/rL245762">r245762</a>.</p></li><li><p>ScalarEvolution has been ported to the new pass manager. <a href="http://reviews.llvm.org/rL245193">r245193</a>.</p></li><li><p>The 'kaleidoscope' tutorials on creating a language backend using LLVM are now partially updated to use C++11 features and idioms. <a href="http://reviews.llvm.org/rL245322">r245322</a>.</p></li><li><p>The peephole optimiser learned to look through PHIs to find additional register sources. <a href="http://reviews.llvm.org/rL245479">r245479</a>.</p></li></ul><h3>Clang commits</h3><ul> <li><p>The ObjCGenericsChecker will catch type errors related to lightweight generics in Objective-C. <a href="http://reviews.llvm.org/rL245646">r245646</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>compiler-rt has gained implementations of some of the missing ARM EABI runtime functions. <a href="http://reviews.llvm.org/rL245648">r245648</a>.</p></li><li><p>libcxx gained a whole bunch of Sphinx-based documentation. <a href="http://reviews.llvm.org/rL245788">r245788</a>.</p></li></ul>
- LLVM Foundation Granted 501(c)(3) Nonprofit Statushttps://blog.llvm.org/2015/08/llvm-foundation-granted-501c3-nonprofit.htmlThu, 20 Aug 2015 08:16:00 +0000https://blog.llvm.org/2015/08/llvm-foundation-granted-501c3-nonprofit.htmlThe LLVM Foundation is proud to announce it has been officially approved as a public charity with tax-exempt status under Section 501(c)(3) of the United States Internal Revenue Code. Contributions donated to the LLVM Foundation are fully tax deductible, retroactive to the organization establishment date of May 5, 2014.<br /><br />The LLVM Foundation's primary mission is to provide accessible and informative educational tools for the LLVM Project and compiler technology to the general public. These educational tools include events such as the annual LLVM Developers' meeting. The LLVM Foundation also gives grants or scholarships to other nonprofit organizations and individuals (such as student travel to LLVM Foundation events). Lastly, the LLVM Foundation funds the infrastructure necessary to support the LLVM Project.<br /><br />We hope to begin accepting donations online before the end of the year. If you are interested in contributing, please contact your employer: they may be willing to match contributions to a 501(c)(3) charity.<br /><br />The IRS letter granting the LLVM Foundation 501(c)(3) tax-exempt status is available upon request until we can get it posted online. Please contact Tanya Lattner ([email protected]), President of the LLVM Foundation. <br /><br />
- LLVM Weekly - #85, Aug 17th 2015https://blog.llvm.org/2015/08/llvm-weekly-85-aug-17th-2015.htmlMon, 17 Aug 2015 03:22:00 +0000https://blog.llvm.org/2015/08/llvm-weekly-85-aug-17th-2015.html<p>Welcome to the eighty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>If you're interested in open source hardware, lowRISC, RISC-V, OpenRISC, and more then consider <a href="http://www.lowrisc.org/blog/2015/08/lowrisc-at-orconf-2015/">joining us at ORConf 2015 in October</a>. I'm also looking for talk submissions.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/85">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Videos from April's EuroLLVM <a href="http://llvm.org/devmtg/2015-04/">are now online</a>.</p><p>The deadline for the 2015 LLVM Developer's Meeting <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88488">call for papers</a> is rapidly approaching. Get your proposal in by August 20th, 11:59PM PDT.</p><p>A new paper covering the AST generation techniques used in Polly in great detail has been published in the July issue of TOPLAS. You can read the preprint <a href="http://www.grosser.es/publications/grosser-2015--polyhedral-AST-generation-is-more-than-scanning-polyhedra--paper.pdf">here</a>.</p><p>The <a href="https://github.com/mapbox/cncc/">Customizable Naming Convention Checker (CNCC)</a> is a new Clang-based tool that can be used to validate class, field, variable, and namespace naming conventions against a chosen regular expression.</p><p><a href="http://akabe.github.io/evilml/">EvilML</a> is a deliciously terrifying compiler that compiles ML to C++ template language.</p><h3>On the mailing lists</h3><ul><li><p>With the 3.7 release on its way, it's important to <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089235.html">fix up the release notes</a> so they reflect the work that's been done over the past six months.</p></li><li><p>Dylan MacKay proposes making the existing 'expand' action of the instruction selection legalizer <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089172.html">into split and expand</a>. Part of the motivation for this is the author's work on an AVR backend.</p></li><li><p>Wang Nan has posted an RFC on <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089244.html">adding an llvm.typeid.for intrinsic</a>. This would be used with the BFP backend to specify the type for buffers passed to perf.</p></li><li><p>Teresa Johnson has posted an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089222.html">update on her ThinLTO work</a>.</p></li><li><p>Peter Collingbourne has proposed <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089136.html">a simple approach to parallelising parallel codegen for link-time optimisation</a>. This gives a speedup on a HP Z620 from 15m20s to 8m06s when 4 partitions are used. Speedup beyond that is limited (partially due to Amdahl's law).</p></li><li><p>Sanjoy Day has shared an RFC for <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089070.html">adding operand bundles to call and invokes</a>. These would be used to help track state required for deoptimization, for instance by attaching a 'deopt' operand bundle to relevant calls which contans the cstate of the abstract virtual machine.</p></li></ul><h3>LLVM commits</h3><ul><li><p>MergeFunctions has been sped up substantially by hashing functions and comparing that hash before performing a full comparison. This results in a speedup of 46% for MergeFunctions in libxul and 117% for Chromium. <a href="http://reviews.llvm.org/rL245140">r245140</a>.</p></li><li><p>i64 loads and stores are now supported for 32-bit SPARC. This is a little fiddly to support as the LDD/STD instructions need a consecutive even/odd pair of 32-bit registers. <a href="http://reviews.llvm.org/rL244484">r244484</a>.</p></li><li><p>Machine basic blocks are now serialized using custom syntax rather than YAML. A later commit documented this syntax. <a href="http://reviews.llvm.org/rL244982">r244982</a>, <a href="http://reviews.llvm.org/rL245138">r245138</a>.</p></li><li><p>A new TargetTransformInfo hook has been added for specifying per-target defaults for interleaved accesses. <a href="http://reviews.llvm.org/rL244449">r244449</a>.</p></li><li><p>The llvm.loop.unroll.enable metadata was introduced. This will cause a loop to be unrolled fully if the trip count is known at compiler time and partially if it isn't (unlike llvm.loop.unroll.full which won't unroll a loop if the trip count isn't known). <a href="http://reviews.llvm.org/rL244466">r244466</a>.</p></li><li><p>Rudimentary support for the new Windows exception handling instructions has been introduced. <a href="http://reviews.llvm.org/rL244558">r244558</a>.</p></li><li><p>Token types have been added to LLVM IR. <a href="http://reviews.llvm.org/rL245029">r245029</a>.</p></li><li><p>The BPF backend gained documentation and an instruction set description. <a href="http://reviews.llvm.org/rL245105">r245105</a>.</p></li></ul><h3>Clang commits</h3><ul> <li><p>The WebKit brace style is now supported by clang-format. <a href="http://reviews.llvm.org/rL244446">r244446</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>Statistics collection in the OpenMP runtime has been tidied up and expanded. <a href="http://reviews.llvm.org/rL244677">r244677</a>.</p></li></ul>
- LLVM Weekly - #84, Aug 10th 2015https://blog.llvm.org/2015/08/llvm-weekly-84-aug-10th-2015.htmlMon, 10 Aug 2015 05:36:00 +0000https://blog.llvm.org/2015/08/llvm-weekly-84-aug-10th-2015.html<p>Welcome to the eighty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/84">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Adrian Sampson has written a fantastic <a href="http://adriansampson.net/blog/llvm.html">introduction to LLVM</a>. It's titled LLVM for Grad Students, but it should be useful for anybody looking to use LLVM or just wanting to understand it better.</p><p>Brandon Holt has written up a short and helpful post giving <a href="http://homes.cs.washington.edu/~bholt/posts/llvm-debugging.html">hints and tips on debugging LLVM</a>.</p><p>The move of the mailing lists from UIUC on to lists.llvm.org is now complete. All public LLVM-related mailing lists <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo">are shown here</a>. List addresses have now changed to [email protected].</p><p>There's been some exciting activity in the world of GCC. Support for the draft C++ Concepts TS <a href="https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=56c12fd4ba064759724236ad896232603b8797ed">has been committed</a>. A draft of the technical specification is <a href="http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2015/n4377.pdf">available here</a>. Additionally, Nick Clifton has posted a useful summary of <a href="https://gcc.gnu.org/ml/gcc/2015-08/msg00013.html">GNU toolchain developments for July/August</a>.</p><h3>On the mailing lists</h3><ul><li><p>Rong Xu has shared an <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089044.html">RFC for late instrumentation in LLVM</a>. The RFC describes (and quantifies) the performance cost of inserting instrumentation for profile-guided optimisation in the frontend and proposes approaches for adding instrumentation in the middle-end instead.</p></li><li><p>Jingyue Wu kicked off a discussion about <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/089023.html">modifying the BasicAA alias analysis to understand whether there is aliasing between different address spaces</a>. </p></li><li><p>Teresa Johnson has posted RFCs for the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/088920.html">ThinLTO file API and data structures</a> and the <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/088916.html">ThinLTO file format</a>.</p></li><li><p>Chandler Carruth is looking to enable the GlobalModsRef in the default pass pipeline. He's found it performance neutral in his tests so far, but would <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/088988.html">appreciate more people to try and benchmark it</a>.</p></li><li><p>Asking for advice on how to get started with LLVM is very common. Few take as much time on detailing their background, motivations, and proposed plan as <a href="http://lists.llvm.org/pipermail/llvm-dev/2015-August/088915.html">Arno Bastenhof in a recent message</a>. Probably because of this, his request has attracted some very high quality replies.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A handy new LLVM Support header was introduced. The TrailingObjects template class abstracts away <code>reinterpret_cast</code>, pointer arithmetic, and size calculation needed for the case where a class has some other objects appended to the end of it. <a href="http://reviews.llvm.org/rL244164">r244164</a>.</p></li><li><p>Initial documentation for the Machine IR serialization format has been written. <a href="http://reviews.llvm.org/rL244292">r244292</a>.</p></li><li><p>Uniquable DICompilerUnits have been disallowed. Old bitcode will be automatically upgraded and the sed script in the commit message should be useful for updating out-of-tree testcases. <a href="http://reviews.llvm.org/rL243885">r243885</a>.</p></li><li><p>All of the TargetTransformInfo cost APIs now use int rather than unsigned. <a href="http://reviews.llvm.org/rL244080">r244080</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A new checker for code-level localizability issues on OSX/iOS was born. It will warn about the use of non-localized NSStrings passed to UI methods and about failing to include a comment in NSLocalizedString macros.<br /><a href="http://reviews.llvm.org/rL244389">r244389</a>.</p></li><li><p>New AST matchers have been introduced for constructors that are default, copy, or move. <a href="http://reviews.llvm.org/rL244036">r244036</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The old COFF linker in LLD has been removed in favour of the new, faster, and simpler implementation. <a href="http://reviews.llvm.org/rL244226">r244226</a>.</p></li><li><p>ThreadSanitizer is now enabled for AArch64. <a href="http://reviews.llvm.org/rL244055">r244055</a>.</p></li></ul>
- LLVM Weekly - #83, Aug 3rd 2015https://blog.llvm.org/2015/08/llvm-weekly-83-aug-3rd-2015.htmlMon, 03 Aug 2015 06:21:00 +0000https://blog.llvm.org/2015/08/llvm-weekly-83-aug-3rd-2015.html<p>Welcome to the eighty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/83">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The CodeChecker static analysis infrastructure built on Clang Static Analyzer <a href="https://github.com/Ericsson/codechecker">has been released</a>. The <a href="http://llvm.org/devmtg/2015-04/slides/Clang_static_analysis_toolset_final.pdf">slides</a> from the talk at EuroLLVM earlier this year give a good overview.</p><p>LLVM/Clang 3.7 RC2 <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/44237">has been tagged</a>. Time to get testing.</p><p>The implementation of the <a href="https://github.com/anssi-fr/picon">Picon</a> Control Flow Integrity protection mechanism has been released. See also the associated paper <a href="https://www.sstic.org/media/SSTIC2015/SSTIC-actes/control_flow_integrity_on_llvm_ir/SSTIC2015-Article-control_flow_integrity_on_llvm_ir-fontaine_chifflier_coudray_esfrDAl.pdf">Picon: Control Flow Integrity on LLVM IR</a>.</p><h3>On the mailing lists</h3><ul><li><p>There is a plan to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88947">jump to Windows 7 as the baseline requirement for LLVM</a>, which has been featured in LLVM Weekly previously many months ago. If such a move would cause a problem for you, now is the time to speak up. There's also a proposal to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88959">drop support for the old mingw.org toolchains</a> in favour of the maintained mingw-w64.</p></li><li><p>James Molloy has prototyped <a href="http://reviews.llvm.org/D11530">LoopEditor</a>, a high-level API for loop transformations in LLVM and is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/260989">seeking additional feedback</a>. The hope is that existing loop transformations could be rewritten and simplified to use it.</p></li><li><p>Easwaran Raman has shared an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88929">RFC on speedup estimation for inlining cost analysis</a>. The idea is that the estimated speedup (reduction in dynamic instruction count) from performing the inlining should be used as part of the cost metric.</p></li><li><p>Chris Bieneman has penned a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88859">CMake in LLVM roadmap</a> and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88858">July CMake update</a>. There's even <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88906">hope the autoconf build system might be marked deprecated before the 3.8 branch</a>.</p></li><li><p>Peter Collingbourne has shared a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88856">proposal for arbitrary relocations in constant global initialisers</a>.</p></li><li><p>Try not to panic, but the LLVM mailing lists <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88811">will be down on August 4th</a> as they will be moving off the UIUC servers. Additionally, SVN access will be read-only and the LLVM bugzilla will be down.</p></li><li><p>Mehdi Amini has issued a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88793">helpful notice for out-of-tree maintainers</a> on the removal of RegisterScheduler::setDefault.</p></li><li><p>Lang Hames has written a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88773">whirlwind introduction to implementing lazy JITting support for a new architecture in Orc</a>.</p></li><li><p>Michael Schlottke-Lakemper kicked off a discussion on the possibility of <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/7802">using lldb.so to create a stack trace</a>. Respondents pointed out a number of possible choices, including using the <code>llvm::sys::printStackTrace()</code> function.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new exception handling representation has been introduced for MSVC compatibility. The commit includes the appropriate updates to the LLVM language reference. <a href="http://reviews.llvm.org/rL243766">r243766</a>.</p></li><li><p>A test to check bitcode compatibility has been added. This will help ensure the bitcode format produced by an X.Y release is readable by the following X.Z releases. <a href="http://reviews.llvm.org/rL243779">r243779</a>.</p></li><li><p>The lli documentation has been updated and now better explains its purpose. <a href="http://reviews.llvm.org/rL243401">r243401</a>.</p></li><li><p>LLVM gained a target-independent thread local storage (TLS) implementation. <a href="http://reviews.llvm.org/rL243438">r243438</a>.</p></li><li><p>A <code>reverse(ContainerTy)</code> range adapter was added. <a href="http://reviews.llvm.org/rL243581">r243581</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The method for emitting metadata for loop hint pragmas has been modified, using CGLoopInfo. <a href="http://reviews.llvm.org/rL243315">r243315</a>.</p></li><li><p>Clang learned to pass <code>-Wa,-mfpu</code>, <code>-Wa,-mhwdiv</code>, and <code>-Wa,-mcpu</code> to the integrated assembler. <a href="http://reviews.llvm.org/rL243353">r243353</a>.</p></li><li><p>Initial support for Open MP 4.1's extended ordered clause was added. <a href="http://reviews.llvm.org/rL243635">r243635</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>lldb is starting to gain support for indicating when you are debugging a function that has been optimized. <a href="http://reviews.llvm.org/rL243508">r243508</a>.</p></li></ul>
- LLVM Weekly - #82, Jul 27th 2015https://blog.llvm.org/2015/07/llvm-weekly-82-jul-27th-2015.htmlMon, 27 Jul 2015 03:01:00 +0000https://blog.llvm.org/2015/07/llvm-weekly-82-jul-27th-2015.html<p>Welcome to the eighty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'd just like to highlight how much I really do appreciate people sending me links for inclusion, e.g. LLVM-related blog posts or new releases of software using LLVM (feature releases rather than simple bugfix updates). I'm not omniescent - if an interesting blog post or software release goes unmentioned here, I probably just didn't know about it!</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/82">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88488">call for papers</a> for the 2015 LLVM Developers' meeting has now gone out. The submission deadline is August 20th. Registration is also <a href="https://www.eventbrite.com/e/2015-llvm-developers-meeting-tickets-17756357744">now open</a>.</p><p>John Regehr and his collaborators working on Souper have <a href="http://blog.regehr.org/archives/1252">shared some initial results from the synthesizing superoptimizer</a>. John is very interested in collecting representative IR from frontends other than Clang. There is also some discussion about these results <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88588">on the mailing list</a>.</p><p>Microsoft have <a href="http://blogs.msdn.com/b/vcblog/archive/2015/07/20/source-now-available-for-gdb-lldb-debug-engine.aspx">open sourced their GDB/LLDB 'debug engine'</a>.</p><h3>On the mailing lists</h3><ul><li><p>Piotr Padlewski has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/44022">shared a plan to improve Clang's devirtualization</a> which he will be working on with Richard Smith at Google this Summer. The hope is to reduce any remaining performance gap between LLVM/Clang and GCC (which has better devirtualization support). The Google Doc <a href="https://docs.google.com/document/d/1f2SGa4TIPuBGm6y6YO768GrQsA8awNfGEJSBFukLhYA/edit">can be read here</a>.</p></li><li><p>Rafael EspÃndola has shared <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88499">some thoughts on handling ELF shared libraries in LLD</a>.</p></li><li><p>Marshall Clow has kicked off a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43985">how C++ library TSes should be packaged</a>. David Chisnall gives the <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/44034">FreeBSD perspective on ABI and API compatibility in libc++</a>.</p></li><li><p>Eric Fiselier has posted an <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43969">RFC on whether libc++ should support the atomic header in C++03</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>dsymutil gained support for one-definition-rule uniquing for C++ code. When linking the DWARF for a debug build of clang, it generates a 150M dwarf file instead of 700M. <a href="http://reviews.llvm.org/rL242847">r242847</a>.</p></li><li><p>The last remnant of the AliasAnalysis legacy update API have been removed. <a href="http://reviews.llvm.org/rL242881">r242881</a>.</p></li><li><p>LoopUnswitch can now unswitch multiple trivial conditions in a single pass invocation. <a href="http://reviews.llvm.org/rL243203">r243203</a>.</p></li></ul><h3>Clang commits</h3><ul> <li><p>Clang gained the <code>isFinal()</code> AST matcher. <a href="http://reviews.llvm.org/rL243107">r243107</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A new ELF linker has been born, based on the PE/COFF linker. <a href="http://reviews.llvm.org/rL243161">r243161</a>.</p></li><li><p>libcxx gained a default searcher for <code>std::experimental::search</code>. <a href="http://reviews.llvm.org/rL242682">r242682</a>.</p></li></ul>
- LLVM Weekly - #81, Jul 20th 2015https://blog.llvm.org/2015/07/llvm-weekly-81-jul-20th-2015.htmlMon, 20 Jul 2015 06:34:00 +0000https://blog.llvm.org/2015/07/llvm-weekly-81-jul-20th-2015.html<p>Welcome to the eighty-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'm "on holiday" (at EuroPython) this week in Bilbao, mostly helping out the Raspberry Pi team with the education track. Do say hello, particularly if you want to chat lowRISC, LLVM, or Raspberry Pi.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/81">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM 3.6.2 <a href="http://llvm.org/releases/download.html#3.6.2">has been released</a>.</p><p>LLVM and Clang 3.7 <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88108">has been branched</a>.</p><p>The team behind Pyston, the LLVM-based Python JIT have written a blog post about <a href="http://blog.pyston.org/2015/07/14/caching-object-code/">their new object code caching feature</a>.</p><h3>On the mailing lists</h3><ul><li><p>Teresa Johnson has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88099">RFC on ThinLTO symbol linkage and renaming</a>.</p></li><li><p>Robert Lougher has written up a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88092">very detailed analysis of a case of poor register allocation</a>, which may make interesting reading for some.</p></li><li><p>Chandler Carruth has written up on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88070">RFC on stateful alias analysis in LLVM</a>. The plan assumes the new pass manager. GlobalsModRef is the trickiest case to handle, and Chandler has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88071">written a separate post about the problems with it</a>.</p></li><li><p>Hal Finkel is interested in using new functionality introduced in C++11 (such as the final keyword) to <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43824">improve devirtualization</a>. The proposal generated quite a lot of discussion.</p></li><li><p>Juergen Ributzka kicked off a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88334">improving the maintenance and management of the LLVM C API</a>. Eric Christopher <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88357">suggests moving the C API to another project</a>, so those who want/require a stable API can take on the burden of keeping it up to date. He <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88413">elaborates on his proposal</a> in response from Chris Lattner. There seems to be <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88420">some support</a> for providing C bindings with the same stability guarantees as the C++ API (i.e. it might break between major releases).</p></li><li><p>Hal Finkel has proposed an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/88200">RFC on defining infinite loops in LLVM</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The API to determine callee-save registers has been rewritten. <a href="http://reviews.llvm.org/rL242165">r242165</a>.</p></li><li><p>The 'debugger tuning' concept has been introduced, allowing the specification of the debugger the debug info should be optimised for. This defaults to lldb on OS X and FreeBSD and GDB for everything else (other than PS4, which defaults to the SCE debugger). <a href="http://reviews.llvm.org/rL242388">r242388</a>.</p></li><li><p>Intrinsics for absolute difference operations have been introduced. <a href="http://reviews.llvm.org/rL242409">r242409</a>.</p></li><li><p>The PostRAScheduler has been disabled for the Apple Swift CPU and MachineScheduler is used in place. The commit message argues PostRAScheduler is not a good fit for out-of-order architectures and suggests the same switch might be worth while for other ARM OoO CPUs. <a href="http://reviews.llvm.org/rL242500">r242500</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Support for armv7-windows-gnu targets has been added to the Clang front-end. <a href="http://reviews.llvm.org/rL242292">r242292</a>.</p></li><li><p>The clang module container format is now selectable from the command line (raw or obj). <a href="http://reviews.llvm.org/rL242499">r242499</a>.</p></li><li><p>A minimal AMDGPU toolchain configuration has been added. <a href="http://reviews.llvm.org/rL242601">r242601</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLD now supports MIPS big-endian targets. <a href="http://reviews.llvm.org/rL242014">r242014</a>.</p></li><li><p>LLDB's gdbserver is moving towards being a single-threaded application. <a href="http://reviews.llvm.org/rL242018">r242018</a>.</p></li><li><p>The OpenMP CMake build system has been massively refactored. <a href="http://reviews.llvm.org/rL242298">r242298</a>.</p></li></ul>
- LLVM Weekly - #80, Jul 13th 2015https://blog.llvm.org/2015/07/llvm-weekly-80-jul-13th-2015.htmlMon, 13 Jul 2015 09:50:00 +0000https://blog.llvm.org/2015/07/llvm-weekly-80-jul-13th-2015.html<p>Welcome to the eightieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/80">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The 2015 LLVM Developers' Meeting <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87925">has been announced</a>. It will take place on October the 29th and 30th in San Jose, California. Registration information and a call for papers will be sent out later in the month.</p><p>LLVM/Clang 3.6.2 <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43613">has been tagged</a>. All being well, we can expect 3.6.2 to be released soon.</p><h3>On the mailing lists</h3><ul><li><p>Daniel Sanders has kicked off an amusingly named conversation on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87804">the trouble with triples</a>. The thread gives context for a proposed change to move from ambiguous TargetTriple to unambiguous TargetTuples.</p></li><li><p>Juergen Ributzka has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87930">proposed a new StackMap format</a>. The feedback seems positive so far.</p></li><li><p>The discussion regarding the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87279">analysis of responses to the C as used in practice survey</a> has rumbled on. Chris Lattner has shared <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87749">some of his thoughts on the freedom undefined behaviour gives the compiler to optimise</a>.</p></li><li><p>Christos Margiolas has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87849">shared patches for his work on heterogeneous execution with LLVM</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The Hexagon backend gained a BitTracker class. This is intended to be target independent. As described at the top of BitTracker.cpp, this is intended to be used with a target-specific machine instruction evaluator. There have been some other large additions to the Hexagon backend this week too. I hope the authors will consider given another talk on their work at some point.<br /><a href="http://reviews.llvm.org/rL241595">r241595</a>.</p></li><li><p>llc learnt the <code>run-pass</code> option, which will run one specific code generation pass only. <a href="http://reviews.llvm.org/rL241476">r241476</a>.</p></li><li><p>LLVM now has documentation on its inline assembly!<br /><a href="http://reviews.llvm.org/rL241698">r241698</a>.</p></li><li><p>The llvm.frameescape and llvm.framerecover intrinsics have been renamed to localescape and localrecover. <a href="http://reviews.llvm.org/rL241463">r241463</a>.</p></li><li><p>Various refactoring commits have been made with the aim of having a single DataLayout used during compilation, owned by the module.<br /><a href="http://reviews.llvm.org/rL241775">r241775</a>.</p></li><li><p>A new llvm.canonicalize intrinsics has been introduced, intended to be used to canonicalize floating point values. <a href="http://reviews.llvm.org/rL241977">r241977</a>.</p></li><li><p>The new argmemonly attribute can be used to mark functions that can only access memory through its argument pointers. <a href="http://reviews.llvm.org/rL241979">r241979</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A few patches landed in Clang improving Objective-C support. This includes parsing, semantic analysis, and AST support for Objective-C type parameters, support for Objective-C type arguments, the <code>__kindof</code> type qualifier. Douglas Gregor has more to say about these changes <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43614">on the mailing list</a>. <a href="http://reviews.llvm.org/rL241541">r241541</a>, <a href="http://reviews.llvm.org/rL241542">r241542</a>, <a href="http://reviews.llvm.org/rL241548">r241548</a>, and more.</p></li><li><p>Clang will attached the readonly or readnone attributes when appropriate to inline assembly instructions, meaning the inline asm will not be treated as conservatively. e.g. in some cases an inline asm block could be hoisted out of a loop. <a href="http://reviews.llvm.org/rL241930">r241930</a>.</p></li><li><p>PCH (pre-compiled headers) are now wrapped in an object file. <a href="http://reviews.llvm.org/rL241690">r241690</a>, <a href="http://reviews.llvm.org/rL241620">r241620</a>.</p></li><li><p>Clang now recognises the GCC-compatible <code>-fprofile-generate</code> and <code>-fprofile-use</code> flags. <a href="http://reviews.llvm.org/rL241825">r241825</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx add <code>try_emplace</code> and <code>insert_or_assign</code> to <code>map</code> and <code>unordered_map</code>, as specified in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4279">N4279</a>. <a href="http://reviews.llvm.org/rL241539">r241539</a>.</p></li><li><p>The new LLD COFF linker now has basic support for x86 (it was previously x86-64 only). <a href="http://reviews.llvm.org/rL241857">r241857</a>.</p></li></ul>
- LLVM Weekly - #79, Jul 6th 2015https://blog.llvm.org/2015/07/llvm-weekly-79-jul-6th-2015.htmlMon, 06 Jul 2015 16:23:00 +0000https://blog.llvm.org/2015/07/llvm-weekly-79-jul-6th-2015.html<p>Welcome to the seventy-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Last week I was in Berkeley for the second RISC-V conference. If you weren't able to make it, worry not because I liveblogged both <a href="http://www.lowrisc.org/blog/2015/06/second-risc-v-workshop-day-one/">day one</a> and <a href="http://www.lowrisc.org/blog/2015/06/second-risc-v-workshop-day-two/">day two</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/79">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Stephen Cross has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43502">released llvm-abi</a>, a library for generating LLVM IR that complies with platform ABIs.</p><p>This is a <a href="http://blog.mattbierner.com/stupid-template-tricks-super-template-tetris/">rather cute implementation of Tetris in C++ header files</a>, compatible with Clang.</p><h3>On the mailing lists</h3><ul><li><p>Kevin Atkinson <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87565">asks whether to use MCJIT or ORCJIT</a>. It sounds like <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87600">ORC is working out well for the LLILC team</a>.</p></li><li><p>Chandler Carruth has kicked off a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87469">discussion about the AliasAnalysis update interface</a> and what should be done about it.</p></li><li><p>In response to a question, Evgeny Astigeevich has given a useful guide to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87416">finding the control dependence graph</a>.</p></li><li><p>Manuel Klimek <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43558">is updating the LLVM Phabricator install</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The initial skeleton of the WebAssembly backend has been committed. It is not yet functional. <a href="http://reviews.llvm.org/rL241022">r241022</a>.</p></li><li><p>DIModule metadata nodes have been introduced. A DIModule is meant to be used to record modules importaed by the current compile unit. <a href="http://reviews.llvm.org/rL241017">r241017</a>.</p></li><li><p>New exception handling intrinsics have been added for recovering and restoring parent frames. <a href="http://reviews.llvm.org/rL241125">r241125</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained support for the x86 builtin <code>__builtin_cpu_supports</code>. <a href="http://reviews.llvm.org/rL240994">r240994</a>.</p></li><li><p>The Clang man pages have been converted to Sphinx (from .pod). <a href="http://reviews.llvm.org/rL241037">r241037</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx gained <code>shared_mutux</code>. <a href="http://reviews.llvm.org/rL241067">r241067</a>.</p></li><li><p>LLD has gained some generally applicable optimisations. e.g. devirtualizing SymbolBody and compacting its in-memory representation. <a href="http://reviews.llvm.org/rL241001">r241001</a>.</p></li><li><p>LLD's COFF linker can now link a working 64-bit debug build of Chrome. chrome.dll takes 24 seconds (vs 48 seconds for linking it with MSVC). <a href="http://reviews.llvm.org/rL241318">r241318</a>.</p></li><li><p>LLDB grew an example of scripted steps in Python. <a href="http://reviews.llvm.org/rL241216">r241216</a>.</p></li></ul>
- LLVM Weekly - #78, June 29th 2015https://blog.llvm.org/2015/06/llvm-weekly-78-june-29th-2015.htmlMon, 29 Jun 2015 03:51:00 +0000https://blog.llvm.org/2015/06/llvm-weekly-78-june-29th-2015.html<p>Welcome to the seventy-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'm in the Bay Area this week for the <a href="http://riscv.org/workshop-jun2015.html">second RISC-V workshop</a> where my colleague and I will of course be talking about <a href="http://www.lowrisc.org">lowRISC</a>. If you're not able to make it, keep an eye on the lowRISC blog which I intend to keep updating semi-live with notes from the talks and presentations.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/78">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Hans Wennborg has shared the <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087060.html">release plan for LLVM/Clang 3.7</a>. This would see the release branch created on 14th July, with a final release targeted for 21st August.</p><p>A <a href="http://www.cl.cam.ac.uk/~pes20/cerberus/notes50-2015-05-24-survey-discussion.html">detailed analysis</a> of the results of the "What is C in practice" survey has now been posted. The survey gained around 300 responses, and aims to help guide the definition of a formal model for the de facto standard of C (i.e. C as it is used rather than purely as specified in the ISO standard).</p><p>The 3.6.2-rc1 LLVM/Clang release <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087111.html">has been tagged</a>. As always, testing is encouraged.</p><h3>On the mailing lists</h3><p>Unfortunately at the time of writing GMANE seems to be having some problems, so for this week I'll be using links to the pipermail archives of the relevant mailing list posts.</p><ul><li><p>Adrian Prantl has a proposal for <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087109.html">improving the quality of debug locations and of DbgValueHistoryCalculator</a>. This will involve adding new heuristics so DbgValueHistoryCalculator is smarter at creating ranges.</p></li><li><p>Sanjoy Patel kicked off a discussion about <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087225.html">conversion between bitwise AND and short-circuit evaluation for booleans</a>. In particularly, he's wanting to ensure that short circuit evaluation is not used (though as is pointed out in the thread, the benefit of saving the branch is highly microarchitecture dependent).</p></li><li><p>Dan Liew has posted an RFC on <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087246.html">improving the testing of exported LLVM CMake targets</a>. He has produced a <a href="https://github.com/delcypher/llvmCMakeImportDemo">toy project</a> making use of these targets, which could be used to help ensure they stay in working shape.</p></li><li><p>Bjarke Roune is proposing <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087234.html">functionality to determine when a posion value is guaranteed to produce undefined behaviour</a>, with the aim of improving handling of nsw/inbounds and similar in LLVM passes such as scalar evolution.</p></li><li><p>Philip Reames has responded to a question from Chandler Carruth with a good summary of the <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-June/087222.html">motivation for supporting inlining through statepoints and patchpoints</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The InterleavedAccess pass has been introduced to identify interleaved memory accesses so they can be transformed into target-specific intrinsics. <a href="http://reviews.llvm.org/rL240751">r240751</a>.</p></li><li><p>Initial serialisation of machine instructions has been added, representing MachineInstructions in YAML. <a href="http://reviews.llvm.org/rL240295">r240295</a>, <a href="http://reviews.llvm.org/rL240425">r240425</a>, and more.</p></li><li><p>The CaptureTracking pass has been optimised to improve performance on very large basic blocks. <a href="http://reviews.llvm.org/rL240560">r240560</a>.</p></li><li><p>A parser for LLVM stackmap sections has been added and made available through llvm-readobj. <a href="http://reviews.llvm.org/rL240860">r240860</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The recently added nullability attributes have been extensively documented. <a href="http://reviews.llvm.org/rL240296">r240296</a>.</p></li><li><p>constexpr can now be specified in condition declarations. <a href="http://reviews.llvm.org/rL240707">r240707</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The README for the COFF linker in LLD has been updated with new performance numbers. It's now 3.5 seconds to self-host (was previously 5 seconds), and this compared 7 seconds with the MSVC linker and 30 seconds with the old LLD. <a href="http://reviews.llvm.org/rL240759">r240759</a>.</p></li><li><p>The safestack TODO list in compiler-rt has been updated. <a href="http://reviews.llvm.org/rL240473">r240473</a>.</p></li><li><p>LLD gained support for thread-local storage in MachO objects. <a href="http://reviews.llvm.org/rL240454">r240454</a>.</p></li><li><p>Polly has had a meaningful improvement in compile time through enabling the small integer optimisation of the ISL (Integer Set Library). Polybench benchmarks on average take 20% less time to compile. <a href="http://reviews.llvm.org/rL240689">r240689</a>.</p></li></ul>
- LLVM Weekly - #77, Jun 22nd 2015https://blog.llvm.org/2015/06/llvm-weekly-77-jun-22nd-2015.htmlMon, 22 Jun 2015 04:52:00 +0000https://blog.llvm.org/2015/06/llvm-weekly-77-jun-22nd-2015.html<p>Welcome to the seventy-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'll be in California next week for the <a href="http://riscv.org/workshop-jun2015.html">second RISC-V workshop</a>. Me and my colleague Wei will both be giving talks about recent <a href="http://www.lowrisc.org/">lowRISC</a> progress. Say hi if you're going to be there. I might have some spare time towards the end of the week too if anyone wants to meet up.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/77">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p><a href="https://github.com/WebAssembly/design">WebAssembly</a> has been announced. It is a new collaboration between browser vendors to define a new binary executable format that can be used as a compilation target. A good summary is available <a href="https://groups.google.com/forum/#!topic/emscripten-discuss/k-egXO7AkJY">here on the emscripten mailing list</a>.</p><p>Tilmann Scheller has written up a <a href="http://blogs.s-osg.org/an-introduction-to-accelerating-your-build-with-clang/">pair</a> <a href="http://blogs.s-osg.org/a-conclusion-to-accelerating-your-build-with-clang/">of</a> blog posts about improving build times of Clang. He steps through a wide range of generic approaches (using Ninja, ccache, the gold linker, LTO+PGO in the host compiler etc etc) and some specific to Clang/LLVM.</p><p>The <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/43303">Cambridge LLVM Social</a> will be taking place on Wed 24th June, 7.30pm at the Blue.</p><h3>On the mailing lists</h3><ul><li><p>Dan Gohman has posted an RFC for the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86952">inclusion of a WebAssembly backend in LLVM</a>. It seems like everyone is in favour of the proposed approach.</p></li><li><p>Yaxun Li has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86950">revised RFC on adding a SPIR-V target to LLVM</a>. There still seems to be some push-back on the proposed approach. Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86966">makes an argument</a> that SPIR-V should make use of the existing SelectionDAG legalization layer.</p></li><li><p>Igor Laevsky is seeking more feedback on adding an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87017">attribute to mark that a function only accesses memory through its arguments</a>. Philip Reames point out in the thread that this isn't a new concept to LLVM, except right now <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/87070">such an attribute can only be specified on intrinsics</a>.</p></li><li><p>Philip Reames is looking for feedback on his plan to implement <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86984">profile-guided inlining</a>.</p></li><li><p>Diego Novillo has posted an RFC to enable the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86970">-fprofile-generate and -fprofile-use Clang flags</a>. Unsurprisingly, people are in favour of supporting these flags for GCC compatibility.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Some initial support for 'fault maps' and a <code>FAULTING_LOAD_OP</code>, intended for use in a managed language runtime, has been added. The new ImplicitNullChecks pass will fold null checks into nearby memory operations. <a href="http://reviews.llvm.org/rL239740">r239740</a>, <a href="http://reviews.llvm.org/rL239743">r239743</a>.</p></li><li><p>The <a href="http://dslab.epfl.ch/proj/cpi/">SafeStack</a> pass to protect against stack-based memory corruption errors has been added. <a href="http://reviews.llvm.org/rL239761">r239761</a>.</p></li><li><p>All temporary symbols are now unnamed. This saves a small amount of memory. <a href="http://reviews.llvm.org/rL240130">r240130</a>.</p></li><li><p>There's been some enhancement to the heuristics for switch lowering. <a href="http://reviews.llvm.org/rL240224">r240224</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The <code>-fsanitize-trap=</code> flag has been introduced, which will be used to control if the given sanitizer traps upon detecting an error. <a href="http://reviews.llvm.org/rL240105">r240105</a>.</p></li><li><p>Appropriate bitsets for use by LLVM's control flow integrity implementation can now be emitted for the Microsoft ABI. <a href="http://reviews.llvm.org/rL240117">r240117</a>.</p></li><li><p>Kernel AddressSanitizer now has basic support. <a href="http://reviews.llvm.org/rL240131">r240131</a>.</p></li><li><p>Clang learned to recognise type nullability specifiers. <a href="http://reviews.llvm.org/rL240146">r240146</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB learnt how to use hardware watchpoints for MIPS. <a href="http://reviews.llvm.org/rL239991">r239991</a>.</p></li><li><p>Compression support has been added to LLDB's implementation of the gdb-remote protocol. <a href="http://reviews.llvm.org/rL240066">r240066</a>.</p></li></ul>
- LLVM Weekly - #76, Jun 15th 2015https://blog.llvm.org/2015/06/llvm-weekly-76-jun-15th-2015.htmlMon, 15 Jun 2015 09:49:00 +0000https://blog.llvm.org/2015/06/llvm-weekly-76-jun-15th-2015.html<p>Welcome to the seventy-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/76">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The big news this week is that Apple have announced Swift 2.0 and, perhaps more importantly, that <a href="https://developer.apple.com/swift/blog/?id=29">Swift will be open source later this year</a>. The intention is that iOS, OS X and Linux will be supported at release.</p><h3>On the mailing lists</h3><ul><li><p>Quentin Colombet has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86783">helpful clarification</a> on the restrictions of a MachineFunctionPass.</p></li><li><p>Getting frustrated maintaining your out-of-tree LLVM backend? It's comforting for me at least to know things could be worse. Patrik Hägglund reports he and his colleague <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86730">maintain patches to support 16-bit bytes and 24/40-bit MachineValueTypes</a>.</p></li><li><p>Chandler Carruth is planning some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86842">AliasAnalysis refactoring for the new pass manager</a>. He's asking for feedback the general plan as well as the all-important question of naming conventions.</p></li><li><p>Zia Ansari has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86742">shared</a> an interesting summary of an investigation of performance swings on Intel architectures related to the post-decode micro-op cache. A <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/attachments/20150610/024ed87f/attachment-0001.pptx">PPTX-formatted summary is available here</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The loop vectorizer gained an optimisation for interleaved memory access. It is disabled by default but can be turned on using <code>-enable-interleaved-mem-accesses=true</code>. An AArch64InterleavedAccess pass was also added. <a href="http://reviews.llvm.org/rL239291">r239291</a>, <a href="http://reviews.llvm.org/rL239514">r239514</a>.</p></li><li><p>A prototype for 32-bit SEH (Structured Exception Handling) has been added. <a href="http://reviews.llvm.org/rL239433">r239433</a>.</p></li><li><p>LLVM has grown LibDriver and llvm-lib, intended to provide a lib.exe compatible utility. <a href="http://reviews.llvm.org/rL239434">r239434</a>.</p></li><li><p>x86 gained a new reassociation MachineCombiner optimisation to increase ILP. <a href="http://reviews.llvm.org/rL239486">r239486</a>.</p></li><li><p>The R600 backend has now been renamed to AMDGPU. <a href="http://reviews.llvm.org/rL239657">r239657</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Support for C99 partial re-initialization behaviour has been implemented. <a href="http://reviews.llvm.org/rL239446">r239446</a>.</p></li><li><p>Clang gained support for the BPF backend. <a href="http://reviews.llvm.org/rL239446">r239496</a>.</p></li><li><p>The loop vectorize pragma now recognises <code>assume_safety</code>. This will tell loop access analysis to skip memory dependency checking. <a href="http://reviews.llvm.org/rL239572">r239572</a>.</p></li><li><p>The target attribute is now supported. Much like GCC's target attribute, it allows adding subtarget features and changing the CPU for a particular function. <a href="http://reviews.llvm.org/rL239579">r239579</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The COFF linker in LLD continues to get faster. <a href="http://reviews.llvm.org/rL239332">r239332</a>, <a href="http://reviews.llvm.org/rL239292">r239292</a>.</p></li><li><p>LLD grew a TypeSystem interface to support adding non-clang languages (though it seems it's reverted for now). <a href="http://reviews.llvm.org/rL239360">r239360</a>.</p></li></ul>
- LLVM Weekly - #75, Jun 8th 2015https://blog.llvm.org/2015/06/llvm-weekly-75-jun-8th-2015.htmlMon, 08 Jun 2015 04:40:00 +0000https://blog.llvm.org/2015/06/llvm-weekly-75-jun-8th-2015.html<p>Welcome to the seventy-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/75">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>Botond Ballo has posted a <a href="https://botondballo.wordpress.com/2015/06/05/trip-report-c-standards-meeting-in-lenexa-may-2015/">wonderfully thorough summary of the recent Lenexa C++ standards meeting</a>, even including a table to summarise the status of various major proposals.</p><p>I have somehow neglected to mention the <a href="http://crystal-lang.org/">Crystal language</a> previously. It is a statically typed language with syntax inspired by Ruby which (of course) compiles using LLVM. It was <a href="https://news.ycombinator.com/item?id=9669166">discussed last week on Hacker News</a>.</p><p>icGrep has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86599">been released</a>. It makes use of the 'Parabix' text representation and LLVM for high performance regex matching. More details are available <a href="http://parabix.costar.sfu.ca/wiki/ICgrep">at the icGrep homepage</a>.</p><p>The winners of the 7th Underhanded C Contest <a href="http://www.underhanded-c.org/">have now been announced online</a>. Congratulations to the winner, Karen Pease, for creating such a monstrous piece of code.</p><h3>On the mailing lists</h3><ul><li><p>Chandler Carruth has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86607">summary of a recent in-person discussion about LLD's future and design</a>. It looks like this was a very positive meeting with agreement in important areas. The recently contributed experimental COFF linker is going to be evaluated to see if its linking model would be appropriate for Darwin. If so, the hope is work can focus on adopting that as the standard model. If not, more work will need to be done on refactoring LLD and making sure that code which makes sense to be shared is.</p></li><li><p>Christos Margiolas has been working as an intern at the Qualcomm Innovation Center on support for heterogeneous compute, including transparent offloading of loops or functions to accelerators. He is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86569">asking for feedback</a> and looking to see if there is interest in getting this upstream. He has <a href="https://drive.google.com/file/d/0B5GasMlWJhTOb2tXTDZsal9qclE/view">shared a slide deck</a> which gives more details.</p></li><li><p>Woodrow Barlow is interested in <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86373">implementing a new PIC backend for LLVM</a>. Renato Golin gave a very thorough and helpful response about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86375">how you might proceed</a>.</p></li><li><p>Frank Winter is looking for a way to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86481">replace a sequence of repetitive code with a loop</a>. It was pointed out that the LLVM loop reroll pass should be helpful for this, but it does need to run on an existing loop. This would mean it requires modification or the IR should be modified to introduce a trivial loop before running the reroll pass.</p></li><li><p>Philip Reames has posted an RFC on adding a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86407">liveoncall parameter attribute</a>. This would be used to leave an argument marked as live even if it isn't actually used (so it might be later inspected at runtime). Chris Lattner queried whether <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86522">adding an intrinsic might be a better approach</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM gained support for the new AArch64 v8.1a atomic instructions. <a href="http://reviews.llvm.org/rL238818">r238818</a>.</p></li><li><p>The MPX (Intel Memory Protection eXtensions) feature bit and bound registers are now supported on the X86 backend. <a href="http://reviews.llvm.org/rL238916">r238916</a>.</p></li><li><p>MIPS FastISel gained more instruction and intrinsic implementations. <a href="http://reviews.llvm.org/rL238756">r238756</a>, <a href="http://reviews.llvm.org/rL238757">r238757</a>, <a href="http://reviews.llvm.org/rL238759">r238759</a>.</p></li><li><p>With the introduction of MCSymbolELF, the base MCSymbol size is now reduced to 48 bytes on x86-64. <a href="http://reviews.llvm.org/rL238801">r238801</a>.</p></li><li><p>Work has started on porting AliasAnalysis to the new pass manager. <a href="http://reviews.llvm.org/rL239003">r239003</a>.</p></li><li><p>The BPF backend now supports big and host endian, in addition to the previously supported little endian. <a href="http://reviews.llvm.org/rL239071">r239071</a>.</p></li><li><p>The naming and structure of the recently added unroll heuristics has been modified. <a href="http://reviews.llvm.org/rL239164">r239164</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p><code>-mcpu</code> for ARM will now ignore the case of its arguments for ARM. <a href="http://reviews.llvm.org/rL239059">r239059</a>.</p></li><li><p>A mass of predefined vector functions for PowerPC has been added. <a href="http://reviews.llvm.org/rL239066">r239066</a>.</p></li><li><p>The concept and requires keywords (as used in the C++ Concepts TS) are now lexed. Let's hope this starting point is followed up with work towards full concepts support in the coming months. <a href="http://reviews.llvm.org/rL239128">r239128</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The lld COFF linker gained an initial implementation of link-time optimisation. <a href="http://reviews.llvm.org/rL238777">r238777</a>.</p></li><li><p>LLDB gained support for software emulation of the MIPS64 branch instructions. <a href="http://reviews.llvm.org/rL238820">r238820</a>.</p></li><li><p>libiomp5 is now libomp. <a href="http://reviews.llvm.org/rL238712">r238712</a>.</p></li></ul>
- LLVM Weekly - #74, Jun 1st 2015https://blog.llvm.org/2015/06/llvm-weekly-74-jun-1st-2015.htmlMon, 01 Jun 2015 06:35:00 +0000https://blog.llvm.org/2015/06/llvm-weekly-74-jun-1st-2015.html<p>Welcome to the seventy-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>You may be interested in the <a href="https://blog.riscv.org/2015/04/registration-now-open-2nd-risc-v-workshop-june-29-30-2015/">second RISC-V workshop</a>, which will be held in Berkeley June 29-30. Early bird registration ends today, but academics can register for free. My colleague Wei and I will be there representing <a href="http://www.lowrisc.org">lowRISC</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/74">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p><a href="https://github.com/0ax1/MPI-Checker">MPI-Checker</a>, a static analysis tool for MPI code has been released. It is of course implemented using Clang's <a href="http://clang-analyzer.llvm.org/">Static Analyzer framework</a>.</p><p>The LLVM-HPC2 workshop will be held on November 15th, co-located with SC15. The <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86349">call for papers</a> has been published. Submissions are due by September 1st.</p><h3>On the mailing lists</h3><ul><li><p>The discussion about improving LLD has resumed. Rui Ueyama has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86306">written about his recent patch for a section-based PE/COFF linker</a>. Sean Silva argues that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86333">refactoring might be a better approach</a>.</p></li><li><p>Hans Wennborg has shared a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42972">preliminary release plan for LLVM/Clang 3.7</a>. This would see the codebase branched on the 14th of July with a release target of the end of August. Tom Stellard has also shared a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86175">schedule for the 3.6.2 release</a>. The deadline for patches is June 15 with the release date targeted for June 29th.</p></li><li><p>Teresa Johnson has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86282">updated RFC of her ThinLTO implementation plan</a>. There are still concerns about the wrapping of LLVM bitcode in ELF. Alex Rosenberg suggests <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86313">implementing an objcopy replacement for LLVM and extending bitcode as necessary</a> as an alternative approach.</p></li><li><p>Chris Bieneman has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86248">status update on the quest to replace the autoconf build system with CMake</a>.</p></li><li><p>Quentin Colombet is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86222">seeking benchmark reports</a> (or indeed bugs!) for the recently added 'shrink wrapping'.</p></li><li><p>Matthias Braun has left a quick note for maintainers of out-of-tree targets that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86291">pristine register semantics have been modified slightly</a>.</p></li><li><p>Chandler Carruth has posted some thoughts on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86137">next steps for loop unrolling analysis</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Codegen for memcpy on Thumb2 has been improved to make use of load/store multiple (more details of how this works in the commit message, worth a read for those interested). <a href="http://reviews.llvm.org/rL238473">r238473</a>.</p></li><li><p>Popcount on x86 will now be implemented using a <a href="http://wm.ite.pl/articles/sse-popcount.html">lookup table in register technique</a>. <a href="http://reviews.llvm.org/rL238636">r238636</a>, <a href="http://reviews.llvm.org/rL238652">r238652</a>.</p></li><li><p>Work continues on reducing peak memory usage through optimisations to debug info. <a href="http://reviews.llvm.org/rL238364">r238364</a>.</p></li><li><p>Initial support for the <code>convergent</code> attribute has landed. <a href="http://reviews.llvm.org/rL238264">r238264</a>.</p></li><li><p>The documentation about the current state of LLVM's Phabricator has been updated along with a call for volunteers to help develop necessary improvements and modifications to Phabricator's PHP codebase. <a href="http://reviews.llvm.org/rL238295">r238295</a>.</p></li><li><p>MCJIT gained support for MIPS64r2 and MIPS64r6. <a href="http://reviews.llvm.org/rL238424">r238424</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang's handling of <code>-fopenmp</code> has been rewritten. <a href="http://reviews.llvm.org/rL235111">r238389</a>.</p></li><li><p>The user documentation on profiling has been extended. <a href="http://reviews.llvm.org/rL238504">r238504</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A new PE/COFF section-based linker has been added to lld. This follows on from discussions about the direction of lld and whether it makes sense to build on top of the atom model. The linker is able to self-link on Windows and is significantly faster than the current implementations (1.2 seconds vs 5 seconds, even without multi-threading). It also takes only 250MB of RAM to self-link vs 2GB. <a href="http://reviews.llvm.org/rL238458">r238458</a>.</p></li><li><p>LLDB on Windows can now demangle Linux or Android symbols. <a href="http://reviews.llvm.org/rL238460">r238460</a>.</p></li></ul>
- LLVM Weekly - #73, May 25th 2015https://blog.llvm.org/2015/05/llvm-weekly-73-may-25th-2015.htmlMon, 25 May 2015 09:39:00 +0000https://blog.llvm.org/2015/05/llvm-weekly-73-may-25th-2015.html<p>Welcome to the seventy-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/73">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The LLVM blog has properly <a href="http://blog.llvm.org/2015/05/openmp-support_22.html">announced</a> full support for OpenMP 3.1 in Clang.</p><p>The Clang-derived <a href="http://www.zapcc.com/">Zapcc</a> has had <a href="https://news.ycombinator.com/item?id=9592601">some attention</a> this week. It claims higher compilation speeds than the baseline Clang or other compilers. Yaron Keren, the principal developer has shared <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42950">many more details about its implementation</a> on the Clang mailing list.</p><h3>On the mailing lists</h3><ul><li><p>The discussion about upstreaming the LLVM/SPIR-V converter has continued. Chandler Carruth has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86000">responded with feedback</a>, and Philip Reames has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86054">shared his concerns</a> about the merge proposal as-is. Neil Henning has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86056">responded to some of these concerns</a>.</p></li><li><p>Adam Nemet has kicked off a thread about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86024">alias-based loop versioning</a>, with the hope that others working in the area can chime in.</p></li><li><p>Félix Cloutier queries why <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/86029">MemoryDependencyAnalysis reports dependencies between NoAlias pointers</a>. Daniel Berlin points to his very interesting looking work on <a href="http://reviews.llvm.org/D7864">MemorySSA</a>.</p></li><li><p>Duncan P.N. Exon Smith has posted an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85981">reducing the memory footprint of debug info entries</a>. The attached patches reduce peak memory usage from 920MB to 884MB for the tested workload.</p></li><li><p>John Criswell has a helpful answer regarding <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85987">how to determine whether a branch instruction may depend on function parameters</a>.</p></li><li><p>Andrew Kaylor has shared a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85926">detailed description of the work to be done for exception handling on Windows</a>.</p></li><li><p>Andrew Bokhanko is looking for feedback on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42622">adding an option to control a level of OpenMP support in Clang</a>. Now that 3.1 support is complete, OpenMP 4.0 is the next target but this is likely to remain incomplete for some time. The question is whether those features which are implemented are available by default, or whether users should opt-in with a compiler flag while support remains incomplete.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The <code>dereferenceable_or_null</code> attribute will now be exploited by the loop environment code motion pass. <a href="http://reviews.llvm.org/rL237593">r237593</a>.</p></li><li><p>Commits have started on the 'MIR serialization' project, which aims to print machine functions in a readable format. <a href="http://reviews.llvm.org/rL237954">r237954</a>.</p></li><li><p>A GCStrategy for CoreCLR has been committed alongside some documentation for it. <a href="http://reviews.llvm.org/rL237753">r237753</a>, <a href="http://reviews.llvm.org/rL237869">r237869</a>.</p></li><li><p>libFuzzer gained some more documentation. <a href="http://reviews.llvm.org/rL237836">r237836</a>.</p></li><li><p>libFuzzer can now be used with user-supplied mutators. <a href="http://reviews.llvm.org/rL238059">r238059</a>, <a href="http://reviews.llvm.org/rL238062">r238062</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p><code>-fopenmp</code> will turn on OpenMP support and link with libiomp5 (libgomp can alternatively be specified). <a href="http://reviews.llvm.org/rL237769">r237769</a>.</p></li><li><p>The <code>-mrecip</code> flag has been added to match GCC. <a href="http://reviews.llvm.org/rL238055">r238055</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>C++1z status for libcxx has been updated. <a href="http://reviews.llvm.org/rL237606">r237606</a>.</p></li><li><p><code>std::bool_constant</code> and <code>uninitialized_copy()</code> was added to libcxx. <a href="http://reviews.llvm.org/rL237636">r237636</a>, <a href="http://reviews.llvm.org/rL237699">r237699</a>.</p></li><li><p>libcxx gained a TODO list. Plenty of tasks that might be interesting to new contributors. <a href="http://reviews.llvm.org/rL237813">r237813</a>, <a href="http://reviews.llvm.org/rL237988">r237988</a>.</p></li><li><p>LDB has enabled debugging of multithreaded programs on Windows and gained support for attaching to process. <a href="http://reviews.llvm.org/rL237637">r237637</a>, <a href="http://reviews.llvm.org/rL237817">r237817</a>.</p></li></ul>
- OpenMP Supporthttps://blog.llvm.org/2015/05/openmp-support_22.htmlFri, 22 May 2015 08:23:00 +0000https://blog.llvm.org/2015/05/openmp-support_22.html<div dir="ltr" style="text-align: left;" trbidi="on"><div class="MsoNormal"><span lang="EN-US">OpenMP support in Clang compiler is completed! Every pragma and clause from <a href="http://www.openmp.org/mp-documents/OpenMP3.1.pdf">3.1 version of the standard</a> is supported in full, including combined directives (like â#pragma omp parallel forâ and â#pragma omp parallel sectionsâ). In addition</span>, some elements of OpenMP 4.0 are supported as well. This includes âalmost completeâ support for â#pragma omp simdâ and full support for â#pragma omp atomicâ (combined pragmas and a couple of clauses are still missing).</div><div class="MsoNormal"><span lang="EN-US"><br /></span></div><div class="MsoNormal"><span lang="EN-US">OpenMP enables Clang users to harness full power of modern multi-core processors with vector units. Pragmas from OpenMP 3.1 provide an industry standard way to employ task parallelism, while â#pragma omp simdâ is a simple yet flexible way to enable data parallelism (aka vectorization).</span><br /><span lang="EN-US"><br /></span></div><div class="MsoNormal"><span lang="EN-US">Clang implementation of OpenMP standard relies on LLVM OpenMP runtime library, available at <a href="http://openmp.llvm.org/">http://openmp.llvm.org/</a>. This runtime supports ARM® architecture processors, PowerPC⢠processors, 32 and 64 bit X86 processors and provides ABI compatibility with GCC and Intel's existing OpenMP compilers.</span><br /><span lang="EN-US"><br /></span></div><div class="MsoNormal"><span lang="EN-US">To enable OpenMP, just add â<tt>-fopenmp</tt>â to the command line and provide paths to OpenMP headers and library with â<tt>-I <</tt><i>path to omp.h</i><tt>> -L <</tt><i>LLVM OpenMP library path</i><tt>></tt>â.</span><br /><span lang="EN-US"><br /></span></div><div class="MsoNormal"><span lang="EN-US">To run a compiled program you may need to provide a path to shared OpenMP library as well:<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><tt>$ export LD_LIBRARY_PATH=<OpenMP library path>:$LD_LIBRARY_PATH</tt></div>or:<br /><div class="MsoNormal"><tt>$ export DYLD_LIBRARY_PATH=<OpenMP library path>:$DYLD_LIBRARY_PATH</tt></div>on Mac OS X.<br /><br /><div class="MsoNormal"><span lang="EN-US">You can confirm that the compiler works correctly by trying this simple parallel C program:<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "trebuchet ms" , sans-serif;">#include <omp.h><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "trebuchet ms" , sans-serif;">#include <stdio.h><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "trebuchet ms" , sans-serif;">int main() {<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "trebuchet ms" , sans-serif;">#pragma omp parallel<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "trebuchet ms" , sans-serif;"> printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: "trebuchet ms" , sans-serif;">}</span><o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US">Compile it (you should see no errors or warnings):<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "courier new"; font-size: 10.0pt;"><span style="font-family: "trebuchet ms" , sans-serif;">$ clang -fopenmp -I <path to omp.h> -L <LLVM OpenMP library path> hello_openmp.c -o hello_openmp</span><o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US">and execute: <o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "trebuchet ms" , sans-serif; font-size: 10.0pt;">$ <span style="background: white; color: #222222;">export [DY]LD_LIBRARY_PATH=<OpenMP library path>:$[DY]LD_LIBRARY_PATH</span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "courier new"; font-size: 10.0pt;"><span style="font-family: "trebuchet ms" , sans-serif;">$ ./hello_openmp</span><o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US">You will see more than one âHelloâ line with different thread numbers (note that the lines may be mixed together). If you see only one line, try setting the environment variable OMP_NUM_THREADS to some number (say 4) and try again.</span><br /><span lang="EN-US"><br /></span></div><div class="MsoNormal"><span lang="EN-US">Hopefully, you will enjoy using OpenMP and witness dramatic boosts of your applicationsâ performance!<o:p></o:p></span></div></div>
- LLVM Weekly - #72, May 18th 2015https://blog.llvm.org/2015/05/llvm-weekly-72-may-18th-2015.htmlMon, 18 May 2015 05:56:00 +0000https://blog.llvm.org/2015/05/llvm-weekly-72-may-18th-2015.html<p>Welcome to the seventy-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Some of you may be interested that over at the lowRISC project, we've announced the <a href="http://www.lowrisc.org/blog/2015/05/summer-of-code-students-for-lowrisc/">full set of summer student projects</a> we're supporting.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/72">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>The Rust programming language, which of course uses LLVM as its compiler backend, has just <a href="http://blog.rust-lang.org/2015/05/15/Rust-1.0.html">released version 1.0</a>.</p><p>The next Cambridge LLVM Social will <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42786">take place on Wednesday 20th May</a> at the Cambridge Beer Festival.</p><h3>On the mailing lists</h3><ul><li><p>Teresa Johnson has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85628">RFC on her ThinLTO implementation plan</a>. It's seen a lot of feedback, too much for me to hope to summarise, though much of it was around emitting bitcode wrapped in ELF.</p></li><li><p>Yaxun Liu is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85609">looking to upstream the Khronos Group LLM to SPIR-V converter</a>. There was some discussion as to whether SPIR-V makes most sense as a backend or as serialisation format alongside the LLVM bitcode output.</p></li><li><p>Reid Kleckner has written up an RFC on a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85783">new exception handling representation for MSVC</a>, given that the Itanium EH representation has been found insufficient.</p></li><li><p>Chris Matthews proposes <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85775">changing LNT's regression detection algorithm</a>, with the aim being to reduce the number of false positives to the extent that people will be motivated to investigate reported regressions.</p></li><li><p>Matt Arsenault is proposing <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85616">upstreaming an LLVM backend for HSAIL</a>. HSAIL presents a virtual target machine (in a way similar to NVPTX), and is defined by the HSA Foundation.</p></li><li><p>Owen Anderson proposes a new <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85633">convergent attribute</a> aiming to make LLVM more suitable for SPMD/SIMT programming models. So far, all feedback has been very positive.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The ARM backend has been updated to use AEABI aligned function variants. <a href="http://reviews.llvm.org/rL237127">r237127</a>.</p></li><li><p>The heuristic for estimating the effect of complete loop unrolling has been reimplemented. <a href="http://reviews.llvm.org/rL237156">r237156</a>.</p></li><li><p>Statepoints are now 'patchable'. <a href="http://reviews.llvm.org/rL237214">r237214</a>.</p></li><li><p>Support for function entry count metadata has been added. <a href="http://reviews.llvm.org/rL237260">r237260</a>.</p></li><li><p>A new loop distribution pass has been born. It is off by default. <a href="http://reviews.llvm.org/rL237358">r237358</a>.</p></li><li><p>New SelectionDAG nodes have been added for signed/unsigned min/max. <a href="http://reviews.llvm.org/rL237423">r237423</a>.</p></li><li><p>A simple speculative execution pass, targeted mainly at GPUs has been added. <a href="http://reviews.llvm.org/rL237459">r237459</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The little endian SPARC target has been added to clang. <a href="http://reviews.llvm.org/rL237001">r237001</a>.</p></li><li><p>clang-format's formatter has undergone some refactoring, which also led to a few bug fixes.<a href="http://reviews.llvm.org/rL237104">r237104</a>.</p></li><li><p>Documentation on adding new attributes has seen a significant update. <a href="http://reviews.llvm.org/rL237268">r237268</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx learnt <code>std::experimental::sample</code> <a href="http://reviews.llvm.org/rL237264">r237264</a>.</p></li><li><p>lldb has enabled multithreaded debugging on Windows. <a href="http://reviews.llvm.org/rL237392">r237392</a>.</p></li><li><p>lldb can now set and clear hardware watchpoints and breakpoints on AArch64. <a href="http://reviews.llvm.org/rL237419">r237419</a>.</p></li><li><p>lldb gained an assembly profiler for mips32. <a href="http://reviews.llvm.org/rL237420">r237420</a>.</p></li></ul>
- LLVM Weekly - #71, May 11th 2015https://blog.llvm.org/2015/05/llvm-weekly-71-may-11th-2015.htmlMon, 11 May 2015 02:42:00 +0000https://blog.llvm.org/2015/05/llvm-weekly-71-may-11th-2015.html<p>Welcome to the seventy-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/71">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The implementation of OpenMP 3.1 in Clang/LLVM is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42620">now complete</a>. Well done to everyone involved.</p><p>Most slides from the presentations at <a href="http://llvm.org/devmtg/2015-04/">EuroLLVM 2015</a> are now online. Video is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85455">coming soon</a>.</p><p>Version 3.5.1 of Clang UPC, the Unified Parallel C compiler has <a href="http://clangupc.github.io/2015/04/15/clang-upc-3-5-1-0-announcment/">been released</a>. The main change seems to be the move to Clang/LLVM 3.5.</p><p>The Pony Language, which features an LLVM backend has recently <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85486">been released</a>. It received quite a lot of <a href="https://news.ycombinator.com/item?id=9482483">discussion on Hacker News</a>.</p><p>Many readers might be interested in this <a href="http://www.reddit.com/r/cpp/comments/35g7f6/">update from the last C++ standardization committee meeting</a>.</p><p>IBM have posted some bounties for <a href="https://www.bountysource.com/issues/11873163-enable-thread-sanitizer-for-ppc64">TSAN support</a> and <a href="https://www.bountysource.com/issues/11872976-enable-memory-sanitizer-for-ppc64">MSAN support</a> for PPC64.</p><h3>On the mailing lists</h3><ul><li><p>Renato Golin has been asking about interest in <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85385">improving the LLVM online code coverage report</a>. Joshua Cranmer shared the work he did on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85424">code coverage for Thunderbird and Firefox</a>.</p></li><li><p>John Criswell has followed up on an older thread about the LLVM DSA work giving <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85380">some useful insight</a>, and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85461">some more</a>.</p></li><li><p>Hubert Tong is interested in working on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42564">implementing the C++ Concepts Technical Specification in Clang</a>, and would like anyone who's interested in collaborating or has already made a start to get in touch.</p></li><li><p>Quentin Colombet has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85322">heads-up about his shrink-wrap pass work</a>, including details on how to enable support in your backend (in-tree or out-of-tree).</p></li><li><p>Last week's discussion about improving LLD has rumbled on. Chris Lattner <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85298">suggested working on two linkers</a>, one to serve the needs of those who primarily want a usable BSD-licensed system linker and another a 'next generation' linker trying to meet the original aims of LLD, developed without the same constraints on compatibility. Alex Rosenberg gave a good <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85247">summary of the original aims of LLD</a> and how recent changes have moved it further from those aims. It looks like <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85483">a path forwards is being identified</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new 'shrink-wrap' pass has been added. It attempts to insert the prologue and epilogue of a function somewhere other than the entry/exit blocks. See the commit message for a motivating example. <a href="http://reviews.llvm.org/rL236507">r236507</a>.</p></li><li><p>Support for the z13 processor and its vector capabilities have been added to the SystemZ backend. <a href="http://reviews.llvm.org/rL236520">r236520</a>, <a href="http://reviews.llvm.org/rL236521">r236521</a>.</p></li><li><p>Documentation has been written for the new masked gather and scatter intrinsics. <a href="http://reviews.llvm.org/rL236721">r236721</a>.</p></li><li><p>The statepoint intrinsic has been extended to allow statepoints to be marked as tranditions from GC-aware code to nonGC-aware code. <a href="http://reviews.llvm.org/rL236888">r236888</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang support for the z13 processor was added. <a href="http://reviews.llvm.org/rL236531">r236531</a>.</p></li><li><p>Thread-safe initialization using the MSVC 2015 ABI has been implemented. <a href="http://reviews.llvm.org/rL236697">r236697</a>.</p></li><li><p>User-friendly <code>-fsanitize-coverage=</code> flags are now available. <a href="http://reviews.llvm.org/rL236790">r236790</a>.</p></li></ul><h3>Other project commits</h3><ul><li>libiomp's CMake has been integrated into the LLVM CMake build system, so you can now checkout libiomp and have it built alongside llvm, clang and so on. <a href="http://reviews.llvm.org/rL236534">r236534</a>.</li></ul>
- LLVM Weekly - #70, May 4th 2015https://blog.llvm.org/2015/05/llvm-weekly-70-may-4th-2015.htmlMon, 04 May 2015 05:33:00 +0000https://blog.llvm.org/2015/05/llvm-weekly-70-may-4th-2015.html<p>Welcome to the seventieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/70">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Microsoft have announced their intention to make use of the <a href="http://blogs.msdn.com/b/vcblog/archive/2015/05/01/bringing-clang-to-windows.aspx">Clang frontend on Windows</a>.</p><p>Bjarne Stroustrup has recently been <a href="http://www.infoq.com/news/2015/04/stroustrup-cpp17-interview">talking about potential C++17 features</a>.</p><p>The Visual C++ developers are going to be open-sourcing their <a href="http://blogs.msdn.com/b/vcblog/archive/2015/04/29/open-sourcing-visual-studio-s-gdb-lldb-debug-engine.aspx">GDB/LLDB debug engine</a>.</p><p>The projects accepted into Google Summer of Code for LLVM <a href="https://www.google-melange.com/gsoc/org2/google/gsoc2015/llvm">have been announced</a>. Four student projects have been accepted.</p><p>The next Bay Area LLVM social is <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/7243">scheduled for</a> 7pm on Thursday the 7th of May. Please sign up if you are attending.</p><h3>On the mailing lists</h3><ul><li><p>Rui Ueyama has been doing quite a lot of work on LLD of late and has proposed an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85190">LLD improvement plan</a>. In it, he proposes some major changes that would hopefully ease the path to LLD becoming a fully functional ELF, Mach-O, and PE-COFF linker. The two main proposals are to use the 'section' rather than the 'atom' model and to stop trying to bend the Unix model to work on other platforms, instead directly implementing the necessary native behaviour. There are understandably some concerns that this direction could result in LLD having to maintain essentially three linkers, but discussion is ongoing and much feedback seems positive.</p></li><li><p>Alex, who will be interning at Apple this summer has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/85003">RFC on a proposed machine level IR text serialisation format</a>. It came out a little mangled on Gmane so you may prefer to read the <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-April/084932.html">pipermail rendering</a>. A lot of the feedback revolves around the pros and cons of a YAML-based format..</p></li><li><p>Andrey Bokhanko suggests <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42449">replacing libgomp with libiomp</a> as the default OpenMP runtime library when using <code>-fopenmp</code>. Ultimately there seems to be agreement and the only issue seems to be on the library naming.</p></li><li><p>Nico Weber reports that although <code>-gline-tables-only</code> makes debug info much smaller, they've <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42419">found with Chromium the resulting stackframes aren't that usable without function parameters and namespaces</a>. The proposal is to add a new variant that does include function parameter info and namespace info.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The LLVM performance tips document has gained another two entries. <a href="http://reviews.llvm.org/rL235825">r235825</a>, <a href="http://reviews.llvm.org/rL235826">r235826</a>.</p></li><li><p>llvm-symbolizer now works on Windows. <a href="http://reviews.llvm.org/rL235900">r235900</a>.</p></li><li><p>SelectionDAG, DAGCombiner and codegen support for masked scatter and gather has been added. <a href="http://reviews.llvm.org/rL235970">r235970</a>, <a href="http://reviews.llvm.org/rL236211">r236211</a>, <a href="http://reviews.llvm.org/rL236394">r236394</a>.</p></li><li><p>Debug locations have been added to all constant SelectionDAG nodes. <a href="http://reviews.llvm.org/rL235989">r235989</a>.</p></li><li><p>Dragonegg support has been dropped from the release script. <a href="http://reviews.llvm.org/rL236077">r236077</a>.</p></li><li><p>The debug info IR constructs have been renamed from <code>MD*</code> to <code>DI*</code>. Duncan suggests that if you're updating an out of tree target, it may be easiest to first get things compiling with the code from before this commit, then continue the merge. <a href="http://reviews.llvm.org/rL236120">r236120</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang can now generate dependencies in the style accepted by the NMake and Jom build tools. <a href="http://reviews.llvm.org/rL235903">r235903</a>.</p></li><li><p>New AVX-512 intrinsics have been added. <a href="http://reviews.llvm.org/rL235986">r235986</a>, <a href="http://reviews.llvm.org/rL236218">r236218</a>.</p></li><li><p>Clang learned <code>-Wpessimizing-move</code> and <code>-Wredundant-move</code> warnings. <a href="http://reviews.llvm.org/rL236075">r236075</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB gained support for the SysV ABI on ARM and AArch64. <a href="http://reviews.llvm.org/rL236097">r236097</a>, <a href="http://reviews.llvm.org/rL236098">r236098</a>.</p></li><li><p>The LLVM test suite gained a <code>frame_layout</code> test. <a href="http://reviews.llvm.org/rL236085">r236085</a>.</p></li></ul>
- LLVM Weekly - #69, Apr 27th 2015https://blog.llvm.org/2015/04/llvm-weekly-69-apr-27th-2015.htmlMon, 27 Apr 2015 05:41:00 +0000https://blog.llvm.org/2015/04/llvm-weekly-69-apr-27th-2015.html<p>Welcome to the sixty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/69">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Ed Jones at Embecosm has written about his work to <a href="http://www.embecosm.com/2015/04/21/flexible-runtime-testing-of-llvm-on-embedded-systems/">use the GCC regression suite on Clang</a> and documented how to run the LLVM test suites on an embedded target.</p><p>GCC 5.1 has now <a href="http://article.gmane.org/gmane.comp.gcc.devel/139625">been released</a>. Congratulations to the GCC team. The versioning scheme is potentially confusing - 5.0 is the development version which saw a stable release as 5.1. The next minor releases will be 5.2, 5.3 etc and the next major release will be 6.1 (referred to as 6.0 during development).</p><h3>On the mailing lists</h3><ul><li><p>Sanjoy Das has posted an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84837">supporting implicit null checks</a> in LLVM. This is intended to support managed languages like Java, C#, or Go where a null check is required before using pointers.</p></li><li><p>Alex L interned at Apple last year, and is interning again this summer. He's <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84778">posted to the list</a> about his project, which is to develop a text-based human readable format that allows LLVM to serialize the machine-level IR. The intention is to make debug and testing easier. He welcomes any feedback or suggestions.</p></li><li><p>libunwind is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84895">moving</a> to its own repository. Hopefully a git mirror will go live soon.</p></li><li><p>Roel Jordans gave a talk at EuroLLVM this year about his software pipelining pass. He has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84852">posted to the mailing list</a> to give a few more details and share his source code.</p></li><li><p>Tom Stellard is looking to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84728">increase the number of code owners</a>, i.e. the set of people who review patches or approve merge requests to stable branches on a certain part of the code. His plan is to start nominating new code owners based on git history whenever he gets a new stable merge request for an unowned component.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Functions can now have metadata attachments. <a href="http://reviews.llvm.org/rL235785">r235785</a>.</p></li><li><p>The stack object allocation for Hexagon has been completely overhauled. <a href="http://reviews.llvm.org/rL235521">r235521</a>.</p></li><li><p>The vim support files have been updated. Changes include a new indentation plugin for .ll files. <a href="http://reviews.llvm.org/rL235369">r235369</a>.</p></li><li><p>llvm-link learned the <code>-override</code> option to override linkage rules. <a href="http://reviews.llvm.org/rL235473">r235473</a>.</p></li><li><p>There is now textual IR support for an explicit type parameter to the invoke instruction (much like for the call instruction). <a href="http://reviews.llvm.org/rL235755">r235755</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Documentation has been added for SanitizerCoverage (simple code coverage using the Sanitizer tools). <a href="http://reviews.llvm.org/rL235643">r235643</a>.</p></li><li><p>Clang's <code>__attribute__((aligned))</code> can now set alignment to a target-specific value, rather than just assuming 16 bytes on all platforms. <a href="http://reviews.llvm.org/rL235397">r235397</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lld now understands <code>--discard-locals</code>. <a href="http://reviews.llvm.org/rL235357">r235357</a>.</p></li><li><p>lldb's 'operation' and 'monitor' threads on Linux have been merged in to one. <a href="http://reviews.llvm.org/rL235304">r235304</a>.</p></li><li><p>It's now possible to build compiler-rt for MIPS with gcc. <a href="http://reviews.llvm.org/rL235299">r235299</a>.</p></li><li><p>libunwind seems to have been moved into its own project. <a href="http://reviews.llvm.org/rL235759">r235759</a>.</p></li></ul>
- LLVM Weekly - #68, Apr 20th 2015https://blog.llvm.org/2015/04/llvm-weekly-68-apr-20th-2015.htmlTue, 21 Apr 2015 01:52:00 +0000https://blog.llvm.org/2015/04/llvm-weekly-68-apr-20th-2015.html<p>Welcome to the sixty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/68">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Last week was of course <a href="http://llvm.org/devmtg/2015-04/">EuroLLVM</a>. It was good to put faces to names for a number of you, or to meet people I've only communicated with over twitter. Slides and videos should be forthcoming, but in the meantime you can read the <a href="http://llvmweekly.org/issue/67">liveblog</a> I maintained for the talks I was able to attend. A big thank you to the organisers and all those who presented.</p><p>The highest profile news for some time in the LLVM community is that <a href="http://blog.llvm.org/2015/04/llilc-llvm-based-compiler-for-dotnet.html">Microsoft are working on an LLVM-based compiler for .NET CoreCLR</a>. What's more, LLILC (pronounced 'lilac') is open source, and they hope to contribute their LLVM changes upstream.</p><p>The <a href="http://www.cl.cam.ac.uk/~pes20/cerberus/">Cerberus team</a> are trying to find an answer to the question '<a href="http://tinyurl.com/csurvey2">What is C in practice?</a>, and you can help by filling out their survey.</p><p>Honza HubiÄka has posted a fantastic overview of the <a href="http://hubicka.blogspot.it/2015/04/GCC5-IPA-LTO-news.html">improvements to link-time and inter-procedural optimisations in GCC5</a>, featuring figures from Firefox builds. It seems like impressive improvements have been made.</p><p>Simon Cook has written a blog post about <a href="http://www.embecosm.com/2015/04/14/utilizing-tablegen-for-non-compiling-processes/">using TableGen outside of LLVM</a>, specifically for things like parameterisable SSH configs. Crazy? Genius? Why not both?</p><h3>On the mailing lists</h3><ul><li><p>Duncan P. N. Exon Smith has proposed an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84555/">RFC for metadata attachments to function definitions</a>. There's some concern about the effect this would have on the size of Function.</p></li><li><p>Ivan Baev is proposing an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84678">indirect call promotion LLVM pass</a>. This mailing list post gives design notes on the implementation and outlines the shortcomings of the current version of the patch.</p></li><li><p>Tom Stellard queries the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84553">difference between Latency and ResourceCycles in MISched</a>. Andy Trick gives a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84574">very handy answer</a>.</p></li><li><p>Paul Robinson is seeking feedback on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42233">adding a 'debugger target'</a>, arguing that currently the target platform is used to infer the desired debugger (and thus make choices on e.g. accelerator tables), but of course the choice of debugger doesn't necessarily follow from the platform.</p></li><li><p>Colin LeMahieu is looking to contribute an assembler for the Hexagon DSP, but has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84541">questions about how its funky grammar should be handled</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The <code>dereferenceable_or_null</code> attribute has been born. As described in the commit message, the motivation is for managed languages such as Java. <a href="http://reviews.llvm.org/rL235132">r235132</a>.</p></li><li><p>A new layer was added to the Orc JIT API for applying arbitrary transforms to IR. <a href="http://reviews.llvm.org/rL234805">r234805</a>.</p></li><li><p>Memory intrinsics can now be tail calls. <a href="http://reviews.llvm.org/rL234764">r234764</a>.</p></li><li><p>A handy Python script has been added for generating C programs that have a control flow graph which is a ladder graph. The intent is to use it to test whether an algorithm expected to be linear time on the CFG really is. <a href="http://reviews.llvm.org/rL234917">r234917</a>.</p></li><li><p>The code for lowering switches and extracting jump tables has been rewritten, and should produce better results now. <a href="http://reviews.llvm.org/rL235101">r235101</a>.</p></li><li><p>Call can now take an explicit type parameter. <a href="http://reviews.llvm.org/rL235145">r235145</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang learned <code>-Wrange-loop-analysis</code>, which will warn when a range-based for loop makes copies of elements in the range. <a href="http://reviews.llvm.org/rL234804">r234804</a>.</p></li><li><p>The <code>preserve-bc-uselistorder</code> option is no longer true by default, but Clang will set it for <code>-emit-llvm</code> or <code>-save-temps</code>. <a href="http://reviews.llvm.org/rL234920">r234920</a>.</p></li><li><p>LLVM has had a lot of changes to the debug API in the last week. This commit updates Clang for them. <a href="http://reviews.llvm.org/rL235112">r235112</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Reducing the amount of template use in LLD has reduced the size of AArch64TargetHandler.cpp.o to 4.1MB, down from 21MB. <a href="http://reviews.llvm.org/rL234808">r234808</a>, <a href="http://reviews.llvm.org/rL234931">r234931</a>.</p></li><li><p>A large patchset has landed in lldb which adds a big chunk of the work necessary for supporting lldb on ARM. <a href="http://reviews.llvm.org/rL234870">r234870</a>.</p></li></ul>
- https://blog.llvm.org/2015/04/llilc-llvm-based-compiler-for-dotnet.htmlTue, 14 Apr 2015 07:03:00 +0000https://blog.llvm.org/2015/04/llilc-llvm-based-compiler-for-dotnet.html<h2 id="-llilc-https-github-com-dotnet-llilc-an-llvm-based-compiler-for-dotnet-coreclr-" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.95312rem; line-height: 3rem; margin-bottom: 0.18358rem; margin-top: 0px; padding-top: 0.81642rem;"><span style="background-color: #f3f3f3;"><a href="https://github.com/dotnet/llilc" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">LLILC</a> : An LLVM based compiler for dotnet CoreCLR.</span></h2><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">The LLILC project (we pronounce it "lilac") is a new effort started at Microsoft to produce MSIL code generators based on LLVM and targeting the open source dotnet <a href="https://github.com/dotnet/coreclr" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">CoreCLR</a>. We are envisioning using the LLVM infrastructure for a number of scenarios, but our first tool is a Just in Time (JIT) compiler for CoreCLR. This new project is being developed on GitHub and you can check it out <a href="https://github.com/dotnet/llilc" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">here</a>. The rest of this post outlines the rational and goals for the project as well as our experience using LLVM.</span></div><h4 id="why-a-new-jit-for-coreclr-" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">Why a new JIT for CoreCLR?</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">While the CoreCLR already has JIT, we saw an opportunity to provide a new code generator that has the potential to run across all the targets and platforms supported by LLVM. To enable this, as part of our project we're opening an MSIL reader that operates directly against the same common JIT interface as the production JIT (RyuJIT). This new JIT will allow any C# program written for the .NET Core class libraries to run on any platform that CoreCLR can be ported to and that LLVM will target.</span></div><h4 id="there-are-several-ongoing-efforts-to-compile-msil-in-the-llvm-community-sharplang-springs-to-mind-why-build-another-one-" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">There are several ongoing efforts to compile MSIL in the LLVM community, SharpLang springs to mind. Why build another one?</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">When we started thinking about the fastest way to get a LLVM based code generation working we looked around at the current open source projects as well as the code we had internally. While a number of the OSS projects already targeted LLVM BitCode, no one had anything that was a close match for the CoreCLR interface. Looking at our options it was simplest for us to refactor a working MSIL reader to target BitCode then teach a existing project to support the contracts and APIs the CoreCLR uses for JITing MSIL. Using a existing MSIL reader let us quickly start using a number of building-block components that we think the community can take advantage of. This fast bootstrap for C# across multiple platforms was the idea that was the genesis of this project and the compelling reason to start a new effort. We hope LLILC will provide a useful example - and reusable components - for the community and make it easier for other projects to interoperate with the CoreCLR runtime.</span></div><h4 id="why-llvm-" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">Why LLVM?</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">Basically we think LLVM is awesome. It's already got great support across many platforms and chipsets and the community is amazingly active. When we started getting involved, just trying to stay current with the developer mailing list was a revelation! The ability for LLVM to operate as both a JIT and as an AOT compiler was especially attractive. By bringing MSIL semantics to LLVM we plan to construct a number of tools that can work against CoreCLR or some sub set of its components. We also hope the community will produce tools what we haven't thought of yet.</span></div><h4 id="tool-roadmap" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">Tool roadmap</span></h4><ul style="box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 0.83999rem; padding-top: 0.16001rem;"><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">CoreCLR JIT</span><ul style="box-sizing: border-box; margin-bottom: 0px; padding-top: 0.16001rem;"><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">Just In Time - A classic JIT. This is expected to be throughput-challenged but will be correct and usable for bringup. Also possible to use with more optimization enabled as a higher tier JIT</span></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">Install-time JIT - What .NET calls NGen. This will be suitable for install-time JITing (LLVM is still slow in a runtime configuration)</span></li></ul></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">Ahead of Time compiler. A build lab compiler that produces standalone executables, using some shared components from CoreCLR. The AOT compiler will be used to improve startup time for important command line applications like the <a href="https://github.com/dotnet/roslyn" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">Roslyn Compiler</a>.</span></li></ul><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">The LLIC JIT will be a functionally correct and complete JIT for the CoreCLR runtime. It may not have sufficient throughput to be a first-tier jit, but is expected to produce high-quality code and so might make a very interesting second-tier or later JIT, or a good vehicle for prototyping codegen changes to feed back into RyuJIT.</span></div><h2 id="what-s-actually-working" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.95312rem; line-height: 3rem; margin-bottom: 0.18358rem; margin-top: 0px; padding-top: 0.81642rem;"><span style="background-color: #f3f3f3;">What's Actually Working</span></h2><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">Today on Windows we have the MSIL reader & LLVM JIT implemented well enough to compile a significant number of methods in the JIT bring up tests included in CoreCLR. In these tests we compile about 90% the methods and then fall back to RyuJIT for cases we can't handle yet. The testing experience is pretty decent for developers. The tests we run can be seen in the CoreCLR <a href="https://github.com/dotnet/coreclr/tree/master/tests/src/JIT/CodeGenBringUpTests" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">test repo</a>.</span></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">We've establish builds on Linux and Mac OSX and are pulling together mscorlib, the base .NET Core library from <a href="https://github.com/dotnet/corefx" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">CoreFx</a>, and test asset dependencies to get testing off-the-ground for those platforms.</span></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">All tests run against the CoreCLR GC in conservative mode - which scans the frame for roots - rather than precise mode. We don't yet support Exception Handling.</span></div><h2 id="architecture" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.95312rem; line-height: 3rem; margin-bottom: 0.18358rem; margin-top: 0px; padding-top: 0.81642rem;"><span style="background-color: #f3f3f3;">Architecture</span></h2><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">Philosophically LLILC is intended to provide a lean interface between CoreCLR and LLVM. Where possible we rely on preexisting technology.</span></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-5_tqqSVjMf4/VS0cQEhSHrI/AAAAAAAAAE0/kOOiDM4_XAs/s1600/JITArch.png" imageanchor="1" style="background-color: #f3f3f3; margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-5_tqqSVjMf4/VS0cQEhSHrI/AAAAAAAAAE0/kOOiDM4_XAs/s1600/JITArch.png" height="255" width="320" /></a></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;"><br /></span></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">For the JIT, when we are compiling on demand, we map the runtime types and MSIL into LLVM BitCode. From there compilation uses LLVM MCJIT infrastructure to produce compiled code that is output to buffers provided by CoreCLR.</span></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-NUl_WpPgYL8/VS0cWHeLVlI/AAAAAAAAAE8/0zJmQGulwc8/s1600/AOTArch.png" imageanchor="1" style="background-color: #f3f3f3; margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-NUl_WpPgYL8/VS0cWHeLVlI/AAAAAAAAAE8/0zJmQGulwc8/s1600/AOTArch.png" height="282" width="320" /></a></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;"><br /></span></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">Our AOT diagram is more tentative but the basic outline is that the code generator is driven using the same interface and the JIT but that there is a static type system behind it and we build up a whole program module with in LLVM and run in a LTO like mode. Required runtime components are emitted with the output objs and the platform linker then produces the target executable. There are still a number of open questions around issues like generics that need resolution but this is our first stake in the ground.</span></div><h2 id="experience-with-llvm" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.95312rem; line-height: 3rem; margin-bottom: 0.18358rem; margin-top: 0px; padding-top: 0.81642rem;"><span style="background-color: #f3f3f3;">Experience with LLVM</span></h2><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">In the few months we've been using LLVM, we've had a really good experience but with a few caveats. Getting started with translating to BitCode has been a very straightforward experience and ramp-up time for someone with compiler experience has been very quick. The MCJIT, which we started with for our JIT, was easy to configure and get code compiled and returned to the runtime. Outside of the COFF issue discussed below, we only had to make adjustments in configuration or straightforward overrides of classes, like EEMemoryManager, to enable working code. Of the caveats, the first was simple, but the other two are going to require sustained work to bring up to the level we'd like. The first issue was a problem with Windows support in the DynamicRuntime of the MCJIT infrastructure. The last two, Precise Garbage Collection, and Exception Handling, arise because of the different semantics of managed languages. Luckily for us, people in the community have already started working in these areas so we don't have to start from zero.</span></div><h4 id="coff-dynamic-loader-support" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">COFF dynamic loader support</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">One of the additions we made to LLVM to unblock ourselves was to implement a COFF dynamic loader. (The patch to add RuntimeDyldCoff.{h,cpp} is through review and has been committed). This was the only addition we directly had to make to LLVM to enable bring-up of the code generator. Once this is in, we see a number of bugs in the database around Windows JIT support that should be easier to close.</span></div><h4 id="precise-garbage-collection" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">Precise Garbage Collection</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">Precise GC is central to the CoreCLR approach to memory management. Its intent is to keep the overhead of managed memory as low as possible. It is assumed by the runtime that the JIT will generate precise information about the GC ref lifetimes and provide it with the compiled code for execution. To support this we're beginning to use the <a href="http://llvm.org/docs/Statepoints.html" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">StatePoint</a> approach, with additions to convert the standard output format to the custom format expected by CoreCLR. We share some of the same concerns that Philip Reames wrote about in the initial design of StatePoints. E.g. preservation of "GCness" through the optimizer is critical, but must not block optimizer transformations. Given this concern one of our open questions is how to enable testing to find GC holes that creep in, but also enable extra checking that can be opted into if the incoming IR contains GC pointers.</span></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">There is a more detailed document included in our repo that outlines our more-specific GC plans <a href="https://github.com/dotnet/llilc/blob/master/Documentation/llilc-gc.md" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">here</a>.</span></div><h4 id="exception-handling" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">Exception Handling</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">The MSIL EH model is specific to the CLR as you'd expect, but it descends in part conceptually from Windows Structured Exception Handling (SEH). In particular, the implicit exception flow from memory accesses to implement null checks, and the use of filters and funclets in the handling of exceptions, mirrors SEH (<a href="https://msdn.microsoft.com/en-us/library/ms173162.aspx" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">here</a>. is an outline of C# EH) Our plans at this point are to add all checks required by MSIL as explicit compare/branch/throw sequences to better match C++ EH as well as building on the SEH support currently being put into Clang. Then, once we have correctness, see if there is a reasonable way forward that improves performance.</span></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><span style="background-color: #f3f3f3;">Like GC, there's a detailed doc outlining our specific issues and plans in the repo <a href="https://github.com/dotnet/llilc/blob/master/Documentation/llilc-jit-eh.md" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">here</a></span></div><h2 id="future-work" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.95312rem; line-height: 3rem; margin-bottom: 0.18358rem; margin-top: 0px; padding-top: 0.81642rem;"><span style="background-color: #f3f3f3;">Future Work</span></h2><ul style="box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 0.83999rem; padding-top: 0.16001rem;"><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">More platforms. Today we're running on Windows and starting to build for Linux and Mac OSX. We'd like more.</span></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">Complete JIT implementation</span><ul style="box-sizing: border-box; margin-bottom: 0px; padding-top: 0.16001rem;"><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">More MSIL opcodes supported</span></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">Precise GC support</span></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">EH support</span></li></ul></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">Specialized memory allocators for hosted solutions. CoreCLR has been used as a hosted solution (run in process by other programs) but to support this we need a better memory allocation story. The runtime should be able to provide a memory allocator that is used for all compilation.</span></li><li style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; margin-left: 1rem;"><span style="background-color: #f3f3f3;">AOT - Fully flesh out the AOT story.</span></li></ul><h4 id="links" style="-webkit-font-feature-settings: 'dlig' 1, 'liga' 1, 'lnum' 1, 'kern' 1; box-sizing: border-box; color: #373d49; font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1.5625rem; line-height: 28px; margin-bottom: 0.54686rem; margin-top: 0px; padding-top: 0.45314rem;"><span style="background-color: #f3f3f3;">Links</span></h4><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><a href="https://github.com/dotnet/llilc" style="background-attachment: initial; background-clip: initial; background-color: #f3f3f3; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">LLILC</a></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><a href="https://github.com/dotnet/coreclr" style="background-attachment: initial; background-clip: initial; background-color: #f3f3f3; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">CoreCLR</a></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><a href="https://github.com/dotnet/corefx" style="background-attachment: initial; background-clip: initial; background-color: #f3f3f3; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">CoreFx</a></div><div style="-webkit-font-feature-settings: 'kern' 1, 'onum' 1, 'liga' 1; box-sizing: border-box; color: #373d49; font-family: Georgia, Cambria, serif; font-size: 14px; line-height: 28px; margin-bottom: 1.33999rem; padding-top: 0.66001rem;"><a href="http://www.dotnetfoundation.org/" style="background-attachment: initial; background-clip: initial; background-color: #f3f3f3; background-image: initial; background-origin: initial; background-position: 0px 0px; background-repeat: initial; background-size: initial; box-sizing: border-box; color: #a0aabf; cursor: pointer;">.NET Foundation</a></div>
- LLVM Weekly - #67, Apr 13th 2015https://blog.llvm.org/2015/04/llvm-weekly-67-apr-13th-2015.htmlMon, 13 Apr 2015 05:25:00 +0000https://blog.llvm.org/2015/04/llvm-weekly-67-apr-13th-2015.html<p>Welcome to the sixty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p><a href="http://llvm.org/devmtg/2015-04/">EuroLLVM</a> is going on today and tomorrow in London. I hope to see a number of you there. Provided there's a reasonable internet connection, I hope to be live-blogging the event on the <a href="http://llvmweekly.org/issue/67">llvmweekly.org version of this issue</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/67">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>A new post on the LLVM Blog deatils <a href="http://blog.llvm.org/2015/04/fuzz-all-clangs.html">how to use LLVM's libFuzzer for guided fuzzing of libraries</a>.</p><p>The Red Hat developer blog has an <a href="http://developerblog.redhat.com/2015/04/07/jit-compilation-using-gcc-5-2/">article about libgccjit</a>, a new feature in GCC5, which may be of interest.</p><h3>On the mailing lists</h3><ul><li><p>Rui Ueyama proposes <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84425">removing the 'native' file format from LLD</a>. The hope was the native file format could be shared between LLD and LLVM and provide higher performance than standard ELF. In the end, it didn't see much development so it's being deleted for now.</p></li><li><p>Hal Finkel has some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84460">questions for compiler developers on optimisations of atomics</a>. Answers will be fed back to the OpenMP standards committee, who are working to formalize their memory model and define its relationship to the C/C++ memory models.</p></li><li><p>The document about a proposed OpenMP offload infrastructure <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84375">has been updated</a>. Comments and feedback are very welcome.</p></li><li><p>Tom Stellard would like to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84363">remind you</a> that bug fixes for the upcoming 3.6.1 release must be merged by the 4th of May.</p></li><li><p>Sanjoy Das is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84298">seeking some clarification on the semantics of shl nsw in the LLVM language reference</a>. It seems that Sanjoy and David Majnemer are reaching an agreement in the thread, but they welcome differing viewpoints.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The R600 backend gained an experimental integrated assembler. <a href="http://reviews.llvm.org/rL234381">r234381</a>.</p></li><li><p>The libFuzzer documentation has been extended to demonstrate how the Heartbleed vulnerability could have been found using it. <a href="http://reviews.llvm.org/rL234391">r234391</a>.</p></li><li><p>The preserve-use-list-order flags are now on by default. <a href="http://reviews.llvm.org/rL234510">r234510</a>.</p></li><li><p>LLVM gained a pass to estimate when branches in a GPU program can diverge. <a href="http://reviews.llvm.org/rL234567">r234567</a>.</p></li><li><p>The ARM backend learnt to recognise the Cortex-R4 processor. <a href="http://reviews.llvm.org/rL234486">r234486</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Lifetime markers for named temporaries are now always inserted. <a href="http://reviews.llvm.org/rL234581">r234581</a>.</p></li><li><p>The quality of error messages for assignments to read-only variables has been enhanced. <a href="http://reviews.llvm.org/rL234677">r234677</a>.</p></li><li><p>clang-format's nested block formatting got a little better. <a href="http://reviews.llvm.org/rL234304">r234304</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Support for the 'native' file format was removed from lld. <a href="http://reviews.llvm.org/rL234641">r234641</a>.</p></li><li><p>Remote debugging, the remote test suite, and the process to cross-compile lldb has been documented. <a href="http://reviews.llvm.org/rL234317">r234317</a>, <a href="http://reviews.llvm.org/rL234395">r234395</a>, <a href="http://reviews.llvm.org/rL234489">r234489</a>.</p></li><li><p>LLDB gained initial runtime support for RenderScript. <a href="http://reviews.llvm.org/rL234503">r234503</a>.</p></li></ul>
- Simple guided fuzzing for libraries using LLVM's new libFuzzerhttps://blog.llvm.org/2015/04/fuzz-all-clangs.htmlThu, 09 Apr 2015 13:40:00 +0000https://blog.llvm.org/2015/04/fuzz-all-clangs.html<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><br /></div><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Fuzzing (or <a href="http://en.wikipedia.org/wiki/Fuzz_testing">fuzz testing</a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">) is becoming increasingly popular. Fuzzing Clang and fuzzing </span><span style="color: black; font-family: Arial; font-size: 15px; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">with</span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> Clang is not new: Clang-based <a href="http://clang.llvm.org/docs/AddressSanitizer.html">AddressSanitizer</a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> has been used for fuzz-testing the Chrome browser for <a href="http://blog.chromium.org/2012/04/fuzzing-for-security.html">several years</a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> and Clang itself has been extensively fuzzed using <a href="https://embed.cs.utah.edu/csmith/">csmith</a> </span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">and, more recently, using <a href="http://lcamtuf.coredump.cx/afl/">AFL</a>.</span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> Now weâve closed the loop and started to fuzz parts of LLVM (including Clang) using LLVM itself.</span><br /><br /><span style="color: black; font-family: Arial; font-size: 15px; line-height: 1.38; vertical-align: baseline; white-space: pre-wrap;"><a href="http://llvm.org/docs/LibFuzzer.html">LibFuzzer</a></span><span style="color: black; font-family: Arial; font-size: 15px; line-height: 1.38; vertical-align: baseline; white-space: pre-wrap;">, recently added to the LLVM tree, is a library for in-process fuzzing that uses <a href="https://code.google.com/p/address-sanitizer/wiki/AsanCoverage">Sanitizer Coverage instrumentation</a></span><span style="color: black; font-family: Arial; font-size: 15px; line-height: 1.38; vertical-align: baseline; white-space: pre-wrap;"> to guide test generation. </span><span style="font-family: Arial; font-size: 15px; line-height: 1.38; vertical-align: baseline; white-space: pre-wrap;">With LibFuzzer one can implement a guided fuzzer for some library by writing one simple function: </span><br /><div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Courier New, Courier, monospace;">extern "C" void TestOneInput(const uint8_t *Data, size_t Size);</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We have implemented two fuzzers on top of LibFuzzer: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/fuzzer/ClangFormatFuzzer.cpp?view=markup">clang-format-fuzzer</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp?view=markup">clang-fuzzer</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. </span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Clang-format is mostly a lexical analyzer, so giving it random bytes to format worked perfectly and discovered <a href="https://llvm.org/bugs/show_bug.cgi?id=23052">over 20 bugs</a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">. Clang however is more than just a lexer and giving it random bytes barely scratches the surface, so in addition to testing with random bytes we also fuzzed Clang in <a href="http://llvm.org/docs/LibFuzzer.html#tokens">token-aware mode</a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">. Both modes found <a href="https://llvm.org/bugs/show_bug.cgi?id=23057">bugs</a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">; some of them were previously <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-January/040705.html">detected </a></span><span style="color: black; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-January/040705.html">by AFL</a>, some others were not: weâve run this fuzzer with AddressSanitizer and some of the bugs are not easily discoverable without it.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Just to give you the feeling, here are some of the input samples discovered by the token-aware clang-fuzzer starting from an empty test corpus: </span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> static void g(){}</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> signed*Qwchar_t;</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> overridedouble++!=~;inline-=}y=^bitand{;*=or;goto*&&k}==n</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> int XS/=~char16_t&s<=const_cast<Xchar*>(thread_local3+=char32_t </span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Fuzzing is not a one-off thing -- it shines when used continuously. We have set up a <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer">public build bot</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> that runs clang-fuzzer and clang-format-fuzzer 24/7. This way, the fuzzers keep improving the test corpus and will periodically find old bugs or fresh regressions (the bot has <a href="http://reviews.llvm.org/D7871">caught</a> at least one such regression already</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">). </span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The benefit of in-process fuzzing compared to out-of-process is that you can test more inputs per second. This is also a weakness: you can not effectively limit the execution time for every input. If some of the inputs trigger superlinear behavior, it may slow down or paralyze the fuzzing. Our fuzzing bot was nearly dead after it discovered <a href="https://llvm.org/bugs/show_bug.cgi?id=23052#c3">exponential parsing time in clang-format</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. You can workaround the problem by setting a timeout for the fuzzer, but itâs always better to fix superlinear behavior.</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">It would be interesting to fuzz other parts of LLVM, but a requirement for in-process fuzzing is that the library does not crash on invalid inputs. This holds for clang and clang-format, but not for, e.g., the LLVM bitcode reader. </span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Help is more than welcome! You can start by fixing one of the existing bugs in clang or clang-format (see <a href="https://llvm.org/bugs/show_bug.cgi?id=23057">PR23057</a>, <a href="https://llvm.org/bugs/show_bug.cgi?id=23052">PR23052</a> and the <a href="http://sli.dy.fi/~sliedes/clang-triage/triage_report.xhtml">results from AFL</a>)</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> or write your own fuzzer for some other part of LLVM or profile one of the existing fuzzers and try to make it faster by fixing performance bugs. </span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Of course, LibFuzzer can be used to test things outside of the LLVM project. As an example, and following <a href="https://blog.hboeck.de/archives/868-How-Heartbleed-couldve-been-found.html">Hanno Böckâs blog post</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> on <a href="http://en.wikipedia.org/wiki/Heartbleed">Heartbleed</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, weâve applied LibFuzzer to <a href="https://www.openssl.org/">openssl</a> </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">and found Heartbleed in <a href="http://llvm.org/docs/LibFuzzer.html#heartbleed">less than a minute</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Also, quite a few new bugs have been discovered in <a href="http://www.pcre.org/">PCRE2</a></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> (<a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=228&r2=227&pathrev=228">1</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=231&r2=230&pathrev=231">2</a>, <a href="http://www.exim.org/viewvc/pcre2?view=revision&revision=232">3</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=233&r2=232&pathrev=233">4</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=234&r2=233&pathrev=234">5</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=235&r2=234&pathrev=235">6</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=236&r2=235&pathrev=236">7</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=237&r2=236&pathrev=237">8</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=238&r2=237&pathrev=238">9</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=241&r2=240&pathrev=241">10</a>, <a href="http://www.exim.org/viewvc/pcre2/code/trunk/ChangeLog?r1=244&r2=243&pathrev=244">11</a>), <a href="https://sourceware.org/glibc/wiki/FuzzingLibc">Glibc</a> </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">and <a href="http://musl-libc.org/">MUSL libc</a> (<a href="http://git.musl-libc.org/cgit/musl/patch/?id=39dfd58417ef642307d90306e1c7e50aaec5a35c">1</a>, <a href="http://git.musl-libc.org/cgit/musl/patch/?id=fc13acc3dcb5b1f215c007f583a63551f6a71363">2</a>)</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> .</span></div><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Fuzz testing, especially coverage-directed and sanitizer-aided fuzz testing, should directly compliment unit testing, integration testing, and system functional testing. We encourage everyone to start actively fuzz testing their interfaces, especially those with even a small chance of being subject to attacker-controlled inputs. We hope the LLVM fuzzing library helps you start leveraging our tools to better test your code, and let us know about any truly exciting bugs they help you find!</span></div></div>
- LLVM Weekly - #66, Apr 6th 2015https://blog.llvm.org/2015/04/llvm-weekly-66-apr-6th-2015.htmlMon, 06 Apr 2015 02:57:00 +0000https://blog.llvm.org/2015/04/llvm-weekly-66-apr-6th-2015.html<p>Welcome to the sixty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/66">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p><code>color_coded</code>, a vim plugin for syntax highlighting using libclang is <a href="https://github.com/jeaye/color_coded">now available</a>.</p><p>Ravi, a dialect of Lua with JIT compilation via LLVM has <a href="https://github.com/dibyendumajumdar/ravi/releases">has its first alpha release</a>. The status of JIT compilation can be seen <a href="http://the-ravi-programming-language.readthedocs.org/en/latest/ravi-jit-status.html">here</a>.</p><h3>On the mailing lists</h3><ul><li><p>James Knight is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84258">asking for advice on supporting 64-bit load/store on a 32-bit arch</a>. Respondents point to examples from ARM and R600.</p></li><li><p>Eric Christopher has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84144">kicked off another discussion on LTO and codegen options</a>.</p></li><li><p>Katya Romanova <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41911">proposes adding doxygen comments for intrinsics</a>. The intention is that the current documentation would be converted in an automated way. So far, people seem to be in favour.</p></li><li><p>Douglas Gregor is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/42046">stepping down as code owner of 'all parts of Clang not covered by someone else'</a>. Richard Smith will be taking over. Thank you Douglas for the years of hard work.</p></li><li><p>Can you <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84251">cross-compile LLVM's test suite?</a>. The answer, is yes.</p></li><li><p>Duncan P.N. Exon Smith proposes that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84196">preserve-bc-use-list-order</a> be on by default.</p></li></ul><h3>LLVM commits</h3><ul><li><p>API migration has started for GEP constant factories. For now, nullptr can be passed for the pointee type, but you'll need to pass the type explicitly to be future-proof. <a href="http://reviews.llvm.org/rL233938">r233938</a>.</p></li><li><p>A proof of concept fuzzer based on DataFlowSanitizer has been added, as well as support for token-based fuzzing. <a href="http://reviews.llvm.org/rL233613">r233613</a>, <a href="http://reviews.llvm.org/rL233745">r233745</a>.</p></li><li><p>DebugLoc's API has been rewritten. <a href="http://reviews.llvm.org/rL233573">r233573</a>.</p></li><li><p>The SystemZ backend now supports transactional execution on the zEC12. <a href="http://reviews.llvm.org/rL233803">r233803</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang gained a toolchain driver for targeting NaCl. <a href="http://reviews.llvm.org/rL233594">r233594</a>.</p></li><li><p>The size of various Stmt subclasses has been optimised on 64-bit targets. <a href="http://reviews.llvm.org/rL233921">r233921</a>.</p></li><li><p>Codegen was added for the OpenMP atomic update construct. <a href="http://reviews.llvm.org/rL233513">r233513</a>.</p></li></ul><h3>Other project commits</h3><ul><li>LLDB system initialization has been reworked. <a href="http://reviews.llvm.org/rL233758">r233758</a>.</li></ul>
- LLVM Weekly - #65, Mar 30th 2015https://blog.llvm.org/2015/03/llvm-weekly-65-mar-30th-2015.htmlMon, 30 Mar 2015 02:49:00 +0000https://blog.llvm.org/2015/03/llvm-weekly-65-mar-30th-2015.html<p>Welcome to the sixty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/65">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The Z3 theorem prover from Microsoft Research is <a href="https://github.com/Z3Prover/z3/">now on Github</a>, and more importantly now <a href="https://github.com/Z3Prover/z3/commit/40269c8511ca343bc6848cae8c4f2d0f0455b949">released under the MIT license</a>. This is a true open source license allowing commercial use, unlike the previous non-commercial use only license. It's been used with LLVM in the <a href="http://blog.regehr.org/archives/1170">ALIVe project</a>.</p><p>The <a href="http://llvm.org/devmtg/2015-04/">schedule</a> for EuroLLVM has been published. There are still a number of <a href="http://www.eventbrite.com/e/eurollvm-2015-tickets-15350278095">early registration tickets left</a>. If you can be in London on 13th and 14th of April then I'd highly recommend registering.</p><h3>On the mailing lists</h3><ul><li><p>Tom Stellard, maintainer of the R600 backend has a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84045">question about manipulating the machine scheduler to intermix ALU instruction with loads</a>.</p></li><li><p>Sanjoy Das is seeking feedback on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84037">an optimisation issue he's seeing due to <code>llvm.$op.with.overflow</code> intrinsics</a>. There is some followup discussion on how this should be dealt with.</p></li><li><p>Martin O'Riordan from Movidius <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84069">asks for guidance on submitting contributing changes back upstream</a>. Tom Stellard has a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41976">useful response</a>.</p></li><li><p>Dylan McKay is working on an AVR backend port and is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/84057">seeking advice on lowering division calls</a>. The current version of his backend is <a href="https://github.com/avr-llvm/llvm">here</a>.</p></li><li><p>Benoit Belley writes in with <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83985">an optimisation puzzle</a>, looking for an explanation for why an icmp isn't removed. Daniel Berlin responds just a couple of hours later with <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83985">an explanation of the missed optimisation</a> as well as a path to fix it.</p></li><li><p>Gordon Kaiser is looking for <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83979">anyone interested in a backend for the Fujitsu FR-series processors</a>, now manufactured by Spansion.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The GlobalMerge pass will no longer run at O1 on AArch64+ARM, and instead will only be enabled at O3. <a href="http://reviews.llvm.org/rL233024">r233024</a>.</p></li><li><p>A float2int pass was added which, as the name suggests, attempts to demote from float to int where possible. <a href="http://reviews.llvm.org/rL233062">r233062</a>.</p></li><li><p>A simple Orc-based lazy JIT has been added to lli. <a href="http://reviews.llvm.org/rL233182">r233182</a>.</p></li><li><p>LLVM gained support for PowerPC hardware transactional memory. <a href="http://reviews.llvm.org/rL233204">r233204</a>.</p></li><li><p>The ARMv8.1a architecture has been added along with some of its new instructions. <a href="http://reviews.llvm.org/rL233290">r233290</a>, <a href="http://reviews.llvm.org/rL233301">r233301</a></p></li></ul><h3>Clang commits</h3><ul><li><p>The on-disk hash table for modules should now have a stable representation. <a href="http://reviews.llvm.org/rL233156">r233156</a>, <a href="http://reviews.llvm.org/rL233249">r233249</a>.</p></li><li><p>Intrinsics have been added for PowerPC hardware transaction memory support. <a href="http://reviews.llvm.org/rL233205">r233205</a>.</p></li><li><p>An initial version of a clang-fuzzer has been added, making use of the LLVMFuzzer library. <a href="http://reviews.llvm.org/rL233455">r233455</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libclc gained more builtin implementations. <a href="http://reviews.llvm.org/rL232977">r232977</a>, <a href="http://reviews.llvm.org/rL232965">r232965</a>, <a href="http://reviews.llvm.org/rL232964">r232964</a>.</p></li><li><p>lld learnt how to understand the MIPS N64 relocation record format (which is described in the commit message). <a href="http://reviews.llvm.org/rL233057">r233057</a>.</p></li><li><p>lld's ARM support has improved with with the addition of indirect function handling and GOT relocations. <a href="http://reviews.llvm.org/rL233383">r233383</a>, <a href="http://reviews.llvm.org/rL233277">r233277</a>.</p></li></ul>
- LLVM Weekly - #64, Mar 23rd 2015https://blog.llvm.org/2015/03/llvm-weekly-64-mar-23rd-2015.htmlMon, 23 Mar 2015 08:09:00 +0000https://blog.llvm.org/2015/03/llvm-weekly-64-mar-23rd-2015.html<p>Welcome to the sixty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/64">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Students have until Friday 27th March to get their applications in for Google Summer of Code. This gives the opportunity to get paid $5500 to work on open source over the summer, under the mentorship of someone from the community. See <a href="https://www.google-melange.com/gsoc/org/list/public/google/gsoc2015?tag=llvm">here</a> for the list of mentoring organisations advertising LLVM-related projects. Please do help spread the word. I am biased, but I'd like to draw particular attention to the wide variety of <a href="http://www.lowrisc.org/docs/gsoc-2015-ideas/">lowRISC GSoC ideas</a>, including a project to implement an LLVM pass using tagged memory to provide protection against control-flow hijacking.</p><p>GCC 5 is starting to <a href="https://gcc.gnu.org/ml/gcc/2015-03/msg00241.html">get near to release</a>. The first release candidate is expected in the first week of April.</p><h3>On the mailing lists</h3><ul><li><p>Peter Collingbourne has kicked off a thread on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41832">controlling the LTO optimization level</a>. Using LTO can cause a massive increase in compile-time. Peter argues that for some features, like the recently added control flow integrity checks in Clang, you require LTO for whole program visibility but perhaps would rather do much fewer optimisations in order to get a more reasonable compile time. He proposes a <code>-flto-level</code> command line option.</p></li><li><p>Eric Christopher has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83858">written to the mailing list</a> about recent changes he's made to the TargetMachine::getSubtarget API.</p></li><li><p>Dario Domizioli proposes <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83665">adding target-specific defaults for options in the LLVM tools</a>. Response was mostly negative on the grounds that opt, llc, and friends are tools meant for LLVM developers rather than end-users. Sean Silva attempted to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83746">clarify the difference between LLVM users, LLVM end-users, and LLVM developers</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The backend for the Hexagon DSP has continued to grow over the past few weeks. Most recently, support for vector instructions has been added. <a href="http://reviews.llvm.org/rL232728">r232728</a>.</p></li><li><p>The LLVM developer documentation grew guidance on writing commit messages. <a href="http://reviews.llvm.org/rL232334">r232334</a>.</p></li><li><p>LLVM learnt to support the ARMv6k target. The commit message has a handy ascii art diagram to explain its position in the ARM family. <a href="http://reviews.llvm.org/rL232468">r232468</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The size of a Release+Asserts clang binary has been reduced by ~400k by devirtualising Attr and its subclasses. <a href="http://reviews.llvm.org/rL232726">r232726</a>.</p></li><li><p>Work on MS ABI continues, with support for HandlerMap entries for C++ catch. <a href="http://reviews.llvm.org/rL232538">r232538</a>.</p></li><li><p>A new warning, <code>-Wpartial-ability</code> will warn when using decls that are not available on all deployment targets. <a href="http://reviews.llvm.org/rL232750">r232750</a>.</p></li><li><p>C++14 sized deallocation has been disabled default due to compatibility issues. <a href="http://reviews.llvm.org/rL232788">r232788</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Performance of a self-hosted lld link has again been improved. It's now down to 3 seconds on the patch author's machine (vs 5 seconds before, and 8 seconds for the GNU BFD linker). <a href="http://reviews.llvm.org/rL232460">r232460</a>.</p></li><li><p>libcxx gained the <code><experimental/tuple></code> header which implements most of the tuple functionality specified in the library fundamentals TS. <a href="http://reviews.llvm.org/rL232515">r232515</a>.</p></li><li><p>LLD now supports the semantics of simple sections mappings in linker scripts and can handle symbols defined in them. <a href="http://reviews.llvm.org/rL232402">r232402</a>, <a href="http://reviews.llvm.org/rL232409">r232409</a>.</p></li><li><p>Mips64 lldb gained an initial assembly profiler. <a href="http://reviews.llvm.org/rL232619">r232619</a>.</p></li></ul>
- LLVM Weekly - #63, Mar 16th 2015https://blog.llvm.org/2015/03/llvm-weekly-63-mar-16th-2015.htmlMon, 16 Mar 2015 08:35:00 +0000https://blog.llvm.org/2015/03/llvm-weekly-63-mar-16th-2015.html<p>Welcome to the sixty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/63">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM is taking part in <a href="https://developers.google.com/open-source/soc/">Google Summer of Code</a> as a mentoring organisation. Students can earn a $5500 stipend by working on open source projects over the summer, and applications upon today (March 16th). See <a href="https://www.google-melange.com/gsoc/org/list/public/google/gsoc2015?tag=llvm">here</a> for the list of mentoring organisations advertising LLVM-related projects. Please do help spread the word. I am biased, but I'd like to draw particular attention to the wide variety of <a href="http://www.lowrisc.org/docs/gsoc-2015-ideas/">lowRISC GSoC ideas</a>, including a project to implement an LLVM pass using tagged memory to provide protection against control-flow hijacking.</p><p>Version 0.11 of Pocl, the portable open-source OpenCL implementation <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83457/">has been released</a>. Additions in this release include initial Android support and MIPS architecture support.</p><p>Version 1.11 of TCE, the TTA-based (Transport Triggered Architecture) Co-design Environment, which uses LLVM <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83377">has been released</a>. This release adds support for LLVM 3.6.</p><p>There will be a <a href="http://wiki.linuxplumbersconf.org/2015:llvm">LLVM microconference</a> at the Linux Plumbers Conference in August. There is a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41706">call for speakers</a>.</p><h3>On the mailing lists</h3><ul><li><p>If you enjoy bikesheds, this thread may be for you. Renato Golin has kicked off a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41760/">thread on commit message policy</a>.</p></li><li><p>Rui Ueyama has posted to the mailing list <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83438">summarising his recent work on LLD performance improvements</a>. The follow up responses discuss potential remaining bottlenecks.</p></li><li><p>William Moses is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83236">interested in parallel extensions to LLVM IR</a>, and the thread spawned quite a few interesting responses.</p></li><li><p>Mohammad Kazem's <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83224">question about counting loads and stores of variables</a> elicited some useful responses.</p></li><li><p>Will Dietz who has been maintaining the <a href="https://github.com/llvm-mirror">unofficial LLVM Github mirror</a> for the past few years is interested in <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83239">LLVM taking over the service 'officially'</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>As DataLayout is now mandatory, LLVM APIs have been updated to use references to DataLayout. <a href="http://reviews.llvm.org/rL231740">r231740</a>.</p></li><li><p>Support was added for part-word atomics on PowerPC. <a href="http://reviews.llvm.org/rL231843">r231843</a>.</p></li><li><p>Initial work on enhancing ValueTracking to infer known bits of a value from known-true conditional expressions has landed. <a href="http://reviews.llvm.org/rL231879">r231879</a>.</p></li><li><p>The PowerPC READMEs have been updated to list potential future enhancements. <a href="http://reviews.llvm.org/rL231946">r231946</a>.</p></li><li><p>The <code>llvm.eh.actions</code> intrinsic has been added. <a href="http://reviews.llvm.org/rL232003">r232003</a>.</p></li><li><p>The documentation for llvm-cov has been updated. <a href="http://reviews.llvm.org/rL232007">r232007</a>.</p></li><li><p>The getting started docs now describe CMake as the preferred way to build LLVM. <a href="http://reviews.llvm.org/rL232135">r232135</a>.</p></li><li><p>llvm-vtabledump is now known as llvm-cxxdump. <a href="http://reviews.llvm.org/rL232301">r232301</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The steady stream of OpenMP patches continues, with the addition of codegen support for the omp task directive and omp for. <a href="http://reviews.llvm.org/rL231762">r231762</a>, <a href="http://reviews.llvm.org/rL232036">r232036</a>.</p></li><li><p>Copy-constructor closures for MS ABI support has been added. <a href="http://reviews.llvm.org/rL231952">r231952</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLD gained support for linker script expression evaluation and parsing of the MEMORY and EXTERN commands. <a href="http://reviews.llvm.org/rL231707">r231707</a>, <a href="http://reviews.llvm.org/rL231928">r231928</a>, <a href="http://reviews.llvm.org/rL232110">r232110</a>.</p></li><li><p>LLDB gained a <code>CODE_OWNERS.txt</code> file. <a href="http://reviews.llvm.org/rL231936">r231936</a>.</p></li></ul>
- LLVM Weekly - #62, Mar 9th 2015https://blog.llvm.org/2015/03/llvm-weekly-62-mar-9th-2015.htmlMon, 09 Mar 2015 03:36:00 +0000https://blog.llvm.org/2015/03/llvm-weekly-62-mar-9th-2015.html<p>Welcome to the sixty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/62">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM is taking part in <a href="https://developers.google.com/open-source/soc/">Google Summer of Code</a> as a mentoring organisation. Students can earn a $5500 stipend by working on open source projects over the summer. See <a href="https://www.google-melange.com/gsoc/org/list/public/google/gsoc2015?tag=llvm">here</a> for the list of mentoring organisations advertising LLVM-related projects. Please do help spread the word, applications open on Monday the 16th of March. I am biased, but I'd like to draw particular attention to the wide variety of <a href="http://www.lowrisc.org/docs/gsoc-2015-ideas/">lowRISC GSoC ideas</a>, including a project to use tagged memory to provide protection against control-flow hijacking.</p><p>Ravi, a programming language based on Lua 5.3 has been <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83199">announced</a>. It features JIT compilation using LLVM, though in the current <a href="https://github.com/dibyendumajumdar/ravi">development version</a> only a fraction of the Lua bytecodes are JIT-compiled.</p><h3>On the mailing lists</h3><ul><li><p>Douglas Gregor has posted an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41568">adding nullability qualifiers</a>. The mailing list post justifies the reason for adding new qualifiers despite the fact <code>__attribute__((nonnull))</code> exists.</p></li><li><p>Jonas Paulsson queries the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83077">current status of spilling support in the PBQP register allocator</a>. As Arnaud confirms, there's still <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83079">work to be done</a> to improve things.</p></li><li><p>Chris Bieneman has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83067">update on the CMake build system's ability to replace autoconf</a>.</p></li><li><p>Tom Stellard has shared his proposed <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/83016">release schedule for 3.5.2 and 3.6.1</a>. This would see 3.5.2 released on the 25th of March and 3.6.1 on the 13th of May.</p></li></ul><h3>LLVM commits</h3><ul><li><p>An initial implementation of a loop interchange pass has landed. This will interchange loops to provide a more cache-friendly memory access. <a href="http://reviews.llvm.org/rL231458">r231458</a>.</p></li><li><p>A high-level support library for the new pass manager has been added. <a href="http://reviews.llvm.org/rL231556">r231556</a>.</p></li><li><p>The LLVM performance tips document has seen some new additions. <a href="http://reviews.llvm.org/rL230995">r230995</a>, <a href="http://reviews.llvm.org/rL231352">r231352</a>.</p></li><li><p>DenseMapIterators will now fail fast when compiled in debug mode. <a href="http://reviews.llvm.org/rL231125">r231035</a>.</p></li><li><p>LowerBitSets will now use byte arrays rather than bit sets to represent in-memory bit sets, which can be looked up with only a few instructions. <a href="http://reviews.llvm.org/rL231043">r231043</a>.</p></li><li><p>Another large portion of the DebugInfo changes has landed. <a href="http://reviews.llvm.org/rL231082">r231082</a>.</p></li><li><p>A new optimisation for AddressSanitizer has been added that reduces the amount of instrumentation needed, eliminating it when accessing stack variables that can be proven to be inbounds. <a href="http://reviews.llvm.org/rL231241">r231241</a>.</p></li><li><p>llvm.frameallocate has been replaced with llvm.frameescape. <a href="http://reviews.llvm.org/rL231386">r231386</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>When the <code>-pedantic</code> flag is given, clang will warn when a format string uses <code>%p</code> with non-<code>void*</code> args. <a href="http://reviews.llvm.org/rL231211">r231211</a>.</p></li><li><p>Work on MS ABI support continues. Throwing a C++ exception under the MS ABI is now supported. <a href="http://reviews.llvm.org/rL231328">r231328</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The lld resolver has had a significant performance optimisation. The commit message indicates linking chrome.dll now takes 30 seconds down from 70 seconds. <a href="http://reviews.llvm.org/rL231434">r231434</a>.</p></li><li><p>The static binary size of lldb-server has been reduced due to a reduction in the number of initialised components. <a href="http://reviews.llvm.org/rL230963">r230963</a>.</p></li></ul>
- LLVM Weekly - #61, Mar 2nd 2015https://blog.llvm.org/2015/03/llvm-weekly-61-mar-2nd-2015.htmlMon, 02 Mar 2015 03:12:00 +0000https://blog.llvm.org/2015/03/llvm-weekly-61-mar-2nd-2015.html<p>Welcome to the sixty-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/61">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The biggest headline this week is undoubtedly the release of LLVM/Clang 3.6. See the <a href="http://llvm.org/releases/3.6.0/docs/ReleaseNotes.html">LLVM 3.6 release notes</a> and the <a href="http://llvm.org/releases/3.6.0/tools/clang/docs/ReleaseNotes.html">Clang 3.6 release notes</a> for a full run-down of the major changes.</p><p>The <a href="http://www.llvmsharp.org/">LLVMSharp</a> C# and .NET bindings to LLVM have been released.</p><p>Pyston, the LLVM-based Python JIT developed by Dropbox has had its <a href="http://blog.pyston.org/2015/02/24/pyston-0-3-self-hosting-sufficiency/">0.3 release</a>. It is now minimally self-hosting. You can also see <a href="http://speed.pyston.org/comparison/">performance results</a> online.</p><p>Readers may enjoy this <a href="http://www.wilfred.me.uk/blog/2015/02/21/my-first-llvm-compiler/">walkthrough of creating a basic compiler with LLVM</a>.</p><h3>On the mailing lists</h3><ul><li><p>Diego Novillo has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82814">announced Google's intention to work on PGO profiling support in LLVM</a>. We can expect a document soon to give more detail on the plans and stimulate further discussion.</p></li><li><p>Ashutosh Nema is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82883">proposing a new loop versioning optimisation</a>. This is where multiple versions of the loop are generated and the implementation chosen based on runtime memory aliasing tests. It was suggested that some recent work on Loop Access Analysis provides some of this functionality.</p></li><li><p>Philip Reames has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82740">suggested writing a performance guide for frontend authors</a>. Unsurprisingly, the idea is popular.</p></li><li><p>Zachary Turner has suggested <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6686">separating embedded Python from the rest of LLDB</a>. As detailed in the post, it is difficult to provide compatibility with the standard Python binary build for Windows and precompiled Python modules.</p></li><li><p>Ahmed Bougacha started a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82870">disabling GlobalMerge</a>, which is currently enabled for ARM and AARch64. Much of the ensuing discussion centers around understanding why there seems to be a performance degradation when using GlobalMerge with LTO.</p></li><li><p>Katya Romanova moved a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82730">discussion on a jump threading optimisation bug</a> to llvm-dev. The issue is due to the fact an unreachable block is generated with ill-formed instruction, and there is a lot of follow on discussion about whether passes should generate unreachable blocks.</p></li><li><p>Dibyendu Majumdar wrote to the list to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82698">ask about issues eliminating redundant loads</a>. He managed to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82816">work out the issue</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Work has started on the move towards opaque pointer types. See the commit messages for more details and help on migrating existing textual IR. <a href="http://reviews.llvm.org/rL230786">r230786</a>, <a href="http://reviews.llvm.org/rL230794">r230794</a>.</p></li><li><p>The PlaceSafepoints and RewriteGCForStatepoints passes have been documented. <a href="http://reviews.llvm.org/rL230420">r230420</a>.</p></li><li><p>The GC statepoints documentation has been cleaned up and extended with example IR, assembly, and stackmaps. <a href="http://reviews.llvm.org/rL230601">r230601</a>.</p></li><li><p>The loop-invariant code motion pass has been refactored to expose its core functionality as utility functions that other transformations could use. <a href="http://reviews.llvm.org/rL230178">r230178</a>.</p></li><li><p>Implementation of support for alloca on MIPS fast-isel has started. <a href="http://reviews.llvm.org/rL230300">r230300</a>.</p></li><li><p>The PowerPC backend gained support for the QPX vector instruction set. <a href="http://reviews.llvm.org/rL230413">r230413</a>.</p></li><li><p>InductiveRangeCheckElimination can now handle loops with decreasing induction variables. <a href="http://reviews.llvm.org/rL230618">r230618</a>.</p></li><li><p>Among other improvements, llvm-pdbdump gained colorized output. <a href="http://reviews.llvm.org/rL230476">r230476</a>.</p></li><li><p>The Forward Control Flow Integrity Pass has been removed as it is being rethought and is currently unused. <a href="http://reviews.llvm.org/rL230780">r230780</a>.</p></li><li><p>The Performance Tips for Frontend Authors document was born. <a href="http://reviews.llvm.org/rL230807">r230807</a>.</p></li></ul><h3>Clang commits</h3><ul><li>The control flow integrity design docs has been updated to document optimisations. <a href="http://reviews.llvm.org/rL230458">r230458</a>, <a href="http://reviews.llvm.org/rL230588">r230588</a>.</li></ul><h3>Other project commits</h3><ul><li><p>Remote testing support was added to the libc++ and libc++abi test suites. <a href="http://reviews.llvm.org/rL230592">r230592</a>, <a href="http://reviews.llvm.org/rL230643">r230643</a>.</p></li><li><p>LLD learned to understand .gnu.linkonce input sections. <a href="http://reviews.llvm.org/rL230194">r230194</a>.</p></li></ul>
- LLVM 3.6 Releasehttps://blog.llvm.org/2015/02/llvm-36-release.htmlFri, 27 Feb 2015 12:48:00 +0000https://blog.llvm.org/2015/02/llvm-36-release.html<p>LLVM 3.6 is now available!</p> <p>Get it here: <a href="http://llvm.org/releases/">http://llvm.org/releases/</a></p> <p>This release contains the work of the LLVM community over the past six months: many many bug fixes, optimization improvements, support for more proposed C++1z features in Clang, better native Windows compatibility, embedding LLVM IR in native object files, Go bindings, and more. For details, see the release notes [<a href="http://llvm.org/releases/3.6.0/docs/ReleaseNotes.html">LLVM</a>, <a href="http://llvm.org/releases/3.6.0/tools/clang/docs/ReleaseNotes.html">Clang</a>].</p> <p>Many thanks to everyone who helped with testing, fixing, and getting the release into a good state!</p> <p>Special thanks to the volunteer release builders and testers, without whom this release would not be possible: Dimitry Andric, Sebastian DreÃler, Renato Golin, Sylvestre Ledru, Ben Pope, Daniel Sanders, and Nikola SmiljaniÄ!</p> <p>If you have any questions or comments about this release, please contact the community on the mailing lists. Onwards to 3.7!</p>
- LLVM Weekly - #60, Feb 23rd 2015https://blog.llvm.org/2015/02/llvm-weekly-60-feb-23rd-2015.htmlMon, 23 Feb 2015 03:05:00 +0000https://blog.llvm.org/2015/02/llvm-weekly-60-feb-23rd-2015.html<p>Welcome to the sixtieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/60">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM/Clang 3.6.0-rc4 is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41432/">now available for testing</a>.</p><p>A new LLVM-based tainted flow analysis tool <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82660/">has been created</a>. It's a tool designed to help detect timing attack vulnerabilities. An <a href="http://cuda.dcc.ufmg.br/flowtracker/">online demo</a> is available.</p><p>The March bay-area LLVM social <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6599/">will take place on Thursday 5th March</a>, along with the Game Developer's Conference.</p><p>The Cambridge LLVM social will take place <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41374/">on Wednesday 25th Feb</a>.</p><p>HHVM, the optimised PHP virtual machine from Facebook <a href="http://hhvm.com/blog/8405/coming-soon-in-hhvm">plan to integrate an LLVM-based optimisation phase</a>.</p><h3>On the mailing lists</h3><ul><li><p>Lefteris Ioannidis has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82321">introduced himself</a> on the mailing list. He is working on propagating parallelism at the IR level, with a hope to ultimately upstream his work. He's interested in chatting to anyone working in this area.</p></li><li><p>Eric Fiselier <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41444/">asks when libc++ can list Linux as an officially supported platform</a>.</p></li><li><p>Hans Wennborg is <a href="http://article.gmane.org/gmane.comp.compilers.clang.scm/117060">asking for people to flesh out the 3.6 release notes</a> with more details.</p></li><li><p>Hayden Livingston is working on a tool to help understand how LLVM IR changes after optimization passes are run and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82398">wonders about adding a new API to support this use case</a>. Greg Fitzgerald points to his <a href="https://github.com/garious/diffdump">handy diffdump tool</a>.</p></li><li><p>Bruce Mitchener suggests <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6570">adding SWIG bindings to LLDB for JS and other languages</a>.</p></li><li><p>Zephyr Zhao has <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6546">shared his work on a GUI frontend to LLDB</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The coding standards document has been updated now that MSVC 2012 support has been dropped. <a href="http://reviews.llvm.org/rL229369">r229369</a>.</p></li><li><p>The Orc API continues to evolve. The JITCompileCallbackManager has been added to create and manage JIT callbacks. <a href="http://reviews.llvm.org/rL229461">r229461</a>.</p></li><li><p>A new pass, the bit-tracking dead code elimination pass has been added. It tracks dead bits of integer-valued instructions and removes them when all bits are set. <a href="http://reviews.llvm.org/rL229462">r229462</a>.</p></li><li><p>The SystemZ backend now supports all TLS access models. <a href="http://reviews.llvm.org/rL229652">r229652</a>, <a href="http://reviews.llvm.org/rL229654">r229654</a>.</p></li><li><p>A new pass for constructing gc.statepoint sequences with explicit relocations was added. The pass will be further developed and bugfixed in-tree. <a href="http://reviews.llvm.org/rL229945">r229945</a>.</p></li><li><p>The old x86 vector shuffle lowering code has been removed (the new shuffle lowering code has been the default for ages and known regressions have been fixed). <a href="http://reviews.llvm.org/rL229964">r229964</a>.</p></li><li><p>A new bitset metadata format and lowering pass has been added. In the future, this will be used to allow a C++ program to efficiently verify that a vtable pointer is in the set of valid vtable pointers for the class or its derived classes. <a href="http://reviews.llvm.org/rL230054">r230054</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>clang-format gained support for JS type annotations and classes. <a href="http://reviews.llvm.org/rL229700">r229700</a>, <a href="http://reviews.llvm.org/rL229701">r229701</a>.</p></li><li><p>Most of the InstrProf coverage mapping generation code has been rewritten. <a href="http://reviews.llvm.org/rL229748">r229748</a>.</p></li><li><p>Clang learnt how to analyze FreeBSD kernel printf extensions. <a href="http://reviews.llvm.org/rL229921">r229921</a>.</p></li><li><p>Support has been added to Clang for a form of Control Flow Integrity for virtual function calls. It verifies the vptr of the correct dynamic type is being used. <a href="http://reviews.llvm.org/rL230055">r230055</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>ThreadSanitizer gained support for MIPS64. <a href="http://reviews.llvm.org/rL229972">r229972</a>.</p></li><li><p>lldb now supports process language on Android from lldb-gdbserver. <a href="http://reviews.llvm.org/rL229371">r229371</a>.</p></li><li><p>OpenMP gained a new user-guided lock API. <a href="http://reviews.llvm.org/rL230030">r230030</a>.</p></li></ul>
- LLVM Weekly - #59, Feb 16th 2015https://blog.llvm.org/2015/02/llvm-weekly-59-feb-16th-2015.htmlMon, 16 Feb 2015 03:15:00 +0000https://blog.llvm.org/2015/02/llvm-weekly-59-feb-16th-2015.html<p>Welcome to the fifty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/59">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>Reminder, the EuroLLVM 2015 call for papers submission deadline is <em>TODAY</em>. See <a href="http://llvm.org/devmtg/2015-04/#callfor">here</a> for details.</p><p>LLVM and Clang 3.6-rc3 <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41186">has been tagged</a>, any help with testing is greatly appreciated.</p><h3>On the mailing lists</h3><ul><li><p>The discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81923">moving towards a singular pointer type</a> has continued. It seems everyone is in favour.</p></li><li><p>Philip Reames has proposed <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82186">an attribute that indicates the value is either null or dereferenceable</a>. The intended use case is for Java, though it may be useful for various other higher level languages.</p></li><li><p>Duncan P.N. Exon Smith is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82185">concerned that llc is becoming less useful as a debugging tool</a> and proposes modifying Clang to store target defaults on a module.</p></li><li><p>Alexey Samsonov <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/82213">proposes dropping support for building the sanitizers with autotools</a>. The autotools build system never reached feature parity with CMake for the sanitizers and is undertested, there seem to be no objections.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The biggest chunk of internal refactoring of debug metadata has landed, with the addition of specialized debug info metadata nodes. <a href="http://reviews.llvm.org/rL228640">r228640</a>.</p></li><li><p>New intrinsics llvm.eh.begincatch and llvm.eh.endcatch intrinsics have been added to support Windows exception handling. <a href="http://reviews.llvm.org/rL228733">r228733</a>.</p></li><li><p>A DebugInfoPDB implementation using the MS Debug Interface Access SDK has landed. <a href="http://reviews.llvm.org/rL228747">r228747</a>.</p></li><li><p>SimplifyCFG will now use TargetTransformInfo for cost analysis. <a href="http://reviews.llvm.org/rL228826">r228826</a>.</p></li><li><p>A profitability heuristic has been added for the x86 mov-to-push optimisation. <a href="http://reviews.llvm.org/rL228915">r228915</a>.</p></li><li><p>PassManager.h is now LegacyPassManager.h. As described in the commit message, if you are an out of tree LLVM user you may need to update your includes. <a href="http://reviews.llvm.org/rL229094">r229094</a>.</p></li></ul><h3>Clang commits</h3><ul> <li><p>The <code>/volatile:ms</code> semantics have been implemented, turning volatile loads and stores into atomic acquire and release operations. <a href="http://reviews.llvm.org/rL229082">r229082</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>C++14's sized deallocation functions have been implemented in libcxx. <a href="http://reviews.llvm.org/rL229281">r229281</a>.</p></li><li><p>lld learnt to handle the <code>--wrap</code> option. <a href="http://reviews.llvm.org/rL228906">r228906</a>.</p></li><li><p>lldb gained the concept of "runtime support values". <a href="http://reviews.llvm.org/rL228791">r228791</a>.</p></li><li><p>The remote-android platform has been added to lldb. <a href="http://reviews.llvm.org/rL228943">r228943</a>.</p></li></ul>
- LLVM Weekly - #58, Feb 9th 2015https://blog.llvm.org/2015/02/llvm-weekly-58-feb-9th-2015.htmlMon, 09 Feb 2015 08:33:00 +0000https://blog.llvm.org/2015/02/llvm-weekly-58-feb-9th-2015.html<p>Welcome to the fifty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/58">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The Red Hat developer blog has a post about the plan to <a href="http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/">change the G++ ABI along with GCC 5</a>. This is required for full C++11 compatibility. Unlike the last ABI change where the libstdc++ soname was changed, it will stay the same and instead different mangled names will be used for symbols.</p><p>Quarks lab have a tutorial on how to <a href="http://blog.quarkslab.com/turning-regular-code-into-atrocities-with-llvm.html">add a simple obfuscation pass to LLVM</a>.</p><h3>On the mailing lists</h3><ul><li><p>It is currently planned to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81596">raise the LLVM minimum required MSVC to 2013</a>. If you are using MSVC 2012 to build LLVM and this would cause significant hardship to you for some reason, now is the time to speak up.</p></li><li><p>Chandler Carruth has shared a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81659">handy cheatsheet</a> for those maintaining an out-of-tree target on how to adjust to the recent TargetTransformInfo changes.</p></li><li><p>The idea of dropping pointer types in LLVM IR has been brought up a few times recently. David Blaikie is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81923">interested in volunteering to do the necessary work</a>. Much of the ensuing discussion is about how this might be done in an incremental way, without causing too many problems for people with out of tree passes. Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81945">proposes a rough work-plan</a>.</p></li><li><p>James Molloy has posted an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81848">inlining of recursive functions</a>.</p></li><li><p>Chris Bieneman has summarised progress on brining the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81741">CMake buildsystem to the point it can replace autoconf</a> in LLVM/Clang.</p></li><li><p>Karthik Bat has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81854">RFC on adding a LoopInterchange pass to LLVM</a>. This is a pass targeted at improving performance through cache locality.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A straight-line strength reduction pass has been introduced. This is intended to simplify statements that are generated after loop unrolling. It is enabled only for NVPTX for the time being. <a href="http://reviews.llvm.org/rL228016">r228016</a>.</p></li><li><p>A MachineInstruction pass that converts stack-relative moves of function arguments to use the X86 push instruction. This is only enabled when optimising for code size. <a href="http://reviews.llvm.org/rL227752">r227752</a>.</p></li><li><p>The BasicAA will now try to disambiguate GetElementPtr through arrays of structs into different fields. <a href="http://reviews.llvm.org/rL228498">r228498</a>.</p></li><li><p>Work on improving support in LLVM for GC continues, with the addition of a pass for inserting safepoints into arbitrary IR. <a href="http://reviews.llvm.org/rL228090">r228090</a>.</p></li><li><p>(Very) minimal support for the newly announced ARM Cortex-A72 landed. For now, the A72 is modeled as an A57. <a href="http://reviews.llvm.org/rL228140">r228140</a>.</p></li><li><p>A new heuristic has been added for complete loop unrolling, which looks at what loads might be made constant if the loop is completely unrolled. <a href="http://reviews.llvm.org/rL228265">r228265</a>.</p></li><li><p>A pass to exploit PowerPC's pre-increment load/store support has been added. <a href="http://reviews.llvm.org/rL228328">r228328</a>.</p></li><li><p>A platform-independent interface to a PDB reader has landed. <a href="http://reviews.llvm.org/rL228428">r228428</a>.</p></li><li><p>LLVM learnt to recognise masked gather and scatter intrinsics. <a href="http://reviews.llvm.org/rL228521">r228521</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang learnt the 'novtable' attribute (for MS ABI support). <a href="http://reviews.llvm.org/rL227796">r227796</a>, <a href="http://reviews.llvm.org/rL227838">r227838</a>.</p></li><li><p>New functionality has been added for thread safety analysis, before/after annotations can now be used on mutexes. <a href="http://reviews.llvm.org/rL227997">r227997</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A whole bunch of work on LLDB with multithreaded applications on Linux has landed. <a href="http://reviews.llvm.org/rL227909">r227909</a>, <a href="http://reviews.llvm.org/rL227912">r227912</a>, <a href="http://reviews.llvm.org/rL227913">r227913</a>, and more.</p></li><li><p>The default Polly build is now completely free of GPL dependencies. The isl and imath dependencies have been imported into the codebase to make it easier to build with a known-good revision. <a href="http://reviews.llvm.org/rL228193">r228193</a>.</p></li></ul>
- LLVM Weekly - #57, Feb 2nd 2015https://blog.llvm.org/2015/02/llvm-weekly-57-feb-2nd-2015.htmlMon, 02 Feb 2015 05:52:00 +0000https://blog.llvm.org/2015/02/llvm-weekly-57-feb-2nd-2015.html<p>Welcome to the fifty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I've been at FOSDEM this weekend in Brussels (which is why this week's issue is perhaps a little shorter than usual!). Most talks were recorded and I'll be linking to the videos from the LLVM devroom once they're up. For those interested, you can <a href="https://speakerdeck.com/asb/lowrisc-the-path-to-an-open-source-soc">see the slides from my lowRISC talk here</a>. If you want to chat about the project, you may want to join #lowRISC on irc.oftc.net.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/57">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Eli Bendersky has written a useful <a href="http://eli.thegreenplace.net/2015/building-and-using-llvmlite-a-basic-example/">introduction to using the llvmlite Python to LLVM binding</a>, which was borne out of the Numba project.</p><p>LLVM/Clang 3.6-rc2 <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81600">has been tagged</a> and is ready for testing.</p><p>The next LLVM bay-area social is taking place <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/41012/">on Feb 5th at 7pm</a>.</p><p>The EuroLLVM <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6413/">call for papers</a> closes on Feb 16th.</p><h3>On the mailing lists</h3><ul><li><p>David Majneer has attempted to describe the often confusing 'poison' semantics for LLVM, and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81383">submitted an RFC</a>. Masses of discussion follows.</p></li><li><p>Dylan McKay has been working on an LLVM backend for AVR and has come to the mailing list with two questions on instruction encoding in the last week. They're interesting questions with useful answers - <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81531">how to modify the encoding based on target features</a> and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81613/">how to encode instructions with inconsistent formats</a>.</p></li><li><p>Saleem Abdulrasool <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81577">kicked off a long discussion on where libunwind should live</a>.</p></li><li><p>Andrew Kaylor has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81284">RFC on adding support for native windows C++ exception handling</a>.</p></li><li><p>Matt Arsenault has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81443">RFC on adding and ISD node for fused multiply add operations</a>.</p></li><li><p>A question about the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81323">meaning of RAUW</a> is a good opportunity to highlight the existence of the very handy <a href="http://llvm.org/docs/Lexicon.html">LLVM lexicon</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A simple in-process fuzzer was added to LLVM. <a href="http://reviews.llvm.org/rL227252">r227252</a>.</p></li><li><p>The programmer's manual gained a section about type hierarchies, polymorphism, and virtual dispatch. <a href="http://reviews.llvm.org/rL227292">r227292</a>.</p></li><li><p>The upstreaming of Sony's patches for their PS4 compiler started with the addition of the PS4 target triple. <a href="http://reviews.llvm.org/rL227060">r227060</a>.</p></li><li><p>DataLayout now lives again in the TargetMachine rather than the TargetSubtagertInfo. <a href="http://reviews.llvm.org/rL227113">r227113</a>.</p></li><li><p>RuntimeDyld learned to support weak symbols. <a href="http://reviews.llvm.org/rL227228">r227228</a>.</p></li><li><p>LLVM gained a new tool, llvm-pdbdump to dump the contents of Microsoft PDB ('Program DataBase') files, including debug tables. <a href="http://reviews.llvm.org/rL227241">r227241</a>, <a href="http://reviews.llvm.org/rL227257">r227257</a>.</p></li><li><p>The loop vectorizer now supports an arbitrary constant step for its induction variables, rather than just -1 or +1. <a href="http://reviews.llvm.org/rL227557">r227557</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The clang-format-fuzzer tool was added, which builds on the LLVM fuzzer lib. <a href="http://reviews.llvm.org/rL227354">r227354</a>.</p></li><li><p>MS ABI work continues with proper support for setjmp. <a href="http://reviews.llvm.org/rL227426">r227426</a>.</p></li><li><p>Clang started to learn about the PS4 target triple. <a href="http://reviews.llvm.org/rL227194">r227194</a>.</p></li></ul><h3>Other project commits</h3><ul><li>The PowerPC ELF target was dropped from lld. <a href="http://reviews.llvm.org/rL227320">r227320</a>.</li></ul>
- LLVM Weekly - #56, Jan 26th 2015https://blog.llvm.org/2015/01/llvm-weekly-56-jan-26th-2015.htmlMon, 26 Jan 2015 06:56:00 +0000https://blog.llvm.org/2015/01/llvm-weekly-56-jan-26th-2015.html<p>Welcome to the fifty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'll be talking the <a href="http://lowrisc.org/">lowRISC</a> project to produce a fully open-source SoC at FOSDEM this coming weekend. Do come and see my <a href="https://fosdem.org/2015/schedule/event/lowrisc/">main track talk</a> and read my <a href="https://fosdem.org/2015/interviews/2015-alex-bradbury/">speaker interview</a> for more background. There is of course an <a href="https://fosdem.org/2015/schedule/track/llvm_toolchain/">LLVM toolchain devroom</a>on the Sunday.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/56">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Stephen Diehl has written an absolutely fantastic tutorial on <a href="http://dev.stephendiehl.com/numpile/">writing an LLVM specializer for Python</a>, guiding you through the process of creating something like <a href="https://github.com/numba/numba">Numba</a>.</p><p>A new tool, <a href="http://pmachata.github.io/dwgrep/">Dwgrep</a> (DWARF Grep) may be of interest to many LLVM Weekly readers. This <a href="http://developerblog.redhat.com/2015/01/22/querying-dwarf-for-fun-and-profit/">blog post</a> gives an intro to using it.</p><p>Paul Smith has a blog post on <a href="https://pauladamsmith.com/blog/2015/01/how-to-get-started-with-llvm-c-api.html">getting started with the LLVM C API</a>.</p><p>A post on the official LLVM Blog announces that <a href="http://blog.llvm.org/2015/01/lldb-is-coming-to-windows.html">LLDB is coming to Windows</a>, announcing to a wider audience that it is now possible to debug simple programs with LLDB on Windows and giving a rationale for investing effort into porting LLDB to Windows and adding support for the MS debug format. The post also features a todo list indicating what's next for Windows support.</p><p>A draft version 0.1 of the IA-32 psABI (processor specific application binary interface) is <a href="https://github.com/hjl-tools/x86-psABI/tree/hjl/x86/master">available</a>. This aims to supplement the existing System V ABI with conventions relevant to newer features such as SSE1-4 and AVX. Comments <a href="https://groups.google.com/forum/#!topic/ia32-abi/nq6cvH_VVV4">are welcome</a>.</p><p>LLVM/Clang 3.6-rc1 is now <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81014">available</a>. Get testing and filing bugs.</p><p>ELLCC 0.1.8 <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/40797">has been released</a>. ELLCC is an LLVM/Clang-based cross compilation toolchain.</p><p>LLDB now <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6352">has it's own IRC channel</a>. You'll want to join #lldb on irc.oftc.net.</p><h3>On the mailing lists</h3><ul><li><p>Chandler Carruth has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81056">canonicalization-related RFC</a>. He demonstrates a case where a trivial function is compiled to two equivalent IR sequences. This was <a href="http://reviews.llvm.org/rL226781">later committed</a>.</p></li><li><p>Michael Zolotukhin has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81173">proposed an RFC on adding a heuristic for complete loop unrolling</a>. Currently, the loop unrolling heuristics don't take account of any new optimisations that maybe enabled by unrolling the loop. Changing that would allow for the profitability of the unroll to be more accurately approximated.</p></li><li><p>Chandler Carruth is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/81143">getting ready to turn on by default the next part of his vector shuffle work</a>. Now is a good time to benchmark and report any regressions you see with <code>-x86-experimental-vector-shuffle-legality</code> on your codebases.</p></li><li><p>Ahmed Bougacha has been having <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80941">problems with the cost model calculations for saturation instructions</a>. The cost is over-estimated because a number of the individual IR instructions fold-away later in lowering. He suggests adding a new method to TargetTransformInfo for multi-instruction cost computation. There hasn't been much feedback thus far.</p></li><li><p>Chandler Carruth has been <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80958">looking through the LLD libraries</a> and trying to work out the current layering, as well as what a potential future layering might be. He proposes offering a basic library offering basic functionality and a second library offering a higher-level interface for actually doing linking.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A backend targeting the extended BPF (Berkeley Packet Filter) interpreter/JIT in the Linux kernel has been added. See <a href="http://lwn.net/Articles/603983/">this LWN article</a> for more background. <a href="http://reviews.llvm.org/rL227008">r227008</a>.</p></li><li><p>The initial version of the new ORC JIT API has landed. <a href="http://reviews.llvm.org/rL226940">r226940</a>.</p></li><li><p>There's been a flurry of work on the new pass manager this week. One commit I will choose to pick out is the port of InstCombine to the new pass manager, which seems like a milestone or sorts. <a href="http://reviews.llvm.org/rL226987">r226987</a>.</p></li><li><p>LLVM learnt how to use the GHC calling convention on AArch64. <a href="http://reviews.llvm.org/rL226473">r226473</a>.</p></li><li><p>InstCombine will now canonicalize loads which are only ever stored to always use a legal integer type if one is available. <a href="http://reviews.llvm.org/rL226781">r226781</a>.</p></li><li><p>The <code>llvm_any_ty</code> type for intrinsics has been born. <a href="http://reviews.llvm.org/rL226857">r226857</a>.</p></li><li><p>llvm-objdump now understands <code>-indirect-symbols</code> to dump the Mach-O indirect symbol table. <a href="http://reviews.llvm.org/rL226848">r226848</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang now supports SPIR calling conventions. <a href="http://reviews.llvm.org/rL226548">r226548</a>.</p></li><li><p>It's now possible to set the stack probe size on the command line. <a href="http://reviews.llvm.org/rL226601">r226601</a>.</p></li><li><p>Clang gained initial support for Win64 SEH IR emission. <a href="http://reviews.llvm.org/rL226760">r226760</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Sun Solaris users, now is the time to celebrate. libc++ will now build on your platform of choice. <a href="http://reviews.llvm.org/rL226947">r226947</a>.</p></li><li><p>A minimal implementation of ARM static linking landed in lld. <a href="http://reviews.llvm.org/rL226643">r226643</a>.</p></li><li><p>Basic support for PPC was added to openmp. <a href="http://reviews.llvm.org/rL226479">r226479</a>.</p></li></ul>
- LLDB is Coming to Windowshttps://blog.llvm.org/2015/01/lldb-is-coming-to-windows.htmlTue, 20 Jan 2015 10:48:00 +0000https://blog.llvm.org/2015/01/lldb-is-coming-to-windows.htmlWe've spoken in the <a href="http://blog.llvm.org/2014/07/clangllvm-on-windows-update.html">past</a> about teaching Clang to fully support Windows and be compatible with MSVC. Until now, a big missing piece in this story has been debugging the clang-generated executables. Over the past 6 months, we've started working on making LLDB work well on Windows and support debugging both regular Windows programs and those produced by Clang.<br /><div><br /></div><div>Why not use an existing debugger such as GDB, Visual Studio's, or WinDBG? There are a lot of factors in making this kind of decision. For example, while GDB understands the DWARF debug information produced by Clang on Windows, it doesn't understand the Microsoft C++ ABI or debug information format. On the other hand, neither Visual Studio nor WinDBG understand the DWARF debug information produced by Clang. With LLDB, we can teach it to support <i>both</i> of these formats, making it usable with a wider range of programs. There are also other reasons why we're really excited to work on LLDB for Windows, such as the tight integration with Clang which lets it support all of the same C++ features in its expression parser that Clang supports in your source code. We're also looking to continue adding new functionality to the debugging experience going forward, and having an open source debugger that is part of the larger LLVM project makes this really easy.</div><div><br /></div><div>The past few months have been spent porting LLDB's core codebase to Windows. We've been fixing POSIX assumptions, enhancing the OS abstraction layer, and removing platform specific system calls from generic code. Sometimes we have needed to take on significant refactorings to build abstractions where they are necessary to support platform specific differences. We have also worked to port the test infrastructure to Windows and set up build bots to ensure things stay green.</div><div><br /></div><div>This preliminary bootstraping work is mostly complete, and you can use LLDB to debug simple executables generated with Clang on Windows today. Note the use of the word "simple". At last check, approximately 50% of LLDB's tests fail on Windows. Our baseline, however, which is a single 32-bit executable (i.e. no shared libraries), single-threaded application built and linked with Clang and LLD using DWARF debug information, works today. We've tested all of the fundamental functionality such as:</div><div><ol><li>Various methods of setting breakpoints (address, source file+line, symbol name, etc)</li><li>Stopping at and continuing from breakpoints</li><li>Process inspection while stopped, such as stack unwinding, frame setting, memory examination, local variables, expression evaluation, stepping, etc (one notable exception to this is that step-over doesn't yet work well in the presence of limited symbol information).</li></ol><div>Of course, there is still more to be done. Here are some of the areas we're planning to work on next:</div></div><div><ol><li>Fixing low hanging fruit by improving the pass-rate of the test suite.</li><li>Better support for debugging multi-threaded applications.</li><li>Support for debugging crash dumps.</li><li>Support for debugging x64 binaries.</li><li>Enabling stepping through shared libraries.</li><li>Understanding PDB (for debugging system libraries, and executables generated with MSVC). Although the exact format of PDB is undocumented, Microsoft still provides a rich API for querying PDB in the form of the DIA SDK.</li><li>Adding debugging commands familiar to users of WinDBG (e.g. !handle, !peb, etc)</li><li>Remote debugging</li><li>Symbol server support</li><li>Visual Studio integration</li></ol><div>If you're using Clang on Windows, we would encourage you to <a href="http://lldb.llvm.org/build.html#BuildingLldbOnWindows">build LLDB</a> (it should be in the Windows <a href="http://llvm.org/builds/">LLVM installer</a> soon) and let us know your thoughts by posting them to <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev">lldb-dev</a>. Make sure you <a href="http://llvm.org/bugs/enter_bug.cgi?product=lldb">file bugs</a> against LLDB if you notice anything wrong, and we would love for you to dive into the code and help out. If you see something wrong, dig in and try to fix it, and post your patch to <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits">lldb-commits</a>.</div></div>
- LLVM Weekly - #55, Jan 19th 2015https://blog.llvm.org/2015/01/llvm-weekly-55-jan-19th-2015.htmlMon, 19 Jan 2015 09:58:00 +0000https://blog.llvm.org/2015/01/llvm-weekly-55-jan-19th-2015.html<p>Welcome to the fifty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>It seems to have been a very busy week in the world of LLVM, particularly with regards to discussion on the mailing list. Due to travel etc and the volume of traffic, I haven't been able to do much summarisation of mailing list discussion I'm afraid.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/55">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLM/Clang 3.6 <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80665">has been branched</a> and subsequently, 3.6 RC1 <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/40736">has been tagged</a>.</p><p>LLVM/Clang 3.5.1 seems to have been <a href="http://llvm.org/releases/download.html#3.5.1">quietly released</a>.</p><p>Registration for <a href="http://llvm.org/devmtg/2015-04/">EuroLLVM 2015</a>, to be held at Goldsmiths College in London, UK on April 13-14th is <a href="http://www.eventbrite.com/e/eurollvm-2015-tickets-15350278095">now open</a>.</p><p>All slides and videos from the last LLVM Developers' meeting are <a href="http://llvm.org/devmtg/2014-10/">now live</a>, including those from Apple employees.</p><h3>On the mailing lists</h3><ul><li><p>Ahmed Bougacha has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80678">RFC on adding integer saturation intrinsics</a> to LLVM. There are various questions in the ensuing thread about whether adding an intrisc is necessary and the best way to go about this. i.e. whether it is possible to just pattern match later on in the compilation flow.</p></li><li><p>In response to a question about using LLDB when attached to a system that may switch between AARch32 and AArch64, Colin Riley has written a good description of <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6184">current support and potential future support for multiple targets in one debugger session</a>.</p></li><li><p>Jonathan Ragan-Kelley <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80499">asks about emitting IR in older formats</a> due to a requirement to emit 3.2-compatible bitcode for Nvidia's libNVVM. Several replies suggest looking at SPIR.</p></li><li><p>Do you wonder what the difference is between the multiple ways of querying operation costs? <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80705">Wonder no more</a>.</p></li><li><p>Duncan P.N. Exon Smith has posted on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80563">RFC on first-class debug info in IR</a>. There have been a few changes since the previous proposal.</p></li><li><p>Chandler Carruth has written a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80841">summary of alias analysis pass ordering in LLVM and Clang</a>. This details both the current situation as well as Chandler's views on how it should change in the future.</p></li><li><p>Philip Reames is seeking wider feedback on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80849/">two implementation issues for GCStrategy</a>. The two key questions are whether GC-specific properties should be checked in the IR verifier and what the access model for GCStrategy should be. No responses yet, so now is the time to dive in.</p></li><li><p>Ramshankar Ramanarayanan has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80798">proof of concept for a loop fusion pass</a>. Meanwhile, Adam Nemet has an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80528">RFC for a loop distribution pass</a>.</p></li><li><p>Lang Hanes has posted <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80639">a proposed new JIT API</a> with a catchy name (ORC: On Request Compilation). The aim is to cleanly support a wider range of JIT uses cases, and to be clear this higher level API would not replace the existing MCJIT.</p></li><li><p>Bjoern Haase has been spending some time examining generated code for armv6 microcontroller targets such as the Cortex M0. He has a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80497">series of suggestions for tweaking default optimizer settings for this target</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new code diversity feature is now available. The NoopInsertion pass will add random no-ops to x86 binaries to try to make ROP attacks more difficult by increasing diversity. <a href="http://reviews.llvm.org/rL225908">r225908</a>. I highly recommend reading up on the <a href="http://www.scs.stanford.edu/brop/">blind ROP</a> attack published last year. It would also be interesting to see an implementation of <a href="http://seclab.tuwien.ac.at/papers/gfree.pdf">G-Free</a> for producing binaries without simple gadgets. The commit was later reverted for some reason.</p></li><li><p>A nice summary of recent MIPS and PowerPC target developments, as well as the OCaml bindings is now there in the form of the 3.6 release notes. <a href="http://reviews.llvm.org/rL225607">r225607</a>, <a href="http://reviews.llvm.org/rL225695">r225695</a>, <a href="http://reviews.llvm.org/rL225779">r225779</a>.</p></li><li><p>LLVM learned the llvm.frameallocate and llvm.framerecover intrinsics, which allow multiple functions to share a single stack allocation from one function's call frame. <a href="http://reviews.llvm.org/rL225746">r225746</a>, <a href="http://reviews.llvm.org/rL225752">r225752</a>.</p></li><li><p>An experimental (disabled by default) 'inductive range check elimination' pass has landed. This attempts to eliminates range checks of the form <code>0 <= A*I + B < Length</code>. <a href="http://reviews.llvm.org/rL226201">r226201</a>.</p></li><li><p>StackMap/PatchPoint support is now available for the PowerPC target. <a href="http://reviews.llvm.org/rL225808">r225808</a>.</p></li><li><p>Initial support for Win64 SEH catch handlers has landed. See the commit message for current missing functionality. <a href="http://reviews.llvm.org/rL225904">r225904</a>.</p></li><li><p>A new utility script has been started to help update simple regression tests. It needs some work to generalise it beyond x86. <a href="http://reviews.llvm.org/rL225618">r225618</a>.</p></li><li><p>TargetLibraryInfo has been moved into the Analysis library. <a href="http://reviews.llvm.org/rL226078">r226078</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The new <code>-fno-inline-asm</code> flag has been added to disallow all inline asm. If it exists in the input code it will be reported as an error.<br /><a href="http://reviews.llvm.org/rL226340">r226340</a>.</p></li><li><p><code>-fsanitize-recover</code> command line flags are again supported. <a href="http://reviews.llvm.org/rL225719">r225719</a>.</p></li><li><p>The integrated assembler is now used by default on 32-bit PowerPC and SPARC. <a href="http://reviews.llvm.org/rL225958">r225958</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The libcxx build system learnt how to cross-compile. <a href="http://reviews.llvm.org/rL226237">r226237</a>.</p></li><li><p>LLD gained a nice speedup by speculative instantiating archive file members. This shaves off a second or two for linking lld with lld. <a href="http://reviews.llvm.org/rL226336">r226336</a>.</p></li><li><p>LLD learnt the <code>--as-needed</code> flag (previously this was the default behaviour). <a href="http://reviews.llvm.org/rL226274">r226274</a>.</p></li><li><p>OpenMP gained an AARch64 port. <a href="http://reviews.llvm.org/rL225792">r225792</a>.</p></li></ul>
- LLVM Weekly - #54, Jan 12th 2015https://blog.llvm.org/2015/01/llvm-weekly-54-jan-12th-2015.htmlMon, 12 Jan 2015 18:10:00 +0000https://blog.llvm.org/2015/01/llvm-weekly-54-jan-12th-2015.html<p>Welcome to the fifty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>As you receive this week's issue, I should be on my way to California where I'll be presenting <a href="http://www.lowrisc.org">lowRISC</a> at the RISC-V workshop in Monterey and having a few mother meetings. I'm in SF Fri-Sun and somewhat free on the Saturday if anyone wants to meet and chat LLVM or lowRISC/RISC-V.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/54">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Euro LLVM 2015 will be held on April 13th-14th in London, UK. The <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80291">call for papers</a> is now open with a deadline of 16th Feb.</p><p>Talks for the <a href="https://fosdem.org/2015/schedule/track/llvm_toolchain/">LLVM devroom at FOSDEM</a>have been announced. The LLVM devroom is on Sunday 1st Feb. Readers will be pleased to know this doesn't clash with <a href="https://fosdem.org/2015/schedule/event/lowrisc/">my talk on lowRISC</a> which is on the Saturday.</p><p>Google now use <a href="http://blog.llvm.org/2015/01/using-clang-for-chrome-production.html">Clang for production Chrome builds on Linux</a>. They were previously using GCC 4.6. Compared to that baseline, performance stayed roughly the same while binary size decreased by 8%. It would certainly have been interesting to compare to a more recent GCC baseline. The blog post indicates they're hopeful to use Clang in the future for building Chrome for Windows.</p><p>Philip Reames did an interesting back of the envelope calculation about the <a href="http://www.philipreames.com/Blog/2015/01/10/how-much-does-it-cost-to-maintain-llvm/">cost of maintaining LLVM</a>. He picked out commits which seems like they could be trivially automated and guesstimated a cost based on developer time. The figure he arrives at is $1400 per month.</p><p>The next LLVM social for Cambridge, UK will be <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80341">on Wed 21st Jan at 7:30pm</a>.</p><h3>On the mailing lists</h3><ul><li><p>LLVM 3.6 will be <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80447">branching soon</a>, on 14th January.</p></li><li><p>Philip Reames asks <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80355">whether address space 1 is reserved on any architecture</a>. It seems the answer is no, though the thread resulted in some discussion on the use of address spaces and the ability to reserve some. Philip <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80370">had a strawman proposal</a> for meanings of different address space numbers.</p></li><li><p>Chandler Carruth has suggested <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80430">new IR features are needed to represent the cases global metadata is currently used for</a>. Metadata was intended to be used to hold information that can be safely dropped, though this isn't true for e.g. module flags.</p></li><li><p>Arch Robinson kicked off a discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80381">floating point range checks in LLVM</a>. This isn't currently supported, though there's agreement it could be useful as well as a fair amount of discussion on some of the expected subtleties.</p></li><li><p>If you're wondering about alias instructions, Bruce Hoult has a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80402">good explanation</a>.</p></li><li><p>Note to out-of-tree backend maintainers, <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80385">get/setLoadExtAction now takes another parameter</a>.</p></li><li><p>Right now, LLDB will compile entered expressions in C++ mode. As <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6141">noted on the lldb mailing list</a> this can be problematic when e.g. debugging a C function which has a local variable called 'this'. Greg Clayton <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/6142">points out how helpful supporting C++ expressions can be</a>, even when debugging C code.</p></li><li><p>A thread about the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80418">design of the new pass manager</a> has been revived. Both Chandler Carruth and Philip Reames suggest <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80424">BasicBlockPasses should die</a>.</p></li><li><p>Philip Reames is seeking feedback on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80386">a transformation which would convert a loop to a loop nest</a> if it contains infrequently executed slow paths. There's some interesting discussion in the thread, and it's also worth reading Duncan P.N. Exon Smith's <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80472">clarification of branch weight, branch probability, block frequency, and block bias</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>An option <code>hoist-cheap-insts</code> has been added to the machine loop invariant code motion pass to enable hosting even cheap instructions (as long as register pressure is low). This is disabled by default. <a href="http://reviews.llvm.org/rL225470">r225470</a>.</p></li><li><p>The calculation of the unrolled loop size has been fixed. Targets may want to re-tune their default threshold. <a href="http://reviews.llvm.org/rL225565">r225565</a>, <a href="http://reviews.llvm.org/rL225566">r225566</a>.</p></li><li><p>DIE.h (datastructures for DWARF info entries) is now a public CodeGen header rather than being private to the AsmPrinter implementation. dsymutil will make use of it. <a href="http://reviews.llvm.org/rL225208">r225208</a>.</p></li><li><p>The new pass manager now has a handy utility for generating a no-op pass that forces a usually lazy analysis to be run. <a href="http://reviews.llvm.org/rL225236">r225236</a>.</p></li><li><p>There's been a minor change to the .ll syntax for comdats. <a href="http://reviews.llvm.org/rL225302">r225302</a>.</p></li><li><p>There have been some minor improvements to the emacs packages for LLVM and tablegen mode. <a href="http://reviews.llvm.org/rL225356">r225356</a>.</p></li><li><p>An example GCStrategy using the new statepoint infrastructure has been added. <a href="http://reviews.llvm.org/rL225365">r225365</a>, <a href="http://reviews.llvm.org/rL225366">r225366</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A <code>Wself-move</code> warning has been introduced. Similar to <code>-Wself-assign</code>, it will warn you when your code tries to move a value to itself. <a href="http://reviews.llvm.org/rL225581">r225581</a>.</p></li><li><p>The I, J, K, M, N, O inline assembly constraints are now checked. <a href="http://reviews.llvm.org/rL225244">r225244</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The libcxx test infrastructure has been refactored into separate modules. <a href="http://reviews.llvm.org/rL225532">r225532</a>.</p></li><li><p>The effort to retire InputElement in lld continues. Linker script files are no longer represented as an InputElement. <a href="http://reviews.llvm.org/rL225330">r225330</a>.</p></li><li><p>Polly has gained a <a href="http://polly.llvm.org/changelog.html">changelog</a> in preparation of the next release.<a href="http://reviews.llvm.org/rL225264">r225264</a>.</p></li><li><p>Polly has also gained a <a href="http://polly.llvm.org/todo.html">TODO list</a> for its next phase of development. <a href="http://reviews.llvm.org/rL225388">r225388</a>.</p></li></ul>
- Using clang for Chrome production builds on Linuxhttps://blog.llvm.org/2015/01/using-clang-for-chrome-production.htmlMon, 05 Jan 2015 10:39:00 +0000https://blog.llvm.org/2015/01/using-clang-for-chrome-production.html<div dir="ltr" style="text-align: left;" trbidi="on"><div><span style="font-family: inherit;">Chrome 38 was released early October 2014. It is the first release where the Linux binaries shipped to users are built by clang. Previously, this was done by gcc 4.6. As you can read in the <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-November/039929.html">announcement email</a>, the switch happened without many issues. Performance stayed roughly the same, binary size decreased by about 8%. In this post I'd like to discuss the motivation for this switch.</span></div><h3 style="text-align: left;"><span style="font-family: inherit;">Motivation</span></h3><span style="font-family: inherit;">There are two reasons for the switch.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">1. Many Chromium developers already used clang on Linux. We've supported <a href="https://code.google.com/p/chromium/wiki/Clang">opting in</a> to clang for since <a href="http://llvm.org/devmtg/2011-11/Weber_Wennborg_UsingClangInChromium.pdf">before clang supported C++</a> â because of this, we have a process in place for shipping new clang binaries to all developers and bots every few weeks. Because of clang's good diagnostics (<a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110530/042515.html">some</a> of <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120227/054412.html">which</a> we <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110613/042785.html">added</a> due to bugs in Chromium we thought the compiler should catch), speed, and because of our <a href="http://www.chromium.org/developers/coding-style/chromium-style-checker-errors">Chromium-specific clang plugin</a>, many Chromium developers switched to clang over the years. Making clang the default compiler removes a stumbling block for people new to the project.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">2. We want to use modern C++ features in Chromium. This requires a recent toolchain â we figured we needed at least gcc 4.8. For Chrome for Android and Chrome for Chrome OS, we updated our gcc compilers to 4.8 (and then 4.9) â easy since these ports use a non-system gcc already. Chrome for Mac has been using Chromium's clang since Chrome 15 and was already in a good state. Chrome for iOS uses Xcode 5's clang, which is also new enough. Chrome for Windows uses Visual Studio 2013 Update 4. On Linux, switching to clang was the easiest way forward.</span><br /><h3 style="text-align: left;">Keeping up with C++'s evolution in a large, multi-platform project</h3><span style="font-family: inherit;">C++ had been static for many years. C++11 is the first real update to the C++ language since the original C++ standard (approved on July 27 1998). C++98 predated the founding of Google, YouTube, Facebook, Twitter, the releases of Mac OS X and Windows XP, and x86 SSE instructions. The time between the two standards saw the rise and fall of the iPod, several waves of social networks, and the smartphone explosion.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">The time between C++11 and C++14 was three years, and the next major iteration of the language is speculated to be finished in 2017, three years from C++14. This is a dramatic change, and it has repercussions on how to build and ship C++ programs. It took us 3+ years to get to a state where we can use C++11 in Chromium; C++14 will hopefully take us less long. (If you're targeting fewer platforms, you'll have an easier time.)</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">There are two parts to C++11: New language features, and new library features. The language features just require a modern compiler at build time on build machines, the library features need a new standard library at runtime on the user's machine.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">Deploying a new compiler is conceptually relatively simple. If your developers are on Ubuntu LTS releases and you make them use the newest LTS release, they get new compilers every two years â so just using the default system compiler means you're up to two years behind. There needs to be some process to relatively transparently deploy new toolchains to your developers â an "evergreen compiler". We now have this in place for Chromium â on Linux, by using clang. (We still accept patches to keep Chromium buildable with gccs >= 4.8 for people who prefer compiling locally over using precompiled binaries, and we still use gcc as the target compiler for Chrome for Android and Chrome OS.)</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">The library situation is slightly more tricky: On Linux and Mac OS X, programs are usually linked against the system C++ library. Chrome wants to support Mac OS X 10.6 a bit longer (our users seem to love this OS X release), and the only C++ library this ships with is libstdc++ 4.2 â which doesn't have any C++11 bits. Similarly, Ubuntu Precise only has libstdc++ 4.6. It seems that with C++ updating more often, products will have to either stop supporting older OS versions (even if they still have many users on these old versions), adopt new C++ features very slowly, or ship with a bundled C++ standard library. The latter implies that system libraries shouldn't have a C++ interface for ABI reasons â luckily, this is mostly already the case.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">To make things slightly more complicated, gcc and libstdc++ expect to be updated at the same time. gcc 4.8 links to libstdc++ 4.8, so upgrading gcc 4.8 while still linking to Precise's libstdc++ 4.6 isn't easy. clang <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140630/109151.html">explicitly supports</a> building with older libstdc++ versions.</span><br /><span style="font-family: inherit;"><br /></span><span style="font-family: inherit;">For Chromium, we opted to enable C++11 language features now, and then allow C++11 library features later once we have figured out the story there. This allows us to <a href="https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/xMscQuYBwyc">incrementally adopt</a> <a href="http://chromium-cpp.appspot.com/">C++11 features in Chromium</a>, but it's not without risks:</span> <span style="font-family: Courier New, Courier, monospace;">vector<int> v0{42}</span> for example means something different with an old C++ library and a new C++ library that has a <span style="font-family: Courier New, Courier, monospace;">vector</span> constructor taking an <span style="font-family: Courier New, Courier, monospace;">initializer_list</span>. We disallow using uniform initialization for now because of this.<br /><br />Since bundling a C++ library seems to become more common with this new C++ update cadence, it would be nice if compiler drivers helped with this. Just statically linking libstdc++ / libc++ isn't enough if you're shipping a product consisting of several executables or shared libraries â they need to dynamically link to a shared C++ library with the right rpaths, the C++ library probably needs mangled symbol names that don't conflict with the system C++ library which might be loaded into the same process due to other system libraries using it internally (for example, maybe using an inline namespace with an application-specific name), etc.<br /><h3 style="text-align: left;">Future directions</h3>As mentioned above, we're trying to figure out the C++ library situation. The tricky cases are Chrome for Android (which currently uses STLport) and Chrome for Mac. We're hoping to switch Chrome for Android to libc++ (while still using gcc as compiler). On Mac, we'll likely bundle libc++ with Chrome too.<br /><br />We're <a href="http://blog.llvm.org/2014/07/clangllvm-on-windows-update.html">working</a> <a href="http://llvm.org/devmtg/2014-10/#talk15">on</a> making clang <a href="http://llvm.org/devmtg/2014-04/PDFs/Talks/clang-cl.pdf">usable</a> for compiling Chrome for Windows. The main motivations for this are using <a href="http://llvm.org/devmtg/2014-10/Slides/ASan%20for%20Windows.pdf">AddressSanitizer</a>, providing a compiler with great diagnostics for developers, and getting our <a href="https://code.google.com/p/chromium/wiki/ClangToolRefactoring">tooling infrastructure</a> working on Windows (used for example <a href="http://crbug.com/417463">automated large-scale cross-OS refactoring</a> and for building our <a href="https://code.google.com/p/chromium/codesearch#chromium/src/apps/launcher.h&sq=package:chromium&type=cs&l=18&rcl=1419953261">code search index</a> â try clicking a few class names; at the moment only code built on Linux is hyperlinked). We won't use clang as a production compiler on Windows unless it produces a chrome binary that's competitive with Visual Studio's on both binary size and performance. (From an open-source perspective, it <i>is</i> nice being able to use an open-source compiler to compile an open-source program.)<br /><br />You can reach us at [email protected]</div>
- LLVM Weekly - #53, Jan 5th 2015https://blog.llvm.org/2015/01/llvm-weekly-53-jan-5th-2015.htmlMon, 05 Jan 2015 06:30:00 +0000https://blog.llvm.org/2015/01/llvm-weekly-53-jan-5th-2015.html<p>Welcome to the fifty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'm going to be in California next week for the <a href="http://riscv.org/workshop">RISC-V workshop</a>. I'm arriving at SFO on Monday 12th and leaving on Sunday the 18th. Do let me know if you want to meet and talk <a href="http://www.lowrisc.org">lowRISC</a>/RISC-V or LLVM, and we'll see what we can do.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/53">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>I was getting ready to break out gitstats for some analysis of the LLVM repo and I find to my delight that Phoronix has saved me the trouble and has <a href="http://www.phoronix.com/scan.php?page=news_item&px=MTg3OTA">shared some stats on activity in the LLVM repo over the past year</a>.</p><p>Tom Stellard has made a blog post <a href="http://www.stellard.net/tom/blog/?p=69">announcing some recent RadeonSI performance improvements</a> on his LLVM development branch. This includes 60% improvement in one OpenCL benchmark and 10-25% in a range of other OpenCL tests.</p><p>Gaëtan Lehmann has written a blog post about <a href="http://blog.glehmann.net/2014/12/29/Playing-with-libclang/">getting started with libclang using the Python bindings</a>.</p><p>The C++ Filesystem Technical Specification, based on the Boost.Filesystem library <a href="http://article.gmane.org/gmane.comp.lib.boost.devel/256220">has been approved</a>.</p><h3>On the mailing lists</h3><ul><li><p>Virgile Bello has some questions on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80215">how he can control the calling convention in LLVM</a>. In this case, he has an CLR frontend and is trying to pass an object on the CLR stack to a native Win32 function. Reid Kleckner <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80217">suggests</a> the best way may be to just link with Clang and use its implementation. In another followup, he links to the <a href="http://llvm.org/devmtg/2014-10/Slides/Skip%20the%20FFI.pdf">talk on this topic</a> at the last LLVM dev meeting.</p></li><li><p><a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/40426">Is anybody using the ModuleBuilder class in Clang?</a>. If so, now is the time to speak up as it's slated to be removed.</p></li><li><p>Sami Liedes has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/40474">set up a new bot to test Clang with fuzzed inputs</a>. A report from the bot is available <a href="http://sli.dy.fi/~sliedes/clang-triage/triage_report.xhtml">here</a> and the code is <a href="https://github.com/sliedes/clang-triage">here</a>.</p></li><li><p>The release of LLVM/Clang 3.5.1 may be slightly delayed due to the addition of new patches late in the process. Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80202">points out</a> that there are some unpleasant bugs in InstCombine in the current 3.5.1 release candidate. If there is a release candidate 3, the patch in question will definitely make it in.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Instruction selection for bit-permuting operations on PowerPC has been improved. <a href="http://reviews.llvm.org/rL225056">r225056</a>.</p></li><li><p>The scalar replacement of aggregates (SROA) pass has started to learn how to more intelligently handle split loads and stores. As explained in detail in the commit message, the old approach lead to complex IR that can be difficult for the optimizer to work with. SROA is now also more aggressive in its splitting of loads. <a href="http://reviews.llvm.org/rL225061">r225061</a>, <a href="http://reviews.llvm.org/rL225074">r225074</a>.</p></li><li><p>InstCombine will now try to transform <code>A-B < 0</code> in to <code>A < B</code>. <a href="http://reviews.llvm.org/rL225034">r225034</a>.</p></li><li><p>The Hexagon (a Qualcomm DSP) backend has seen quite a lot of work recently. Interested parties are best of flicking through the commit log of lib/Target/Hexagon. <a href="http://reviews.llvm.org/rL225005">r225005</a>, <a href="http://reviews.llvm.org/rL225006">r225006</a>, etc.</p></li></ul><h3>Clang commits</h3><ul><li>More crash bugs have been uncovered and fixed by the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79491">naive fuzzing technique</a> previously covered in LLVM Weekly. e.g. <a href="http://reviews.llvm.org/rL224915">r224915</a>.</li></ul><h3>Other project commits</h3><ul><li>The lldb website has been updated with more information about LLDB on windows, including <a href="http://lldb.llvm.org/build.html#BuildingLldbOnWindows">build instructions</a>. <a href="http://reviews.llvm.org/rL225023">r225023</a>.</li></ul>
- LLVM Weekly - #52, Dec 29th 2014https://blog.llvm.org/2014/12/llvm-weekly-52-dec-29th-2014.htmlMon, 29 Dec 2014 02:20:00 +0000https://blog.llvm.org/2014/12/llvm-weekly-52-dec-29th-2014.html<p>Welcome to the fifty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This issue marks the end of one full year of LLVM Weekly. It's a little shorter than usual as the frenetic pace of LLVM/Clang development has slowed over the holiday period. Surprising even to me is that we managed to make it full all 52 weeks with an issue every Monday as promised. This requires a non-trivial amount of time each week (2-3+ hours), but I am intending to keep it going into 2015. I'd like to give a big thank you to everyone who's said hi at a conference, sent in corrections or tips on content, or just sent a random thank you. It's been very helpful in motivation. I don't currently intend to change anything about the structure or content of each issue for next year, but if you have any ideas then please let me know.</p><p>I can't make it to 31C3 due to the awkward timing of the event, but do let me know if there are any LLVM/Clang related talks worth sharing. There was a <a href="https://events.ccc.de/congress/2014/Fahrplan/events/6050.html">talk about Code Pointer Integrity</a> which has previously been covered in LLVM Weekly and is working towards upstreaming. The video is <a href="http://streaming.media.ccc.de/relive/6050">here</a>. If you're interested in <a href="http://www.lowrisc.org">lowRISC</a> and at 31C3, Bunnie is leading a <a href="https://events.ccc.de/congress/2014/wiki/Session:LowRISC_Discussion">discussion about it</a>at 2pm on Monday (today).</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/52">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>There doesn't seem to have been any LLVM or Clang related news over the past week. Everyone seems to be busy with non-LLVM related activities over the christmas break. If you're looking for a job though, Codeplay tell me they have two vancancies: one for a <a href="https://www.codeplay.com/company/jobs/view.html?uid=15#.VJft5P84JA">debugger engineer</a> and another for a <a href="https://www.codeplay.com/company/jobs/view.html?uid=12#.VJft7_84JA">compiler engineer</a>.</p><h3>On the mailing lists</h3><ul><li><p>David Li has shared some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80167">early info on Google's plans for LTO</a>. He describes the concept of 'peak optimization performance' and some of the objectives of the new design. This includes the ability to handle programs 10x or 100x the size of Firefox. We can expect more information in 2015, maybe as early as January.</p></li><li><p>The discussion on possible approaches to reducing the size of libLLVM has continued. Chris Bieneman has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80096">shared some more size stats</a>. These gains come from removing unused intrinsics. Chandler Carruth has followed up with a pleasingly thought-provoking argument on a different approach: <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80130">target-specific intrinsics shouldn't exist in the LLVM front or middle-end</a>. He describes the obvious issues with this, with the most fiddly probably being instruction selection converting appropriate IR to the right target-specific functionality.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The SROA (scalar replacement of aggregates) pass has seen some refactoring to, in the future, allow for more intelligent rewriting. <a href="http://reviews.llvm.org/rL224742">r224742</a>, <a href="http://reviews.llvm.org/rL224798">r224798</a>.</p></li><li><p>The masked load and store intrinsics have been documented. <a href="http://reviews.llvm.org/rL224832">r224832</a>.</p></li><li><p>CodeGenPrepare learned to speculate calls to llvm.cttz/ctlz (count trailing/leading zeroes) if <code>isCheapToSpeculateCtlz/isCheapToSpeculatCttz</code> in TargetLowering return true. <a href="http://reviews.llvm.org/rL224899">r224899</a>.</p></li></ul><h3>Clang commits</h3><ul><li>The Clang internals manual has been extended with stub sections on Parse, Sema, and CodeGen. <a href="http://reviews.llvm.org/rL224894">r224894</a>.</li></ul><h3>Other project commits</h3><ul><li>The libcxx LIT test-suite has seen a number of new configuration options. Even better, these are <a href="http://libcxx.llvm.org/lit_usage.html">now documented</a>. <a href="http://reviews.llvm.org/rL224728">r224728</a>.</li></ul>
- LLVM Weekly - #51, Dec 22nd 2014https://blog.llvm.org/2014/12/llvm-weekly-51-dec-22nd-2014.htmlMon, 22 Dec 2014 02:57:00 +0000https://blog.llvm.org/2014/12/llvm-weekly-51-dec-22nd-2014.html<p>Welcome to the fifty-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Last week as part of the <a href="http://www.lowrisc.org/">lowRISC project</a> I was involved in <a href="http://www.lowrisc.org/docs/memo-2014-001-tagged-memory-and-minion-cores/">sharing our plans for tagged memory and 'minion' cores</a> in the initial version. We've almost made it a full year of LLVM Weekly with no interruption of service!</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/51">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>3.5.1-rc2 <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/80017">has been tagged</a>, time to get testing again.</p><p>Version 0.15.1 of LDC, the LLVM D Compiler <a href="http://forum.dlang.org/thread/[email protected]">has been released</a>. The most prominent feature is probably the addition of preliminary support for MSVC on Win64.</p><p>SN Systems (part of Sony) have written a blog post <a href="http://www.snsystems.com/technology/2014/12/18/abi-bugs-are-a-nightmare/">describing their recently contributed ABI test suite</a>.</p><p>Peter Wilmott has <a href="https://p8952.info/ruby/2014/12/12/benchmarking-ruby-with-gcc-and-clang.html">benchmarked Ruby across various GCC and Clang releases</a>. The <a href="https://news.ycombinator.com/item?id=8762654">discussion at HN</a> may be of interest.</p><h3>On the mailing lists</h3><ul><li><p>Elena Demikhovsky has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79936">proposal for indexed load and store intrinsics</a>. These are intended for AVX-512 or AVX2 gather/scatter instructions which allow read/write access to multiple memory addresses.</p></li><li><p>Chad Rosier kicked off a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79849">lowering switch statements in the presence of data from profile guided optimisation</a>. There's some quite detailed discussion about when to use a Huffman tree vs a jump table.</p></li><li><p>Andrew Kaylor has posted <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79965">his impression of what needs to be done for MSVC exception handling support</a>. Reid Kleckner's <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79997">response</a> is informative.</p></li><li><p>Ulrich Weigand is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79912">taking over ownership of the SystemZ port</a>.</p></li><li><p>LLVM/Clang 3.6 is expected to branch in January. Marshall Clow has shared a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/40292">summary of the timings of releases over the past few years</a>.</p></li><li><p>Sean Silva has shared some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79962">thorough notes on the use of standard deviation and benchmarking in general</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Metadata is now typeless in assembly. <a href="http://reviews.llvm.org/rL224257">r224257</a>.</p></li><li><p>PowerPC instruction selection for bit-permuting operations has been improved. <a href="http://reviews.llvm.org/rL224318">r224318</a>.</p></li><li><p>An optimisation has been added to move sign/zero extends close to loads which causes performance improvements of 2-3% on a few benchmarks on x86. <a href="http://reviews.llvm.org/rL224351">r224351</a>.</p></li><li><p>More overflow arithmetic intrinsics are strength reduced into regular arithmetic operations if possible. <a href="http://reviews.llvm.org/rL224417">r224417</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Codegen for 'omp for' has started to be committed. <a href="http://reviews.llvm.org/rL224233">r224233</a>.</p></li><li><p><code>-save-temps</code> will now emit unoptimized bitcode files. <a href="http://reviews.llvm.org/rL224688">r224688</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The libcxx test suite can be run with ccache now. <a href="http://reviews.llvm.org/rL224603">r224603</a>.</p></li><li><p>Breakpoints can now be tagged with a name in lldb. <a href="http://reviews.llvm.org/rL224392">r224392</a>.</p></li></ul>
- LLVM Weekly - #50, Dec 15th 2014https://blog.llvm.org/2014/12/llvm-weekly-50-dec-15th-2014.htmlMon, 15 Dec 2014 03:29:00 +0000https://blog.llvm.org/2014/12/llvm-weekly-50-dec-15th-2014.html<p>Welcome to the fiftieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'll be at <a href="http://www.microarch.org/micro47/">MICRO-47</a> this week. If you're there do say hi, especially if you want to chat about LLVM or lowRISC/RISC-V.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/50">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The videos and slides from the 2014 LLVM dev meeting went online last week. I already linked to them then, but there's enough interesting stuff there I think I can justify <a href="http://llvm.org/devmtg/2014-10/">linking again</a>.</p><p>LLVM/Clang 3.5.1-rc1 <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79743">has been tagged</a>. Volunteer testers are very welcome.</p><p>Clang UPC 3.4.1 <a href="http://clangupc.github.io/2014/11/03/clang-upc-3-4-1-1-announcement/">has been released</a>. This is a Unified Parallel C compiler that can target SMP systems or <a href="http://clangupc.github.io/portals4/">Portals4</a>.</p><h3>On the mailing lists</h3><ul><li><p>Discussion has continued on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79435">future plans for GC in LLVM</a> with input from <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79567">Russel Hadley at Microsoft</a> and <a href="article.gmane.org/gmane.comp.compilers.llvm.devel/79581">Ben Karel</a>, who seems to be the most extensive user of the existing GC infrastructure with his <a href="https://code.google.com/p/foster/">Foster language</a>.</p></li><li><p>Chris Bieneman started a discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79657">supporting stripping out unused instrinsics</a> with the aim of reducing the size of libLLVM. The proposed patches reduce binary size by <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79736">~500k</a>, which he later points out is more significant in the context of their already size-reduced build.</p></li><li><p>Marshall Clow has shared a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/40061">proposal on how to manage ABI changes in libc++</a>. The proposal involves introducing macros to enable ABI-breaking changes.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The LLVM Kaleidoscope tutorial has been extended with an 8th chapter, describing how to add debug information using DWARF And DIBuilder. <a href="http://reviews.llvm.org/rL223671">r223671</a>. A rendered version can be found <a href="http://llvm.org/docs/tutorial/LangImpl8.html">here</a>.</p></li><li><p>Extensive documentation has been added for the MergeFunctions pass. <a href="http://reviews.llvm.org/rL223931">r223931</a>.</p></li><li><p>A monster commit to split Metadata from the Value class hierarchy has landed. <a href="http://reviews.llvm.org/rL223802">r223802</a>.</p></li><li><p>InstrProf has been born. This involves the <code>llvm.instrprof_increment</code> instrinsic and the <code>-instrprof</code> pass. This moves logic from Clang's CodeGenPGO into LLVM. <a href="http://reviews.llvm.org/rL223672">r223672</a>.</p></li><li><p>With the addition of support for SELECT nodes, the MIPS backend now supports codegen of MIPS-II targets on the LLVM test-suite. Code generation has also been enabled for MIPS-III. <a href="http://reviews.llvm.org/rL224124">r224124</a>, <a href="http://reviews.llvm.org/rL224128">r224128</a>.</p></li><li><p>Work has started on an LLVM-based dsymutil tool, with the aim to replace Darwin's dsymutil (a DWARF linker). <a href="http://reviews.llvm.org/rL224134">r223793</a>.</p></li><li><p>LiveInterval has gained support to track the liveness of subregisters. <a href="http://reviews.llvm.org/rL223877">r223877</a>.</p></li><li><p>Work has started on converting moves to pushes on X86 when appropriate. <a href="http://reviews.llvm.org/rL223757">r223757</a>.</p></li><li><p>Print and verify passes are now added after each MachineFunctionPass by default, rather than on some arbitrarily chosen subset. <a href="http://reviews.llvm.org/rL224059">r224042</a>.</p></li><li><p>LLVM now requires Python 2.7. Previously 2.5 was required. <a href="http://reviews.llvm.org/rL224129">r224129</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The <code>__builtin_call_with_static_chain</code> GNU extension has been implemented. <a href="http://reviews.llvm.org/rL224167">r224167</a>.</p></li><li><p>Clang's CodeGenPGO has moved to using the new LLVM <code>-instrprof</code> pass. <a href="http://reviews.llvm.org/rL223683">r223683</a>.</p></li><li><p>Clang now accepts Intel microarchitecture names as the <code>-march</code> argument. <a href="http://reviews.llvm.org/rL223776">r223776</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx gained relational operators in std::experimental::optional. <a href="http://reviews.llvm.org/rL223775">r223775</a>.</p></li><li><p>libcxx can now be built as a 32-bit library. <a href="http://reviews.llvm.org/rL224096">r224096</a>.</p></li><li><p>The lldb unwinder has learned to use unwind information from the compact-unwind section for x86-64 and i386 on Darwin. <a href="http://reviews.llvm.org/rL223625">r223625</a>.</p></li></ul>
- LLVM Weekly - #49, Dec 8th 2014https://blog.llvm.org/2014/12/llvm-weekly-49-dec-8th-2014.htmlMon, 08 Dec 2014 08:14:00 +0000https://blog.llvm.org/2014/12/llvm-weekly-49-dec-8th-2014.html<p>Welcome to the forty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/49">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Most of the 2014 LLVM Developers' Meeting videos and slides are <a href="http://llvm.org/devmtg/2014-10/index.html">now online</a>. Sadly, there are no videos from the talks by Apple employees yet. Hopefully they'll be appearing later.</p><p>QuarksLab has a rather nice write-up of <a href="http://blog.quarkslab.com/deobfuscation-recovering-an-ollvm-protected-program.html">deobfuscating an OLLVM-protected program</a>.</p><p>The LLVM-based ELLCC has been making progress on <a href="http://ellcc.org/blog/?p=22979">ELK, a bare-metal POSIX-like environment</a>.</p><p>Support for statepoints landed in LLVM this week, and Philip Reames has a blog post detailing <a href="http://www.philipreames.com/Blog/2014/12/04/statepoint-patches-have-landed/">some notes and caveats</a>. See also the mailing list discussion linked to below about future plans for GC in LLVM.</p><h3>On the mailing lists</h3><ul><li><p>Sami Liedes <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79491">shares his workflow for using afl-fuzz with the Clang test suite</a>. In 11 hours of testing he managed to find 34 distinct assertion failures and at least one segmentation fault.</p></li><li><p>Duncan P.N. Exon Smith has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79437">shared an updated on his work on the metadata-value split</a>, detailing the new semantic restrictions this will entail.</p></li><li><p>Philip Reames has a post <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79435">detailing his future plans for GC in LLVM</a>. Comments are invited. The aim is to eventually delete the existing gcroot lowering code. If you are actively using this, please do speak up.</p></li><li><p>John Yates, who worked on the compiler for the Apollo Computer's DN10K has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79416">shared a description of how that compiler would have handled one of the recent examples from the Souper work</a>.</p></li><li><p>How can you reproduce Clang's <code>-O3</code> using <code>opt</code>? The <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79367">answer</a>, thanks for Tobias Grosser, is <code>clang -O3 -mllvm -disable-llvm-optzns</code> followed by <code>opt -O3</code>.</p></li><li><p>Tobias Grosser is seeking community feedback on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79366">where in the pipeline the Polly loop optimiser should run</a>. The post is well worth a read for the discussion of expected trade-offs.</p></li><li><p>Rafael EspÃndola has been working on type merging during LTO and ultimately <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/218148">proposes moving to a single pointer type in LLVM IR</a>. There seems to be positive feedback on the idea, given that pointer types don't convey useful information to the optimizer and don't really provide safety.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The statepoint infrastructure for garbage collection has landed. See the final patch in the series for documentation. <a href="http://reviews.llvm.org/rL223078">r223078</a>, <a href="http://reviews.llvm.org/rL223085">r223085</a>, <a href="http://reviews.llvm.org/rL223137">r223137</a>, <a href="http://reviews.llvm.org/rL223143">r223143</a>.</p></li><li><p>The LLVM assembler gained support for ARM's funky modified-immediate assembly syntax. <a href="http://reviews.llvm.org/rL223113">r223113</a>.</p></li><li><p>The OCaml bindings now has a CMake buildsystem. <a href="http://reviews.llvm.org/rL223071">r223071</a>.</p></li><li><p>The PowerPC backend gained support for readcyclecounter on PPC32. <a href="http://reviews.llvm.org/rL223161">r223161</a>.</p></li><li><p>Support for 'prologue' metadata on functions has been added. This can be used for inserting arbitrary code at a function entrypoint. This was previously known as prefix data, and that term has been recycled to be used for inserting data just before the function entrypoint. <a href="http://reviews.llvm.org/rL223189">r223189</a>.</p></li><li><p>PowerPC gained a Power8 instruction schedule definition <a href="http://reviews.llvm.org/rL223257">r223257</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>LLVM IR for vtable addresses now uses the type of the field being pointed to, to enable more optimisations. <a href="http://reviews.llvm.org/rL223267">r223267</a>.</p></li><li><p>New attributes have been added to specify AMDGPU register limits. This is a performance hint that can be used to attempt to limit the number of used registers. <a href="http://reviews.llvm.org/rL223384">r223384</a>.</p></li><li><p>Clang gained the <code>__has_declspec_attribute</code> preprocessor macro. <a href="http://reviews.llvm.org/rL223467">r223467</a>.</p></li><li><p><code>__has_attribute</code> now only looks for GNU-style attributes. You should be able to use <code>__has_cpp_atribute</code> or <code>__has_declspec_attribute</code> instead. <a href="http://reviews.llvm.org/rL223468">r223468</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>DataFlowSanitizer is now supported for MIPS64. <a href="http://reviews.llvm.org/rL223517">r223517</a>.</p></li><li><p>libcxx now supported <code>std::random_device</code> on (P)NaCl. <a href="http://reviews.llvm.org/rL223068">r223068</a>.</p></li><li><p>An effort has started in lld to reduce abstraction around InputGraph, which has been found to get in the way of new features due to excessive information hiding. <a href="http://reviews.llvm.org/rL223330">r223330</a>. The commit has been temporarily reverted due to breakage on Darwin and ELF.</p></li><li><p>A large chunk of necessary code for Clang module support has been added to LLDB. <a href="http://reviews.llvm.org/rL223433">r223433</a>.</p></li><li><p>LLDB now has <a href="http://lldb.llvm.org/lldb-coding-conventions.html">documented coding conventions</a>. <a href="http://reviews.llvm.org/rL223543">r223543</a>.</p></li></ul>
- LLVM Weekly - #48, Dec 1st 2014https://blog.llvm.org/2014/12/llvm-weekly-48-dec-1st-2014.htmlMon, 01 Dec 2014 06:57:00 +0000https://blog.llvm.org/2014/12/llvm-weekly-48-dec-1st-2014.html<p>Welcome to the forty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/48">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>John Regehr has posted an <a href="http://blog.regehr.org/archives/1192">update on the Souper superoptimizer</a> which he and his collaborators have been working on. They have implemented a reducer for Souper optimizations that tries to reduce the optimization to something more minimal. There current results given ~4000 distinct optimisations of which ~1500 LLVM doesn't know how to do. Of course many of these may in fact be covered by a single rule or pass. One of the next steps for Souper is to extend Souper to support the synthesis of instruction sequences. See also the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79104">discussion on the llvm mailing list</a>.</p><p>The LLVM Blog features a summary of <a href="http://blog.llvm.org/2014/11/loop-vectorization-diagnostics-and.html">recent advances in loop vectorization for LLVM</a>. This includes diagnostics remarks to get feedback on why loops which aren't vectorized are skipped, the loop pragma directive in Clang, and performance warnings when the directive can't be followed.</p><p>The LLVM Haskell Compiler (LHC) has been <a href="http://lhc-compiler.blogspot.co.uk/2014/11/the-new-lhc.html">newly reborn</a> along with <a href="http://lhc-compiler.blogspot.co.uk/2014/11/very-minimal-hello-world.html">its blog</a>. The next steps in development are to provide better support for Haskell2010, give reusable libraries for name resolution and type checking, and to produce human-readable compiler output.</p><p>The next LLVM Social in Paris <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/5830">will take place on December 9th</a>.</p><p>Intel have published a blog post <a href="https://software.intel.com/en-us/blogs/2014/11/24/what-is-new-for-x86-in-upcoming-gcc-50">detailing new X86-specific optimisations in GCC 5.0</a>. You may also be interested in the <a href="https://news.ycombinator.com/item?id=8675274">discussion of this post on Hacker News</a>.</p><h3>On the mailing lists</h3><ul><li><p>Hal Finkel has posted an RFC suggesting the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79192">removal of the BBVectorize pass</a> on the basis that it hasn't progressed to production quality while the SLP vectorizer exists and has been enabled for some time and it has various bugs and code fixmes. If you feel differently, now is the time to speak up.</p></li><li><p>Yichao Yu is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79113">curious about the current state of MCJIT for ARM</a>. Several people responded to say they've been using it with few problems on ARM, though Renato Golin <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79147">would like to see a few more success stories</a> before marking it as 'supported' on the appropriate status page.</p></li><li><p>Tom Stellard is planning to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79059">start the 3.5.1 release cycle</a> shortly. Let him know if you'd like to help with testing.</p></li><li><p>When developing a non-upstreamed LLVM backend, <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79145">should you do it as a loadable module or just apply to a cloned LLVM repo</a>? Rafael Auler has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/79191">tried the approach of building his backend as a loadable module</a> and feels it would have been better to fork LLVM and rebase when necessary. This is the approach your esteemed editor has taken (though admittedly it's been far too long since he rebased...).</p></li></ul><h3>LLVM commits</h3><ul><li><p>Support for <code>-debug-ir</code> (emitting the LLVM IR in debug data) was removed. There's no real justification or explanation in the commit message, but it's likely it was unfinished/unused/non-functional. <a href="http://reviews.llvm.org/rL222945">r222945</a>.</p></li><li><p>InstCombine will now canonicalize toward the value type being stored rather than the pointer type. The rationale (explained in more detail in the commit message) is that memory does not have a type, but operations and the values they produce do. <a href="http://reviews.llvm.org/rL222748">r222748</a>.</p></li><li><p>The documentation for <code>!invariant.load</code> metadata has been clarified. <a href="http://reviews.llvm.org/rL222700">r222700</a>.</p></li><li><p>In tablegen, neverHasSideEffects=1 is now hasSideEffects=0. <a href="http://reviews.llvm.org/rL222801">r222801</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Four new ASTMatchers have been added: typedefDecl, isInMainFile, isInSystemFile, and isInFileMatchinName. <a href="http://reviews.llvm.org/rL222646">r222646</a>.</p></li><li><p>The documentation on MSVC compatibility has been updated to represent the current state of affairs. Clang has also gained support for rethrowing MS C++ exceptions. <a href="http://reviews.llvm.org/rL222731">r222731</a>, <a href="http://reviews.llvm.org/rL222733">r222733</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Initial tests have been added for lldb-mi (the LLDB machine interface). <a href="http://reviews.llvm.org/rL222750">r222750</a>.</p></li><li><p>libcxxabi can now be built and tested without threads using CMake. <a href="http://reviews.llvm.org/rL222702">r222702</a>.</p></li><li><p>The compact-unwind-dumper tool now has complete support for x86-64 and i386 binaries. <a href="http://reviews.llvm.org/rL222951">r222951</a>.</p></li></ul>
- Loop Vectorization: Diagnostics and Controlhttps://blog.llvm.org/2014/11/loop-vectorization-diagnostics-and.htmlMon, 24 Nov 2014 15:12:00 +0000https://blog.llvm.org/2014/11/loop-vectorization-diagnostics-and.html<span style="font-weight: normal;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><a href="http://llvm.org/docs/Vectorizers.html" style="letter-spacing: 0px; text-align: justify;"><span style="letter-spacing: 0px;">Loop vectorization</span></a><span style="letter-spacing: 0px; text-align: justify;"> was first introduced in LLVM 3.2 and turned on by default in LLVM 3.3. It has been discussed previously on this blog in </span><a href="http://blog.llvm.org/2012/12/new-loop-vectorizer.html" style="letter-spacing: 0px; text-align: justify;"><span style="letter-spacing: 0px;">2012</span></a><span style="letter-spacing: 0px; text-align: justify;"> and </span><a href="http://blog.llvm.org/2013/05/llvm-33-vectorization-improvements.html" style="letter-spacing: 0px; text-align: justify;"><span style="letter-spacing: 0px;">2013</span></a><span style="letter-spacing: 0px; text-align: justify;">, as well as at </span><a href="https://archive.fosdem.org/2014/schedule/event/llvmautovec/" style="letter-spacing: 0px; text-align: justify;"><span style="letter-spacing: 0px;">FOSDEM 2014</span></a><span style="letter-spacing: 0px; text-align: justify;">, and at </span><a href="http://llvm.org/devmtg/2013-11/#talk10" style="letter-spacing: 0px; text-align: justify;"><span style="letter-spacing: 0px;">Apple's WWDC 2013</span></a><span style="letter-spacing: 0px; text-align: justify;">. The LLVM loop vectorizer combines multiple iterations of a loop to improve performance. Modern processors can exploit the independence of the interleaved instructions using advanced hardware features, such as multiple execution units and out-of-order execution, to improve performance.</span></span></span><br /><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;">Unfortunately, when loop vectorization is not possible or profitable the loop is silently skipped. This is a problem for many applications that rely on the performance vectorization provides. Recent updates to LLVM provide command line arguments to help diagnose vectorization issues and new a pragma syntax for tuning loop vectorization, interleaving, and unrolling.</span></div><h2><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large; letter-spacing: 0px;"><b>New Feature: Diagnostics Remarks</b></span></h2><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0px; text-decoration: underline;"><a href="http://llvm.org/docs/Vectorizers.html#diagnostics">Diagnostic remarks</a></span><span style="letter-spacing: 0px;"> provide the user with an insight into the behavior of the behavior of LLVMâs optimization passes including unrolling, interleaving, and vectorization. They are enabled using the <a href="http://clang.llvm.org/docs/UsersManual.html#options-to-emit-optimization-reports"><span style="letter-spacing: 0px;">Rpass command line arguments</span></a>. Interleaving and vectorization diagnostic remarks are produced by specifying the âloop-vectorizeâ pass. For example, specifying â-Rpass=loop-vectorizeâ tells us the following loop was vectorized by 4 and interleaved by 2.</span><span style="letter-spacing: 0px;"><span style="letter-spacing: 0px;"></span></span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">void test1(int *List, int Length) {</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> int i = 0;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> while(i < Length) {</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> List[i] = i*2;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> i++;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> }</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">}</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">clang -O3 </span><span style="color: #ae1916; letter-spacing: 0.0px;">-Rpass=loop-vectorize </span><span style="letter-spacing: 0.0px;">-S test1.c -o /dev/null</span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">test1.c:4:5: </span><span style="color: #5330e1; letter-spacing: 0.0px;">remark: </span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #5330e1; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="letter-spacing: 0.0px;">vectorized loop (vectorization factor: 4, unrolling interleave factor: 2)</span></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> <span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="font-family: Courier New, Courier, monospace;">while(i < Length) {</span></div><div style="color: #34bd26;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;"> <span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="color: #01a900; letter-spacing: 0px;">^</span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0.0px;">Many loops cannot be vectorized including loops with complicated control flow, unvectorizable types, and unvectorizable calls. For example, to prove it is safe to vectorize the following loop we must prove that array âAâ is not an alias of array âBâ. However, the bounds of array âAâ cannot be identified.</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">void test2(int *A, int *B, int Length) {</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> for (int i = 0; i < Length; i++)</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> A[B[i]]++;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">}</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;">clang -O3 </span><span style="color: #ae1916; letter-spacing: 0px;">-Rpass-analysis=loop-vectorize </span><span style="letter-spacing: 0px;">-S test2.c -o /dev/null</span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">test2.c:3:5: </span><span style="color: #5330e1; letter-spacing: 0.0px;">remark:<br /></span></span></div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #5330e1; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="letter-spacing: 0.0px;">loop not vectorized: cannot identify array bounds</span></span><br /><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Courier New, Courier, monospace;">for (int i = 0; i < Length; i++)</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="color: #01a900; letter-spacing: 0.0px;">^</span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;">Control flow and other unvectorizable statements are reported by the '-Rpass-analysis' command line argument. For example, many uses of âbreakâ and âswitchâ are not vectorizable.</span><br /><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;"><br /></span></div><table align="center" style="border-collapse: collapse; width: 90%;"><thead><tr style="background-color: silver;"><th width="300px"><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace; font-size: small;">C/C++ Code</span></span></th><th><span style="font-family: Courier New, Courier, monospace;">-Rpass-analysis=loop-vectorize</span></th></tr></thead><tbody><tr style="background-color: #e8e8e8;"><td><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;">for (int i = 0; i < Length; i++) {</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> if (A[i] > 10.0)</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> break;</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> A[i] = 0;</span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></td><td><div style="text-align: justify;"><div style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;">control_flow.cpp:5:9: </span><span style="color: #5330e1; letter-spacing: 0px;">remark: </span><span style="letter-spacing: 0px;">loop not vectorized: loop control flow is not understood by vectorizer</span></span></div></div><div style="text-align: justify;"><div style="text-align: left;"><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> if (A[i] > 10.0)</span></span></div></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div style="text-align: justify;"><div style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;"> </span><span style="color: #578726; letter-spacing: 0px;">^</span></span></div></div></td></tr><tr style="background-color: #d7d7d7;"><td><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;">for (int i = 0; i < Length; i++) {</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> switch(A[i]) {</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> case 0: B[i] = 1; break;</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> case 1: B[i] = 2; break;</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> default: B[i] = 3;</span></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></td><td><div style="text-align: justify;"><div style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;">no_switch.cpp:4:5: </span><span style="color: #5330e1; letter-spacing: 0px;">remark: </span><span style="letter-spacing: 0px;">loop not vectorized: loop contains a switch statement</span></span></div></div><div style="text-align: justify;"><div style="text-align: left;"><span style="letter-spacing: 0px;"><span style="font-family: Courier New, Courier, monospace;"> switch(A[i]) {</span></span></div></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div style="text-align: justify;"><div style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;"> </span><span style="color: #578726; letter-spacing: 0px;">^</span></span></div></div></td></tr></tbody></table><br /><h2><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large; letter-spacing: 0px;"><b>New Feature: Loop Pragma Directive</b></span></h2><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0px;">Explicitly control over the behavior of vectorization, interleaving and unrolling is necessary to fine tune the performance. For example, when compiling for size (-Os) it's a good idea to vectorize the hot loops of the application to improve performance. Vectorization, interleaving, and unrolling can be explicitly specified using the </span><a href="http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations" style="letter-spacing: 0px;"><span style="letter-spacing: 0px;">#pragma clang loop</span></a><span style="letter-spacing: 0px;"> </span>directive<span style="letter-spacing: 0px;"> prior to any for, while, do-while, or c++11 range-based for loop. For example, the vectorization width and interleaving count is explicitly specified for the following loop using the loop pragma directive.</span><span style="letter-spacing: 0px;"><span style="letter-spacing: 0px;"></span></span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">void test3(float *Vx, float *Vy, float *Ux, float *Uy, float *P, int Length) {</span></div><div style="color: #ae1916;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">#pragma clang loop vectorize_width(4) interleave_count(4)</span></div><div style="color: #ae1916;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">#pragma clang loop unroll(disable)</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> for (int i = 0; i < Length; i++) {</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> float A = Vx[i] * Ux[i];</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> float B = A + Vy[i] * Uy[i];</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> P[i] = B;</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> }</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">}</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">clang -O3 </span><span style="color: #ae1916; letter-spacing: 0.0px;">-Rpass=loop-vectorize </span><span style="letter-spacing: 0.0px;">-S test3.c -o /dev/null</span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">test3.c:5:5: </span><span style="color: #5330e1; letter-spacing: 0.0px;">remark:</span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #5330e1; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="letter-spacing: 0.0px;">vectorized loop (vectorization factor: 4, unrolling interleave factor: 4)</span></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Courier New, Courier, monospace;">for (int i = 0; i < Length; i++) {</span></div><div style="color: #34bd26;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="color: #01a900; letter-spacing: 0px;">^</span></span></div><h3><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large; letter-spacing: 0px;"><b>Integer Constant Expressions</b></span></h3><div style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;">The options vectorize_width, interleave_count, and unroll_count take an integer constant expression. So it can be computed as in the example below.</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">template <int ArchWidth, int ExecutionUnits></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">void test4(float *Vx, float *Vy, float *Ux, float *Uy, float *P, int Length) {</span></div><div style="color: #ae1916;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">#pragma clang loop vectorize_width(ArchWidth)</span></div><div style="color: #ae1916;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">#pragma clang loop interleave_count(ExecutionUnits * 4)</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> for (int i = 0; i < Length; i++) {</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> float A = Vx[i] * Ux[i];</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> float B = A + Vy[i] * Uy[i];</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> P[i] = B;</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> }</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">}</span></div><div style="min-height: 13px;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">void compute_test4(float *Vx, float *Vy, float *Ux, float *Uy, float *P, int Length) {</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> const int arch_width = 4;</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> const int exec_units = 2;</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> test4<arch_width, exec_units>(Vx, Vy, Ux, Uy, P, Length);</span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">}</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">clang -O3 </span><span style="color: #ae1916; letter-spacing: 0.0px;">-Rpass=loop-vectorize </span><span style="letter-spacing: 0.0px;">-S test4.cpp -o /dev/null</span></span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">test4.cpp:6:5: </span><span style="color: #5330e1; letter-spacing: 0.0px;">remark:</span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #5330e1; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="letter-spacing: 0.0px;">vectorized loop (vectorization factor: 4, unrolling interleave factor: 8)</span></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="font-family: Courier New, Courier, monospace;">for (int i = 0; i < Length; i++) {</span></div><div style="color: #34bd26;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span><span style="color: #01a900; letter-spacing: 0px;">^</span></span></div><h3><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large; letter-spacing: 0.0px;"><b>Performance Warnings</b></span></h3><div style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;">Sometimes the loop transformation is not safe to perform. For example, vectorization fails due to the use of complex control flow. If vectorization is explicitly specified a warning message is produced to alert the programmer that the directive cannot be followed. For example, the following function which returns the last positive value in the loop, cannot be vectorized because the âlast_positive_valueâ variable is used outside the loop.</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">int test5(int *List, int Length) {</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> int last_positive_index = 0;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> #pragma clang loop vectorize(enable)</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> for (int i = 1; i < Length; i++) {</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> if (List[i] > 0) {</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> last_positive_index = i;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> continue;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> }</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> List[i] = 0;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> }</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> return last_positive_index;</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">}</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;">clang -O3 -g -S test5.c -o /dev/null</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="letter-spacing: 0.0px;">test5.c:5:9: </span><span style="color: #d53bd3; letter-spacing: 0.0px;">warning:</span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #d53bd3; letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="letter-spacing: 0.0px;">loop not vectorized: failed explicitly specified loop vectorization</span></span></div><div><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> </span><span style="font-family: Courier New, Courier, monospace;">for (int i = 1; i < Length; i++) {</span></div><div style="color: #34bd26;"><span style="font-family: Courier New, Courier, monospace; letter-spacing: 0.0px;"> ^</span></div><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="letter-spacing: 0.0px;"></span><br /></span></div><div style="text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;">The debug option â-gâ allows the source line to be provided with the warning.</span></div><h3><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large; letter-spacing: 0.0px;"><b>Conclusion</b></span></h3><div style="min-height: 13px; text-align: justify;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; letter-spacing: 0px;">Diagnostic remarks and the loop pragma directive are two new features that are useful for feedback-directed-performance tuning. Special thanks to all of the people who contributed to the development of these features. Future work includes adding diagnostic remarks to the SLP vectorizer and an additional option for the loop pragma directive to declare the memory operations as safe to vectorize. Additional ideas for improvements are welcome.</span></div>
- LLVM Weekly - #47, Nov 24th 2014https://blog.llvm.org/2014/11/llvm-weekly-47-nov-24th-2014.htmlMon, 24 Nov 2014 06:00:00 +0000https://blog.llvm.org/2014/11/llvm-weekly-47-nov-24th-2014.html<p>Welcome to the forty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/47">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Version 3.0 of the Capstone disassembly framework <a href="http://capstone-engine.org/Version-3.0.html">has been released</a>. Python bindings have been updated to support Python 3, and this release also adds support for Sparc, SystemZ and XCore. It also has performance improvements.</p><p>Herb Sutter has penned a <a href="https://isocpp.org/blog/2014/11/trip-report-fall">trip report</a> of the recent ISO C++ meeting.</p><p>Emscripten has <a href="https://groups.google.com/forum/#!topic/emscripten-discuss/y1_efkXYIQM">updated to use LLVM 3.4 from the PNaCl team</a>. There's more work to be done to rebase on top of 3.5.</p><p>Woboq has written a blog post <a href="http://woboq.com/blog/cpp14-in-qt.html">detailing C++14 features of interest to Qt programmers</a>, though I suspect the article has a wider potential audience than that. Recent Clang of course has <a href="http://clang.llvm.org/cxx_status.html#cxx14">good support</a> for the new C++14 features.</p><p>There is going to be an LLVM Devroom at FOSDEM 2015, and the <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/5757">submission deadline for presentations/talks/tutorials is on Dec 1st</a>.</p><p>Apple's LLVM Source Tools and Program Analysis teams are <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39769">looking for interns for Summer 2015</a>.</p><h3>On the mailing lists</h3><ul><li><p>If you're wondering how the process of adding OpenMP support to Clang is going, the <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39749">answer</a> is that it's still ongoing and there's hope it will be done by the 3.6 release, depending on the speed of code reviews.</p></li><li><p>Siva Chandra kicked off a discussion on the mailing list about <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/5765">how to better manage breakages caused by LLVM or Clang API changes</a>. Siva suggests LLDB should be developed against a known-good version of LLVM/Clang that gets periodically bumped. Vince Harron says that he is <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/5780">looking to add a continuous build on curated versions of Clang/LLVM</a> in addition to a continuous build on top of tree for everything. This should help improve the signal to noise ratio and make it easier for LLDB developers to tell when a breaking change is due to their addition or a change elsewhere. Reid Kleckner <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/5783">suggests lldb should be treated part of the same project as Clang/LLDB</a> and more pressure should be put on developers to fix breakages, presumably in the same way that API changes in LLVM almost always come with an associated patch to fix Clang.</p></li><li><p>Peter Collingbourne has proposed <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78981">adding the llgo frontend to the LLVM project</a>. Chris Lattner is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78982">in favour of this</a>, but would like to see the GPLv3+runtime exception dependencies rewritten before being checked in. Some people in the thread expressed concern that the existing base of LLVM/Clang reviewers know C++ and may not be able to review patches in Go, though it looks like a non-zero of existing LLVM reviewers are appropriately multilingual.</p></li><li><p>Brett Simmers is working on HHVM and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78971">is interested if there are ways to control where a BasicBlock ends up in memory</a>, with the motivation to make best of the instruction cache by keeping frequently executed pieces of code closer together. There's general agreement this would be a great feature to have, but it doesn't sound like this is easily supported in LLVM right now.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A small doc fix has the honour of being <a href="http://reviews.llvm.org/rL222222">commit 222222</a>.</p></li><li><p>A nice little optimisation has been committed which replaces a switch table with a mul and add if there is a linear mapping between index and output. <a href="http://reviews.llvm.org/rL222121">r222121</a>.</p></li><li><p>The SeparateConstOffsetFromGEP, EarlyCSE, and LICM passes have been enabled on AArch64. This has <a href="http://reviews.llvm.org/D5864">measurable gains for some SPEC benchmarks</a>. <a href="http://reviews.llvm.org/rL222331">r222331</a>.</p></li><li><p>The description of the noalias attribute has been clarified. <a href="http://reviews.llvm.org/rL222497">r222497</a>.</p></li><li><p>MDNode is being split into two classes, GenericMDNode and MDNodeFwdDecl. <a href="http://reviews.llvm.org/rL222205">r222205</a>.</p></li><li><p>The LLVM CMake-based build system learned to support <code>LLVM_USE_SANITIZER=Thread</code>. <a href="http://reviews.llvm.org/rL222258">r222258</a>.</p></li><li><p>The R600 backend gained the SIFoldOperands pass which attempts to fold source operands of mov and copy instructions into their uses. <a href="http://reviews.llvm.org/rL222581">r222581</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang now distinguishes between <code>-fpic</code> and <code>-fPIC</code>. <a href="http://reviews.llvm.org/rL222227">r222227</a>.</p></li><li><p>The <code>-Wuninitialized</code> warning will now trigger when accessing an uninitialized base class in a constructor. <a href="http://reviews.llvm.org/rL222503">r222503</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB can now perform basic debugging operations on Windows. <a href="http://reviews.llvm.org/rL222474">r222474</a>.</p></li><li><p>LLDB's line editing support was been completely rewritten. <a href="http://reviews.llvm.org/rL222163">r222163</a>.</p></li><li><p>MemorySanitizer gained support for MIPS64. <a href="http://reviews.llvm.org/rL222388">r222388</a>.</p></li><li><p>A sample tool was added to lldb to extract and dump unwind information from Darwin's compact unwind section. <a href="http://reviews.llvm.org/rL222127">r222127</a>.</p></li></ul>
- LLVM Weekly - #46, Nov 17th 2014https://blog.llvm.org/2014/11/llvm-weekly-46-nov-17th-2014.htmlTue, 18 Nov 2014 05:43:00 +0000https://blog.llvm.org/2014/11/llvm-weekly-46-nov-17th-2014.html<p>Welcome to the forty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/46">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Chrome on Linux <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39700">now uses Clang for production builds</a>. Clang has of course been used on OS X Chrome for quite some time. The switch saw reduction in binary size of ~8%, but this was vs GCC 4.6 rather than something more up-to-date.</p><p>The LLVM in HPC workshop at SC14 is taking place on Monday and the full agenda with abstracts <a href="http://llvm-hpc-workshop.github.io/">is available online</a></p><h3>On the mailing lists</h3><ul><li><p>Duncan P.N. Exon Smith has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78738">RFC on splitting out metadata from the Value hierarchy</a>. There seems to be general support for the idea. If you have concerns, now is the time to speak up.</p></li><li><p>Tom Stellard has posted a proposed <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78752">LLVM/Clang 3.5.1 release schedule</a>. RC1 is currently planned for November 26th.</p></li><li><p>Zachary Turner raised the issue <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/5710">referencing Apple rdar bugs in commit messages</a>. The concern is that sometimes the commit messages are hard to work out without the context of the bug, which many of us do not have access to.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Work on call lowering for MIPS FastISel has started. <a href="http://reviews.llvm.org/rL221948">r221948</a>.</p></li><li><p>Work has started on an assembler for the R600 backend. <a href="http://reviews.llvm.org/rL221994">r221994</a>.</p></li><li><p>A pass implementing forward control-flow integrity as been added. <a href="http://reviews.llvm.org/rL221708">r221708</a>.</p></li><li><p>A whole slew of patches that made MDNode a Value have been reverted due to a change in plan. The aim is now to separate metadata from the Value hierarchy. <a href="http://reviews.llvm.org/rL221711">r221711</a>.</p></li><li><p>There are two ways to inform the optimizer the result of a load is never null. Either with metadata or via assume. The latter is now canonicalized into the former. <a href="http://reviews.llvm.org/rL221737">r221737</a>.</p></li><li><p><code>vec_vsx_ld</code> and <code>vec_vsx_st</code> intrinsics have been added for PowerPC. <a href="http://reviews.llvm.org/rL221767">r221767</a>.</p></li><li><p>PowerPC gained support for small-model PIC. <a href="http://reviews.llvm.org/rL221791">r221791</a>.</p></li><li><p>The llvm.arm.space intrinsic was added to make it easier to write tests for ARM ConstantIslands. <a href="http://reviews.llvm.org/rL221903">r221903</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The constant trickle of OpenMP patches continues. Codegen for threadprivate variables has been added. <a href="http://reviews.llvm.org/rL221663">r221663</a>.</p></li><li><p>Support for <code>__has_cpp_attribute</code> is now present. <a href="http://reviews.llvm.org/rL221991">r221991</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Breakpoint stop/resume has been implemented on Windows for LLDB. <a href="http://reviews.llvm.org/rL221642">r221642</a>.</p></li><li><p>The <a href="http://libcxx.llvm.org/cxx1z_status.html">libcxx status page</a> has been updated with the current state of C++1z support. <a href="http://reviews.llvm.org/rL221601">r221601</a>).</p></li></ul>
- LLVM Weekly - #45, Nov 10th 2014https://blog.llvm.org/2014/11/llvm-weekly-45-nov-10th-2014.htmlMon, 10 Nov 2014 05:11:00 +0000https://blog.llvm.org/2014/11/llvm-weekly-45-nov-10th-2014.html<p>Welcome to the forty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/45">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Adrian Sampson has posted a <a href="http://homes.cs.washington.edu/~asampson/blog/quala-codegen.html">status update on his Quala project</a> to add custom type annotations to C and C++ in Clang/LLVM.</p><p>Bruce Mitchener has posted to the Dylan blog describing <a href="http://dylanfoundry.org/2014/11/05/integrating-with-llvm/">how Dylan integrates with LLVM</a>. Interestingly, Dylan doesn't link with the LLVM libraries and instead generates bitcode files directly.</p><p>The Numba project has released <a href="https://github.com/numba/llvmlite">llvmlite</a>, lightweight python bindings to LLVM for writing JIT compilers. This was developed based on experience using the old llvmpy bindings.</p><p>Obfuscator-LLVM <a href="https://twitter.com/ollvm/status/529687887529656321">has been updated to work with LLVM 3.5</a>.</p><h3>On the mailing lists</h3><ul><li><p>Arnaud A. de Grandmaison kicked off a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78544">the semantics of lifetime.start and lifetime.end intrinsics</a>. Right now, if lifetime intrinsics are enabled for smaller objects a self-hosted build is broken. The question is whether this is due to a misunderstanding of the lifetime spec or just a hidden bug. Reid Kleckner <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78568">suggests different intrinsics for the simple case of stack allocated data</a>. He also clarifies what he means by <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78619">stack colouring</a>. This is followed by some in-depth back-and-forth discussion on the validity of transformations involving lifetime.start/lifetime.end and whether new intrinsics are required.</p></li><li><p>James Molloy has been experimenting with the scheduling model on the Cortex-A57 and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78492">found some oddities</a>. I noted the MicroOpBufferSize is currently set to 128, and reducing it right down to 2 seems to have no effect. Andrew Trick responded with some suggetions on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78603">implementing a custom scheduling strategy</a>.</p></li><li><p>Volodymyr Kuznetsov and his collaborators are <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78512">asking for feedback on their patchset to implement their recently published work on control flow hijacking protection</a>. The OSDI paper is <a href="http://dslab.epfl.ch/pubs/cpi.pdf">available here</a>. The current patchset covers the stack protection aspect of the paper, providing stronger protection than stack cookies at a lower overhead.</p></li><li><p>Frédéric Riss is interested in <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78706">reimplementing Darwin's dsymutil as an lld helper</a>. dsymutil is a standalone DWARF linker which is used to load merge and optimize dwarf debug info and write it out to a .dSYM file.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The PBQP register allocator has had its spill costs and coalescing benefits tweaked. This apparently results in a few percent improvement on benchmarks such as EEMBC and SPEC. <a href="http://reviews.llvm.org/rL221292">r221292</a>, <a href="http://reviews.llvm.org/rL221293">r221293</a>.</p></li><li><p>The new SymbolRewriter pass is an IR to IR transformation allowing adjustment of symbols during compilation. It is intended to be used for symbol interpositioning in sanitizers and performance analysis tools. <a href="http://reviews.llvm.org/rL221548">r221548</a>.</p></li><li><p>Hexagon gained a basic ELF object emitter. <a href="http://reviews.llvm.org/rL221465">r221465</a>.</p></li><li><p>llvm-vtabledump gained support for the Itanium ABI. <a href="http://reviews.llvm.org/rL221133">r221133</a>.</p></li><li><p>LLVM's CMake build system gained the <code>LLVM_BUILD_STATIC</code> option. <a href="http://reviews.llvm.org/rL221345">r221345</a>.</p></li><li><p>The usage of Inputs/ for extra test files has been documented. <a href="http://reviews.llvm.org/rL221406">r221406</a>.</p></li><li><p>The MIPS backend has reached a milestone in support for the N32/N64 ABI. This commit fixes all known bugs for this ABI and the first 10000 tests generated by ABITest.py pass. <a href="http://reviews.llvm.org/rL221534">r221534</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>clang-format gained various improvements for formatting Java code. <a href="http://reviews.llvm.org/rL221104">r221104</a>, <a href="http://reviews.llvm.org/rL221109">r221109</a>, and others.</p></li><li><p>Support was added for C++1z nested namespace definitions, u8 character literals, and attributes on namespaces or enumerators. <a href="http://reviews.llvm.org/rL221574">r221574</a>, <a href="http://reviews.llvm.org/rL221576">r221576</a>, <a href="http://reviews.llvm.org/rL221580">r221580</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLD learned how to parse most linker scripts. Before getting too excited, do note this is parsing only, semantic actions will come in the future. <a href="http://reviews.llvm.org/rL221126">r221126</a>.</p></li><li><p>The common Sanitizer code gained a generic stack frame renderer. This allows the user to control the format of stack frame output. <a href="http://reviews.llvm.org/rL221409">r221409</a>, <a href="http://reviews.llvm.org/rL221469">r221469</a>.</p></li><li><p>The basic framework for live debugging on Windows was added to LLDB. It will detect changes such as DLL loads and unloads etc, but these need to be propagated through LLDB properly. <a href="http://reviews.llvm.org/rL221207">r221207</a>.</p></li><li><p>lldb-gdbserver now supports the Android target. <a href="http://reviews.llvm.org/rL221570">r221570</a>.</p></li></ul>
- LLVM Weekly - #44, Nov 3rd 2014https://blog.llvm.org/2014/11/llvm-weekly-44-nov-3rd-2014.htmlMon, 03 Nov 2014 03:29:00 +0000https://blog.llvm.org/2014/11/llvm-weekly-44-nov-3rd-2014.html<p>Welcome to the forty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/44">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The <a href="http://llvm.org/devmtg/2014-10/">2014 LLVM Dev meeting</a> was held last week. I couldn't make it, but it seems like there was a great selection of talks. Sadly the keynote about Swift's high-level IR <a href="http://lists.cs.uiuc.edu/pipermail/llvm-devmeeting/2014-October/000176.html">was cancelled</a>. No word yet on when we can expect slides and videos online. However, slides by Philip Reames and Sanjoy Das from their talk on on implementing fully relocating garbage collection in LLVM <a href="http://www.playingwithpointers.com/llvm-dev-2014-slides.pdf">are online</a>.</p><p><a href="http://whitequark.org/">Peter Zotov</a> has been doing lots of work on the LLVM OCaml bindings recently, and is looking for additional help. Recently, he's closed almost all open bugs for the bindings, migrated them to ocamlfind, fixed <code>Lllvm_executionengine</code>, and ensured pretty much the whole LLM-C API is exposed. Tasks on the todo list include writing tests in OUnit2 format, migrating the Kaleidoscope tutorial off camlp4, and splitting up and adding OCaml bindings to <a href="http://reviews.llvm.org/D2176">this patch</a>. More ambitiously, it would be interesting to writing LLVM passes in OCaml and to represent LLVM IR as pure AST. If any of this interests you, do get in touch with Peter. He's able to review any patches, but could do with help on working through this list of new features.</p><p>The LLVM Bay Area monthly social is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39524">going to be held on 6th November</a>.</p><h3>On the mailing lists</h3><ul><li><p>Reid Kleckner has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78419">proposed dropping support for running LLVM on Windows XP</a>. This would allow the use of system APIs only available in Vista and above. Thus far all responses have been positive, with one even suggesting raising the minimum to Windows 7.</p></li><li><p>Tom Stellard suggests <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78453">deprecating the autoconf build system</a>. Right now there is both an autotools based system and a CMake system, though CMake seems most used by developers for LLVM at least. Bob Wilson <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78459">points out</a> that the effort required to keep the existing makefiles working is much less than what might be needed to update the CMake build to support all uses cases. Though other replies make it seems that the CMake build supports pretty much all configurations people use now. If there are people who actually enjoy fiddling with build systems (far-fetched, I know), it seems like a little effort could go a long way and allow the makefile system to be jettisoned.</p></li><li><p>Betul Buyukkurt has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78415">RFC on indirect call target profiling</a>. The goal is to use the collected data for optimisation. Kostya Serebryany <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39563">described how it can be used to provide feedback to fuzzers</a> and detailed properties that would be useful for this usecase.</p></li><li><p>Chris Matthews <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78319">announces</a> that a new Jenkins-based OSX build cluster is up and running. This includes multiple build profiles and an O3 LTO performance tracker. The Jenkins config should be committed to zorg soon.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Support for writing sampling profiles has been committed. In the future, support to read (and maybe write) profiles in GCC's gcov format will be added, and llvm-profdata will get support to manipulate sampling profiles. <a href="http://reviews.llvm.org/rL220915">r220915</a>.</p></li><li><p>A comment has been added to X86AsmInstrumentation to describe how asm instrumentation works. <a href="http://reviews.llvm.org/rL220670">r220670</a>.</p></li><li><p>The Microsoft vectorcall calling convention has been implemented for x86 and x86-64. <a href="http://reviews.llvm.org/rL220745">r220745</a>.</p></li><li><p>The C (and OCaml) APIs gained functions to query and modify branches, and to obtain the values for floating point constants. There have been a whole bunch of additional commits related to the OCaml bindings, too many to pick out anything representative. <a href="http://reviews.llvm.org/rL220814">r220814</a>, <a href="http://reviews.llvm.org/rL220815">r220815</a>, <a href="http://reviews.llvm.org/rL220817">r220817</a>, <a href="http://reviews.llvm.org/rL220818">r220818</a>.</p></li><li><p>The loop and SLP (superword level parallelism) vectorizers are now enabled in the Gold plugin. <a href="http://reviews.llvm.org/rL220886">r220886</a>, <a href="http://reviews.llvm.org/rL220887">r220887</a>.</p></li></ul><h3>Clang commits</h3><ul><li>A refactoring of libTooling to reduce required dependencies means that clang-format's binary is now roughly half the size. <a href="http://reviews.llvm.org/rL220867">r220867</a>.</li></ul><h3>Other project commits</h3><ul><li><p>lldb has started to adopt the StringPrinter API. <a href="http://reviews.llvm.org/rL220894">r220894</a>.</p></li><li><p>Initial support for PowerPC/PowerPC64 on FreeBSD has been added to LLDB. <a href="http://reviews.llvm.org/rL220944">r220944</a>.</p></li></ul>
- LLVM Weekly - #43, Oct 27th 2014https://blog.llvm.org/2014/10/llvm-weekly-43-oct-27th-2014.htmlMon, 27 Oct 2014 04:02:00 +0000https://blog.llvm.org/2014/10/llvm-weekly-43-oct-27th-2014.html<p>Welcome to the forty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This week it's the LLVM Developers' Meeting in San Jose. Check out the <a href="http://llvm.org/devmtg/2014-10/">schedule</a>. Unfortunately I won't be there, so I'm looking forward to the slides and videos going online.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/43">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>Philip Reames has written up a detailed <a href="http://www.philipreames.com/Blog/2014/10/21/statepoints-vs-gcroot-for-representing-call-safepoints/">discussion of statepoints vs gcroot</a> for representing call safepoints. The aim is to clearly explain how the safepoint functionality provided by the <a href="http://reviews.llvm.org/D5683">patches currently up for review</a> differ to the current gc.root support.</p><p>The Haskell community have put together a <a href="https://ghc.haskell.org/trac/ghc/wiki/ImprovedLLVMBackend">proposal for an improved LLVM backend to GHC</a>. They intend to ship GHC with its own local LLVM build.</p><p>CoderGears have published a blog post about <a href="http://www.codergears.com/Blog/?p=246">using Clang to get better warnings in Visual C++ projects</a>.</p><p>There is going to be a dedicated LLVM devroom at FOSDEM 2015. Here is the <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39450">call for speakers and participation</a>.</p><h3>On the mailing lists</h3><ul><li><p>Elena Demikhovsky has asked for comments on a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78160">proposal to add masked vector load and store intrinsics</a>. Essentially all feedback so far is positive on the idea.</p></li><li><p>Renato Golin <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78099">proposes moving libunwind into compiler-rt</a>. One of the subtleties is hat libunwind isn't fully compatible with GCC's unwind implementation (due to different data structure layouts), which means they can't be mixed.</p></li><li><p>Kristof Beyls has posted some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/78068">notes in preparation for the benchmarking infrastructure BoF at the LLVM dev meeting</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The <code>nonnull</code> metadata has been introduced for Load instructions. <a href="http://reviews.llvm.org/rL220240">r220240</a>.</p></li><li><p>minnum and maxnum intrinsics have been added. <a href="http://reviews.llvm.org/rL220341">r220341</a>, <a href="http://reviews.llvm.org/rL220342">r220342</a>.</p></li><li><p>The Hexagon backend gained a basic disassembler. <a href="http://reviews.llvm.org/rL220393">r220393</a>.</p></li><li><p>PassConfig gained usingDefaultRegAlloc to tell if the default register allocator is being used. <a href="http://reviews.llvm.org/rL220321">r220321</a>.</p></li><li><p>An llvm-go tool has been added. It is intended to be used to build components such as the Go frontend in-tree. <a href="http://reviews.llvm.org/rL220462">r220462</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>C compilation defaults to C11 by default, matching the behaviour of GCC 5.0. <a href="http://reviews.llvm.org/rL220244">r220244</a>.</p></li><li><p>Clang should now be better at finding Visual Studio in non-standard setups. <a href="http://reviews.llvm.org/rL220226">r220226</a>.</p></li><li><p>The Windows toolchain is now known as MSVCToolChain, to allow the addition a CrossWindowsToolChain which will use clang/libc++/lld. <a href="http://reviews.llvm.org/rL220362">r220362</a>, <a href="http://reviews.llvm.org/rL220546">r220546</a>.</p></li></ul><h3>Other project commits</h3><ul><li>The libcxxabi gained support for running libc++abi tests with sanitizers. <a href="http://reviews.llvm.org/rL220464">r220464</a>.</li></ul>
- LLVM Weekly - #42, Oct 20th 2014https://blog.llvm.org/2014-10-20-llvm-weekly-42-oct-20th-2014.htmlMon, 20 Oct 2014 04:31:00 +0000https://blog.llvm.org/2014-10-20-llvm-weekly-42-oct-20th-2014.html<p>Welcome to the forty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>If you're local to London, you may be interested to know that I'll be talking about <a href="http://www.lowrisc.org">lowRISC</a> at the <a href="http://oshug.org/event/36">Open Source Hardware User Group on Thursday</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/42">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>ELLCC, the LLVM-based cross-compilation toolchain <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39439">now has pre-built binaries for all LLVM tools</a>.</p><p>Eli Bendersky's repository of examples for using LLVM and Clang as libraries and for building new passes aren't new, but they are incredibly useful for newcomers to LLVM/Clang and I haven't featured them before. If you want to build something using LLVM or Clang, the <a href="https://github.com/eliben/llvm-clang-samples">llvm-clang-samples repos</a> is one of the best places to start.</p><h3>On the mailing lists</h3><ul><li><p>If you enjoy bikeshedding, I have the perfect thread for you. <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77786">Should LLVM change its naming convention for variables</a>? There actually seems to be a lot of consensus that the current approach of using capitalized variable names is weird.</p></li><li><p>Richard Smith has proposed <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39379">switching the default C language mode from gnu99 to gnu11</a>. GNU trunk has just switched from gnu89 by default to gnu11. There seems to be almost universal support for gnu11 by default.</p></li><li><p>Junio Cezar writes to the mailing list <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77757">to share his experiments on time taken in various LLVM passes</a>. His webpage has <a href="http://homepages.dcc.ufmg.br/~juniocezar/llvm/">plots of time taken in each stage for csmith-generated programs</a>. Hal Finkel had some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77758">suggestions on improving the analysis</a>.</p></li><li><p>Bill Wendling is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39357">stepping down as LLVM release manager</a>. He nominated Tom Stellard and Hans Wennborg as his replacements, who have been accepted by unanimous agreement.</p></li><li><p>Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77997">suggests making DataLayout non-optional</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Go LLVM bindings have been committed. <a href="http://reviews.llvm.org/rL219976">r219976</a>.</p></li><li><p>Invoking patchpoint intrinsics is now supported. <a href="http://reviews.llvm.org/rL220055">r220055</a>.</p></li><li><p>LLVM gained a workaround for a Cortex-A53 erratum. <a href="http://reviews.llvm.org/rL219603">r219603</a>.</p></li><li><p>Basic support for ARM Cortex-A17 was added. <a href="http://reviews.llvm.org/rL219606">r219606</a>.</p></li><li><p>The C API has been extended with the LLVMWriteBitcodeToMemoryBuffer function. <a href="http://reviews.llvm.org/rL219643">r219643</a>.</p></li><li><p>NumOperands has been moved from User to Value. On 64-bit host architectures this reduces <code>sizeof(User)</code> and subclasses by 8. <a href="http://reviews.llvm.org/rL219845">r219845</a>.</p></li><li><p>The LLVMParseCommandLineOptions was added to the C API. <a href="http://reviews.llvm.org/rL219975">r219975</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Constant expressions can now be used in pragma loop hints. <a href="http://reviews.llvm.org/rL219589">r219589</a>.</p></li><li><p>The libclang API gained a function to retrieve the storage class of a declaration. <a href="http://reviews.llvm.org/rL219809">r219809</a>.</p></li><li><p>With the <code>-fsanitize-address-field-padding</code> flag, Clang can insert poisoned paddings between fields in C++ classes to allow AddressSanitizer to find intra-object overflow bugs. <a href="http://reviews.llvm.org/rL219961">r219961</a>.</p></li></ul><h3>Other project commits</h3><ul><li>lldb now supports a gdb-style batch mode. <a href="http://reviews.llvm.org/rL219654">r219654</a>.</li></ul>
- LLVM Weekly - #41, Oct 13th 2014https://blog.llvm.org/2014/10/llvm-weekly-41-oct-13th-2014.htmlTue, 14 Oct 2014 03:59:00 +0000https://blog.llvm.org/2014/10/llvm-weekly-41-oct-13th-2014.html<p>Welcome to the forty-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I've been in Munich for ORCONF this weekend. Slides from my talk about <a href="http://www.lowrisc.org">lowRISC</a> are available <a href="https://speakerdeck.com/asb/lowrisc-a-first-look">here</a>.</p><p>The canonical home for this issue <a href="http://llvmweekly.org/issue/41">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>ELLCC, the LLVM/Clang-based cross development toolkit <a href="http://ellcc.org/blog/?p=18096">now has Windows binaries available</a>.</p><p>IBM have <a href="https://www.bountysource.com/issues/5136793-addresssanitizer-tests-fail-for-powerpc64">posted a bounty</a> on fixing the AddressSanitizer tests that fail on PowerPC.</p><p>GCC needs you! A large number of <a href="https://gcc.gnu.org/ml/gcc/2014-10/msg00040.html">potential starting points for new contributors</a> has been posted to the GCC mailing list.</p><h3>On the mailing lists</h3><ul><li><p>Hayden Livingston is curious about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77745">examples of LLVM usage for whole program optimisations</a>, mentioning LLVM JIT functionality and GC as areas of interest. Philip Reames <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77750">responded</a> with a good description of the current state and also noted his patchset for <a href="http://reviews.llvm.org/D5683">GC statepoint intrinsics</a> is up for review and should hopefully be merged in the coming weeks. Filip Pizlo who worked on Apple's FTL JS JIT <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77753">responded to advocate use of a Bartlett-style mostly-copying collector</a>.</p></li><li><p>Peter Collingbourne has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77678">proposed official Go bindings be added to the LLVM project</a>. Thus far all replies seem positive.</p></li><li><p>Saleem Abdulrasool points out that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77537">lld doesn't conform to the LLVM/Clang coding style</a>. As you can imagine, few topics attract more feedback from developers than whitespace and variable naming conventions so the thread is rather long. There's general agreement that it would be better if lld used the LLVM style, though unease about moving over in a single large patch on the basis that this would dirty commit history and make git/svn blame less useful. A patch was submitted to git some years ago to <a href="http://git.661346.n2.nabble.com/PATCH-blame-can-specify-shas-of-commits-to-ignore-on-command-line-td5001395.html">implement the ability to ignore certain shas in git blame</a> but it seems the feature was never added.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Switches with only two cases and a default are now optimised to a couple of selects. <a href="http://reviews.llvm.org/rL219223">r219223</a>.</p></li><li><p>llvm-symbolizer will now be used to symbolize LLVM/Clang crash dumps. <a href="http://reviews.llvm.org/rL219534">r219534</a>.</p></li><li><p>The calculation of loop trip counts for loops with multiple exits has been de-pessimized. <a href="http://reviews.llvm.org/rL219517">r219517</a>.</p></li><li><p>MIPS fast-isel learnt integer and floating point compare and conditional branches. <a href="http://reviews.llvm.org/rL219518">r219518</a>, <a href="http://reviews.llvm.org/rL219530">r219530</a>, <a href="http://reviews.llvm.org/rL219556">r219556</a>.</p></li><li><p>R600 gained a load/store machine optimizer pass. <a href="http://reviews.llvm.org/rL219533">r219533</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The integrated assembler has been turned on by default for ppc64 and ppc64le. <a href="http://reviews.llvm.org/rL219129">r219129</a>.</p></li><li><p>clang-format's interpretation of special comments to disable formatting within a delimited range has been documented. <a href="http://reviews.llvm.org/rL219204">r219204</a>.</p></li><li><p>The integrated assembler has been turned on by default for SystemZ. <a href="http://reviews.llvm.org/rL219426">r219426</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lld gained support for 'fat' mach-o archives. <a href="http://reviews.llvm.org/rL219268">r219268</a>.</p></li><li><p>The lldbtk example has seen some further development. <a href="http://reviews.llvm.org/rL219219">r219219</a>.</p></li><li><p>lldb-gdbserver can now be used for local-process Linux debugging. <a href="http://reviews.llvm.org/rL219457">r219457</a>.</p></li><li><p>The disassembly format for lldb can now be customized. <a href="http://reviews.llvm.org/rL219544">r219544</a>.</p></li></ul>
- LLVM Weekly - #40, Oct 6th 2014https://blog.llvm.org/2014/10/llvm-weekly-40-oct-6th-2014.htmlMon, 06 Oct 2014 05:49:00 +0000https://blog.llvm.org/2014/10/llvm-weekly-40-oct-6th-2014.html<p>Welcome to the fortieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'll be in Munich next weekend for the <a href="http://tum-lis.github.io/orconf2014/">OpenRISC conference</a> where I'll be presenting on the <a href="http://lowrisc.org/">lowRISC</a> project to produce an open-source SoC. I'll be giving a similar talk in London at the Open Source Hardware User Group <a href="http://oshug.org/event/36">on 23rd October</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/40">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Capstone 3.0 RC1 <a href="http://capstone-engine.org/Version-3.0-RC1.html">has been released</a> Capstone is an open source disassembly engine, based initially on code from LLVM. This release features support for Sparc, SystemZ and XCore as well as the previously supported architectures. Among other changes, the Python bindings are now compatible with Python 3.</p><p>An interesting paper from last year came up on the mailing list. From EPFL, it proposes <a href="http://dslab.epfl.ch/pubs/overify.pdf">adding -OVERIFY to optimise programs for fast verification</a>. The performance of symbolic execution tools is improved by reducing the number of paths to explore and the complexity of branch conditions. They managed a maximum 95x reduction in total compilation and analysis time.</p><p>The next Cambridge (UK) social <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77453">will take place on Wed 8th Oct at 7.30 pm</a>.</p><h3>On the mailing lists</h3><ul><li><p>Reid Kleckner has posted an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39152">approaches to representing structured exception handling (SEH) in LLVM IR</a>. This is the exception handling model used on Windows.</p></li><li><p>Chandler Carruth has written to the list to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77439">announce his new x86 vector shuffle lowering path is now enabled by default</a>. This code path has seen extensive fuzz testing. The performance improvement is largest on AMD chips with older SSE versions. If anyone is able to find a performance regression, you are encouraged to report it.</p></li><li><p>Richard Pennington who maintains the Clang/LLVM ELLCC cross-development toolchain is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77431">considering dropping support for Microblaze</a>. The Microblaze backend was dropped from LLVM last year, but Richard has been maintaining it out of tree. However there seems to be very little actual interest. If somebody wants to pick it up, now is the time to jump in.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The expansion of atomic loads/stores for PowerPC has been improved. <a href="http://reviews.llvm.org/rL218922">r218922</a>. The documentation on atomics has also been updated. <a href="http://reviews.llvm.org/rL218937">r218937</a>.</p></li><li><p>For the past few weeks, Chandler Carruth has been working on a new vector shuffle lowering implementation. There have been too many commits to summarise, but the time has come and the new codepath is now enabled by default. It claims 5-40% improvements in the right conditions (when the loop vectorizer fires in the hot path for SSE2/SSE3). <a href="http://reviews.llvm.org/rL219046">r219046</a>.</p></li><li><p>The Cortex-A57 scheduling model has been refined. <a href="http://reviews.llvm.org/rL218627">r218627</a>.</p></li><li><p>SimplifyCFG now has a configurable threshold for folding branches with common destination. Changing this threshold can be worthwhile for GPU programs where branches are expensive. <a href="http://reviews.llvm.org/rL218711">r218711</a>.</p></li><li><p>Basic support for the newly-announced Cortex-M7 has been added. <a href="http://reviews.llvm.org/rL218747">r218747</a>.</p></li><li><p>As discussed on the mailing list last week, the sqrt intrinsic will now return undef when given a negative input. <a href="http://reviews.llvm.org/rL218803">r218803</a>.</p></li><li><p>llvm-readobj learnt <code>-coff-imports</code> which will print out the COFF import table. <a href="http://reviews.llvm.org/rL218891">r218891</a>, <a href="http://reviews.llvm.org/rL218915">r218915</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Support for the <code>align_value</code> attribute has been added, matching the behaviour of the attribute in the Intel compiler. The commit message explains why this attribute is useful in addition to <code>aligned</code>. <a href="http://reviews.llvm.org/rL218910">r218910</a>.</p></li><li><p>A rather useful diagnostic has been added. <code>-Winconsistent-missing-override</code> will warn if override is missing on an overridden method if that class has at least one override specified on its methods. <a href="http://reviews.llvm.org/rL218925">r218925</a>.</p></li><li><p>Support for MS ABI continues. <code>thread_local</code> is now supported for global variables. <a href="http://reviews.llvm.org/rL219074">r219074</a>.</p></li><li><p>Matcher and DynTypedMatcher saw some nice performance tweaking, resulting in a 14% improvement on a clang-tidy benchmark and compilation of Dynamic/Registry.cpp sped up by 17%. <a href="http://reviews.llvm.org/rL218679">r218616</a>.</p></li><li><p>lifetime.start and lifetime.end markers are now emitted for unnamed temporary objects. <a href="http://reviews.llvm.org/rL218865">r218865</a>.</p></li><li><p>The <code>__sync_fetch_and_nand</code> intrinsic was re-added. See the commit message for a history of its removal. <a href="http://reviews.llvm.org/rL218905">r218905</a>.</p></li><li><p>Clang gained its own implementation of C11 <code>stdatomic.h</code>. The system header will be used in preference if present. <a href="http://reviews.llvm.org/rL218957">r218957</a>.</p></li><li><p>Clang now understands <code>-mthread-model</code> to specify the thread model to use, e.g. posix, single (for bare-metal and single-threaded targets). <a href="http://reviews.llvm.org/rL219027">r219027</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxxabi should now work with the ARM Cortex-M0. <a href="http://reviews.llvm.org/rL218869">r218869</a>.</p></li><li><p>lldb gained initial support for scripting stepping. This is the ability to add new stepping modes implemented by python classes. The example in the follow-on commit has a large comment at the head of the file to explain its operation. <a href="http://reviews.llvm.org/rL218642">r218642</a>, <a href="http://reviews.llvm.org/rL218650">r218650</a>.</p></li></ul>
- LLVM Weekly - #39, Sep 29th 2014https://blog.llvm.org/2014/09/llvm-weekly-39-sep-29th-2014.htmlMon, 29 Sep 2014 05:23:00 +0000https://blog.llvm.org/2014/09/llvm-weekly-39-sep-29th-2014.html<p>Welcome to the thirty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/39">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>An implementation of Common Lisp with an LLVM backend, Clasp, <a href="http://drmeister.wordpress.com/2014/09/18/announcing-clasp/">has been announced</a>. There's a lot of work to be done on performance, but development is <a href="https://github.com/drmeister/clasp">very active on Github</a>.</p><p>A backend for the educational 'y86' instruction set architecture has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77236">been started</a>. The source is <a href="https://github.com/ltcmelo/llvm">on Github</a>.</p><p>A new binary snopshot of the ELLCC cross compilation toolchain is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39063">now available</a>. Pre-compiled binaries are available for ARM, MIPS, PPC, and x86. All tarballs contain header files and runtime libraries for all targets to allow you to build for any supported target.</p><h3>On the mailing lists</h3><ul><li><p>Bill Schmidt started off an interesting discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77238">whether sqrt of a negative number should be optimised to 0 or NaN</a>. The xalanc benchmark in SPEC CPU2006 relies on it returning a NaN apparently.</p></li><li><p>Chandler Carruth has posted an RFC proposing that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77148">LLVM should require a working C++11 thread, mutex, and atomic</a> with the intention being that support for MinGW and win32threads is dropped. Switching to MinGW-win64 seems like a feasible path forwards.</p></li><li><p>Wondering how to use noalias and alias.scope metadata notations? Hal Finkel <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77174">has the answer</a> for you.</p></li><li><p>Should the LLVM project standardise on a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39017">commit message policy</a>? Renato Golin suggests trying to keep the first line short followed by some number of 80 character paragraphs. It seems there's massive agreement on this sort of guidance.</p></li><li><p>Richard Pennington has posted a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/39084">size comparison of bzip2 compiled for different architectures</a>. All executables are statically linked with musl and compiler-rt.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Segmented stacks support for the x32 ABI has been fixed. <a href="http://reviews.llvm.org/rL218247">r218247</a>.</p></li><li><p>Robin Morisset's work on optimisation of atomics continues. AtomicExpandPass now inserts fences itself rather than SelectionDAGBuilder. <a href="http://reviews.llvm.org/rL218329">r218329</a>.</p></li><li><p>LLVM's libSupport gained a type-safe alternative to <code>llvm::format()</code>. <a href="http://reviews.llvm.org/rL218463">r218463</a>.</p></li><li><p>llvm-vtabledump learned how to dump RTTI structures for the MS ABI. <a href="http://reviews.llvm.org/rL218498">r218498</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The <code>assume_aligned</code> function attribute is now supported. <a href="http://reviews.llvm.org/rL218500">r218500</a>.</p></li><li><p>The thread safety analysis documentation has seen a hefty update. <a href="http://reviews.llvm.org/rL218420">r218420</a>.</p></li><li><p>MS compatibility is further improved with support for the <code>__super</code> scope specifier. <a href="http://reviews.llvm.org/rL218484">r218484</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>ASan in compiler-rt gained the start of a debugging API. <a href="http://reviews.llvm.org/rL218538">r218538</a>.</p></li><li><p>LLDB gained the beginnings of an example Tk UI. <a href="http://reviews.llvm.org/rL218279">r218279</a>.</p></li></ul>
- LLVM Weekly - #38, Sep 22nd 2014https://blog.llvm.org/2014/09/llvm-weekly-38-sep-22nd-2014.htmlMon, 22 Sep 2014 08:57:00 +0000https://blog.llvm.org/2014/09/llvm-weekly-38-sep-22nd-2014.html<p>Welcome to the thirty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I've been at PyConUK this past weekend so I'm afraid it's another slightly shorter than normal issue. I've been talking about <a href="http://www.pyland.org">Pyland</a>, a programming game that aims to teach children programming in Python (and of course, runs on Raspberry Pi).</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/38">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>A paper has recently been published about <a href="http://arcade.cs.columbia.edu/harmony">Harmony</a>. In the words of the authors "Harmony is an open source tool (built as an LLVM pass) that creates a new kind of application profile called Parallel Block Vectors, or PBVs. PBVs track dynamic program parallelism at basic block granularity to expose opportunities for improving hardware design and software performance." Their most recent <a href="http://arcade.cs.columbia.edu/parashares-europar14.pdf">paper on ParaShares</a> describes how they find the most 'important' basic blocks in multithreaded programs.</p><p>Richard Pennington has written up <a href="http://ellcc.org/blog/?p=13246">some more thoughts on cross compilation configuration for Clang</a>.</p><p><a href="https://github.com/combinatorylogic/clike">Clike</a> is a low-level programming language with an extensible syntax based on C. It of course targets LLVM.</p><p>If you want your Emacs editor to automatically disassemble LLVM bitcode inside Emacs buffers, then <a href="https://github.com/gbalats/autodisass-llvm-bitcode">autodisass-llvm-bitcode</a> is for you.</p><h3>On the mailing lists</h3><ul><li><p>Stephen Wu has published an RFC regarding <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77010">exhaustive bitcode compatibility tests for IR features</a>. The proposal involves testing every existing IR feature so that backward compatibility can be tested and it will become obvious when it is broken inadvertently.</p></li><li><p>If you're wondering about the current status of compiling glibc with Clang/LLVM, Kostya Serebryany <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/77025">has the answer</a>. There are about ten instances of nested functions and four of VLAIS, with some patches waiting to be reviewed by upstream.</p></li><li><p>Daniel Stewart has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76915">suggested postponing various passes to the linking stage when using LTO</a>. There's agreement on this, suggesting that vectorisation and inlining should be delayed.</p></li><li><p>Christophe Duvernois <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76887">asks whether LLVM link against miniz rather than zlib</a>. If you're interested in a long discussion about the disadvantages of checking in dependencies locally to a codebase, this is the thread for you.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The LLVM MC layer can now write BigObj-style COFF object files. <a href="http://reviews.llvm.org/rL217812">r217812</a>.</p></li><li><p>X86AtomicExpandPass has been removed in favour of using the generic AtomicExpandHooks (which now has the necessary hooks). <a href="http://reviews.llvm.org/rL217928">r217928</a>.</p></li><li><p>llvm-cov's internal API has been reworked. <a href="http://reviews.llvm.org/rL217975">r217975</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang can now use 'response files' when calling other tools when the length of the command line exceeds system limits. <a href="http://reviews.llvm.org/rL217792">r217792</a>.</p></li><li><p>The <code>-Wbind-to-temporary-copy</code> warning is no longer on by default. <a href="http://reviews.llvm.org/rL218008">r218008</a>.</p></li><li><p>Clang's thread safety analysis gained <code>-Wthread-safety-reference</code> which warns when a guarded variable is passed by reference as a function argument. <a href="http://reviews.llvm.org/rL218087">r218087</a>.</p></li></ul><h3>Other project commits</h3><ul><li>libcxx gained some support for using newlib as its C library. <a href="http://reviews.llvm.org/rL218144">r218144</a>.</li></ul>
- LLVM Weekly - #37, Sep 15th 2014https://blog.llvm.org/2014/09/llvm-weekly-37-sep-15th-2014.htmlMon, 15 Sep 2014 07:01:00 +0000https://blog.llvm.org/2014/09/llvm-weekly-37-sep-15th-2014.html<p>Welcome to the thirty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This week's issue comes to you from sunny Tenerife. Yes, my dedication to weekly LLVM updates is so great that I'm writing it on holiday. Enjoy! I'll also note that I'm at PyCon UK next week where I'll be <a href="http://pyconuk.net/Schedule">presenting</a> on the results of a project we had some interns working on over the summer creating a programming game for the Raspberry Pi.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/37">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Not only does Pyston have a shiny new blog, they've also <a href="http://blog.pyston.org/2014/09/11/9/">released version 0.2</a>. Pyston is an implementation of Python using LLVM, led by Dropbox. This release supports a range of language features that weren't supported in 0.1, including support for the native C API. The plan is to focus on performance during the development cycle for 0.3.</p><p>Sylvestre Ledru has posted a <a href="http://sylvestre.ledru.info/blog/2014/09/11/rebuild-of-debian-using-clang-3-5">report of progress in building Debian with Clang</a> following the completion of this year's Google Summer of Code projects. Now with Clang 3.5.0 1261 packages fail to build with Clang. Sylvestre describes how they're attacking the problem from both sides, by submitting patches to upstream projects as well as to Clang where appropriate (e.g. to ignore some unsupported optimisation flags rather than erroring out).</p><h3>On the mailing lists</h3><ul><li><p>Philip Reames has started a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76702">adding optimisation hints for 'constant' loads</a>. A common case is where a field is initialised exactly once and then is never modified. If this invariant could be expressed, it could improve alias analysis as the AA pass would never consider that field to MayAlias with something else (Philip reports that the obvious approach of using type-based alias analysis isn't quite enough).</p></li><li><p>Hal Finkel has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76647">RFC on attaching attributes to values</a>. Currently, attributes such as noalias and nonnull can be attached to function parameters, but in cases such as C++11 lambdas these can be packed up into a structure and the attributes are lost. Some followup discussion focused on whether these could be represented as metadata. The problem there of course is that metadata is intended to be droppable (i.e. is semantically unimportant). I very much like the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76700">suggestion</a> from Philip Reames that the test suite should run with a pass that forcibly drops metadata to verify it truly is safe to drop.</p></li><li><p>Robin Morisset has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76800">proposal on implementing a fence elimination algorithm</a>. The proposed algorithm is based on partial redundancy elimination. He's looking for feedback on the suggested implementation approach.</p></li><li><p>There's been a little bit of discussion on the topic of <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76679">rekindling work on VMKit</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The start of the llvm.assume infrastructure has been committed, as well as an AlignmentFromAssumptions pass. See <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74941">the original RFC</a> for a refresher on the llvm.assume intrinsic. <a href="http://reviews.llvm.org/rL217342">r217342</a>, <a href="http://reviews.llvm.org/rL217344">r217344</a>.</p></li><li><p>LLVM's sample profile reader has been refactored into lib/ProfileData. <a href="http://reviews.llvm.org/rL217437">r217437</a>.</p></li><li><p>The AMD 16H Jaguar microarchitecture now has a scheduling model. <a href="http://reviews.llvm.org/rL217457">r217457</a>.</p></li><li><p>The 'bigobj' COFF variant can now be read. <a href="http://reviews.llvm.org/rL217496">r217496</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The <code>__builtin_assume</code> and <code>__builtin_assume_aligned</code> intrinsics have been added. <a href="http://reviews.llvm.org/rL217349">r217349</a>.</p></li><li><p>The thread safety TIL (Typed Intermediate Language) has seen a major update. <a href="http://reviews.llvm.org/rL217556">r217556</a>.</p></li></ul><h3>Other project commits</h3><ul><li>LLD gained support for AArch64 Mach-O. <a href="http://reviews.llvm.org/rL217469">r217469</a>.</li></ul>
- LLVM Weekly - #36, Sep 8th 2014https://blog.llvm.org/2014/09/llvm-weekly-36-sep-8th-2014.htmlMon, 08 Sep 2014 07:51:00 +0000https://blog.llvm.org/2014/09/llvm-weekly-36-sep-8th-2014.html<p>Welcome to the thirty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/36">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The biggest news this week is of course undoubtedly the long-awaited <a href="http://lists.cs.uiuc.edu/pipermail/llvm-announce/2014-September/000055.html">release of LLVM/Clang 3.5</a>. See the <a href="http://llvm.org/releases/3.5.0/docs/ReleaseNotes.html">release notes</a> for a full breakdown of what's changed.</p><p><a href="https://github.com/artagnon/rhine">Rhine</a>, a Clojure-inspired Lisp with an LLVM JIT backend has been released (or at least, I wasn't aware of it before). There's plenty of discussion about it <a href="https://news.ycombinator.com/item?id=8277410">over at HN</a>.</p><p>Intel have <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76551">released a new version</a> of their <a href="http://cilkplus.github.io/">CilkPlus LLVM-basd compiler</a>. This releases implements support for version 1.2 of Intel's Cilk Plus Language Extension Specification.</p><h3>On the mailing lists</h3><ul><li><p>Hal Finkel is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76487">calling for testers</a> of the new contrext-free language pointer aliasing analysis algorithm. As well as some speedup, there are some benchmark slowdowns which sound worth of further investigation.</p></li><li><p>Richard Pennington is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38774">seeking feedback</a> on his proposal for a cross compiler config file format for Clang. The initial prototype spec is <a href="http://ellcc.org/blog/?p=11877">described over at his blog</a>.</p></li><li><p>Balaram Makam triggered an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76467">interesting discussion on whether a particular case of loop-invariant code motion can be considered safe</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM gained a new alias analysis implementation, the CFL (Context-free language) alias analysis algorithm. When bootstrapping LLVM, this pass gives 7-8% NoAlias responses to queries that TBAA and BasicAA couldn't answer. <a href="http://reviews.llvm.org/rL216970">r216970</a>.</p></li><li><p>The old JIT has finally been removed. <a href="http://reviews.llvm.org/rL216982">r216982</a>.</p></li><li><p>FastISel gained the option to skip target-independent instruction selection. This is now used by AARch64, which uses target-dependent instruction selection only. <a href="http://reviews.llvm.org/rL216947">r216947</a>, <a href="http://reviews.llvm.org/rL216955">r216955</a>.</p></li><li><p>MCAnalysis has been removed. The code was judged to be buggy and poorly tested. <a href="http://reviews.llvm.org/rL216983">r216983</a>.</p></li><li><p>AArch64 gained a pass to try to remove redundant comparison operations. <a href="http://reviews.llvm.org/rL217220">r217220</a>.</p></li><li><p>FastISel has seen some spring cleaning. <a href="http://reviews.llvm.org/rL217060">r217060</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p><code>VariantMatcher::MatcherOps</code> was modified to reduce the amount of generated code. This reduces object size and compilation time. <a href="http://reviews.llvm.org/rL217152">r217152</a>.</p></li><li><p>Support for the 'w' and 'h' length modifiers in MS format strings was added. <a href="http://reviews.llvm.org/rL217195">r217195</a>, <a href="http://reviews.llvm.org/rL217196">r217196</a>.</p></li><li><p>A new warning is born. <code>-Wunused-local-typedef</code> will warn about unused local typedefs. <a href="http://reviews.llvm.org/rL217298">r217298</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB has gained initial support for 'type validators'. To quote the commit message, "Type Validators have the purpose of looking at a ValueObject, and making sure that there is nothing semantically wrong about the object's contents For instance, if you have a class that represents a speed, the validator might trigger if the speed value is greater than the speed of light". <a href="http://reviews.llvm.org/rL217277">r217277</a>.</p></li><li><p>It is now possible to build libc++ on systems without POSIX threads. <a href="http://reviews.llvm.org/rL217271">r217271</a>.</p></li><li><p>A <code>target.process.memory-cache-line-size</code> option has been added to LLDB which changes the size of lldb's internal memory cache chunks read from the remote system. <a href="http://reviews.llvm.org/rL217083">r217083</a>.</p></li></ul>
- LLVM Weekly - #35, Sep 1st 2014https://blog.llvm.org/2014/09/llvm-weekly-35-sep-1st-2014.htmlMon, 01 Sep 2014 10:48:00 +0000https://blog.llvm.org/2014/09/llvm-weekly-35-sep-1st-2014.html<p>Welcome to the thirty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects.LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>As I mentioned in a previous issue, I am involved in the <a href="http://lowrisc.org">lowRISC</a> projects to produce a fully open-source SoC. Just a quick reminder that <a href="http://www.jobs.cam.ac.uk/job/4665/">we are hiring</a>, and you have just over a week to get your application in.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/35">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM/Clang 3.5 is inching ever closer to release. The fourth and hopefully final release candidate is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76370">available for testing</a>.</p><p>Quarks Lab have published a <a href="http://blog.quarkslab.com/scaf-source-code-analysis-framework-based-on-clang-pre-alpha-preview.html">preview of SCAF</a>, a Source Code Analysis Framework built on Clang. It promises a release soon.</p><p>The <a href="http://vmkit.llvm.org/">VMKit project website</a> has this week been <a href="http://reviews.llvm.org/rL216831">updated</a> to mark the project as retired. VMKit was a project to implement virtual machines such as a JVM on top of LLVM. People interested in restarting the project are encouraged to get in touch with Gaël Thomas.</p><p>AMD and Microsoft have <a href="http://sdtimes.com/amd-announces-heterogeneous-c-amp-language-developers/">released a C++ AMP compiler targeting version 1.2 of the specification</a>. The C++ AMP (Accelerated Massive Parallelism) compiler is of course based on LLVM and Clang, and can be <a href="https://bitbucket.org/multicoreware/cppamp-driver-ng/wiki/Home">found here</a>.</p><h3>On the mailing lists</h3><ul><li><p>Manuel Klimek has provided a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38657">quick run-down of the state of his work on Clang C++ refactoring tools</a>. He reports there are a number of standalone, single-use refacotring tools but more work needs to be done on generalising and integrating them. The plan is to push more of these tools to tools-extra (where clang-rename lives), make them integratable as a library, integrate them into libclang and then integrate them into projects like <a href="https://github.com/Valloric/ycmd">ycmd</a>.</p></li><li><p>Robin Morisset has been working on optimisations for lowering of atomics and has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76400">asked for input on a fence elimination algorithm</a> he's been thinking about. He has outlined two possible implementation routes he would like feedback on.</p></li><li><p>A discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76278">improving llvm-objdump</a>, kicked offed by Steve King, makes an interesting read. I'm looking forward to a future with a more featureful llvm-objdump that prints symbols of branch targets by default.</p></li><li><p>David Blaikie has started a discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76341">supporting -gmlt in LLVM/Clang</a>. Vital to having any chance of understanding this thread is to know that gmlt refers to debug info containing 'minimal line tables', a feature that <a href="https://gcc.gnu.org/ml/gcc-patches/2011-04/msg02075.html">was added to GCC a while back</a>.</p></li><li><p>I linked last week to the mailing list thread on removing static initializers for command line options and regrettably was unable to summarise the extensive discussion. The bad news is discussion has continued at a rapid pace, but thankfully Chandler Carruth has rather helpfully <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76279">sumarised the main outcomes of the discussion</a>. It's also worth reading <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76382">this thread</a> for an idea of what the new infrastructure might look like.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The AArch64 backend learned about v4f16 and v8f16 operations, <a href="http://reviews.llvm.org/rL216555">r216555</a>.</p></li><li><p>The LLVM CMake build system now includes support for building with UndefinedBehaviourSanitizer. <a href="http://reviews.llvm.org/rL216701">r216701</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The <code>-fdevirtualize</code> and <code>-fdevirtualize-speculatively</code> flags are now recognised (and ignored) for compatibility with GCC. <a href="http://reviews.llvm.org/rL216477">r216477</a>.</p></li><li><p>Some Google Summer of Code work has started to land. In particular, the Clang static analyzer gained initial infrastructure to support for synthesizing function implementations from external model files. See the commit message for full details on the intent of this feature. <a href="http://reviews.llvm.org/rL216550">r216550</a>.</p></li><li><p>Support was added for capturing variable length arrays in C++11 lambda expressions. <a href="http://reviews.llvm.org/rL216649">r216649</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB gained documentation on its internal register numbering scheme. <a href="http://reviews.llvm.org/rL216372">r216372</a>.</p></li><li><p>LLDB is making progress towards AArch64 support. <a href="http://reviews.llvm.org/rL216737">r216736</a>.</p></li></ul>
- LLVM Weekly - #34, Aug 25th 2014https://blog.llvm.org/2014/08/llvm-weekly-34-aug-25th-2014.htmlMon, 25 Aug 2014 12:28:00 +0000https://blog.llvm.org/2014/08/llvm-weekly-34-aug-25th-2014.html<p>Welcome to the thirty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects.LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>.Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/34">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The third release candidate for LLVM/Clang 3.5 is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38553">now available</a>. As ever, test it on your codebases and report any regressions.</p><p>Adrian Sampson has written a <a href="https://homes.cs.washington.edu/~asampson/blog/quala.html">blog post about Quala</a>, a tool for implementing pluggable type systems for C/C++ using Clang. The example type systems are a system allowing nullable and non-nullable pointers as well as an information flow tracking system. In the future, Adrian wants to connect type annotations to LLVM IR.</p><p>C++14 is <a href="http://isocpp.org/blog/2014/08/we-have-cpp14">now done</a>. A quick look at the <a href="http://clang.llvm.org/cxx_status.html#cxx14">Clang C++14 implementation status</a>confirms that Clang support is in pretty good shape.</p><p>Santiago Fernandez has been an intern on the .NET team at Microsoft this summer. In this MSDN Channel9 posting, Beth Massi <a href="http://channel9.msdn.com/Blogs/funkyonex/Fun-with-the-Interns-Santiago-Fernandez-on-LLVM-Based-Optimizer-for-MSIL">interviews him about his work on using LLVM in the .NET native code generator</a>.</p><p>The next Cambridge (UK) LLVM social <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75952">will be held on Weds 27th August, 7.30pm</a>.</p><h3>On the mailing lists</h3><ul><li><p>There is a <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/4887">proposal</a> to move the minimum supported Visual Studio version for compiling LLVM/Clang up to 2013 from 2012. LLVM/Clang 3.6 would be the first stable release with this requirement assuming there are no objections. With the introduction of C++11 features into the LLVM/Clang codebases, MSVC2012 support is troublesome due to a number of unsupported constructs. If this change would effect you negatively, now is the time to pipe up.</p></li><li><p>Richard Carback <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75943">reports</a> that two of his interns at Draper Laboratories have been working on resurrecting the LLVM C Backend, with <a href="https://github.com/draperlaboratory/llvm-cbe">source on Github</a>. If this is to make it back into the mainstream repository, somebody will have to volunteer to maintain it which <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75974">Richard has kindly done</a>.</p></li><li><p>Diego Novillo has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/76135">update on his plans for supporting profile data from Perf in LLVM</a>. He is now planning on keeping conversion to Perf's format out-of-tree. The current LLVM representation can be used as an exchange format, but Diego will be submitting a more compact representation for internal use.</p></li><li><p>Chris Bieneman has posted an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75954">removing static initializers for command line options</a>. This would make it easier for LLVM clients like WebKit and Mesa. There is a lot of discussion about this proposal that I'm afraid I don't have time to summarise.</p></li></ul><h3>LLVM commits</h3><ul><li><p>X86 Haswell gained a detailed scheduling model. <a href="http://reviews.llvm.org/rL215094">r215094</a>, <a href="http://reviews.llvm.org/rL215095">r215905</a>, and more.</p></li><li><p>LLVM's code coverage mapping format gained extensive documentation. <a href="http://reviews.llvm.org/rL215990">r215990</a>.</p></li><li><p>FastISel for AArch64 saw yet more changes, this time optimisations for ADDS/SUBS emission and support for variable shifts. <a href="http://reviews.llvm.org/rL216033">r216033</a>, <a href="http://reviews.llvm.org/rL216242">r216242</a>.</p></li><li><p>The MIPS assembler gained support for <code>.set arch=x</code>. <a href="http://reviews.llvm.org/rL215978">r215978</a>.</p></li><li><p>The PeepholeOptimizer has been improved to take advantage of the recently added isRegSequence, isExtractSubreg, and isInsertSubreg properties. <a href="http://reviews.llvm.org/rL216088">r216088</a>, <a href="http://reviews.llvm.org/rL216136">r216136</a>, <a href="http://reviews.llvm.org/rL216144">r216144</a>.</p></li><li><p>A thread-model option has been added along with the 'single' option for lowering atomics on baremetal and single-threaded systems. <a href="http://reviews.llvm.org/rL216182">r216182</a>.</p></li><li><p>The gold plugin has been rewritten in order to fix <a href="http://llvm.org/bugs/show_bug.cgi?id=19901">bug 19901</a>. <a href="http://reviews.llvm.org/rL216215">r216215</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>C++1y is now called C++14. <a href="http://reviews.llvm.org/rL215982">r215982</a>.</p></li><li><p>CGcall (code generation for function call) has been refactored. <a href="http://reviews.llvm.org/rL216251">r216251</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The libcxx build and test system gained support for <code>LLCM_USE_SANITIZER</code>. <a href="http://reviews.llvm.org/rL215872">r215872</a>.</p></li><li><p>libcxxabi/libunwind now supports baremetal ARM. <a href="http://reviews.llvm.org/rL216202">r216202</a>.</p></li></ul>
- LLVM Weekly - #33, Aug 18th 2014https://blog.llvm.org/2014/08/llvm-weekly-33-aug-18th-2014.htmlMon, 18 Aug 2014 05:07:00 +0000https://blog.llvm.org/2014/08/llvm-weekly-33-aug-18th-2014.html<p>Welcome to the thirty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects.LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>.Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>The canonical home for this issue <a href="http://llvmweekly.org/issue/33">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Binaries for LLVM/Clang 3.5RC2 are now <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75752">available for testing</a>. Try it on your codebases, and be sure to report any regressions.</p><p>LDC 0.14.0 <a href="https://github.com/ldc-developers/ldc/releases/tag/v0.14.0">has been released</a>. LDC is an LLVM-based compiler for the D programming language. There's a mixture of new features and bug fixes, see the release notes for full details of what's changed.</p><p>Viva64, who sell the PVS-Studio static analyzer has written up their experiences of <a href="http://www.viva64.com/en/b/0270/">using the Clang static analyzer on the PVS-Studio codebase</a>. It managed to find 12 issues which the blog author considers genuine bugs.</p><h3>On the mailing lists</h3><ul><li><p>Matt Arsenault has written on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/201804">RFC on adding fmin/fmax intrinsics</a>. Both the R600 and AArch64 platforms support fmin/fmax instructions with semantics that match the libm functions.</p></li><li><p>Chris Matthews writes that Apple are <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75776">working on bringing up a new Darwin build cluster and switching from Buildbot to Jenkins</a>. There was an amount of followup discussion on Buildbot vs Jenkins, and David Chisnall has <a href="http://reviews.llvm.org/D4901">shared a patch</a> that makes lit produce JUnit XML output that Jenkins can consume.</p></li><li><p>Arch Robinson has written a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75769">proposal for llvm.mem.vectorize.safelen metadata</a>. This allows the user to bless a loop as having no memory dependences that prevent vectorization.</p></li><li><p>Daniel Berlin has written a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75731">very brief summary of LLVM's TypeBasedAliasAnalysis</a> in response to a question, that others may find enlightening.</p></li><li><p>Hans Wennborg <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75707">shares his results from profiling the run-time sizes of SmallVector and similar classes</a>. The intention is to see if there are cases where they are misused (i.e. a heap allocation always results so there is no benefit from being initially allocated on the stack).</p></li><li><p>There has been some <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38411">discussion about an extended Clang API</a>. The initial discussion frames this as an 'ABI support library'. An extended Clang API could be used for automatically generating bindings to C or even C++ code (which right now Julia is using private interfaces to do).</p></li><li><p>Renato Golin has started a discussion about <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38465">a target specific parsing API</a>. The <a href="http://llvm.org/bugs/show_bug.cgi?id=20683">bug report</a> describes the problem more fully, which is duplication of code which performs the same parsing task (e.g. <code>-mfpu</code> on command line and the <code>.fpu</code> assembly directive).</p></li></ul><h3>LLVM commits</h3><ul><li><p>FastISel for AArch64 will now make use of the zero register when possible and supports more addressing modes. <a href="http://reviews.llvm.org/rL215591">r215591</a>, <a href="http://reviews.llvm.org/rL215597">r215597</a>.</p></li><li><p>MIPS gained support for the .end, .end, .frame, .mask, and .fmask assembler directives. <a href="http://reviews.llvm.org/rL215359">r215359</a>.</p></li><li><p>ARM gained the MRS/MSR system instructions. <a href="http://reviews.llvm.org/rL215700">r215700</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Documentation has been added describing how the Language options in .clang-format files works. <a href="http://reviews.llvm.org/rL215443">r215443</a>.</p></li><li><p>Prefetch intrinsics were added for ARM and AArch64. <a href="http://reviews.llvm.org/rL215568">r215568</a>, <a href="http://reviews.llvm.org/rL215569">r215569</a>.</p></li><li><p>The logic for the <code>-include</code> command line parameter is now properly implemented. <a href="http://reviews.llvm.org/rL215433">r215433</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLD now has initial support for ELF/AArch64. <a href="http://reviews.llvm.org/rL215544">r215544</a>.</p></li><li><p>UndefinedBehaviourSanitizer gained a returns-nonnull sanitizer. This verifies that functions annotated with <code>returns_nonnull</code> do return nonnull pointers. <a href="http://reviews.llvm.org/rL215485">r215485</a>.</p></li><li><p>A number of lldb tests now compile on Windows. <a href="http://reviews.llvm.org/rL215562">r215562</a>.</p></li></ul>
- LLVM Weekly - #32, Aug 11th 2014https://blog.llvm.org/2014/08/llvm-weekly-32-aug-11th-2014.htmlMon, 11 Aug 2014 04:15:00 +0000https://blog.llvm.org/2014/08/llvm-weekly-32-aug-11th-2014.html<p>Welcome to the thirty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>.Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Some readers may be interested to know that <a href="http://lowrisc.org/">lowRISC</a>, a project to produce a fully open-source SoC started by a number of us at the University of Cambridge Computer Lab has been announced. <a href="http://www.jobs.cam.ac.uk/job/4665/">We are hiring</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/32">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Codeplay contributed the LLDB MI (Machine Interface) frontend a while ago, and have now committed some additional features. To coincide with that, they've published a <a href="http://lists.cs.uiuc.edu/pipermail/lldb-dev/2014-August/004768.html">series of blog posts</a> covering the MI driver's implementation, how to set it up from within Eclipse, and how to add support for new MI commands.</p><p>McSema, a framework for transforming x86 programs to LLVM bitcode has <a href="http://blog.trailofbits.com/2014/08/07/mcsema-is-officially-open-source/">now been open-sourced</a>. The talk about McSema from the ReCON conference is also now online.</p><p>Registration for the LLVM Developer's Meeting 2014 is <a href="http://llvm.org/devmtg/2014-10/#registration">now open</a>. The event will take place in San Jose on October 28th-29th. You have until September 1st to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75567">submit your talk/BoF/poster/tutorial proposal</a>.</p><h3>On the mailing lists</h3><ul><li><p>Robin Morisset, currently an intern at Google has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75534">written about his plan to optimize C11/C++11 atomics in LLVM</a>. This resulted in a discussion on <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-August/075573.html">whether some of these transformation should be done at the IR level</a>.</p></li><li><p>Dan Liew has written a long post about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75575">re-organising and improving zorg</a> (LLVM's testing and buildbot infrastructure).</p></li><li><p>Eric Christopher has written to the mailing list to warn us of <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75475">incoming API changes</a>. These changes include modifying getSubtarget/getSubtargetImpl to take a Function/MachineFunction, so sub-targets could be used based on attributes on the function.</p></li><li><p>Sergey Ostanevich from Intel has <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-August/075606.html">shared</a> a <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/attachments/20140809/cd6c7f7a/attachment-0001.pdf">proposal for the implementation of OpenMP offloading in LLVM</a>. This proposal was created by contributors from IBM, Intel, ANL, TI, and AMD. The example given would allow code to be offloaded to e.g. a Xeon Phi co-processor if present, or a GPU.</p></li><li><p>Delesley Hutchins has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38248">shared an update on his work on thread safety analysis</a>. This details the recently added negative capabilities patch. He is looking for feedback on how to limit the propagation of negative capabilities.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Initial work on the MachineCombiner pass landed. This estimates critical path length of the original instruction sequence vs a transformed (combined) instruction sequence and chooses the faster code. An example given in the commit message is choosing between add+mul vs madd on AArch64, and a followup commit implements MachineCombiner for this target. <a href="http://reviews.llvm.org/rL214666">r214666</a>, <a href="http://reviews.llvm.org/rL214669">r214669</a>.</p></li><li><p>A few useful helper functions were added to the LLVM C API: <code>LLVM{IsConstantString, GetAsString, GetElementAsConstant}</code>. <a href="http://reviews.llvm.org/rL214676">r214976</a>.</p></li><li><p>A whole load of AVX512 instructions were added. <a href="http://reviews.llvm.org/rL214719">r214719</a>.</p></li><li><p>FastISel for AArch64 now support basic argument lowering. <a href="http://reviews.llvm.org/rL214846">r214846</a>.</p></li><li><p>A flag has been added to experiment with running the loop vectorizer before the SLP vectorizer. According to the commit message, eventually this should be the default. <a href="http://reviews.llvm.org/rL214963">r214963</a>.</p></li><li><p>The old JIT is almost dead, it has been removed (for those not paying close attention, 3.5 has already been branched so still contains the old JIT). However, the patch was then reverted, so it's in zombie status. <a href="http://reviews.llvm.org/rL215111">r215111</a>.</p></li><li><p>AArch64 gained a load balancing pass for the Cortex-A57, which tries to make maximum use of available resources by balancing use of even and odd FP registers. <a href="http://reviews.llvm.org/rL215199">r215199</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Thread safety analysis gained support for negative requirements to be specified. <a href="http://reviews.llvm.org/rL214725">r214725</a>.</p></li><li><p>Coverage mapping generation has been committed. The <code>-fcoverage-mapping</code> command line option can be used to generate coverage mapping information, which can then be combined with execution counts from instrumentation-based profiling to perform code coverage analysis. <a href="http://reviews.llvm.org/rL214752">r214752</a>.</p></li><li><p>A command line option to limit the alignment that the compiler can assume for an arbitrary pointer. <a href="http://reviews.llvm.org/rL214911">r214911</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB's FileSpec class learned to understand Windows paths. <a href="http://reviews.llvm.org/rL215123">r215123</a>.</p></li><li><p>LLDB learned a whole bunch of new commands and features for its Machine Interface. <a href="http://reviews.llvm.org/rL215223">r215223</a>.</p></li><li><p>OpenMP gained PowerPC64 support. <a href="http://reviews.llvm.org/rL215093">r215093</a>.</p></li></ul>
- LLVM Weekly - #31, Aug 4th 2014https://blog.llvm.org/2014/08/llvm-weekly-31-aug-4th-2014.htmlMon, 04 Aug 2014 09:20:00 +0000https://blog.llvm.org/2014/08/llvm-weekly-31-aug-4th-2014.html<p>Welcome to the thirty-first issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/31">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Renato Golin has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75207">summary of feedback from his talk on LLVM and GCC collaboration at the GNU Tools Cauldron</a>. This both summarises the main areas he's looking for collaboration, and the feedback that people gave at the event or afterwards.</p><p>This blog post describes <a href="http://fuzion24.github.io/android/obfuscation/ndk/llvm/o-llvm/2014/07/27/android-obfuscation-o-llvm-ndk/">how to use Obfuscator-LLVM to to obfuscate Android NDK binaries</a>.</p><h3>On the mailing lists</h3><ul><li><p>Johannes Kapfhammer, a Google Summer of Code student has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38105">posted an RFC on adding a fuzzy parser for highlighting C++</a>. The Clang parser can't be used for this as it may be highlighting incomplete snippets where not all types or functions are included. It was pointed out in responses that this is similar to clang-format's parser, but apparently this parser is not easily reusable and very tied to the clang-format implementation.</p></li><li><p>In response to a query about whether there is interest in a performance tracking BOF at the LLVM Dev meeting, Renato Golin has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75410">summary of related issues discussed at the last meeting and progress made on them</a>.</p></li><li><p>John KÃ¥re Alsaker posted a question about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75230">adding a stack probe function attribute</a>. This would be used for languages like Rust that attempt to detect stack overflow with the use of a guard page. Philip Reames responded with <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75399">a number of thoughts on this feature</a>.</p></li><li><p>Daniel Stewart has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75350">implemented ELF/AArch64 support for lld</a> and is looking for how to upstream it. People are happy for a single patch to be posted for review.</p></li><li><p>In response to a question about documentation for adding builders to the LLVM buildbot service, Dan Liew has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75355">summary of how he has done it</a>. He's looking for feedback on whether this is the best way to do things.</p></li><li><p>John KÃ¥re Alsaker has asked for feedback on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75231">enhancing BasicAliasAnalysis for Rust</a>. Rust's restrictions on aliasing are not currenly fully taken advantage of. Both <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75260">Hal Finkel</a> and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75286">Cameron Zwarich</a> respond with thoughts on how to proceed.</p></li><li><p>Tom Stellard <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75214">proposes renaming the R600 target to AMDGPU</a>. The motivation is that the backend has the name since the R600 was the first AMD GPU targeted, but it has added support for all AMD GPUs since then. There seems to be agreement this would be a sensible renaming.</p></li></ul><h3>LLVM commits</h3><ul><li><p>FastISel for AArch64 saw a number of improvements, including support for shift-immediate, arithmetic with overflow intrinsics. <a href="http://reviews.llvm.org/rL214345">r214345</a>, <a href="http://reviews.llvm.org/rL214348">r214348</a>, and more.</p></li><li><p>The SLPVectorizer has seen a largeish commit that implements an "improved scheduling algorithm". Sadly the commit message offers no further details. <a href="http://reviews.llvm.org/rL214494">r214494</a>.</p></li><li><p>TargetInstrInfo gained <code>isAsCheapAsMove</code> which takes a MachineInstruction and returns true if that instruction is as cheap as a move instruction. <a href="http://reviews.llvm.org/rL214158">r214158</a>.</p></li><li><p>LLVM libraries can now be exported as importable CMake targets, making it easier for those building LLVM-based projects. This is now documented. <a href="http://reviews.llvm.org/rL214077">r214077</a>.</p></li><li><p>Release notes for PowerPC changes during 3.5 development have been committed. <a href="http://reviews.llvm.org/rL214403">r214403</a>.</p></li><li><p>Initial work towards supporting debug locations for fragmented variables (e.g. by-value struct arguments passed in registers) has been committed. <a href="http://reviews.llvm.org/rL214576">r214576</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Work on support for the MSVC ABI continues. Clang will now consider required alignment constraints on fields. <a href="http://reviews.llvm.org/rL214274">r214274</a>.</p></li><li><p>AddressSanitizer now passes source-level information from Clang to ASan using metadata rather than by creating global variables. <a href="http://reviews.llvm.org/rL214604">r214604</a>.</p></li><li><p>The PowerPC backend now support selection of the ELFv1/ELFv2 ABI via the <code>-mabi=</code> option. <a href="http://reviews.llvm.org/rL214074">r214074</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lld gained support for interworking between thumb and ARM code with Mach-O binaries. <a href="http://reviews.llvm.org/rL214140">r214140</a>.</p></li><li><p>A massive ABI testsuite (contributed by Sony) has been committed to the test-suite repo. <a href="http://reviews.llvm.org/rL214126">r214126</a>.</p></li></ul>
- LLVM Weekly - #30, Jul 28th 2014https://blog.llvm.org/2014/07/llvm-weekly-30-jul-28th-2014.htmlMon, 28 Jul 2014 12:55:00 +0000https://blog.llvm.org/2014/07/llvm-weekly-30-jul-28th-2014.html<p>Welcome to the thirtieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>The canonical home for this issue <a href="http://llvmweekly.org/issue/30">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>Nuno Lopes, David Menendez, Santosh Nagarakatte, and John Regehr have <a href="http://blog.regehr.org/archives/1170">written about ALIVe</a>. This is a very promising tool that aims to aid the specification and proof of peephole optimisations (such as those currently found in LLVM's InstCombine). It uses an SMT solver in order to prove optimisations correct (and if incorrect, provides a counter-example).</p><p>Source and binaries for the first LLVM/Clang 3.5 Release Candidate <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37969">are now available</a>. If you like your LLVM releases to be on-time and regression-free, do your part and test them on your codebases.</p><p>Thomas Ströder and colleagues have recently published a paper "Proving Termination and Memory Safety for Programs with Pointer Arithmetic" which creates symbolic execution graphs from LLVM IR in order to perform its analysis. The preprint is <a href="http://verify.rwth-aachen.de/giesl/papers/IJCAR14-LLVM.pdf">available here</a>.</p><p>The next Cambridge (UK) LLVM Social will be on the <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37979">30th July, at 7.30 pm</a>.</p><h3>On the mailing lists</h3><ul><li><p>Amin Shali from Google has posted an <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/38026">RFC on adding a rename refactoring tool to Clang</a>. The proposed feature addition would consist of a command-line tool to semantically rename a symbol and an API that could be used by IDEs/editors to do the same.</p></li><li><p>Lang Hames <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75175">reminds LLVM users to switch to MCJIT</a>. The old JIT infrastucture will be removed after 3.5, so now is the time to look at porting to MCJIT if you haven't already.</p></li><li><p>Rekha R <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75099">posed a question about the semantics of add nsw</a> which elicited some useful responses that might help clarify things if you too have found it unclear.</p></li></ul><h3>LLVM commits</h3><ul><li><p>Support for scoped noalias metadata has been added. The motivation for this is to preserve noalias function attribute information when inlining and to model block-scope C99 restrict pointers. <a href="http://reviews.llvm.org/rL213864">r213864</a>, <a href="http://reviews.llvm.org/rL213948">r213948</a>, <a href="http://reviews.llvm.org/rL213949">r213949</a>.</p></li><li><p>The llvm-vtabledump tool is born. This will dump vtables inside object files. Right now it only supports MS ABI, but will in the future support Itanium ABI vtables as well. <a href="http://reviews.llvm.org/rL213903">r213903</a>.</p></li><li><p>The llvm.assume intrinsic has been added. This can be used to provide the optimizer with a condition it may assume to be true. <a href="http://reviews.llvm.org/rL213973">r213973</a>.</p></li><li><p>The loop vectorizer has been extended to make use of the alias analysis infrastructure. <a href="http://reviews.llvm.org/rL213486">r213486</a>.</p></li><li><p>Various additions have been made to support the PowerPC ELFv2 ABI. <a href="http://reviews.llvm.org/rL213489">r213489</a>, <a href="http://reviews.llvm.org/rL213490">r213490</a>, and more.</p></li><li><p>The R600 backend gained an instruction shrinking pass, which will convert 64-bit instructions to 32-bit when possible. <a href="http://reviews.llvm.org/rL213561">r213561</a>.</p></li><li><p>The llvm.loop.vectorize.unroll metadata has been renamed to llvm.loop.interleave.count. <a href="http://reviews.llvm.org/rL213588">r213588</a>.</p></li><li><p>LLVM 3.5 release notes for MIPS have been committed, if you're interested in seeing a summary of work in the last development cycle. <a href="http://reviews.llvm.org/rL213749">r213749</a>.</p></li><li><p>The IR backward compatibility policy is now documented. <a href="http://reviews.llvm.org/rL213813">r213813</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Support for <code>#pragma unroll</code> was added. <a href="http://reviews.llvm.org/rL213574">r213574</a>.</p></li><li><p>Clang learned a range of AVX-512 intrinsics. <a href="http://reviews.llvm.org/rL213641">r213641</a>.</p></li><li><p>Work on MS ABI support continues. <a href="http://reviews.llvm.org/rL214004">r214004</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A dynamic loader for the Hexagon DSP was committed to lldb as well as an ABI description. <a href="http://reviews.llvm.org/rL213565">r213565</a>, <a href="http://reviews.llvm.org/rL213566">r213566</a>.</p></li><li><p>A new fast-path implementation of C++ demangling has been added to lldb. It promises significantly better performance. <a href="http://reviews.llvm.org/rL213671">r213671</a>.</p></li></ul>
- LLVM Weekly - #29, Jul 21st 2014https://blog.llvm.org/2014/07/llvm-weekly-29-jul-21st-2014.htmlMon, 21 Jul 2014 03:31:00 +0000https://blog.llvm.org/2014/07/llvm-weekly-29-jul-21st-2014.html<p>Welcome to the twenty-ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects.LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>.Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This is a special extended issue which I'm choosing to subtitle "LLVM Weekly visits the GNU Tools Cauldron". The <a href="https://gcc.gnu.org/wiki/cauldron2014">event</a> took place over the weekend and had a wide range of interesting talks. You can find my notes at the end of this newsletter. Talks were recorded and the videos should be made available in the next month or two.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/29">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The eighth annual LLVM Developers meeting has been <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74893">announced</a> and will take place on October 28th and 29th in San Jose, CA. It is looking for sponsors and talk/poster submissions.</p><p>A new blog post as been published on the LLVM Blog giving <a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html">more details on FTL: WebKit's LLVM-based JIT</a>.</p><p>A tentative <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37785">schedule for the release of LLVM/Clang 3.5</a> has been posted.</p><p>Botond Ballo has posted a <a href="http://botondballo.wordpress.com/2014/07/17/trip-report-c-standards-committee-meeting-in-rapperswil-june-2014/">summary of June's C++ Standards Committee Meeting</a>.</p><h3>On the mailing lists</h3><ul><li><p>Hal Finkel has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74941">RFC on adding an IR-level intrinsic to LLVM to represent invariants</a>. These are conditions that the optimizer is allowed to assume will be valid during the execution of the program. The post also comes with a complete set of patches implementing the concept. An issue raised by Philip Reames is that by representing the invariant as an IR instruction, this may affect profitability heuristics in optimisation passes. Chandler Carruth followed up with a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74946">clear description of the trade-offs</a> which it seems people mostly agree with.</p></li><li><p>Yuri Gribov has re-opened a previously discussed issue, that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74863">LLVM and GCC set the frame pointer to point to different stack slots on ARM</a>. Renato Golin <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74908">responded</a> with an explanation of how GCC ended up doing things differently. The AddressSanitizer people would prefer things to be unified so they can use knowledge of the layout to perform unwinding without using tables (a speed optimisation). It doesn't seem likely that either LLVM or GCC will be changing though.</p></li><li><p>Diego Novillo is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74881">soliciting feedback on integrating his autofdo tool into LLVM</a>. AutoFDO is a tool that converts data collected from Linux perf to a format that can be used by LLVM.</p></li><li><p>Philip Reames <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74887">asks whether anyone has implemented a framework for asking liveness questions for SSA values in the IR</a>. The lack of an immediate answer suggests they have not, though Andrew Trick points to <a href="http://hal.inria.fr/docs/00/58/53/03/PDF/RR-7503.pdf">Computing Liveness Sets for SSA-Form Programs</a> while Dibyendu Das points to <a href="http://hal.inria.fr/docs/00/64/73/69/PDF/ramakrishna_taco.pdf">Efficient Liveness Computation Using Merge Sets and DJ-Graphs</a> which is along the same lines.</p></li><li><p>Tim Northover has written an RFC suggesting that <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37777">llvm.convert.to.fp16 and related intrinsics should be dropped</a>. Instead the 'half' type can be used in combination with fpext/fptrunc.</p></li><li><p>Chandler Carruth has written an RFC regarding <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/75018">legalizing operations and post-legalization DAG combining</a>. It's only just been posted so there's no feedback yet.</p></li><li><p>Andrew Kaylor has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74930">proposed</a> that Lang Hames take over from him as code owner for MCJIT, RuntimeDyld, and JIT event listener. This was agreed and <code>CODE_OWNERS.txt</code> has been updated appropriately.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A dereferenceable attribute was added. This indicates that the parameter or return pointer is dereferenceable (i.e. can be loaded from speculatively without a risk of trapping). This is subtly different to the nonnull attribute which doesn't necessarily imply dereferenceability (you might for instance have a pointer to one element past the end of an array). <a href="http://reviews.llvm.org/rL213385">r213385</a>.</p></li><li><p>A new subtarget hook was added to allow targets to opt-out of register coalescing.<a href="http://reviews.llvm.org/rL213078">r213078</a>, <a href="http://reviews.llvm.org/rL213188">r213188</a>.</p></li><li><p>A MergedLoadStoreMotion pass was added. <a href="http://reviews.llvm.org/rL213396">r213396</a>.</p></li><li><p>RegionInfo has been templatified to it works on MachineBasicBlocks. <a href="http://reviews.llvm.org/rL213456">r213456</a>.</p></li><li><p>A monster patch from Nvidia adds a whole bunch of surface/texture intrinsics to the NVPTX backend. <a href="http://reviews.llvm.org/rL213256">r213256</a>.</p></li><li><p>Support was added for emitting warnings if vectorization is forced and fails. <a href="http://reviews.llvm.org/rL213110">r213110</a>.</p></li><li><p>Improvements to FastISel continue with the implementation of the FastLowerCall hook for X86. This actually reproduces what was already being done in X86, but is refactored against the target independent call lowering. <a href="http://reviews.llvm.org/rL213049">r213049</a>.</p></li><li><p>The ARM dmb, dsb and isb intrinsics have been implemented for AARch64. <a href="http://reviews.llvm.org/rL213247">r213247</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang's rewrite engine is now a core feature (i.e. it can not be disabled at configure time). <a href="http://reviews.llvm.org/rL213171">r213171</a>.</p></li><li><p>Error recovery when the programmer mistypes <code>::</code> as <code>:</code> was improved. <a href="http://reviews.llvm.org/rL213120">r213120</a>.</p></li><li><p>The AARch64 Clang CLI interface proposal for <code>-march</code> has been implemented. See the commit message for details. <a href="http://reviews.llvm.org/rL213353">r213353</a>.</p></li><li><p>OpenMP work continues with the addition of initial parsing and semantic analysis for the <code>final</code>, <code>untied</code> and other clauses, and the <code>master</code> directive. <a href="http://reviews.llvm.org/rL213232">r213232</a>, <a href="http://reviews.llvm.org/rL213257">r213257</a>, <a href="http://reviews.llvm.org/rL213237">r213237</a>, and more.</p></li></ul><h3>Other project commits</h3><ul><li>The 'Kalimba' platform is now supported by lldb (presumably this refers to the CSR processor). <a href="http://reviews.llvm.org/rL213158">r213158</a>.</li></ul><h3>LLVM Weekly at the GNU Tools Cauldron</h3><p>For full details on the conference and details on the speakers for the talks I've summarised below see the <a href="https://gcc.gnu.org/wiki/cauldron2014">GNU Tools Cauldron 2014 web page</a>. Apologies for any inaccuracies, please do get in touch if you spot anything I may have noted incorrectly. LLVM followers may be particularly interested in Renato Golin's talk on collaboration between the GCC and LLVM communities.</p><h4>Glibc BoF</h4><ul><li>2.20 is in "slushy" freeze mode. What else is left? fmemopen, fd locking, some <code>-Wundef</code> work</li><li>Anyone planning to check in something big for 2.21?<ul><li>Mentor Graphics planning to check in a NIOS II port. They won't be accepted until Linux kernel patches are in a kernel release.</li><li>A desire for AArch64 ILP32 ABI to get in. Kernel patches currently in review, compiler work is ready.</li><li>OpenRISC</li><li>NaCl (nptl)</li></ul></li><li>Benchmarking glibc? Does anyone have a good approach. There is a preload library approach (see notes from Ondrej's talk).</li><li>Glibc has been built with AddressSanitizer, help needed to get it integrated into the build system. There was a comment this would be nice to get in to distributions.</li><li>Red Hat are working on supporting alternate libm implementations, including a low-precision and high-precision implementation. Intel are looking to add math functions that work on small vectors.</li></ul><h4>Abigail: toward ABI taming</h4><ul><li>Want to determine if changes to your shared library break apps for users, and users want to know whether an updated library remains compatible with their code. The bidiff tool will tell you the differences in terms of ABI given two object files as its input.</li><li>libabi consists of modules such as a DWARF reader, the comparison engine. Tools such as bidiff are built on this API</li><li>What's next for libabigail?<ul><li>bicompat will help application authors determine whether their application A is still compatibile with an updated version of a given library L by examining the undefined symbols of A that are resolved by L.</li><li>More amenable to automation (such as integration into build systems)</li><li>Support for un-instantiated templates. This would require declarations of uninstantiated templates to be represented in DWARF.</li></ul></li><li>A first official release (though source is available at <a href="https://sourceware.org/libabigail/">https://sourceware.org/libabigail/</a>)</li></ul><h4>Writing VMs in Java and debugging them with GDB</h4><ul><li>Oracle Labs have been working on various dynamic language implementations in Java (e.g. Ruby, Python, R, JS, ...).</li><li>FastR is a reimplementation of R in Java featuring an interpreter (Truffle) and dynamic compiler (Graal).</li><li>Truffle and Graal starts with an AST interpreter. The first time a node is evaluated it is specialised to the type that was seen at runtime. Later the tree is compiled using partial evaluation.</li><li>It may be deployed on standard HotSpot (no compilation), GraalVM, or the SubstrateVM (SVM) which uses Graal to ahead-of-time compile the language implementation. Debugging the SVM is difficult as Java debugging tools are not available. The solution is to generate DWARF information in the SVM's output.</li><li>Truffle and Graal are open source, the SubstrateVM is not (yet?).</li></ul><h4>GCC and LLVM collaboration</h4><ul><li>Good news: license issues, personal grudges and performance are off-topic.</li><li>Users should be protected from whatever disagreements take place. In the future we should have more pro-active discussions on various issues as opposed to reactive discussions regarding e.g. compiler flags that have been noticed to be arbitrarily different after the fact.</li><li>Renato lists common projects that we may collaborate on: binutils, glibc, sanitizers. Sanitizers are a collaboration success story.</li><li>Can we agree on a (new?) common user interface?</li><li>There's a surprising amount of confusion about <code>-march</code>, <code>-mtune</code>, and <code>-mcpu</code> considering we're in a room of compiler developers. It sounds like there's not much support for re-engineering the set of compiler flags as the potential gain is not seen as being great enough.</li><li>Can we agree to standardise on attributes, C/C++ extensions, builtins, ASM, the linker API?</li><li>GCC docs have just been rewritten, so some criticisms about how difficult it is to dig in are no longer valid.</li></ul><h4>Machine Guided Energy Efficient Compilation</h4><ul><li>Initial investigations in 2012 found that compiler flags can have a meaningful effect on energy consumption. This raises the question of how to determine which flags to use.</li><li>MAGEEC will target both GCC and LLVM initially. It is implemented as a compiler plugin which performs feature extraction and allows the output of the machine learning algorithm to change the sequence of passes which are run. Fractional Factorial Design is used to reduce the optimisation space to explore.</li><li>Turning passes on/off arbitrarily can often result in internal compiler errors. Should the machine learning algorithm learn this, or should GCC better document pass requirements?</li><li>It would be useful to MAGEEC if the (currently internal) plugin API could be stabilized. They also currently have to use a hacked up Clang as it doesn't provide plugin hooks.</li><li>The project has produced a low cost energy measurement board as well as their own benchmark suite (Bristol/Embecosm Embedded Benchmark Suite, or BEEBS). BEEBS 2.0 is schedule for release by 31st August 2014 with a much wider range of benchmarks (currently 93). Jeremy showed a rather pleasing live demo where you can run a benchmark on a microcontroller development board and immediately find the number of mJ consumed in running it.</li><li>The current state of the project has it not achieving better results than GCC O2, but this is expected to change over the coming months.</li></ul><h4>Just-in-time compilation using GCC</h4><ul><li><a href="https://gcc.gnu.org/wiki/JIT">libgccjit.so</a> is an experimental branch of GCC which allows you to build GCC as a shared library and embed it in other programs in order to allow in-process code generation at runtime.</li><li>A dedicated API for JIT will allow better stability guarantees. It provides a high-level API designed for ease of use.</li><li>The API doesn't offer solutions for type inference, escape analysis, unboxing, inline caching, etc.</li><li>It has a C++ API wich includes some cunning operator overloading to massively reduce verbosity, and a Python API.</li><li>David Malcolm has written <a href="https://github.com/davidmalcolm/coconut">Coconut</a>, a JIT compiler for Python using libgccjit.so. It is incomplete and experimental.</li><li>Drawback: currently have to write out a .s to a file and invoke gcc on it.<br />Some might make a cheeky comment about the benefits of architecting a compiler so it can be used as a library, but I of course wouldn't dare. The good news is the speaker is actively looking at what would be needed to use GAS and GNU ld as a library.</li></ul><h4>Introduction to new Intel SIMD ISA and its impact on GCC</h4><ul><li>AVX-512 offers 64 simple precision or 32 double precision floating point operations per cycle. It also has 8x64-bit mask registers.</li><li>Rounding modes can be set on a per-instruction process</li><li>Basic support is available from GCC 4.9.x.</li></ul><h4>News from Sanitizers</h4><ul><li>MemorySanitizer detects use of uninitialized memory. Increases CPU by about 2.5x and RAM by 2x. Was released in LLVM in 2013. It is currently Linux/x86-64 only.</li><li>History growth is limited by limiting the history depth and the number of new history nodes per stack trace.</li><li>MSan has found hundreds of bugs across Google internal code, Chromium, LLVM, etc. It was more challenging for Chromium due to the number of system libs that had to be rebuilt.</li><li>AddressSanitizer annotations allows you to detect access to the regions of e.g. <code>std::vector<></code> which has been allocated as part of its capacity but not yet been used (i.e. will start to be used in the next <code>push_back</code>). Next is to do the same for <code>std::string</code> and <code>std::deque</code>.</li><li>Glibc uses GNU-C instead of ANSI C which currently prevents compilation with Clang (nested functions in particular are problematic). It can however be built with ASan by GCC.</li><li>Evgeniy comments that the lack of standardisation between Clang and GCC for things like <code>__has_feature(address_sanitizer)</code> vs <code>__SANITIZE_ADDRESS__</code> is irritating. This is just the sort of thing Renato was talking about yesterday of course.</li></ul><h4>glibc performance tuning</h4><ul><li>Use memset as an example. Look at 3 variants.</li><li>Writing a useful benchmark is more difficult than you might think. Simply running <code>memset</code> many times in a loop is not a good benchmark when using the same memory locations due to the processor's load-store forwarding. Even when fixing this, the branch predictor may perform much better than it would when memset is used in a real world scenario and lead to unrepresentative results.</li><li>To move beyond microbenchmarks, Ondrej has been using <code>LD_PRELOAD</code> to link against instrumented versions of the functions which record details about the time taken.</li><li>See <a href="http://kam.mff.cuni.cz/~ondra/benchmark_string/i7_nehalem/memset_profile/results_gcc/result.html">here</a>for memset benchmarks and <a href="http://kam.mff.cuni.cz/~ondra/benchmark_string/i7_nehalem/memset_profile/results_gcc/doc/properties.html">here</a> for more background.</li><li>strcmp was the most frequently called glibc function in Ondrej's testing (when running Firefox).</li></ul><h4>Devirtualization in GCC</h4><ul><li>This is a special case of indirect call removal, and although the talk is given in the context of C++ the techniques apply to other languages too. Some basic cases are handled in the front-end and even specified by the language standard.</li><li>It is a special case of constant propagation across aggregates, which is already done by Global Value Numbering and Interprocedural Constant Propagation. But these passes only catch a tiny number of possible cases.</li><li>Loss of information between the frontend and middle end can make some cases almost impossible. The intermediate language can be extended with explicit representations of base types, locations of virtual table pointers, and vtables. Also annotate polymorphic calls specifying instance and polymorphic call type and flags to denote constructors/destructors.</li><li>I'm not able to summarise details on the GCC devirt implementation better than the slides do. Hopefully they'll be made available online.</li><li>A particular challenge is to match types between different compilation units. The C++ One Definition Rule is used.</li><li>It can be used to strengthen unreachable function removal.</li><li>Feedback-directed devirtualization was extended in GCC 4.9 to work inter-module with LTO.</li></ul>
- FTL: WebKitâs LLVM based JIThttps://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.htmlWed, 16 Jul 2014 23:00:00 +0000https://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.htmlOver the past year, the WebKit project made tremendous progress on the ability to optimize JavaScript applications. A major part of that effort was the introduction of the Fourth Tier LLVM (FTL) JIT. The Fourth Tier JIT targets long-running JavaScript content and performs a level of optimization beyond WebKit's interpreter, baseline JIT, and high-level optimizing JIT. See the FTL Optimization Strategy section below for more on WebKit's tiered optimizations. The engineering advancements within WebKit that made the FTL possible were described by Filip Pizlo in the Surfin' Safari Blog post, <a href="http://www.webkit.org/blog/3362/introducing-the-webkit-ftl-jit/">Introducing the WebKit FTL JIT</a>. On April 29, 2014, the WebKit team enabled FTL by default on trunk: <a href="http://trac.webkit.org/changeset/167958">r167958</a>. <p/>This achievement also represents a significant milestone for the LLVM community. FTL makes it clear that LLVM can be used to accelerate a dynamically type checked languages in a competitive production environment. This in itself is a tremendous success story and shows the advantage of the highly modular and flexible design of LLVM. It is the first time that the LLVM infrastructure has supported self-modifying code, and the first time profile guided information has been used inside the LLVM JIT. Even though this project pioneered new territory for LLVM, it was in no way an academic exercise. To be successful, FTL must perform at least as well as non-FTL JavaScript engines in use today across a range of workloads without compromising reliability. This post describes the technical aspects of that accomplishment that relate to LLVM and future opportunities for LLVM to improve JIT compilation and the LLVM infrastructure overall. <p/> Read on for more information.<br /><a name='more'></a> <ul><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#ftl-performance">FTL Performance</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#ftl-optimization-strategy">FTL Optimization Strategy</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#llvm-patch-points">LLVM Patch Points</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#ftl-style-llvm-ir">FTL-Style LLVM IR</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#mcjit-and-the-llvm-c-api">MCJIT and the LLVM C API</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#linking-webkit-with-llvm">Linking WebKit with LLVM</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#ftl-efficiency">FTL Efficiency</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#optimization-improvements">Optimization Improvements</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#extending-patch-points">Extending Patch Points</a> </li><li><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#conclusion">Conclusion</a></li></ul><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="ftl-performance">FTL Performance</a></h2>JavaScript pages are ubiquitous and users expect fast load times, which WebKit's architecture is well suited for. However, some JavaScript applications require nontrivial computation and may run for periods longer than one hundred milliseconds. These applications demand aggressive compiler optimization and code generation tuned for the target CPU. FTL brings the full gamut of compiler technology to bear on the problem. <p/>As with any high level language, high level optimizations must come first. Grafting an optimizing compiler backend onto an immature frontend would be futile. The marriage of WebKit's JIT with LLVM's optimizer and code generation works for two key reasons: <p/><ol><li>Before translating to LLVM IR, WebKit's optimizing JIT operates on an IR that clearly expresses JavaScript semantics. Through type inference and profile-driven speculation, WebKit removes as much of the JavaScript abstraction penalty as possible. </li><li>LLVM IR has now adopted features for supporting speculative, profile-driven optimization and avoiding the performance penalty associated with abstractions when they cannot be removed. </li></ol>As a result, WebKit can engage the FTL on any long-running JavaScript method. In areas of the code dominated by abstraction overhead, FTL-compiled code is at least competitive with that of a custom JIT designed specifically for JavaScript. In areas of the code where WebKit can remove the abstraction penalty, FTL can achieve fantastic speedups. <p/>Asm.js is a subset if JavaScript that avoids abstraction penalties, allowing JITs to directly benefit from low-level performance optimization. Consequently, the performance advantage of FTL is likely to be quite apparent on asm.js benchmarks. But although FTL performs well on asm.js, it is in no way customized to the standard. In fact, with FTL, regular JavaScript code written in a style similar to asm.js will derive the same benefits. Furthermore, as WebKit's high-level optimizations become even more advanced, the benefits of FTL will expand to a broader set of idiomatic JavaScript code. <p/>A convenient way to measure the impact of LLVM optimizations on JavaScript code is by running C/C++ benchmarks that have been compiled to asm.js code via emscripten. This allows us to compare native C/C++ performance with WebKit's third tier (DFG) compiler and with WebKit FTL. <p/><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/--gmTvH6H5ho/U8XprFD79_I/AAAAAAAAG1I/spxgXk6WL4M/s1600/asm_js_ftl_results.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/--gmTvH6H5ho/U8XprFD79_I/AAAAAAAAG1I/spxgXk6WL4M/s1600/asm_js_ftl_results.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><b>Figure 1</b>: Time to run benchmarks from LLVM test-suite.</div>Figure 1 shows the time taken to run a handful of benchmarks from LLVM's own test-suite. The benchmark workloads have been adjusted to run for approximately one second. In every case, FTL achieves significant improvement over WebKit's non-LLVM JIT (DFG). In some cases, the emscripten compiled JavaScript code is already approaching native C performance, but in other cases FTL code still takes about twice as long as clang compiled C code<b>[1]</b>. One reason for the discrepancy between clang and FTL is the call overhead required for maintaining the JavaScript runtime's additional frame information. Another reason is that LLVM loop optimizations are not yet sophisticated enough to remove bounds and overflow checks and thus have not been enabled. These benchmarks are very tight loops, so a minor inefficiency, such as an extra compare or store in the loop, can result in a significant slowdown. <p/><b>[1]</b> gcc-loops is currently an outlier because clang performance recently sped up dramatically from auto-vectorization that has not been enabled yet in FTL. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="ftl-optimization-strategy">FTL Optimization Strategy</a></h2>WebKit's tiered architecture provides flexibility in balancing responsiveness, profile collection, and compiler optimization. The first tier is the low-level interpreter (LLInt). The second is the baseline JIT--a straightforward translation from JavaScript to machine code. WebKit's third tier is known as the Data Flow Graph (DFG) JIT. The DFG has its own high-level IR allowing it to perform aggressive JavaScript-specific optimization based on the profile data collected in earlier tiers. When running as a third tier, the DFG quickly emits code with additional profiling hooks. It may be invoked again as a fourth tier, but this time it produces LLVM IR for traditional compiler optimization. <p/><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-anUsfTvvZCs/U8XtyOp5l-I/AAAAAAAAG1Y/qjoH0nTncE0/s1600/ftl_pipeline.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-anUsfTvvZCs/U8XtyOp5l-I/AAAAAAAAG1Y/qjoH0nTncE0/s1600/ftl_pipeline.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><b>Figure 2.</b> The DFG and FTL JIT optimization pipelines (from <a href="http://www.webkit.org/blog/3362/introducing-the-webkit-ftl-jit/">Introducing the WebKit FTL JIT</a>). </div>We reuse most of the DFG phases. The new FTL pipeline is a drop-in replacement for the third-tier DFG backend. It involves additional JavaScript-aware optimizations over DFG SSA form, followed by a phase that lowers DFG IR to LLVM IR. We then invoke LLVM's optimization pipeline and LLVM's MCJIT backend to generate machine code. <p/>The DFG JIT front end generates LLVM IR in a form that is amenable to the same optimizations traditionally performed with C code. The most notable differences are summarized in <a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html#ftl-style-llvm-ir">FTL-Style LLVM IR</a>. <p/><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-Hg0qG-SDMUM/U8XtyKA16tI/AAAAAAAAG1U/jEyHRJGVfqw/s1600/ftl-llvm-pipeline.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-Hg0qG-SDMUM/U8XtyKA16tI/AAAAAAAAG1U/jEyHRJGVfqw/s1600/ftl-llvm-pipeline.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><b>Figure 3.</b> The FTL optimization pipeline after lowering to LLVM IR.</div>After lowering to LLVM IR, FTL applies a subset of mid-level optimizations that are currently the most important in JavaScript code. It then invokes the LLVM backend for the host architecture with full optimization. This optimizes the code for the target CPU using aggressive instruction selection, register allocation, and machine-specific optimization. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="llvm-patch-points">LLVM Patch Points</a></h2>Patch points are the key LLVM feature that allows dynamic type checking, inline caching, and runtime safety checks without penalizing performance. In October, 2013, we submitted a <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-October/066573.html">proposal to amend LLVM IR with patch points</a> to the LLVM developer list. Since then, we've successfully implemented patch points for multiple architectures and their performance impact has been validated for various use cases, including branch-to-fail safety checks, inline caches, and code invalidation points. The details of the current design are explained in the <a href="http://llvm.org/docs/StackMaps.html">LLVM specification of stack map and patch point intrinsics</a>. <p/>Patch points are actually two features in one intrinsic. The first feature is the ability to identify the location of specific values at the intrinsic's final instruction address. During code emission, LLVM records that information as meta-data alongside the object code in what we call a "stack map". A stack map communicates to the runtime the location of important values. This is a slight misnomer given that locations may refer to register names. Typically, the runtime will read values out of stack map locations when it needs to reconstruct a stack frame. This commonly occurs during "deoptimization"--the process of replacing an FTL stack frame with a lower-tier frame. <p/>The second feature of patch points is the ability of the runtime to patch the compiled code at specific instruction address. To allow this, the intrinsic reserves a fixed amount of instruction encoding space and records the instruction address of that space along with the stack map. Because the runtime needs to know the location of values precisely at the point it patches code, the two features must be combined into one intrinsic. <p/>Patch points are viewed by LLVM passes much like unknown call sites. An important aspect of their design is the ability to specify the effective calling convention. For example, code invalidation points are almost never taken and the call site should not clobber any registers, otherwise the register allocator could be severely restricted by frequent runtime checks. An optional feature of stack maps is the ability to record the registers that are actually live in compiled code at each call site. This way the JIT can declare a call as preserving all registers to maximize compiler freedom, but at the same time the runtime can avoid unnecessary save and restore operations when the "cold" call is actually taken. <p/>To better support inline cache optimizations, LLVM now has a special "anyregcc" calling convention. This convention allows any number of arguments to be forced into registers without pinning down the name of the register. Consequently, the compiler does not have to place arguments in particular registers or stack locations, or emit extra copies and spills around call sites, and the runtime can emit efficient patched code sequences that operate directly on registers. <p/>The current patch point design is labeled experimental so that it may continue to evolve without preserving bitcode compatibility. LLVM should soon be ready to adopt the patch point intrinsic in its final form. However, the current design should first be extended to capture the semantics of high level language runtime checks. See Extending Patchpoints. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="ftl-style-llvm-ir">FTL-Style LLVM IR</a></h2>FTL attempts to generate LLVM IR that closely resembles what the optimizer expects to see from other typical compiler frontends. Nonetheless, lowering JavaScript semantics into LLVM operations tends to result in IR with different characteristics from statically compiled C code. This section summarizes those differences. More details and examples will be provided in a subsequent blog post. <p/>The prevalence of patch points in the IR means that values tend to have many more uses and can be live into a large number of patch point call sites. FTL emits patch points for a few distinct situations. First, when the FTL front end (DFG) fails to eliminate type checks or bounds checks, it emits explicit compare and branch operations in the IR. The branch target lands at a patch point intrinsic followed by unreachable. This can result in much more branchy code than LLVM typically handles with C benchmarks. Fortunately, LLVM's awareness of branch probability means that the branch-to-fail idiom does not excessively hinder optimization and code generation. Heap access and polymorphic calls also use patch points, but these are emitted directly inline with the hot path. This allows the runtime to implement inline caches with specific instruction sequences that can be patched as program behavior evolves. Finally, runtime calls may act as code invalidation points. A runtime event, such as a potential change in object layout, may invalidate speculatively optimized code. In this case WebKit emits nop patch points that can be overwritten with a separate runtime call at an invalidation event. This effectively invalidates all code that follows the original runtime call. <p/>Some type checks result in multiple fast paths. For example, WebKit may check a numeric value for either a floating-point or fixed point representation and emit LLVM IR for both paths. This may result in a sequence of redundant checks interleaved with control flow merges. <p/>To support integer overflow checks, when they cannot be removed through optimization, FTL emits llvm.sadd.with.overflow intrinsics in place of normal add instructions. These intrinsics ensure that the code generator produces an optimal code sequence for the overflow checks. They are also used by other active LLVM projects and are gradually gaining support within LLVM optimization passes. <p/>LLVM heuristics are often sufficient to guess branch probability. However FTL makes the job easier by directly emitting LLVM branch weight meta-data based on profiling. This is particularly important when partially compiling a method starting at the inner loop. Such compilations can squash nested loops so that LLVM's heuristics can no longer infer the loop depth from the CFG structure. <p/>FTL builds an internal model of the JavaScript program's type system determined by profiling. It conveys this information to LLVM via type-based-alias-analysis (tbaa) meta-data. In FTL tbaa, each object field has a unique tag. This is a very effective approach to memory disambiguation, and much simpler than the access-path scheme that clang now uses. <p/>Another way that FTL deviates from the norm, is in its use of inttoptr instructions. These are used to materialize addresses of runtime objects, including all data and code from outside the current compilation unit (currently a single method at a time). inttoptr is also used to convert an untyped JS value to a pointer. Occasionally, pointer arithmetic is performed on non-pointer types rather than using getelementptr instructions. This is primarily a convenience and has not proven to hinder optimization. FTL's use of tbaa is effective enough to obviate the need to analyze getelementptr when the base address is already an unknown object. <p/>An important pattern that occurs in FTL's LLVM IR is the repeated use of the same large constants that are used as masks to disambiguate tagged values, or several constants that represent global addresses that tend to be at small offsets from each other. LLVM's current one basic block a time code generation approach resulted in redundant rematerialization of the same large constant in each basic block. The fact that FTL creates a large number of basic blocks even further exacerbated this problem. The LLVM code generator has been enhanced to avoid these expensive repeated rematerialization of such constant values. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="mcjit-and-the-llvm-c-api">MCJIT and the LLVM C API</a></h2>The FTL JIT successfully leverages LLVM's existing <a href="http://llvm.org/docs/MCJITDesignAndImplementation.html">MCJIT framework</a> for runtime compilation. MCJIT was designed as a low-level toolkit that allows runtime compilers to be built by reusing as much of the static compiler's machinery as possible. This approach improves maintainability on the LLVM side. It integrates with the existing compiler toolchain and allows developers to test features of the runtime compiler without understanding a particular JIT client. The current API, however, does not provide a simple out-of-the-box abstraction for portable JITs. Overcoming the impedance mismatch between WebKit goals and the low-level MCJIT API required close collaboration between WebKit and LLVM engineers. As LLVM becomes more important as a JIT platform, it should provide a more complete C API to improve interoperability with JIT clients and decrease the fragility and maintenance burden within the client code base. <p/>Bridging the gap between LLVM internals and portable JITs can be accomplished by providing more convenience wrappers around the existing MCJIT framework and adding richer C APIs for object code parsing and introspection. Ideally, a cross-platform JIT client like WebKit should not need to embed target-specific details about LLVM code generation on the client side. The JIT should be able to request LLVM to emit code for the current host process without understanding LLVM's language of target triples and CPU features. LLVM could generally provide a more obvious C API for lazily invoking runtime compilation. Along these lines, a JIT should be able to reuse the MCJIT execution engine for multiple modules without the overhead of reinitializing pass manager instances each time. An API also needs to be added for configuring the code generation pass manager. Most of the coordination between the JIT and LLVM now occurs directly through a memory manager API, which can be awkward for the JIT client. For example, WebKit looks for platform-specific section names when allocating section memory in order to locate frame meta-data and debug information. A better interface for WebKit would be a portable API that communicates object code meta-data, including frame information and stack maps. In general, the JIT codebase should not need to provide its own support for platform-specific object file formats. LLVM already has this support, it only needs to be exposed through the C API. Similarly, a JIT should be able to lookup line numbers without implementing its own DWARF parser. An additional layer of functionality for general purpose debug info parsing and object code introspection would not be specific to JIT compilation and could benefit a variety of LLVM clients. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="linking-webkit-with-llvm">Linking WebKit with LLVM</a></h2>FTL illustrates an important use case for LLVM: embedding LLVM optimization and codegen libraries cleanly within a larger application running in the same process. The ideal solution is to build a set of LLVM components as a shared library that exports only a limited C API. Several problems have made this a challenging endeavor: <ul><li>The dynamic link time initialization overhead of the static initializers that LLVM defines is unacceptable at program launch time - especially if only parts of the library or nothing at all are used. </li><li>LLVM initializes global variables that require running exit-time destructors. This causes a multi-threaded parent application that attempts to exit normally to crash instead. </li><li>As with static initializers, weak vtables introduce an unnecessary and unacceptable dynamic link time overhead. </li><li>In general only a limited set of methods - the LLVM API - should be exported from the shared library. </li><li>LLVM usurps process-level API calls like assert, raise, and abort. </li><li>The resulting size of the LLVM shared library naively built from static libraries is larger than it needs to be. Build logic and conditional compilation should be added to ensure that only the passes and platform support required by the JIT client are ultimately linked into the shared library. </li></ul>The issues listed above have required clever engineering tricks to circumvent. These are the sort of tricks that hinder adoption of LLVM. Therefore it would be in the best interest of the LLVM community to cooperate on improving the infrastructure for embedding LLVM. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="ftl-efficiency">FTL Efficiency</a></h2>The LLVM optimizer and code generator are composed of generic, retargetable components designed to generate optimal code across an extremely diverse range of platforms. The compile time cost of this infrastructure is substantial and may be an order of magnitude greater than that of a custom-built JIT. Fortunately, WebKit's architecture for concurrent, tiered compilation largely sidesteps this penalty. Nonetheless, there is considerable opportunity to reengineer LLVM for use as a JIT, which will decrease FTL's CPU consumption and increase the breadth of JavaScript applications that benefit from FTL. <p/>When running in a JIT environment, an opportunity exists for LLVM to strike a better balance between compile time and optimization strength. To this end, an alternate "compile-fast" optimization pass pipeline should be standardized so that the LLVM community can work together to maintain an ideal sequence of lighter-weight passes. Long running, iterative IR optimization passes, such as GVN, should be adapted to optionally run in fewer iterations. Hodge-podge passes like InstCombine that run many times should be optionally broken up so that some subset of functionality can run at different times: for example, canonicalize first and optimize later. <p/>There are also considerable opportunities for improving code generation efficiency which will benefit JITs and static compilers alike. LLVM machine IR should be generated directly from LLVM IR without generating a Selection DAG, as proposed by Jakob Olesen in his <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-August/064727.html">Proposal for a global instruction selector</a>. The benefit of this improvement would be considerable and widespread. More specific to high level languages, codegen passes should be tuned to handle branchy code more efficiently. For example, the register allocator can be taught to skip expensive analysis at points in the code where branches are not expected to be executed. <p/>One overhead that will remain with the above improvements is simply the cost of bridging WebKit's DFG IR into LLVM IR. This involves lowering to SSA form and constructing LLVM instructions, which currently takes significant amount of time relative to DFG's non-LLVM codegen path. With some scrutiny, this could likely be made more efficient. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="optimization-improvements">Optimization Improvements</a></h2>Without incurring significant compile time increase, LLVM optimizations can be further improved to handle prevalent idioms in JavaScript programs. One straightforward LLVM IR enhancement would be to associate type-based alias information with call sites. This would improve redundant instruction elimination across runtime calls and patch points. Another area of improvement would be better handling of branch-and-merge idioms. These are quite common in FTL produced IR and can improved through CFG simplification, jump threading, or tail duplication. With careful pass pipeline management, loop optimizations can be enabled, such as auto-vectorization. Once LLVM is analyzing loops, bounds and overflow check elimination optimization can also be implemented. To do this well, patch points will need to be extended with new semantics. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="extending-patch-points">Extending Patch Points</a></h2>In settings like JavaScript and other high level languages, patch points will be used to transfer control to the runtime when speculative optimization fails in the sense that the program behaves differently than predicted. It is always safe to assume a misprediction and give control back to the runtime because the runtime always knows how to recover. Consequently, patch points could optionally be associated with a check condition and given the following semantics: the patch point code sequence must be executed whenever the condition holds, but may safely be executed at its current location under any superset of the condition. When combined with LLVM loop optimization, the conditional patch point semantics would allow powerful optimization of runtime checks. In particular, bounds and overflow checks could be safely hoisted outside loops. For example, the following simplified IR: <p/><pre><code><br />%a = cmp <TrapConditionA><br />call @patchpoint(1, %a, <state-before-loop>)<br />Loop:<br /> %b = cmp <TrapConditionB><br /> @patchpoint(2, %b, <state-inside-loop>)<br /> <do something...><br /><br />Could be safely optimized into:<br /><br />%c = cmp <TrapConditionC> // where C implies both A and B<br />@patchpoint(1, %c, <state-before-loop>)<br />Loop:<br /> do something...<br /></code></pre>Note that the first patch point operand is an identifier that tells the runtime the program location of the intrinsic, allowing it find the correct stack map record for the program state at that location. After the above optimization, not only does LLVM avoid performing repeated checks within the loop, but it also avoids maintaining additional runtime state throughout the loop body. <p/>Generally, high level optimization requiring knowledge of language-specific semantics is best performed on a higher level IR. But in this case, extending LLVM with one aspect of high level semantics allows LLVM's loop and expression analysis to be directly leveraged and naturally extended into a new class of optimization. <p/><h2><a href="http://blog.llvm.org/2014/07/ftl-webkits-llvm-based-jit.html" name="conclusion">Conclusion</a></h2>WebKit's FTL JIT already shows considerable value in improving JavaScript performance, demonstrating LLVM's remarkable success as a backend for a JavaScript JIT compiler. The FTL project highlights the value of further improving LLVM's JIT infrastructure and reveals several exciting opportunities: improved efficiency of optimization passes and codegen, optimizations targeted toward common idioms present in high level language, enabling more aggressive standard optimizations like vectorization, and extending and formalizing patch point intrinsics. Realizing these goals will require the continued support of the LLVM community and will advance and improve the LLVM project as a whole.
- LLVM Weekly - #28, Jul 14th 2014https://blog.llvm.org/2014/07/llvm-weekly-28-jul-14th-2014.htmlMon, 14 Jul 2014 06:49:00 +0000https://blog.llvm.org/2014/07/llvm-weekly-28-jul-14th-2014.html<p>Welcome to the twenty-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>.Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'll be at the <a href="https://gcc.gnu.org/wiki/cauldron2014">GNU Tools Cauldron 2014</a> next weekend, being held at the University of Cambridge Computer Laboratory (which handily is also where I work). If you're there, do say hi.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/28">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>An update on Clang/LLVM on Windows has been <a href="http://blog.llvm.org/2014/07/clangllvm-on-windows-update.html">posted on the LLVM blog</a>. Impressive progress has been made, and as I mentioned last week the <a href="http://clang.llvm.org/docs/MSVCCompatibility.html">MSVC compatibility page</a> has been updated.</p><p>There is (somewhat amazingly) now a <a href="http://john-tornblom.github.io/llvm-p86/">Pascal-86 frontend for LLVM</a>. The compiler frontend is written entirely in Python. More information is available in the author's <a href="http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-105456">Master's thesis</a> (via <a href="http://www.phoronix.com/scan.php?page=news_item&px=MTczODY">Phoronix</a>).</p><h3>On the mailing lists</h3><ul><li><p>Edward Diener has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37699">kicked off a discussion on whether clang-cl should reproduce buggy VC++ preprocessor behaviour</a>. A concern is that this might hold back people wanting to use preprocessor metaprogramming on the Windows platform. As is pointed out in one of the responses, bug-for-bug compatibility mode could always be disabled via a new flag.</p></li><li><p>Corey Richardson has a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37761">query about using clang-c for a bindings generator</a>. No responses yet, but it's certainly of interest to me.</p></li><li><p>Kuba BÅeÄka <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74718">proposes extending LLDB to offer tighter integration with Address Sanitizer-enabled binaries</a>.</p></li><li><p>Peter Collingbourne has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74602">proposed offering a native object on-disk module format storing LLVM bitcode in an ELF/COFF/MACH-O section</a>. Dan Liew <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74641">points out that unrecognised sections are included in the output by the linker</a>, meaning if you linked these .o files the bitcode would be included in the produced binary. Peter says the current plan wouldn't have these object files used directly by the linker.</p></li></ul><h3>LLVM commits</h3><ul><li><p>FastISel gained some infrastructure to support a target-independent call lowering hook as well as target-independent lowering for the patchpoint intrinsic. <a href="http://reviews.llvm.org/rL212848">r212848</a>, <a href="http://reviews.llvm.org/rL212849">r212849</a>.</p></li><li><p>DominanceFrontier has been templatified, so in theory it can now be used for MachineBasicBlocks (where previously it was only usable with BasicBlocks). <a href="http://reviews.llvm.org/rL212885">r212885</a>.</p></li><li><p>The quality of results for CallSite vs CallSite BasicAA queries has been improved by making use of knowledge about certain intrinsics such as memcpy and memset. <a href="http://reviews.llvm.org/rL212572">r212572</a>.</p></li><li><p>Work on overhauling x86 vector lowering continues. Chandler now reports that with the new codepath enabled, LLVM is now at performance pairty with GCC for the core C loops of the x264 code when compiling for SSE2/SSE3. <a href="http://reviews.llvm.org/rL212610">r212610</a>.</p></li><li><p>ASM instrumentation for AddressSanitizer is now generated entirely in MachineCode, without relying on runtime helper functions. <a href="http://reviews.llvm.org/rL212455">r212455</a>.</p></li><li><p>Generation of the new mips.abiflags section was added to the MIPS backend. <a href="http://reviews.llvm.org/rL212519">r212519</a>.</p></li><li><p>isDereferenceablePointer will now look through some bitcasts. <a href="http://reviews.llvm.org/rL212686">r212686</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A new checker was added, to flag code that tests a variable for 0 after using it as a denominator (implying a potential division by zero). <a href="http://reviews.llvm.org/rL212731">r212731</a>.</p></li><li><p>Clang gained initial support for omp parallel for, the omp parallel sections directive, and omp task. <a href="http://reviews.llvm.org/rL212453">r212453</a>, <a href="http://reviews.llvm.org/rL212516">r212516</a>, <a href="http://reviews.llvm.org/rL212804">r212804</a>.</p></li><li><p>On the ARM target, LLVM's atomicrmw instructions will be used when ldrex/strex are available. <a href="http://reviews.llvm.org/rL212598">r212598</a>.</p></li><li><p>Support was adding for mips-img-linux-gnu toolchains. <a href="http://reviews.llvm.org/rL212719">r212719</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>ThreadSanitizer's deadlock detector is enabled by default after being battle-tested on the Chromium codebase for some time. <a href="http://reviews.llvm.org/rL212533">r212533</a>.</p></li><li><p>Support for Android's bionic C library has been added to libcxx. <a href="http://reviews.llvm.org/rL212724">r212724</a>.</p></li><li><p>LLDB's Python scripting interface should now work on Windows. <a href="http://reviews.llvm.org/rL212785">r212785</a>.</p></li></ul>
- Clang/LLVM on Windows Updatehttps://blog.llvm.org/2014/07/clangllvm-on-windows-update.htmlMon, 07 Jul 2014 20:34:00 +0000https://blog.llvm.org/2014/07/clangllvm-on-windows-update.html<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Itâs time for an update on Clangâs support for building native Windows programs, compatible with Visual C++! Weâve been working hard over the last few months and have improved the toolchain in a variety of ways. All C++ features aside from debug info and exceptions should work well. This </span><a href="http://clang.llvm.org/docs/MSVCCompatibility.html" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">link</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> provide more specific details. In February we reached an exciting milestone that we can self-host Clang and LLVM using clang-cl (without fallback), and both projects pass all of their tests! Additionally both Chrome and Firefox now compile successfully with fallback! Here are some of the highlights of recent improvements:</span></div><b id="docs-internal-guid-2b2f973e-119b-7120-2d4c-138311c64483" style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Microsoft compatible record layout is done! Itâs been thoroughly fuzz tested and supports all Microsoft specific components such as virtual base table pointers, </span><a href="http://msdn.microsoft.com/en-us/library/453x4xdd.aspx" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">vtordisps</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">, __declspec(align) and #pragma pack. This turned out to be a major effort due to subtle interactions between various features. For example, __declspec(align) and #pragma pack behave in an analogous manner to the gcc variants, but interact with each other in a different manner. Each version of Visual Studio changes the ABI slightly. As of today clang-cl is layout compatible with VS2013.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Clang now supports all of the calling conventions used up to VS2012. VS2013 added some new ones that we havenât implemented yet. One of the other major compatibility challenges we overcame was passing C++ objects by value on 32-bit x86. Prior to this effort, LLVM modeled all outgoing arguments as SSA values, making it impossible to take the address of an argument to a call. It turns out that on Windows C++ objects passed by value are constructed directly into the argument memory used for the function call. Achieving 100% compatibility in this area required making fundamental changes to LLVM IR to allow us to compute this address.</span></div><b style="font-weight: normal;"><br /></b><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Most recently support for run time type information (RTTI) was completed. With RTTI support, a larger set of programs and libraries (for example </span><a href="http://site.icu-project.org/" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">ICU</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">) compile without fallback and dynamic_cast and typeid both work. RTTI support also brings along support for std::function. We also recently added support for lambdas so you can enjoy all of the C++11 functional goodness!</span></div><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We invite you to </span><a href="http://llvm.org/builds/" style="text-decoration: none;"><span style="background-color: transparent; color: #1155cc; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">try it out for yourself</span></a><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> and, as always, we encourage everyone to file bugs!</span></div>
- LLVM Weekly - #27, Jul 7th 2014https://blog.llvm.org/2014/07/llvm-weekly-27-jul-7th-2014.htmlMon, 07 Jul 2014 07:35:00 +0000https://blog.llvm.org/2014/07/llvm-weekly-27-jul-7th-2014.html<p>Welcome to the twenty-seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects.LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>.Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/27">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>An LLVM code generator has been <a href="https://github.com/MLton/mlton/commit/bf36a151a4b0cc366ba32b5ebea5d8ce25239a0b">merged</a> into the MLton whole-program optimizing compiler for Standard ML. This was written by Brian Leibig as part of his <a href="http://www.cs.rit.edu/~mtf/student-resources/20124_leibig_msproject.pdf">Master's thesis</a>, which contains more information on its performance and design.</p><p>Eli Bendersky has <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-July/037782.html">written a tool</a> which converts the output of Clang's <code>-ast-dump</code> to HTML. See <a href="https://dl.dropboxusercontent.com/u/15602400/template-insts-dump.html">here</a> for an example. The code is <a href="https://github.com/eliben/llvm-clang-samples/blob/master/tools/htmlize-ast-dump.py">available on Github</a>.</p><p>Clang's Microsoft Visual C++ <a href="http://clang.llvm.org/docs/MSVCCompatibility.html">compatibility page</a> has been updated to reflect the status of the current SVN trunk. As can be seen from the <a href="http://reviews.llvm.org/rL212193">relevant diff</a>, record layout has been marked complete along with RTTI. Lambdas are now marked mostly complete.</p><h3>On the mailing lists</h3><ul><li><p>Edwin Amsler is <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074472.html">interested in producing an LLVM backend for the 6502 processor</a>. He later starts a thread asking for <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074523.html">advice on targeting a CPU with no general purpos registers</a>. David Given <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074530.html">suggests</a> it might be worth viewing the 6502 as a machine with 256 byte-sized registers.</p></li><li><p>Pavel Chupin has written to the list on behalf of Intel to get feedback on <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074451.html">upstreaming support for the x32 ABI</a>. As you might expect, people are in favour of the idea. The NativeClient team are <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074457.html">also interested</a>, particularly as NaCl's x86-64 ABI is fairly similar to x32.</p></li><li><p>Sunil Srivastava has shared a <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-July/037812.html">proposal for an ABI test suite for Clang</a>. There is wide support for Sony submitting the implementation for code review. A later response clarifies that of the 400 test files, about 20% are hand-written and the rest come from the test case generator.</p></li><li><p>In a thread about using the Clang API to extract information about the memory layout of structs, Reid Kleckner <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-July/037778.html">points to the handy -fdump-record-layouts flag</a>.</p></li><li><p>There's a massive thread on <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074408.html">the usability of Phabricator review threads for non-Phabricator users</a>. There seem to be some issues with email reviews showing up on Phabricator and possibly vice-versa. There's more than I have time to summarize, so those interested are advised to read the thread.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The X86 backend now expands atomics in IR instead of as MachineInstrs. Doing the expansions at the IR level results in shorter code and potentially there may be benefit from other IR passes being able to run on the expanded atomics. <a href="http://reviews.llvm.org/rL212119">r212119</a>.</p></li><li><p>The ARM backend learned the ISB memory barrier intrinsic. <a href="http://reviews.llvm.org/rL212276">r212276</a>.</p></li><li><p>The X86 backend gained support for <code>__builtin_ia32_rdpmc</code> which is used to read performance monitoring counters. <a href="http://reviews.llvm.org/rL212049">r212049</a>.</p></li><li><p>The peephole optimizer gained new code (currently disabled) to rewrite copies to avoid copies across register banks. <a href="http://reviews.llvm.org/rL212100">r212100</a>.</p></li><li><p>Control flow graph building code has been moved from MC to a new MCAnalysis library. <a href="http://reviews.llvm.org/rL212209">r212209</a>.</p></li><li><p>TableGen gained support for MSBuiltin, which allows for adding intrinsics for Microsoft compatibility. <a href="http://reviews.llvm.org/rL212350">r212350</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>MSVC RTTI (run-time type information) implementation has been completed. <a href="http://reviews.llvm.org/rL212125">r212125</a>.</p></li><li><p>The <code>__builin_arm_ldaex</code> and <code>__builtin_arm_stlex</code> intrinsics were added. <a href="http://reviews.llvm.org/rL212175">r212175</a>.</p></li><li><p>Nested blocks are now supported in Microsoft inline assembly. <a href="http://reviews.llvm.org/rL212389">r212389</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lldb-gdbserver support has been merged for Linux x86-64. <a href="http://reviews.llvm.org/rL212069">r212069</a>.</p></li><li><p>AddressSanitizer gained support for i686-linux-android. <a href="http://reviews.llvm.org/rL212273">r212273</a>.</p></li><li><p>libcxxabi gained a CMake build system. <a href="http://reviews.llvm.org/rL212286">r212286</a>.</p></li><li><p>lld now supports parsing of x86 and ARM/Thumb relocations for MachO. <a href="http://reviews.llvm.org/rL212239">r212239</a>, <a href="http://reviews.llvm.org/rL212306">r212306</a>.</p></li></ul>
- LLVM Weekly - #26, Jun 30th 2014https://blog.llvm.org/2014/06/llvm-weekly-26-jun-30th-2014.htmlMon, 30 Jun 2014 11:53:00 +0000https://blog.llvm.org/2014/06/llvm-weekly-26-jun-30th-2014.html<p>Welcome to the twenty-sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/26">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Vladmir Makarov has done his <a href="https://gcc.gnu.org/ml/gcc/2014-06/msg00254.html">yearly comparison of GCC and LLVM</a>, posting performance comparisons using SPECInt2000 on ARM and x86-64.</p><p>Version 0.13.0 of LDC, the LLVM-based D compiler has <a href="https://github.com/ldc-developers/ldc/releases/tag/v0.13.0">been released</a>. This brings a whole host of improvements, listed in detail within the release announcement.</p><p>Some Mozilla engineers have been looking at using clang-cl (the MSVC-compatible Clang driver) to build Firefox. With the help of the fallback flag (which falls back o compiling with MSVC if Clang fails) they've <a href="http://ehsanakhgari.org/blog/2014-06-26/building-firefox-on-windows-with-clang-cl">managed to get a completed build</a>. Ehsan tells us that <a href="https://twitter.com/ehsanakhgari/status/482271470010105857">602 of the 7168 files, about 8% require the MSVC fallback</a> at the moment.</p><p>Trail of Bits have posted a <a href="http://blog.trailofbits.com/2014/06/23/a-preview-of-mcsema/">preview of McSema</a>, a framework for translating x86 binaries to LLVM bitcode. The accompanying talk took place on the 28th June, so hopefully we'll hear more about this soon. The blog post tells us that McSema will be open source and made available soon.</p><p>Bruce Mitchener has written up his <a href="http://dylanfoundry.org/2014/06/25/integrating-with-lldb/">experience of integrating with LLDB for Dylan</a>.</p><p>Codeplay (based in Edinburgh) are advertising for a <a href="http://www.codeplay.com/company/jobs/view.html?uid=12#.U7B4jzksa00">full time compiler engineer</a>.</p><h3>On the mailing lists</h3><ul><li><p>Alp Toker kicked off a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74274">long thread about the use of Phabricator for code reviews</a>. The main problem is that Phabricator reviews aren't necessarily going through llvm-commits which is potentially harming development. A very sensible step has been taken of <a href="https://secure.phabricator.com/T5495">filing a feature request with Phabricator</a> for the ability to warn when no mailing list is subscribed to a code review.</p></li><li><p>James Molloy has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74269">shared some rough benchmark data on LLVM targeting Cortex-A57</a>. For SPEC, LLVM is apparently less than 5% behind GCC for most benchmarks. James also lists a number of missed optimisation opportunities he's noticed so far in comparing the output.</p></li><li><p>Alexander Kornienko <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74314">questions whether it's time to bump the minimum Python requirement from 2.5 to 2.7</a>. Replies o the thread made the distinction between the minimum to run tests using lit (which is written in Python) and the minimum for tooling scripts that may need to be less portable. Despite 2.5 being ancient, the reason for wanting to support it is for long-lived releases such as RHEL.</p></li><li><p>Diego Novillo <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74351">suggests turning on debug column info by default</a>. He found almost no difference in compile time and only a 1% growth in debug info size. There seems to be support for doing this, with the only concern being that some debuggers might not interpret the data properly leading to odd behaviour. David Blaikie found a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/74376">few regressions in the gdb test suite</a>, but has yet to investigate further.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A significant overhaul of how vector lowering is done in the x86 backend has been started. While it's under development it's off by default, though it's hoped that in times there will be measurable performance improvements on benchmarks conducive to vectorization. <a href="http://reviews.llvm.org/rL211888">r211888</a> and more.</p></li><li><p>X86 FastISel will use EFLAGS directly when lowering select instructions if the condition comes from a compare. It also now supports floating-point selects among other improvements. <a href="http://reviews.llvm.org/rL211543">r211543</a>, <a href="http://reviews.llvm.org/rL211544">r211544</a>, and more.</p></li><li><p>ScaledNumber has been split out from BlockFrequencyInfo into the Support library. <a href="http://reviews.llvm.org/rL211562">r211562</a>.</p></li><li><p>The loop vectorizer now features <code>-Rpass-missed</code> and <code>-Rpass-analysis</code> reports. <a href="http://reviews.llvm.org/rL211721">r211721</a>.</p></li><li><p>The developer documentation has been updated to clarify that although you can use Phabricator to submit code for review, you should also ensure the relevant -commits mailing list is added as a subscriber on the review and be prepared to respond to comments there. <a href="http://reviews.llvm.org/rL211731">r211731</a>.</p></li><li><p>COMDATs have been added to the IR. What's a COMDAT? <a href="http://stackoverflow.com/a/2440933">StackOverflow has you covered</a>. <a href="http://reviews.llvm.org/rL211920">r211920</a>.</p></li><li><p>The NVPTX backend saw a whole series of commits. <a href="http://reviews.llvm.org/rL211930">r211930</a>, <a href="http://reviews.llvm.org/rL211932">r211932</a>, <a href="http://reviews.llvm.org/rL211935">r211935</a>, and more.</p></li><li><p>LLVM gained an abstraction for a random number generator (RNG). <a href="http://reviews.llvm.org/rL211705">r211705</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A nice little diagnostic improvement has been added for when the user accidentally puts braces before the identifer, e.g. <code>int [4] foo;</code>. <a href="http://reviews.llvm.org/rL211641">r211641</a>.</p></li><li><p>OpenMP learned the 'section' directive (and some more, see the full commit logs). <a href="http://reviews.llvm.org/rL211685">r211685</a>, <a href="http://reviews.llvm.org/rL211767">r211767</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Support for ARM EHABI unwinding was added to libunwind. <a href="http://reviews.llvm.org/rL211743">r211743</a>.</p></li><li><p>The lldb Machine Interface gained a number of new commands and bug fixes. <a href="http://reviews.llvm.org/rL211607">r211607</a>.</p></li></ul>
- LLVM Weekly - #25, Jun 23rd 2014https://blog.llvm.org/2014/06/llvm-weekly-25-jun-23rd-2014.htmlMon, 23 Jun 2014 03:31:00 +0000https://blog.llvm.org/2014/06/llvm-weekly-25-jun-23rd-2014.html<p>Welcome to the twenty-fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/25">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Facebook have released a number of clang plugins they have been using internally. This includes plugins to the clang analyzer primarily for iOS development as well as a plugin to export the Clang AST to JSON. The code is <a href="https://github.com/facebook/facebook-clang-plugins">available on Github</a> and they have started a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37318">discussion on the mailing list</a> about moving some of this code upstream.</p><p>This week saw the <a href="http://lists.cs.uiuc.edu/pipermail/llvm-announce/2014-June/000053.html">release</a> of LLVM and Clang 3.4.2. This is a bug-fix release which maintains ABI and API compatibility with 3.4.1.</p><p>Clang's C++ status page <a href="http://clang.llvm.org/cxx_status.html#cxx17">now lists C++1z feature status</a>.</p><h3>On the mailing lists</h3><ul><li><p>Rafael EspÃndola has started a thread to discuss <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73948">clarification on the backward compatibility promises of LLVM</a>. He summarises what seems to be the current policy (old .bc is upgraded upon read, there is no strong guarantee on .ll compatibility). Much of the subsequent discussion is about issues such as compatibility with metadata format changes.</p></li><li><p>Duncan P.N. Exon Smith has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73968">review of the new pass manager</a> in its current form. He starts with a high-level overview of what Chandler Carruth's new PassManager infrastructure offers and has a list of queries and concerns. There are no responses yet, but it's worth keeping your eyes on this thread if you're interested in LLVM internals development.</p></li><li><p>This week has brought two separate proposals for LLVM code coverage support (neither of which have any replies at the time of writing). Christian Holler has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73919">proposed inclusion of LLCov code</a>. This is a module pass that instruments basic blocks with calls to functions that will track coverage. The current LLCov code is <a href="https://github.com/choller/LLCov">available on Github</a>. Alex L has also posted a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37289">detailed proposal on improving code coverage support for Clang and LLVM</a>. He is looking for feedback on the approach before starting to submit patches.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The LLVM global lock is dead, and the LLVM Programmer's Manual has been updated to reflect this. <code>llvm_start_multithreaded</code> and <code>llvm_stop_multithreaded</code> have been removed.<br /><a href="http://reviews.llvm.org/rL211277">r211277</a>, <a href="http://reviews.llvm.org/rL211287">r211287</a>.</p></li><li><p>The patchset to improve MergeFunctions performance from O(NxN) to O(N x log(N)) has finally been completely merged. <a href="http://reviews.llvm.org/rL211437">r211437</a>, <a href="http://reviews.llvm.org/rL211445">r211445</a> and more.</p></li><li><p>Range metadata can now be attached to call and invoke (previously it could only be attached to load). <a href="http://reviews.llvm.org/rL211281">r211281</a>.</p></li><li><p>ConvertUTF in the Support library was modified to find the maximal subpart of an ill-formed UTF-8 sequence. <a href="http://reviews.llvm.org/rL211015">r211015</a>.</p></li><li><p>LoopUnrollPass will now respect loop unrolling hints in metadata. <a href="http://reviews.llvm.org/rL211076">r211076</a>.</p></li><li><p>The R600 backend has been updated to make use of LDS (Local Data Share) and vectors for private memory. <a href="http://reviews.llvm.org/rL211110">r211110</a>.</p></li><li><p>X86FastISel continues to improve with optimisation for predicates, cmp folding, and support for 64-bit absolute relocations. <a href="http://reviews.llvm.org/rL211126">r211126</a>, <a href="http://reviews.llvm.org/rL211130">r211130</a>.</p></li><li><p>The SLPVectorizer (superword-level parallelism) will now recognize and vectorize non-SIMD instruction patterns like sequences of fadd,fsub or add,sub. These will be vectorized as vector shuffles if they are profitable. <a href="http://reviews.llvm.org/rL211339">r211339</a>.</p></li><li><p>LLVM can now generate native unwind info on Win64. <a href="http://reviews.llvm.org/rL211399">r211399</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang's OpenMP implementation now contains initial support of the 'reduction' clause, <code>#pragma omp for</code>, the 'schedule' clause, the 'ordered' clause, and the 'nowait' clause. <a href="http://reviews.llvm.org/rL211007">r211007</a>, <a href="http://reviews.llvm.org/rL211140">r211140</a>, <a href="http://reviews.llvm.org/rL211342">r211342</a>, <a href="http://reviews.llvm.org/rL211347">r211347</a>, <a href="http://reviews.llvm.org/rL211352">r211352</a>.</p></li><li><p>MS ABI support continues with the merging of support for x86-64 RTTI. <a href="http://reviews.llvm.org/rL211041">r211041</a>.</p></li><li><p>The <code>-std=c+++1z</code> flag was added to enable support for C++17 features. <a href="http://reviews.llvm.org/rL211030">r211030</a>.</p></li><li><p>The clang User's Manual has been expanded with documentation for profile-guided optimisation with instrumentation. <a href="http://reviews.llvm.org/rL211085">r211085</a>.</p></li><li><p>Emission of ARM NEON intrinsics has been totally rewritten to be easier to read and maintain as well as to provide better protection against coding errors. <a href="http://reviews.llvm.org/rL211101">r211101</a>.</p></li></ul><h3>Other project commits</h3><ul><li>compiler-rt now offers add, sub, and mul for IEEE quad precision floating point. <a href="http://reviews.llvm.org/rL211312">r211312</a>, <a href="http://reviews.llvm.org/rL211313">r211313</a>.</li></ul>
- LLVM Weekly - #24, Jun 16th 2014https://blog.llvm.org/2014/06/llvm-weekly-24-jun-16th-2014.htmlMon, 16 Jun 2014 04:54:00 +0000https://blog.llvm.org/2014/06/llvm-weekly-24-jun-16th-2014.html<p>Welcome to the twenty-fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/24">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><ul><li><p>Philip Reames has written another blog post about the support for precise relocating GC he has been working on with his colleagues. In this post, he <a href="http://www.philipreames.com/Blog/2014/06/12/ir-restrictions-for-late-safepoint-placement/">describes the IR restrictions for late safepoint placement</a>.</p></li><li><p>Videos from this year's EuroLLVM conference are <a href="http://llvm.org/devmtg/2014-04/">now available</a>. Enjoy!</p></li><li><p>Evan Swick has written a <a href="http://www.eswick.com/2014/06/inside-swift/">blog post about Swift internals</a> using information gleaned from reverse engineering Swift binaries and the runtime.</p></li><li><p>The next Paris LLVM social will <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73838">take place on June 23rd</a>.</p></li><li><p>The next Cambridge LLVM Social will <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73717">take place on the 25th of June</a>.</p></li></ul><h3>On the mailing lists</h3><ul><li><p>George Burgess has posted to the list to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73724">announce he'll be interning with Google and working on a new alias analysis algorithm for LLVM</a>. He will be implementing an algorithm based on <a href="http://www.cse.cuhk.edu.hk/lyu/_media/paper/pldi2013.pdf">this paper</a>. His full proposal is <a href="https://docs.google.com/document/d/1nGFKMmr-HbdEiag9G1GeWurgOV0CweSUjLXFr3LAwqg/edit">available here</a>.</p></li><li><p>Tim Northover has written an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/192081">RFC on adding cmpxchg weak to the LLVM IR</a>. This seems to have been rapidly accepted as patches were commited this week.</p></li><li><p>Mark Tullsen is working on a tool that allows programmers to write custom program properties in a high level DSL. They are using libclang but are <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37229">missing the ability to perform transformations on the AST</a>. David Chisnall gives a good <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37236">motivation for why AST transformations are not supported</a>.</p></li><li><p>Apple are <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73730">advertising for engineers to join their Swift team</a>. This started a discussion about what the rules about job postings to the LLVM list should be and also elicited <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37217">another response from Chris Lattner on whether Swift will be open-sourced</a>. "You can imagine that many of us want it to be open source and part of llvm, but the discussion hasn't happened yet, and won't for some time."</p></li><li><p>Alp Toker has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73768">announced to those using LLVM</a> that the llvm/Config/config.h header is becoming internal to the LLVM source tree. Out-of-tree LLVM-based projects should be updated.</p></li><li><p>Tom Stellard has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73721">announced to the list</a> that <code>setOperationAction(ISD::SELECT_CC, MVT::Other, Expand)</code> is no longer supported and you must explicitly set the <code>SELECT_CC</code> operations for each supported type.</p></li><li><p>A <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37258">pre-reminder for LLVM 3.5</a>. The process will be starting in mid-July (more details to come later).</p></li></ul><h3>LLVM commits</h3><ul><li><p>A weak variant of cmpxchg has been added to the LLVM IR, as has been <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/192081">argued for</a> on the mailing list. Weak cmpxchg allows failure and the operation returns <code>{iN, i1}</code> (in fact, for uniformity all cmpxchg instructions do this now). According to the commit message, this change will mean legacy assembly IR files will be invalid but legacy bitcode files will be upgraded during read. <a href="http://reviews.llvm.org/rL210903">r210903</a>.</p></li><li><p>X86 FastISel gained support for handling a bunch more intrinsics. <a href="http://reviews.llvm.org/rL210709">r210709</a>, <a href="http://reviews.llvm.org/rL210720">r210720</a> and more. FastISel also saw some target-independent improvements <a href="http://reviews.llvm.org/rL210742">r210742</a>.</p></li><li><p>This week there were many updates to the MIPS backend for mips32r6/mips64r6. e.g. <a href="http://reviews.llvm.org/rL210899">r210899</a>, <a href="http://reviews.llvm.org/rL210784">r210784</a> and many more.</p></li><li><p>NoSignedWrap, NoUnsignedWrap and Exact flags are now exposed to the SelectionDAG. <a href="http://reviews.llvm.org/rL210467">r210467</a>.</p></li><li><p>Support has been added for variable length arrays on the Windows on ARM Itanium ABI. <a href="http://reviews.llvm.org/rL210489">r201489</a>.</p></li><li><p>Some simple reordering of fields in Value and User saves 8 bytes of padding on 64-bit. <a href="http://reviews.llvm.org/rL210501">r210501</a>.</p></li><li><p>FastISel will now collect statistics on when it fails with intrinsics. <a href="http://reviews.llvm.org/rL210556">r210556</a>.</p></li><li><p>The MIPS backend gained support for jr.hb and jalr.hb (jump register with hazard barrier, jump and link register with hazard barrier). <a href="http://reviews.llvm.org/rL210654">r210654</a>.</p></li><li><p>AArch64 gained a basic schedule model for the Cortex-A57. <a href="http://reviews.llvm.org/rL210705">r210705</a>.</p></li><li><p>LLVM has transitioned to using <code>std::error_code</code> instead of <code>llvm::error_code</code>. <a href="http://reviews.llvm.org/rL210687">r210687</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The <code>-Wdate-time</code> preprocessor warning from GCC has been implemented. This is useful when trying to create reproducible builds. <a href="http://reviews.llvm.org/rL210511">r210511</a>.</p></li><li><p>Loop unroll pragma support was added. <a href="http://reviews.llvm.org/rL210667">r210667</a>.</p></li><li><p>Yet more progress has been made on MS ABI compatibility. e.g. <a href="http://reviews.llvm.org/rL210813">r210813</a>, <a href="http://reviews.llvm.org/rL210637">r210637</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxx gained an implementation of <code>string_view</code> as proposed in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4023.html">N4023</a>. <a href="http://reviews.llvm.org/rL210659">r210659</a>.</p></li><li><p>Some of the iOS8/OS X Yosemite specific lldb support has been merged. <a href="http://reviews.llvm.org/rL210874">r210874</a>.</p></li></ul>
- LLVM Weekly - #23, Jun 9th 2014https://blog.llvm.org/2014/06/llvm-weekly-23-jun-9th-2014.htmlMon, 09 Jun 2014 04:24:00 +0000https://blog.llvm.org/2014/06/llvm-weekly-23-jun-9th-2014.html<p>Welcome to the twenty-third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/23">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Philip Reames has <a href="http://www.philipreames.com/Blog/2014/06/04/code-for-late-safepoint-placement-available/">announced that code for late safepoint placement is now available</a>.<br />This is a set of patches to LLVM from Azul Systems that aim to support precise relocating garbage collection in LLVM. Phlip has a long list of questions where he is seeking feedback from the community on how to move forwards with these patches. There's not been much response so far, hopefully it will come soon as I know there are many communities who are very interested in seeing better GC support in LLVM (e.g. Rust, Ocaml).</p><p>The biggest LLVM news this week is of course the announcement of <a href="https://developer.apple.com/swift/">the Swift programming language</a> from Apple. Its development was led by Chris Lattner, original author of LLVM. He has some more info about Swift <a href="https://developer.apple.com/swift/">on his website</a>. There is no source release as of yet, and <a href="http://article.gmane.org/gmane.comp.compilers.clang.user/493">no indication</a> from Apple as to whether it will remain proprietary. Either way, it's an interesting development. Chris Lattner is now on Twitter and has been <a href="https://twitter.com/clattner_llvm/status/474411823223959552">passing out tidbits about the Swift implementation</a>.</p><p>LunarG have <a href="http://lunarg.com/glassymesa/">announced the Glassy Mesa project</a>. This project, funded by Valve, will explore increasing game performance in Mesa through improvements in the shader compiler. The current parser and optimisation layer are replaced with glslang and the LLVM-based LunarGlass. More technical details are <a href="http://media.lunarg.com/wp-content/uploads/2014/06/GlassyMesaSlides-05Jun2014.pdf">available in the slide deck</a>.</p><p>Sébastien Métrot has released <a href="https://github.com/meeloo/xspray">xspray</a>, a frontend for lldb on OS X. One of its interesting features is the inbuilt support for plotting your data.</p><p>With all the LLVM news recently, it seems <a href="http://www.google.com/trends/explore#q=llvm">search traffic for 'llvm' has skyrocketed</a>.</p><h3>On the mailing lists</h3><ul><li><p>Zachary Tuner has started a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73604">multi-threading and mutexes in LLVM</a>, following from his patches (currently in review) that tries to replace LLVM's own mutex implementation with <code>std::mutex</code> and <code>std::recursive_mutex</code>. The key questions are whether multi-threading should be a compile-time or tunetime parameter, what should happen if you attempt to acquire a mutex in an app with threading disabled, and whether debugging code for finding deadlocks should be included.</p></li><li><p>Sean Silva queries <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73597">whether stack maps should be marked as stable in LLVM 3.5</a> given that the feature now has a number of users, including WebKit. Andrew Trick <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73599">suggests another round of RFC</a> before this, and intends to submit another proposal in the coming week.</p></li><li><p>Gerolf Hoflehner is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73502">asking for feedback on his proposed instruction combiner pass</a>. This would run at the machine IR level and aims to overcome some of the deficiencies observed when combining instructions at the ISEL level.</p></li><li><p>A question has arisen over <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73465">whether LLVM 3.3/3.4 IR is backward compatible with 3.2</a>. This isn't a form of compatibility that LLVM offers, though Stephen Hines notes that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73563">Android maintains an LLVM 3.2 bitcode writer</a>.</p></li><li><p>Quite some time ago, Dennis Luehring drew attention to <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/31855">a case where the GCC optimiser seems to do better than Clang</a>. Benjamin Kramer and Richard Smith both submitted patches which <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/37067">now results in Clang acing this testcase</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The jumptable attribute has been introduced. If you mark a function with this attribute, references to it can be rewritten with a reference to the appropriate jump-instruction-table function pointer. <a href="http://reviews.llvm.org/rL210280">r210280</a>.</p></li><li><p>Support was added for Windows ARM exception handling data structures, including decoding them. <a href="http://reviews.llvm.org/rL209998">r209998</a>, <a href="http://reviews.llvm.org/rL210192">r210192</a>.</p></li><li><p>GlobalAlias can now point to an arbitrary ConstantExpression. See the commit message for a discussion of the consequences of this. <a href="http://reviews.llvm.org/rL210062">r210062</a>.</p></li><li><p>The subword level parallelism (SLP) vectorizer has been extended to support vectorization of getelementptr expressions. <a href="http://reviews.llvm.org/rL210342">r210342</a>.</p></li><li><p>The LLVM programmer's manual has been improved with an example of using IRBuilder. <a href="http://reviews.llvm.org/rL210354">r210354</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Semantic analysis to make sure a loop is in OpenMP canonical form has been committed. <a href="http://reviews.llvm.org/rL210095">r210095</a>.</p></li><li><p><code>__builtin_operator_new</code> and <code>__builtin_operator_delete</code> have been added. Some optimisations are allowed on these which would not be on <code>::operator new</code> and are intended for the implementation of things like std::allocator. <a href="http://reviews.llvm.org/rL210137">r210137</a>.</p></li><li><p>New pragmas have been introduced to give optimisation hints for vectorization and interleaving. You can now use <code>#pragma clang loop vectorize(enable)</code> as well as <code>vectorize(disable)</code>, <code>vectorize_width(n)</code>, <code>interleave(enable/disable)</code>, and <code>interleave_count(n)</code>. <a href="http://reviews.llvm.org/rL210330">r210330</a>.</p></li><li><p>Support for the MSVC++ ABI continues with the addition of <code>dynamic_cast</code> for MS. <a href="http://reviews.llvm.org/rL210377">r210377</a>.</p></li><li><p>Support for global named registers has been expanded slightly to allow pointer types to be held in these variables. <a href="http://reviews.llvm.org/rL210274">r210274</a>.</p></li><li><p>GCC's <code>-Wframe-larger-than=bytes</code> diagnostic is now supported. <a href="http://reviews.llvm.org/rL210293">r210293</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>A benchmarking-only mode has been added to the testsuite <a href="http://reviews.llvm.org/rL210251">r210251</a>.</p></li><li><p>A <a href="http://libcxx.llvm.org/ts1z_status.html">status page</a> for post-C++14 features in libcxx has been added. <a href="http://reviews.llvm.org/rL210056">r210056</a>.</p></li><li><p>An initial set of Makefiles has been committed to lld. <a href="http://reviews.llvm.org/rL210177">r210177</a>.</p></li><li><p>lldb gained support for inspecting enum members. <a href="http://reviews.llvm.org/rL210046">r210046</a>.</p></li><li><p>Polly can now be built without any GPLed software. <a href="http://reviews.llvm.org/rL210176">r210176</a>.</p></li></ul>
- LLVM Weekly - #22, Jun 2nd 2014https://blog.llvm.org/2014/06/llvm-weekly-22-jun-2nd-2014.htmlMon, 02 Jun 2014 07:39:00 +0000https://blog.llvm.org/2014/06/llvm-weekly-22-jun-2nd-2014.html<p>Welcome to the twenty-second issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects.LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Last week I expressed worry about GMANE not updating. I'm happy to report that it's back to normal now. Some of my readers might be interested in my <a href="http://www.raspberrypi.org/raspberry-pi-projects-at-the-maker-faire-bay-area/">account of the neat Raspberry Pi-based projects I saw at Maker Faire Bay Area</a>.</p><p>The canonical home for this issue <a href="http://llvmweekly.org/issue/22">can be found here at llvmweekly.org</a>. </p> <a name='more'></a><h3>News and articles from around the web</h3><p>David Given has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73349">shared</a> his partially complete backend for the VideoCore IV VPU as used in the BCM2835 in the Raspberry Pi. It would also be interesting to see a QPU LLVM backend now it has been <a href="http://www.raspberrypi.org/a-birthday-present-from-broadcom/">publicly documented</a>.</p><p>Documentation on how TableGen's DAGISel backend works <a href="https://github.com/draperlaboratory/fracture/wiki/How-TableGen%27s-DAGISel-Backend-Works">has been updated</a>.</p><p>The <a href="http://llvm-hpc-workshop.github.io/">LLVM Compiler Infrastructure in HPC Workshop</a> has been announced. This is a workshop to be held in conjunction with SC14. The deadline for the call for papers is September 1st.</p><p><a href="http://people.collabora.com/~pwith/gnome-clang/">Tartan</a> is a Clang analysis plugin for GLib and GNOME. To quote its homepage "The plugin works by loading gobject-introspection metadata for all functions it encounters (both functions exported by the code being compiled, if it is a library; and functions called by it). This metadata is then used to add compiler attributes to the code, such as non-NULL attributes, which the compiler can then use for static analysis and emitting extra compiler warnings."</p><h3>On the mailing lists</h3><ul><li><p>Jack Howarth has posted to ask <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36961">what can be done to merge the clang-omp merge along more quickly</a>. Andrey Bokhanko followed up with some <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36974">clarifications and elaborations</a>. Hal Finkel has also <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36981">more clearly described the OpenMP language support vs the OpenMP runtime library</a>.</p></li><li><p>Simon Cook posed an interesting question about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73365">a backend with 32-bit registers for load/store but otherwise mostly 16 bit</a>. Sadly there are no answers yet.</p></li><li><p>Qiong Cai has a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73325">few questions on LLVM JIT</a>. Philip Reames <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73339">answers concisely</a>.</p></li><li><p>Tim Northover <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73355">proposes adding load linked and store conditional atomic instructions to LLVM IR</a>. David Chisnall has a thorough <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73413">answer to the proposal</a> that suggests weak cmpxchg would be an easier and overall better addition.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A LoadCombine pass was added, though is disabled by default for now. <a href="http://reviews.llvm.org/rL209791">r209791</a>.</p></li><li><p>AAPCS-VFP has been taught to deal with Cortex-M4 (which only has single precision floating point). <a href="http://reviews.llvm.org/rL209650">r209650</a>.</p></li><li><p>InstructionCombining gained support for combining GEPs across PHI nodes. <a href="http://reviews.llvm.org/rL209843">r209843</a>.</p></li><li><p>Vectorization of intrinsics such as powi, cttz and ctlz is now allowed. <a href="http://reviews.llvm.org/rL209873">r209873</a>.</p></li><li><p>MIPS64 long branch has been optimised to be 3 instructions smaller. <a href="http://reviews.llvm.org/rL209678">r209678</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>OpenMP implementation continues. Parsing and Sema have been implemented for OMPAlignedClause. <a href="http://reviews.llvm.org/rL209816">r209816</a>.</p></li><li><p>The <code>-Rpass-missed</code> and <code>-Rpass-analysis</code> flags have been added. pass-missed is used by optimizers to inform the user when they tried to apply an optimisation but couldn't, while pass-analysis is used to report analysis results back to the user. A followup commit documents the family of flags. <a href="http://reviews.llvm.org/rL209839">r209839</a>, <a href="http://reviews.llvm.org/rL209841">r209841</a>.</p></li><li><p>The clang optimize pragma has now been documented. <a href="http://reviews.llvm.org/rL209738">r209738</a>.</p></li><li><p>There has been some API refactoring. The release and take methods were removed from ActionResult and Owned removed from Sema. <a href="http://reviews.llvm.org/rL209800">r209800</a>, <a href="http://reviews.llvm.org/rL209812">r209812</a>.</p></li></ul><h3>Other project commits</h3><ul><li>ThreadSanitizer has seen a refactoring of storage of meta information for heap blocks and sync objects. <a href="http://reviews.llvm.org/rL209810">r209810</a>.</li></ul>
- LLVM Weekly - #21, May 26th 2014https://blog.llvm.org/2014/05/llvm-weekly-21-may-26th-2014.htmlMon, 26 May 2014 04:32:00 +0000https://blog.llvm.org/2014/05/llvm-weekly-21-may-26th-2014.html<p>Welcome to the 21st issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'm back in the UK and mostly recovered from the ensuing jetlag. I am however disturbed that all mailing lists on <a href="http://gmane.org/">GMANE</a> don't seem to have been updated for the past week and have been unable to find any explanation of what is going on online. GMANE is an important and massively useful aggregrator and archiver of free software development lists and I really hope these are only temporary problems. For this issue, I have instead linked directly to the mailman archives at UIUC.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/21">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Jonathan Mah has written a <a href="http://devetc.org/code/2014/05/17/safe-and-sane-key-paths.html">Clang plugin for checking key path strings in Objective C code</a>. The implementation is <a href="https://github.com/jmah/Clang-KeyPathValidator">available on Github</a>.</p><p>LWN has published an <a href="http://lwn.net/Articles/598486/">article about ThreadSanitizer v2</a>.</p><p>This week, the merge of the AArch64 and the Apple-contributed ARM64 backends was completed. The old AArch64 was deleted and the result of merging code from AArch64 in to ARM64 was renamed to AArch64.</p><p>A paper '<a href="http://arxiv.org/abs/1405.4565">Static energy consumption analysis of LLVM IR programs</a>' has been posted to arXiv.org.</p><h3>On the mailing lists</h3><ul><li><p>Philip Reames wonders <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-May/073180.html">why can't atomic loads and stores handle floats</a>. David Chisnall has a good followup which explains <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-May/073191.html">why just bitcasting floats to use atomic load/store on them is far from ideal</a>.</p></li><li><p>Louis Gerbarg has shared an <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-May/073125.html">RFC on indexing of structs vs arrays in getelementpointr</a>. This is inspired by his recent work to optimise getelementptr across different basic blocks.</p></li><li><p>Jingyue Wu <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-May/073079.html">asks for advice on sinking incoming values of a PHI node in CodeGenPrepare</a>. Louis Gerbarg points out that <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-May/073096.html">these optimisations are similar to his recent GetElementPtr work</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new attribute, 'nonnull' has been added. When applied to a parameter or return pointer this indicates it is not null, which may allow additional optimisations (at least, avoiding comparisons between that value and null). <a href="http://reviews.llvm.org/rL209185">r209185</a>, <a href="http://reviews.llvm.org/rL209193">r209193</a>.</p></li><li><p>The llvm.arm.undefined intrinsic has been added. This is used to generate the 0xde opcode on ARM. It takes an integer parameter, which might be used by the OS to implement custom behaviour on the trap. <a href="http://reviews.llvm.org/rL209390">r209390</a>.</p></li><li><p>The MIPS disassembler has seen some work. Some support has been added for MIPS64r6 and various issues fixed. <a href="http://reviews.llvm.org/rL209415">r209415</a>.</p></li><li><p>LLVM learned the <code>-pass-remarks-missed</code> and <code>-pass-remarks-analysis</code> command line options. <code>-pass-remarks-missed</code> shows diagnostics when a pass tried to apply a transformation but couldn't. <code>-pass-remarks-analysis</code> shows information about analysis results. <a href="http://reviews.llvm.org/rL209442">r209442</a>.</p></li><li><p>The documentation for the <code>llvm.mem.parallel_loop_access</code> metadata has been updated. <a href="http://reviews.llvm.org/rL209507">r209507</a>.</p></li><li><p>Old AArch64 has been removed and ARM64 renamed to AArch64. <a href="http://reviews.llvm.org/rL209576">r209576</a>, <a href="http://reviews.llvm.org/rL209577">r209577</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>clang-format has seen more JS support. It can now reformat ES6 arrow functions and ES6 destructuring assignments. <a href="http://reviews.llvm.org/rL209112">r209112</a>, <a href="http://reviews.llvm.org/rL209113">r209113</a>.</p></li><li><p>Experimental checkers for the clang static analyzer are <a href="http://clang.llvm.org/analyzer/alpha_checks.html">now documented</a>. <a href="http://reviews.llvm.org/rL209131">r209131</a>.</p></li><li><p>Support was added to clang for global named registers, using the LLVM intrinsics which were recently added. <a href="http://reviews.llvm.org/rL209149">r209149</a>.</p></li><li><p>Clang learned the <code>no_split_stack</code> attribute to turn off split stacks on a per-function bases. <a href="http://reviews.llvm.org/rL209167">r209167</a>.</p></li><li><p>Clang learned the <code>flatten</code> attribute. This causes calls within the function to be inlined where possible. <a href="http://reviews.llvm.org/rL209217">r209217</a>.</p></li><li><p>An initial version of codegen for pragma omp simd has been committed. This also adds CGLoopInfo which is a helper for marking memory instructions with <code>llvm.mem.parallel_loop_access</code> metadata. <a href="http://reviews.llvm.org/rL209411">r209411</a>.</p></li><li><p>The pragma <code>clang optimize {on,off}</code> has been implemented. This allows you to selectively disable optimisations on certain functions. <a href="http://reviews.llvm.org/rL209510">r209510</a>.</p></li><li><p>An implementation of Microsoft ABI-compatible RTTI (run-time type information) has landed. <a href="http://reviews.llvm.org/rL209523">r209523</a>.</p></li></ul><h3>Other project commits</h3><ul><li>'Chained origins' as used by MemorySanitizer has been redesigned. <a href="http://reviews.llvm.org/rL209284">r209284</a>.</li></ul>
- LLVM Weekly - #20, May 19th 2014https://blog.llvm.org/2014/05/llvm-weekly-20-may-19th-2014.htmlMon, 19 May 2014 04:48:00 +0000https://blog.llvm.org/2014/05/llvm-weekly-20-may-19th-2014.html<p>Welcome to the twentieth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This week's issue is perhaps a little less thorough than normal. I've been in San Francisco most of the week for Maker Faire this weekend, where I was at the Raspberry Pi booth with some other Foundation members. As this issue goes out, I'll be enjoying my last day in SF before heading to the airport for the long flight home and the ensuing jetlag.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/20">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The WebKit blog features an <a href="https://www.webkit.org/blog/3362/introducing-the-webkit-ftl-jit/">excellent and detailed article about the new Fourth Tier LLVM JIT</a> which sheds light on the how and why.</p><p>The <a href="http://neu.andrometa.net/">Neu framework</a> has recently been announced. It is a C++11 framework, collection of programming languages and software system designed for artificial intelligence applications and technical computing in general. It makes use of the LLVM MC JIT for its NPL language as well as generating high performance neural networks.</p><h3>On the mailing lists</h3><ul><li><p>Tim Northover has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73034">RFC on removing the AArch64 backend and renaming ARM64 to AArch64</a>. This would represent the culmination of the work to merge the two backends.</p></li><li><p>In case you're wondering about when we'll see LLVM/Clang 3.5, Bill Wending has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36750">posted to inform us the current plan is to start testing in July and target a release in August</a>.</p></li><li><p>I always enjoy pointing out excellent answers to questions on the mailing lists. The large and helpful community is one of the greatest assets of LLVM. This week, I draw special attention to Jordan Rose's <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36755">answer to a question about tracking a function parameter with the static analyzer</a>.</p></li><li><p>The testing phase for LLVM 3.4.2 <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/73069">has started</a>. According to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72919">the schedule</a> it should be released on May 25 provided the testing phase didn't raise issues. Tom Stellard is also looking for backup release managers.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The inliner has been taught how to preserve musttail invariants. <a href="http://reviews.llvm.org/rL208910">r208910</a>.</p></li><li><p>A new C API has been added for a thread yielding callback. <a href="http://reviews.llvm.org/rL208945">r208945</a>.</p></li><li><p>Another patch in the series to improve MergeFunctions performance has been committed. A total ordering has now been implemented among operations. <a href="http://reviews.llvm.org/rL208973">r208973</a>, <a href="http://reviews.llvm.org/rL208976">r208976</a>.</p></li><li><p>The ARM load/store optimisation pass has been fixed to work with Thumb1. <a href="http://reviews.llvm.org/rL208992">r208992</a>.</p></li><li><p>GlobalValue has been split into GlobalValue and GlobalObject, which allows a code to statically accept a Function or a GlobalVariable but not an alias. <a href="http://reviews.llvm.org/rL208716">r208716</a>.</p></li><li><p>Integral reciprocal was optimised to not use division. This optimisation was influenced by <a href="http://www.cs.utah.edu/~regehr/souper/">Souper</a>. <a href="http://reviews.llvm.org/rL208750">r208750</a>. Another optimisation opportunity uncovered by Souper was signed icmp of -(zext V). <a href="http://reviews.llvm.org/rL208809">r208809</a>.</p></li><li><p>I rather like that these transforms for single bit tests were <a href="http://rise4fun.com/Z3/Pmsh">verified with Z3</a>. <a href="http://reviews.llvm.org/rL208848">r208848</a>.</p></li><li><p>PowerPC gained global named register support, for r1, r2 and r13 (depending on the subtarget). <a href="http://reviews.llvm.org/rL208509">r208509</a>.</p></li><li><p>Documentation was added for the ARM64 BigEndian NEON implementation. <a href="http://reviews.llvm.org/rL208577">r208577</a>.</p></li><li><p>The constant folder is now better at looking through bitcast constant expressions. This is a first step towards fixing this <a href="http://ericniebler.com/2014/04/27/range-comprehensions/">poor performance of these range comprehensions</a>. <a href="http://reviews.llvm.org/rL208856">r208856</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Initial support for MS ABI compliant RTTI mangling has been committed. <a href="http://reviews.llvm.org/rL208661">r208661</a>, <a href="http://reviews.llvm.org/rL208509">r208668</a>.</p></li><li><p>Clang will no longer copy objects with trivial, deleted copy constructors. This fixes bugs and improves ABI compatibility with GCC and MSVC. <a href="http://reviews.llvm.org/rL208786">r208786</a>. Though the itanium C++ ABI part was reverted for now. <a href="http://reviews.llvm.org/rL208836">r208836</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The LLDB Machine Interface has been committed. This is an implementation of the <a href="https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html">GDB Machine Interface</a>, useful for implementing your own frontend to LLDB. <a href="http://reviews.llvm.org/rL208972">r208972</a>.</p></li><li><p>AddressSanitizer started to gain some windows tests. <a href="http://reviews.llvm.org/rL208554">r208554</a>, <a href="http://reviews.llvm.org/rL208859">r208859</a>, <a href="http://reviews.llvm.org/rL208873">r208873</a> and more.</p></li><li><p>The instrumented profiling library API was fixed to work with shared objects, and profiling is now supported for dlopened shared libraries.. <a href="http://reviews.llvm.org/rL208940">r208940</a>, <a href="http://reviews.llvm.org/rL209053">r209053</a>.</p></li></ul>
- LLVM Weekly - #19, May 12th 2014https://blog.llvm.org/2014/05/llvm-weekly-19-may-12th-2014.htmlMon, 12 May 2014 06:47:00 +0000https://blog.llvm.org/2014/05/llvm-weekly-19-may-12th-2014.html<p>Welcome to the ninteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'm flying out to San Francisco tomorrow and will be there for the Bay Area Maker Faire at the weekend with some other Raspberry Pi Foundation people. If you're around, be sure to say hi.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/19">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>LLVM 3.4.1 <a href="http://blog.llvm.org/2014/05/llvm-341-release.html">has been released</a>. This is a bug-fix release so offers API and ABI compatibility with LLVM 3.4. Thanks to everyone who contributed to the release by suggesting or backporting patches, and for testing.</p><p>John Regehr has <a href="http://blog.regehr.org/archives/1146">shared some early results and discussion</a> on using <a href="https://github.com/google/souper/">Souper</a> (a new superoptimizer for LLVM IR) in combination with Csmith and C-reduce in order to find missed optimisations and then produce minimal test cases. This has already resulted in a <a href="http://llvm.org/bugs/show_bug.cgi?id=19711">new performance bug being filed</a> with I'm sure many more to come.</p><p><a href="https://github.com/crange/crange">Crange</a>, a tool to index and cross-reference C/C++ source code built on top of Clang has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36677">been released</a>. It aims to offer a more complete database than e.g. ctags, though the running time on a large codebase like the Linux kernel is currently very high.</p><p><a href="https://github.com/go-llvm/llgo">llgo</a>, the LLVM-based compiler for Go is <a href="https://groups.google.com/forum/#!topic/llgo-dev/8uBfmIkGM88/discussion">now self-hosting</a>.</p><p>Last week I asked for benchmarks of the new <a href="https://trac.webkit.org/wiki/FTLJIT">JavascriptCore Fourth Tier LLVM JIT</a>. Arewefastyet from Mozilla now includes such results. FTLJIT <a href="http://arewefastyet.com/#machine=12&view=breakdown&suite=asmjs-apps">does particularly well on asm.js examples</a>.</p><h3>On the mailing lists</h3><ul><li><p>The merge of AArch64 in to ARM64 has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72832">made impressive progress</a>. It's likely the final switchover will take place this week, with AArch64 being deleted and ARM64 renamed to AArch64. Ana Pazos <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/187546">shared a list of bugs currently waiting to be squashed</a>.</p></li><li><p>Andy Lutomirski <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36685">requests that the llvm integer arithmetic with overflow intrinsics be exposed as C intrinsics</a>. It was pointed out that they <a href="http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins">actually are exposed</a> though Google is doing a poor job of indexing this fact, and in response a <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61129">bug has been filed with GCC</a> to expose similar intrinsics.</p></li><li><p>Suminda Dharmasena <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72850">kicked off a conversation about reducing or removing platform specific LLVM instructions</a>. The thread morphed into an interesting discussion about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72866">the issues arising from gaps in LLVM's coverage for atomic memory operations</a>.</p></li><li><p>Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72847">asks for input on the problem of safely suspending JITting threads through the C LLVM API</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new algorithm has been implemented for tail call marking. A build of clang now ends up with 470k calls in the IR marked as tail vs 375k before. The total tail call to loop conversions remains the same though. <a href="http://reviews.llvm.org/rL208017">r208017</a>.</p></li><li><p><code>llvm::function_ref</code> has been introduced and described in the LLVM programmers manual. It is a type-erased reference to a callable object. <a href="http://reviews.llvm.org/rL208025">r208025</a>, <a href="http://reviews.llvm.org/rL208067">r208067</a>.</p></li><li><p>Initial support for named register intrinsics (as previously discussed <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71567">on the mailing list</a> has landed. Right now, only the stack pointer is supported. Other non-allocatable registers could be supported with not too much difficulty, allocatable registers are much harder. <a href="http://reviews.llvm.org/rL208104">r208104</a>.</p></li><li><p>The <code>-disable-cfi</code> option has been removed. LLVM now requires assemblers to support cfi (control-flow integrity) directives in order to generate stack unwinding information. <a href="http://reviews.llvm.org/rL207979">r207979</a>.</p></li><li><p>The superword-level parallelism (SLP) pass is now enabled by default for link time optimisation. <a href="http://reviews.llvm.org/rL208013">r208013</a>.</p></li><li><p>The llvm-cov documentation has been expanded <a href="http://reviews.llvm.org/rL208098">r208098</a>.</p></li><li><p>The second and third patch of a series to improve MergeFunctions performance to <code>O(n*log(n))</code> has been merged. <a href="http://reviews.llvm.org/rL208173">r208173</a>, <a href="http://reviews.llvm.org/rL208189">r208189</a>.</p></li><li><p>The standard 'x86-64' CPU used as the default architecture now uses the Sandy Bridge scheduling model in the hope this provides a reasonable default over a wide range of modern x86-64 CPUs. <a href="http://reviews.llvm.org/rL208230">r208230</a>.</p></li><li><p>Custom lowering for the <code>llvm.{u|s}add.with.otherflow.i32</code> intrinsics as been added for ARM. <a href="http://reviews.llvm.org/rL208435">r208435</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>MSVC ABI compatibility has again been improved. Clang now understands that the 'sret' (a structure return pointer) is passed after 'this' for MSVC. <a href="http://reviews.llvm.org/rL208458">r208458</a>.</p></li><li><p>Initial codegen from OpenMP's <code>#pragma omp parallel</code> has landed. <a href="http://reviews.llvm.org/rL208077">r208077</a>.</p></li><li><p>Field references to struct names and C++11 aliases are now supported from inline asm. <a href="http://reviews.llvm.org/rL208053">r208053</a>.</p></li><li><p>Parsing and semantic analysis has been implemented for the OpenMP <code>proc_bind</code> clause. <a href="http://reviews.llvm.org/rL208060">r208060</a>.</p></li><li><p>clang-format gained initial support for JavaScript regex literals (yes, clang-format can reformat your JavaScript!). <a href="http://reviews.llvm.org/rL208281">r208281</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>libcxxabi gained support for ARM zero-cost exception handling. <a href="http://reviews.llvm.org/rL208466">r208466</a>.</p></li><li><p>In libcxx, std::vector gained Address Sanitizer support. <a href="http://reviews.llvm.org/rL208319">r208319</a>.</p></li><li><p>The test suite from <a href="http://web.cs.uh.edu/~openuh/">OpenUH</a> has been added to the openmp repository. <a href="http://reviews.llvm.org/rL208472">208472</a>.</p></li></ul>
- LLVM 3.4.1 Releasehttps://blog.llvm.org/2014/05/llvm-341-release.htmlFri, 09 May 2014 10:28:00 +0000https://blog.llvm.org/2014/05/llvm-341-release.htmlLLVM 3.4.1 has been released! This is a bug-fix release that contains fixes for the AArch64, ARM, PowerPC, R600, and X86 targets as well as a number of other fixes in the core libraries.<br /><br />The LLVM and Clang core libraries in this release are API and ABI compatible with LLVM 3.4, so projects that make use of the LLVM and Clang API and libraries will not need to make any changes in order to take advantage of the 3.4.1 release.<br /><br />Bug-fix releases like this are very important for the project, because they help get critical fixes to users faster than the typical 6 month release cycle, and also make it easier for operating system distributors who in the past have had to track and apply bug fixes on their own.<br /><br />A lot of work went into this release, and special thanks should be given to all the testers who helped to qualify the release:<br /><br />Renato Golin<br />Sebastian DreÃler<br />Ben Pope<br />Arnaud Allard de Grandmaison<br />Erik Verbruggen<br />Hal Finkel<br />Nikola Smiljanic<br />Hans Wennborg<br />Sylvestre Ledru<br />David Fang<br /><br />In addition there were a number community members who spent time tracking down bugs and helping to resolve merge conflicts in the 3.4 branch. This is what made this release possible, so thanks to everyone<br />else who helped.<br /><br />I would like to keep the trend of stable releases going to 3.5.x and beyond (Maybe even 3.4.2 if there is enough interest), but this can only be<br />done with the help of the community. If you would like to help with the next stable release or even regular release, then the next time you see a proposed release schedule on the mailing list, let the release manager know you can help. We can never have too many volunteers.<br /><br />Thanks again to everyone who helped make this release possible.<br /><br />-Tom<br /><br /><br /><br /><br /><br />
- LLVM Weekly - #18, May 5th 2014https://blog.llvm.org/2014/05/llvm-weekly-18-may-5th-2014.htmlMon, 05 May 2014 09:01:00 +0000https://blog.llvm.org/2014/05/llvm-weekly-18-may-5th-2014.html<p>Welcome to the eighteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'm going to be in the San Francisco area May 13th-20th with some other Raspberry Pi people. We'll be at Maker Faire Bay Area on the 17th and 18th. Let me know if there's anything else I should check out while over there.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/18">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Andrew Ruef has written a blog post about <a href="http://blog.trailofbits.com/2014/04/27/using-static-analysis-and-clang-to-find-heartbleed/">using static analysis and Clang to find the SSL heartbleed bug</a>. The code for the checker described in the blog post is <a href="https://github.com/awruef/find-heartbleed">available on Github</a>.</p><p>The FTL ('Fourth tier LLVM') Javascript JIT is <a href="https://trac.webkit.org/changeset/167958">now enabled in WebKit for Mac</a>. The WebKit Wiki has <a href="https://trac.webkit.org/wiki/FTLJIT">more information</a>. I haven't seen any public benchmark figures. Please do share if you have any.</p><p>Eli Bendersky has written an article about <a href="http://eli.thegreenplace.net/2014/05/01/modern-source-to-source-transformation-with-clang-and-libtooling/">how to use libTooling to implement source to source transformations</a>.</p><p>The next <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/3828">Paris LLVM Social</a> will take place on May 5th (i.e. this evening).</p><p>The LLVM Bay Area social <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36443">will take place on May 8th</a>. Please RSVP if you are interested.</p><h3>On the mailing lists</h3><ul><li><p>Discussion is still going on regarding <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72466">last week's proposal to add intrinsics for safe division</a>. Philip Reames has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72588">shared his reasoning againt the proposal</a>. This triggered a <em>lot</em> of discussion which is unfortunately more than I have time to summarise.</p></li><li><p>Kevin Modzelewski is working on exceptions for Pyston, the LLVM-based Python JIT and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72668">asks for advice/experiences on how others have implemented them in projects like VMKit</a>. There are a number of useful responses.</p></li><li><p>Alp Toker <a href="http://article.gmane.org/gmane.comp.compilers.clang.scm/97880">suggests adding a coding style policy to discourage excessive use of default arguments</a>.</p></li><li><p>Yi Kong has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72598">suggested improvements to LNT for benchmarking</a>. One of the concerns raised in followup responses is that benchmark results may not be stable and may take too long to be practical on e.g. ARM hardware. Chris Matthews suggests <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72619">performing a geometric mean similar to the SPEC benchmarks</a> as an alternative to a plain total execution time metric.</p></li><li><p>Dario Domizioli has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36314">posted an RFC for an optnone pragma</a>. This proposal triggered robust discussion about whether there is any advantage to supporting this in addition to the optnone function attribute, though it seems as though there is enough support for the feature for it to make its way in.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The patch to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72366">perform common subexpression elimination for a group of getelementptrs</a> that was discussed a couple of weeks ago has been merged. It is currently only enabled for the NVPTX backend. <a href="http://reviews.llvm.org/rL207783">r207783</a>.</p></li><li><p>X86 code generation has been implemented for the musttail function attribute. <a href="http://reviews.llvm.org/rL207598">r207598</a>.</p></li><li><p>Pass run listeners were added to the pass manager. This adds C/C++ APIs to enable fine-grain progress report and safe suspension points. See the commit message for more info <a href="http://reviews.llvm.org/rL207430">r207430</a>.</p></li><li><p>The optimisation remark system has started to be used, with calls to emitOptimizationRemark added to the loop unroller and vectorizer. <a href="http://reviews.llvm.org/rL207528">r207528</a>, <a href="http://reviews.llvm.org/rL207574">r207574</a>.</p></li><li><p>The SLPVectorizer gained the ability to recognize and vectorize intrinsic math functions. <a href="http://reviews.llvm.org/rL207901">r207901</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>NRVO (named return value optimisation) determination was rewritten. According to the commit message, "a variable now has NRVO applied if and only if every return statement in that scope returns that variable." Also, NRVO is performed roughly 7% more often in a bootstrap clang build. <a href="http://reviews.llvm.org/rL207890">r207890</a>.</p></li><li><p>libclang's documentation comment API has been split in to a separate header. <a href="http://reviews.llvm.org/rL207392">r207392</a>.</p></li><li><p>The SLPVectorizer (superword-level parallelism) is now disabled at O0, O1 and Oz. <a href="http://reviews.llvm.org/rL207433">r207433</a>. It was later re-enabled at Oz. <a href="http://reviews.llvm.org/rL207858">r207858</a>.</p></li><li><p>The libclang API now supports attributes 'pure', 'const', and 'noduplicate'. <a href="http://reviews.llvm.org/rL207767">r207767</a>.</p></li><li><p>The comment parser no longer attempts to validate HTML attributes (the previous solution was insufficient). <a href="http://reviews.llvm.org/rL207712">r207712</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p><code>R_MIPS_REL32</code> relocation are now supported in lld. <a href="http://reviews.llvm.org/rL207494">r207494</a>.</p></li><li><p>A collection of CTRL+C related issues were fixed in lldb. <a href="http://reviews.llvm.org/rL207816">r207816</a>.</p></li></ul>
- LLVM Weekly - #17, Apr 28th 2014https://blog.llvm.org/2014/04/llvm-weekly-17-apr-28th-2014.htmlMon, 28 Apr 2014 07:50:00 +0000https://blog.llvm.org/2014/04/llvm-weekly-17-apr-28th-2014.html<p>Welcome to the 17th issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Last week I wondered why the GCC logo is a <a href="http://commons.wikimedia.org/wiki/File:GNU_Compiler_Collection_logo.svg">GNU leaping out of an egg</a>. Thank you to everyone who wrote in to let me know it is a reference to EGCS. GCC was of course famously forked as EGCS which was later merged back in. Apparently this was pronounced by some as "eggs". Mystery solved.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/17">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>GCC 4.9.0 was <a href="http://gcc.gnu.org/ml/gcc/2014-04/msg00195.html">released last Tuesday</a>. See <a href="http://gcc.gnu.org/gcc-4.9/changes.html">here</a> for more detailed notes on changes in this release.</p><p>Honza HubiÄka wrote a blog post on the <a href="http://hubicka.blogspot.co.uk/2014/04/linktime-optimization-in-gcc-1-brief.html">history of linktime optimisation in GCC</a>, which was followed by a post containing a <a href="http://hubicka.blogspot.ca/2014/04/linktime-optimization-in-gcc-2-firefox.html">benchmark comparison of LTO in GCC vs LLVM</a>.</p><p>On Twitter, @lambdamix drew my attention to <a href="http://www.cs.umb.edu/~offner/files/flow_graph.pdf">Notes on Graph Algorithms Used in Optimizing Compilers</a> (PDF). I imagine it will be of interest to many LLVM Weekly readers.</p><h3>On the mailing lists</h3><ul><li><p>Michael Zolotukhin <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72466">proposes extending LLVM IR with new intrinsics for safe division</a>. These join the existing intrinsics for addition with overflow. Filip Pizlo follows up with a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72510">description of how it would be used for various potential language frontends</a>. Michael has also posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72533">detailed justification in answer to concerns raised</a>.</p></li><li><p>James Molloy <a href="http://article.gmane.org/gmane.comp.compilers.llvm.cvs/185388/">shares an updated on the AArch64 to ARM64 merge</a>, including time estimates for remaining tasks. The initial merge should be complete before LLVM 3.5. Additionally, Ana Pazos has gained permission to share <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72454/">relative SPEC2000 figures for ARM64 vs AArch64</a>.</p></li><li><p>Sylvestre Ledru <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36229">proposes removing outdated marketing material from the Clang website</a>. In particular, the performance comparisons are with GCC 4.0 or 4.2 which is of course rather outdated, particularly given how GCC has improved since then.</p></li><li><p>Kostya Serebryany reports that <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36234">AddressSanitizer and LeakSanitizer are finding many many leaks within Clang</a>. The bug tracking this is <a href="http://llvm.org/bugs/show_bug.cgi?id=19521">#19521</a>.</p></li><li><p>Tom Stellard has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72524">kicked off the second testing phase for LLVM and Clang 3.4.1</a>. This is expected to be the last release candidate, so 3.4.1 shouldn't be far away.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The 'musttail' marker which was <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71775">proposed several weeks ago</a> has been added. Unlike the 'tail' marker, musttail guarantees that tail call optimization will occur. Check the documentation added in the commit for a more detailed explanation. <a href="http://reviews.llvm.org/rL207143">r207143</a>.</p></li><li><p>The rewrite of BlockFrequencyInfo finally landed. A description of the advantages of the new algorithm is in the original commit message, <a href="http://reviews.llvm.org/rL206548">r206548</a>. After a series of bounces, it landed in <a href="http://reviews.llvm.org/rL206766">r206766</a>.</p></li><li><p>LLVM can now generate PE/COFF object files targeting 'Windows on ARM'. <a href="http://reviews.llvm.org/rL207345">r207345</a>.</p></li><li><p>A CallGraph strongly connected components pass manager has been added making use of the new LazyCallGraph analysis framework. This is part of the new pass manager work Chandler Carruth has been working on and is of course a work in progress. <a href="http://reviews.llvm.org/rL206745">r206745</a>.</p></li><li><p>The scheduler model for the Intel Silvermont microarchitecture has been replaced. The commit message claims substantial improvements on integer tests. I'm assuming RAL in this context refers to RegAllocLocal? <a href="http://reviews.llvm.org/rL206957">r206957</a>.</p></li><li><p>ARM64 has of course seen a large number of changes. Among those, support for feature predicates for NEON/FP/CYPTO instructions. This allows the compiler to generate code without using those instructions. <a href="http://reviews.llvm.org/rL206949">r206949</a>. Additionally, there is now a big endian version of the ARM64 target machine. <a href="http://reviews.llvm.org/rL206965">r206965</a>.</p></li><li><p>getFileOffset has been dropped from LLVM's C API. Justification is in the commit message. <a href="http://reviews.llvm.org/rL206750">r206750</a>.</p></li><li><p>The LoopVectorize pass now keeps statistics on the number of analyzed loops and the number of vectorized loops. <a href="http://reviews.llvm.org/rL206956">r206956</a>.</p></li><li><p>The x86 backend gained new intrinsics for Read Time Stamp Counter. <a href="http://reviews.llvm.org/rL207127">r207127</a>.</p></li><li><p>Initial work on mutation support for the lazy call graph has landed. As with most of Chandler's commits, there's much more information in the commit message. <a href="http://reviews.llvm.org/rL206968">r206968</a>.</p></li><li><p>MCTargetOptions has been introduced, which for now only contains a single flag. SanitizeAddress enabled AddressSanitizer instrumentation of inline assembly. <a href="http://reviews.llvm.org/rL206971">r206971</a>.</p></li><li><p>llvm-cov now supports gcov's <code>--long-file-names</code> option. <a href="http://reviews.llvm.org/rL207035">r207035</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Documentation for sample profiling was added. <a href="http://reviews.llvm.org/rL206994">r206994</a>.</p></li><li><p>Support for parsing the linear clause for the 'omp simd' directive was added. <a href="http://reviews.llvm.org/rL206891">r206891</a>.</p></li><li><p>Clang gained support for the <code>-fmodules-search-all</code> option, which searches for symbols in non-imported modules (i.e. those referenced in module maps but not imported). <a href="http://reviews.llvm.org/rL206977">r206977</a>.</p></li></ul><h3>Other project commits</h3><ul> <li><p>AddressSanitizer gained an experimental detector for "one definition rule" violations (where two globals with the same name are defined in different modules). <a href="http://reviews.llvm.org/rL207210">r207210</a>.</p></li></ul>
- LLVM Weekly - #16, Apr 21st 2014https://blog.llvm.org/2014/04/llvm-weekly-16-apr-21st-2014.htmlMon, 21 Apr 2014 05:46:00 +0000https://blog.llvm.org/2014/04/llvm-weekly-16-apr-21st-2014.html<p>Welcome to the 16th issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>Apologies that last week's LLVM Weekly went out twice via email. Mailgun have the useful ability to schedule an email for the future, but when this is done incorrectly have no ability to cancel it via the API. Possibly there is no way for them to cancel it either, I have no way to know as my support ticket on the issue was never answered.</p><p>Seeing as it's Easter, does anybody know why GCC has a <a href="http://commons.wikimedia.org/wiki/File:GNU_Compiler_Collection_logo.svg">GNU breaking out of an egg as a logo</a>?</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/16">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The new backend to <a href="https://github.com/kripken/emscripten">Emscripten</a> which is implemented as an LLVM backend has <a href="https://groups.google.com/forum/#!topic/emscripten-discuss/FACubOKw2TI">now been merged to Emscripten's master branch</a>. This should result in a noticeable speedup in compile times.</p><p>Phoronix have published a <a href="http://www.phoronix.com/scan.php?page=article&item=gcc49_compiler_llvm35&num=1">small set of benchmarks comparing GCC 4.9RC1 and Clang 3.5 HEAD</a>.</p><p>Diego Novillo has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72199">announced AutoFDO</a>, a tool which will convert profile data generated with <a href="https://perf.wiki.kernel.org">Linux Perf</a> to a format compatible with LLVM's sample-based profiler.</p><p>The Polly project have <a href="https://docs.google.com/document/d/14d3ehkh3/edit">minutes from another phone call</a>, this time focusing on delinearization.</p><h3>On the mailing lists</h3><ul><li><p>Jingyue Wu <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72366">shares an initial patch for common sub-expression elimination (CSE) for getelementptr</a>. He and his colleagues had found that with the NVPTX backend, loop unrolling often lead to groups of getelementptr instructions which added to register pressure, but that these could often to optimised with some simple CSE. Feedback so far is positive on including something like this is a target-independent pass, though there's interest in seeing whether it helps on any other backends with open source benchmarks.</p></li><li><p>Austin Seipp has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72374">revived the issue of named register variables</a>. He adds perspective on the the utility of this feature for the Glasgow Haskell Compiler (GHC). They are currently suffering a large performance loss on OS X with clang due to the inability to dedicate a register for fast access to thread-local storage. Renato Golin <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72378">followed up</a> with how he thinks it is best to move forwards on the issue, while Mark Seaborn <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72375">shared a neat trick the NaCl team use</a> where they inline <code>pthread_getspecific</code> after verifying it contains the code they expect.</p></li><li><p>Kostya Serebryany <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72247">shares his concerns about contention between threads on access to profile counters</a>. For a multi-threaded VP9 encoder, he's seeing 7x overhead when running with <code>-fprofile-instr-generate</code> vs 15% when single-threaded. There's too much for me to summarise, but there's a lot of discussion on potential solutions which the interested reader should certainly take a look at.</p></li><li><p>Dan Gohman answers a question about LLVM IR access to struct fields with a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72331">concise summary of how alias analysis information is currently used in LLVM</a>.</p></li><li><p>Richard Carback is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72201">seeking feedback on his TableGen DAGISel documentation</a>. His <a href="https://github.com/draperlaboratory/fracture/wiki/How-TableGen%27s-DAGISel-Backend-Works">notes</a> seem like a great start at documenting what has been up till now one of the more mysterious parts of LLVM. Particularly those who have experience with this code are encouraged to check the document for accuracy.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM's internal BumpPtrAllocator has been switched to using a vector of pointers to slabs rather than a single linked list and the underlying allocator is now a template parameter. <a href="http://reviews.llvm.org/rL206147">r206147</a>, <a href="http://reviews.llvm.org/rL206149">r206149</a>. The allocator can now also pass the size to the deallocation function, which improves performance with some libraries (e.g. tcmalloc). <a href="http://reviews.llvm.org/rL20265">r206265</a>.</p></li><li><p>Support for building persistent strongly connected components has been added to the LazyCallGraph. There are detailed comments on the reasoning of this approach and some details on implementation in the commit message. <a href="http://reviews.llvm.org/rL206581">r206581</a>.</p></li><li><p>Constant hoisting has been enabled on PowerPC. <a href="http://reviews.llvm.org/rL206141">r206141</a>.</p></li><li><p>PseudoSourceValue is no longer a subclass of Value. <a href="http://reviews.llvm.org/rL206255">r206255</a>.</p></li><li><p>A DebugInfoVerifier has been implemented. <a href="http://reviews.llvm.org/rL206300">r206300</a>.</p></li><li><p>MIPS gained initial support for the IEEE 754-2008 NaN encoding. <a href="http://reviews.llvm.org/rL202812">r206396</a>.</p></li><li><p>OnDiskHashTable has been moved from Clang to LLVM. <a href="http://reviews.llvm.org/rL206438">r206438</a>.</p></li><li><p>ARM's IR-based atomics pass has been moved from Target to CodeGen, which allows it to be used by ARM64. <a href="http://reviews.llvm.org/rL206485">r206485</a>, <a href="http://reviews.llvm.org/rL206490">r206490</a>.</p></li><li><p>Module verification is now off by default in release builds for the JIT, but this can be overridden. <a href="http://reviews.llvm.org/rL206561">r206561</a>.</p></li><li><p>The Cortex-A53 machine model description has been ported from AArch64 to ARM64. <a href="http://reviews.llvm.org/rL206652">r206652</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>There is now a new hash algorithm for calculating the function hash for instruction profiling, rewritten to help ensure the hash changes when control flow does. <a href="http://reviews.llvm.org/rL206397">r206397</a>.</p></li><li><p>The thread safety analysis SSA pass has been rewritten. <a href="http://reviews.llvm.org/rL206338">r206338</a>.</p></li><li><p>Support for big endian ARM64 was added to Targets.cpp. <a href="http://reviews.llvm.org/rL206390">r206390</a>. It is also now possible to disable NEON and crypto support for ARM64. <a href="http://reviews.llvm.org/rL206394">r206394</a>.</p></li></ul><h3>Other project commits</h3><ul><li>LLD now supports <code>--defsym=<symbol>=<symbol></code>, as supported by GNU LD. <a href="http://reviews.llvm.org/rL206417">r206417</a>.</li></ul>
- LLVM Weekly - #15, Apr 14th 2014https://blog.llvm.org/2014/04/llvm-weekly-15-apr-14th-2014.htmlMon, 14 Apr 2014 07:54:00 +0000https://blog.llvm.org/2014/04/llvm-weekly-15-apr-14th-2014.html<p>Welcome to the 15th issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>The canonical home for this issue <a href="http://llvmweekly.org/issue/15">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Videos are not yet ready, but <a href="http://llvm.org/devmtg/2014-04/">most slides from last week's EuroLLVM meeting are now up</a>.</p><p>ARM have <a href="http://www.arm.com/about/newsroom/arm-compiler-builds-on-open-source-llvm-technology.php">announced</a> the release of version 6 of the ARM compiler, which is now built on LLVM and Clang.</p><p>Philip Reames has <a href="http://www.philipreames.com/Blog/2014/04/10/late-safepoint-placement-an-update/">written an update on his work on late safepoint placement</a>, which is useful for implementing efficient precise garbage collection on LLVM. The bad news is their initial plan did not survive contact with the enemy, though they're hard at work on fixing it and a new update can be expected in good time.</p><p>As <a href="http://www.phoronix.com/scan.php?page=news_item&px=MTY2MjY">reported by Phoronix</a>, a number of patches towards the goal of compiling the Linux kernel with clang have been <a href="http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=09c9b61d5da24174b867a6ffda29b7435e1fda74">merged</a> by Linus.</p><p>The first release candidate of GCC 4.9 has been <a href="http://article.gmane.org/gmane.comp.gcc.devel/135468">released</a>. New features in the 4.9 branch are <a href="http://gcc.gnu.org/gcc-4.9/changes.html">documented here</a>.</p><p>Polly had a meeting via phone call, and <a href="https://docs.google.com/document/d/12W-qZjiZGEQ_lVrob4OzvKJI3EooonC-ap1b9f9KCUE/edit">notes of that meeting are available</a>. The part of most general interest is probably discussion around the potential of merging Polly into the LLVM mainline.</p><h3>On the mailing lists</h3><ul><li><p>LLVM 3.4.1 has now <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72127">entered the testing phase</a> and help testing the release would be greatly appreciated.</p></li><li><p>Tim Northover has [summarised the discussion about merging AArch64 and ARM64 from EuroLLVM]. The view is still in favour of merging from AArch64 to ARM64. Interestingly, <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71996">apparently</a> Google are working on a framework to build and run benchmarks (something different to <a href="http://llvm.org/docs/lnt/">LNT</a> I guess). Also of interest are [benchmarks of ARM64 LLVM vs AArch64 LLVM vs GCC 4.9] on Cortex-A53. There's now a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72133">somewhat detailed plan for the merge</a> and remaining tasks.</p></li><li><p>Alon Zakai has shared <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71989">some details on his work on a C backend for Emscripten</a>. Right now he describes it as a 'quick hack', though current performance seems quite good with only a 19% slowdown on zlib. The current version of the code is in emscripten's <a href="https://github.com/kripken/emscripten/tree/c_backend"><code>c_backend</code> branch</a> (in <code>tools/c_backend.py</code>).</p></li><li><p>David Blaikie started a discussion about <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/36014">debug info for captured variables in a C++11 lambda</a>. There's too much here for me to comfortably summarise, but do dig in if you're interested.</p></li><li><p>Jim Grosbach suggests <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71992">low-level tools like llc should not do CPU auto-detection</a>. There's general agreement that this is a good idea and will help to avoid the problem of tests failing on one machine but not another due to this auto-detection. The change has now been merged.</p></li><li><p>Jonas Wagner <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72036">shared his workflow using a gold linker plugin to link LLVM bitcode</a>.</p></li><li><p>Will Dietz <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72019">responded</a> to a query about unexpected code generation with a great analysis of what may be going on.</p></li><li><p>Robert Matusewicz is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/72083">looking for interest in keeping the poolalloc project alive</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The NVPTX backend gained preliminary intrinsics and codegen support for textures and surfaces. <a href="http://reviews.llvm.org/rL205907">r205907</a>.</p></li><li><p>Support for optimisation report diagnostics was added. This starts to implement the idea <a href="https://docs.google.com/document/d/1FYUatSjZZO-zmFBxjOiuOzAy9mhHA8hqdvklZv68WuQ/edit#heading=h.qk42du84eyjg">documented and discussed previously</a>. In the future it will be possible to get a report of the major optimization decisions taken by compiler transformations. <a href="http://reviews.llvm.org/rL205774">r205774</a>, <a href="http://reviews.llvm.org/rL205775">r205775</a>.</p></li><li><p>The merge of AArch64 and ARM4 continues. Named immediate operand mapping logic and enums have been copied from AArch64 to ARM64. <a href="http://reviews.llvm.org/rL205866">r205866</a>. The ARM64 backend has seen a large series of smaller commits as well.</p></li><li><p>Constant hoisting is now enabled for the ARM64 backend. <a href="http://reviews.llvm.org/rL205791">r205791</a>.</p></li><li><p>Previously, optimisation logic in CodeGenPrepare that tried to merge address computation in to the memory operation itself (when supported by the platform's addressing modes) would do so by adding integer operations and using ptrtoint and inttoptr. This caused issues when trying to use alias analysis during CodeGen. There is now opt-in support for doing this using GetElementPtr. <a href="http://reviews.llvm.org/rL206092">r206092</a>.</p></li><li><p>The debug info compression support introduced two weeks ago was reverted, and replaced with a new implementation that compresses the whole section rather than a fragment. <a href="http://reviews.llvm.org/rL205989">r205989</a>, <a href="http://reviews.llvm.org/rL205990">r205990</a>.</p></li><li><p>The segmented stack switch has been moved to a function attribute and the old <code>-segmented-stacks</code> command line flag removed. <a href="http://reviews.llvm.org/rL205997">r205997</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>A major refactoring of the thread safety analysis has been started. <a href="http://reviews.llvm.org/rL205728">r205728</a>, <a href="http://reviews.llvm.org/rL205745">r205745</a>, and more.</p></li><li><p>libclang gained a <code>clang_CXXMethod_isConst</code> method. <a href="http://reviews.llvm.org/rL205714">r205714</a>.</p></li><li><p>As part of the ongoing project to support the MSVC++ ABI, support for <code>#pragma section</code> and related programs was added. <a href="http://reviews.llvm.org/rL205810">r205810</a>.</p></li><li><p>New command line options were added to support big or little endian for ARM and AArch64. <a href="http://reviews.llvm.org/rL205966">r205966</a>, <a href="http://reviews.llvm.org/rL205907">r205967</a>.</p></li></ul><h3>Other project commits</h3><ul><li>The openmp project gained the offload directory, which contains code needed to support OpenMP 4.0 target directives. <a href="http://reviews.llvm.org/rL205909">r205909</a>.</li></ul>
- LLVM Weekly - #14, Apr 7th 2014https://blog.llvm.org/2014/04/llvm-weekly-14-apr-7th-2014.htmlMon, 07 Apr 2014 06:47:00 +0000https://blog.llvm.org/2014/04/llvm-weekly-14-apr-7th-2014.html<p>Welcome to the fourteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>There seems to have been a flood of LLVM-related news this week, hopefully I've managed to collect it all. If you're in London next week, you might be interested in attending <a href="http://www.meetup.com/X-Dev-London/events/174666532/">my introductory LLVM talk</a> on Wednesday. Abstract is <a href="http://pastebin.com/StSzTzMv">here</a>.</p><p>EuroLLVM is of course taking place on Monday and Tuesday of this week. Sadly I won't be in attendance. If anyone is blogging the event, please do send me links.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/14">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The LLVM-related news that has made the biggest splash this week is surely the <a href="https://tech.dropbox.com/2014/04/introducing-pyston-an-upcoming-jit-based-python-implementation/">announcement of Pyston, a JIT for Python targeting LLVM</a>. More technical details are <a href="https://github.com/dropbox/pyston#technical-features">available on the Github repo</a>. For many this immediately conjures up memories of the <a href="http://code.google.com/p/unladen-swallow/">Unladen Swallow project</a>, started by Google engineers with the same aim of JITting Python with LLVM. That project was eventually unsuccessful, but it's unfair to the authors of Pyston to assume it will have the same fate. It's unclear how much developer time Dropbox are contributing to Pyston. They clearly have a lot of work to do, though it's no secret that <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-October/066573.html">Apple are also looking to target LLVM from JavaScript</a> which means they're not the only developers working in this area. Kevin Modzelewski <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71870">shared some more info</a> on the LLVM mailing list which details some of the LLVM work they've implemented so far (including some initial escape analysis for GCed memory).</p><p>An independent, non-profit LLVM Foundation <a href="http://blog.llvm.org/2014/04/the-llvm-foundation.html">is to be formed</a>. As a vendor neutral organisation it will represent the community interest and aims to be set up by the end of the year.The initial board of directors will be Vikram Adve, Chandler Carruth, Doug Gregor, David Kipping, Anton Korobeynikov, Chris Lattner, Tanya Lattner, and Alex Rosenberg.</p><p>Rust 0.10 <a href="https://mail.mozilla.org/pipermail/rust-dev/2014-April/009387.html">has been released</a>. See also the discussion on <a href="https://news.ycombinator.com/item?id=7524945">Hacker News</a> and <a href="http://www.reddit.com/r/programming/comments/224gh3/rust_010_released/">Reddit</a>. Rust is a systems programming language from Mozilla which uses LLVM as its code generator backend.</p><p>The <a href="http://dagger.repzret.org/">Dagger</a> LLVM-based decompilation framework has <a href="http://dagger.repzret.org/update-a-sneak-peek-of-the-source/">released its source</a> as well as publishing a series of five articles documenting its implementation approach and documenting the next steps or 'TODOs'.</p><p>An <a href="https://github.com/AccelerateHS/accelerate-llvm">LLVM backend for the Accelerate Array Language</a> has been released. It compiles Accelerate code to LLVM IR and can target multicore CPUs as well as NVIDIA GPUs.</p><p>The <a href="https://github.com/gannimo/MalDiv/raw/master/paper/talk_payerm_syscan14.pdf">PDF slides</a>for a recent talk about the LLVM-based <a href="https://github.com/gannimo/MalDiv">MalDiv</a> diversifying compiler have been published. Such a tool effectively defeats signature-based matching of malware.</p><h3>On the mailing lists</h3><ul><li><p>James Molloy from ARM has been looking at the recently open sourced ARM64 backend from Apple, and has come to the conclusion that <a href="article.gmane.org/gmane.comp.compilers.llvm.devel/71737">it's easier to use ARM64 as a base an merge in from AArch64</a>. The key justification is that ARM64 backend is more performant but has some correctness issues, and porting performance fixes is more difficult than correctness. There seems to be agreement from the followup responses. Bradley Smith reports <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71861">good progress on fixing observed correctness issues and some interesting performance results</a>. Of interest to those attending EuroLLVM this week, there will be discussions on Monday and after the main conference on Wednesday (details <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71947">here</a>).</p></li><li><p>Requests for patches to be included in LLVM/Clang 3.4.1 have started to come in. These include <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71788">a large number of AArch64 patches</a> (plus <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71849">another</a>), plus some <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71809">assorted bugfixes</a>.</p></li><li><p>Reid Kleckner has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71775">proposed a new tail call marker</a>, 'musttail' which guarantees that tail call optimization will occur.</p></li><li><p>Shankar Easwaran starts a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71852">adding support to lld for demangling symbols</a>.</p></li><li><p>Jeroen Dobbelaere has an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71881">interesting problem</a> with an architecture he is targeting. The architecture has 64-bit registers, but the pointer size is always 32-bits. JF Bastien suggests <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71923">this is similar to PNaCl and the x32 ABI</a>.</p></li><li><p>Peter Collingbourne <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71773">proposes an IR extension for loads/stores with deterministic trap/unwind behaviour</a>. The aim is to support zero cost exception handling for operations that may trap. The proposal comes with initial patches, though Andrew Trick <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71934">questions whether adding new IR instructions is the right approach</a>.</p></li><li><p>The LLVM project Phabricator instance has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35992">been moved to reviews.llvm.org</a>. Currently links to the old one are broken, but hopefully a redirect will be set up. By the time you read this I should have updated all broken links from llvmweekly.org.</p></li></ul><h3>LLVM commits</h3><ul><li><p>MipsAsmParser and MipsOperand was rewritten. The improvements are documented in the commit message. <a href="http://reviews.llvm.org/rL205292">r205292</a>.</p></li><li><p>The ARM backend gained support for segmented stacks. <a href="http://reviews.llvm.org/rL205430">r205430</a>.</p></li><li><p>Windows on ARM support is now possible with the MachineCode layer. <a href="http://reviews.llvm.org/rL205459">r205459</a>.</p></li><li><p>TargetLowering gained a hook to control when <code>BUILD_VECTOR</code> might be expanded using shuffles. <a href="http://reviews.llvm.org/rL205230">r205230</a>. Targets might choose to use ExpandBVWithShuffles which was added in a later commit. <a href="http://reviews.llvm.org/rL205243">r205243</a>.</p></li><li><p>X86TargetTransformInfo gained getUnrollingPreferences, which is used by the generic loop unroller. This helps to optimise use of the micro-op caches on X86. This produced 7.5%-15% speedups in the TSVC benchmark suite. <a href="http://reviews.llvm.org/rL205348">r205348</a>.</p></li><li><p>ARM gained a nice little optimisation pass that removes duplicated DMB instructions. <a href="http://reviews.llvm.org/rL205409">r205409</a>.</p></li><li><p>Atomic ldrex/strex loops are now expanded in IR rather than at MachineInstr emission time. This cleans up code, but should also make future optimisations easier. <a href="http://reviews.llvm.org/rL205525">r205525</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The clang static analyzer gained double-unlock detection in PthreadLockChecker, as well as a check for using locks after they are destroyed. <a href="http://reviews.llvm.org/rL205274">r205274</a>, <a href="http://reviews.llvm.org/rL205275">r205275</a>.</p></li><li><p>The OpenMP 'copyin' clause was implemented. <a href="http://reviews.llvm.org/rL205164">r205164</a>.</p></li><li><p>The 'optnone' attribute was added, which suppresses most optimisations on a function. <a href="http://reviews.llvm.org/rL205255">r205255</a>.</p></li><li><p>The heuristics for choosing methods to suggest as corrections were improved, to ignore methods that obviously won't work. <a href="http://reviews.llvm.org/rL205653">r205653</a>.</p></li><li><p>The 'BitwiseConstraintManager' idea was added to the open projects page. <a href="http://reviews.llvm.org/rL205666">r205666</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>AddressSanitizer can now be used as a shared library on Linux. <a href="http://reviews.llvm.org/rL205308">r205308</a>.</p></li><li><p>compiler-rt gained support for IEEE754 quad precision comparison functions. <a href="http://reviews.llvm.org/rL205312">r205312</a>.</p></li><li><p>lld now supports <code>.gnu.linkonce</code> sections. <a href="http://reviews.llvm.org/rL205280">r205280</a>.</p></li></ul>
- The LLVM Foundationhttps://blog.llvm.org/2014/04/the-llvm-foundation.htmlThu, 03 Apr 2014 09:02:00 +0000https://blog.llvm.org/2014/04/the-llvm-foundation.html<br /><div>The LLVM umbrella project has grown over the years into a vibrant community made up of many sub-projects, with hundreds of contributors. The results of this project are used by millions of people every day. Today, I'm happy to announce that we are taking the next big step, and forming a new, independent non-profit to represent the community interest. "The LLVM Foundation" will allow us to:</div><div><br /></div><div> - Solve infrastructure problems.</div><div> - Address financial challenges around the developer meetings and infrastructure expenses.</div><div> - Deliver improved transparency into operational and policy matters</div><div> - Provide a company-neutral organization to help ensure success well into the future.</div><div><br /></div><div>We are working towards a goal of having this organization functioning by the end of the year, possibly sooner.</div><div><br /></div><div>In terms of structure, we expect the foundation to be lean: an oversight board of volunteers and a dedicated administrator. The expectations of this administrator will be to oversee long-overdue upgrades to our infrastructure (such as the web site design, bug database, mailing lists, etc), organize the US LLVM Developer Meeting, and drive the formation of the foundation itself. We do not expect significant change to our developer policies (i.e. licensing & copyright). Our system of domain-expert "code owners" will continue to drive the technical direction of their areas. As an LLVM contributor, the biggest changes that you can expect to see are things operating more smoothly and infrastructure issues getting the attention they deserve.</div><div><br /></div><div>Tanya Lattner has been spearheading the formation of the Foundation and has graciously agreed to take on the administrator role. Tanya has been actively involved in LLVM since 2003. Many of you know Tanya from her LLVM community involvement such as organizing the US LLVM Developer Meetings and management of the website and other infrastructure. She implemented Swing Modulo Scheduling in LLVM for her Masters thesis at UIUC, served as the release manager from LLVM 1.7 through 2.7, and in a commercial setting she implemented LLVM based optimization tools and contributed to an LLVM-based OpenCL implementation.</div><div><br /></div><div>We have also been quietly speaking with members of the community, working to select a diverse board of directors, that accurately reflects the communityâs interests. We looked to active members of the community, representing both academic and commercial interests, people from organizations that contribute to the developer meeting and testing infrastructure, and technical leads from some of the prominent LLVM sub-projects. We sought diversity in the board, while trying to keep it small enough to be nimble. The initial board of directors will be:</div><div><br /></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Vikram Adve</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Chandler Carruth</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Doug Gregor</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>David Kipping</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Anton Korobeynikov</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Chris Lattner</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Tanya Lattner</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>Alex Rosenberg</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div>I expect that there will be many questions and comments. The foundation is intended to represent the interests of the community, so please send questions to the <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVMdev mailing list</a>. More information will be coming over the next few months as things progress.</div><div><br /></div><div>-Chris</div><div><br /></div>
- LLVM Weekly - #13, Mar 31st 2014https://blog.llvm.org/2014/03/llvm-weekly-13-mar-31st-2014.htmlMon, 31 Mar 2014 07:39:00 +0000https://blog.llvm.org/2014/03/llvm-weekly-13-mar-31st-2014.html<p>Welcome to the thirteenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>Thanks in no small part to a <a href="http://www.raspberrypi.org/archives/6535">mention on the Raspberry Pi blog</a>, <a href="http://www.amazon.co.uk/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058/">Learning Python with Raspberry Pi</a> by myself and Ben Everard is at the time of writing #1 in the Programming books section on Amaon UK. Also, keep your eyes on the <a href="http://www.meetup.com/X-Dev-London/">X-Dev London meetup page</a> as I'm expecting to give an LLVM-related talk there on the 9th April, though it's not listed yet and is subject to change.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/13">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>It's only a week to go until <a href="http://llvm.org/devmtg/2014-04/">EuroLLVM 2014</a>, which wil be held in Edinburgh on the 7th and 8th of April. Tragically I'm not going to be there as I'm trying to focus on getting my PhD finished, but the schedule looks fantastic.</p><p>The Linux Collaboration Summit featured an update on progress of the LLVMLinux project to build the Linux kernel using LLVM/Clang (<a href="http://events.linuxfoundation.org/sites/events/files/slides/2014-Collab-LLVMLinux.pdf">slides</a>). As of right now, there are approximately 48 kernel patches still working their way upstream for the project.</p><p>John Regehr has written an interesting blog post on the subject of <a href="http://blog.regehr.org/archives/1122">using Z3 to prove some things about LLVM optimisations</a>.</p><p>Facebook have <a href="https://code.facebook.com/posts/476987592402291/under-the-hood-warp-a-fast-c-and-c-preprocessor/">released the Warp C and C++ preprocessor</a>, written in D. It claims to benchmark much faster than GCC's preprocessor resulting in faster build times, though a <a href="https://news.ycombinator.com/item?id=7489532">quick comparison with Clang</a> didn't show it in a favourable light speed-wise.</p><p>Meeting C++ have published a helpful summary of <a href="http://meetingcpp.com/index.php/br/items/cpp-status.html">what might make its way in to C++17 or C++1y</a>.</p><h3>On the mailing lists</h3><ul><li><p>Apple are <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71638">contributing their 64-bit ARM backend upstream</a>. Initially, this will co-exist with the current AArch64 backend (the Apple implementation is called ARM64), and over time the backends will be merged.</p></li><li><p>Tom Stellard has [announced a tentative release schedule for LLVM and Clang 3.4.1] and is searching for volunteers to test, as well as nominations for patches that should be included. The proposed schedule is Mar 26 - April 9: Identify and backport additional bug fixes to the 3.4 branch. April 9 - April 18: Testing Phase April 18: 3.4.1 Release</p></li><li><p>Frank Winter started a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71487">how to specify the alignment of a pointer in LLVM IR</a>, which yields some interesting responses.</p></li><li><p>Renato Golin kicked off a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71567">discussion about supporting named registers in LLVM/Clang</a>. This is a GNU extension not currently supported. There seemed to be some agreement that this is worth supporting, which resulted in a follow-on thread on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71625">how to implement support for named registers</a>.</p></li><li><p>A <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35858">query from Geoffrey Irving</a> about how to safely make use of floating point rounding mode resulted in an interesting discussion about how a changing rounding modes could be supported. For example, with the introduction of a <code>fp_rounding_sensitive</code> annotation.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The ARM big-endian targets armeb and thumbeb have been added. <a href="http://reviews.llvm.org/rL205007">r205007</a>.</p></li><li><p>Apple's ARM64 backend has been merged, and will for a time live side-by-side with the existing AArch64 backend (see 'on the mailing lists' for more details). <a href="http://reviews.llvm.org/rL205090">r205090</a>.</p></li><li><p>The <code>@llvm.clear_cache</code> builtin has been born. <a href="http://reviews.llvm.org/rL204802">r204802</a>, <a href="http://reviews.llvm.org/rL204806">r204806</a>.</p></li><li><p>Windows target triple spellings have been canonicalised. See the commit for full details, but in short i686-pc-win32 is now i686-pc-windows-msvc, i686-pc-mingw32 is now i686-pc-windows-gnu and i686-pc-cygwin is now i686-pc-windows-cygnus. <a href="http://reviews.llvm.org/rL204977">r204977</a>.</p></li><li><p>The first step towards little-endian code generation for PowerPC has been committed. This initial patch allows the PowerPC backend to produce little-endian ELF objects. <a href="http://reviews.llvm.org/rL204634">r204634</a>.</p></li><li><p>Another LLVM optimisation pass has been fixed to be address space aware, and will no longer perform an addrspacecast. <a href="http://reviews.llvm.org/rL204733">r204733</a>.</p></li><li><p>It is now disallowed for an alias to point to a weak alias. <a href="http://reviews.llvm.org/rL204934">r204934</a>.</p></li><li><p>CloneFunctions will now clone all attributes, including the calling convention.<a href="http://reviews.llvm.org/rL204866">r204866</a>.</p></li><li><p>DebugInfo gained support for compressed debug info sections. <a href="http://reviews.llvm.org/rL204958">r204958</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The static analyzer is now aware of <code>M_ZERO</code> and <code>__GFP_ZERO</code> flags for kernel mallocs. <a href="http://reviews.llvm.org/rL204832">r204832</a>.</p></li><li><p>Clang learned how to de-duplicate string the MSVC way. <a href="http://reviews.llvm.org/rL204675">r204675</a>.</p></li><li><p>Capability attributes can be declared on a typedef declaration as well as a structure declaration. <a href="http://reviews.llvm.org/rL204657">r204657</a>.</p></li><li><p><code>module.private.modulemap</code> and <code>module_private.map</code> are now documented. <a href="http://reviews.llvm.org/rL205030">r205030</a>.</p></li><li><p>Clang's CodeGen module now allows different RTTI emission strategies. This was added for ARM64. <a href="http://reviews.llvm.org/rL205101">r205101</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>ThreadSanitizer has new benchmarks for synchronization handling. <a href="http://reviews.llvm.org/rL204608">r204608</a>.</p></li><li><p>Initial infrastructure for IEEE quad precision was added to compiler-rt. <a href="http://reviews.llvm.org/rL204999">r204999</a>.</p></li><li><p>LLD gained the <code>--allow-multiple-definition</code> and <code>--defsym</code> options. <a href="http://reviews.llvm.org/rL205015">r205015</a>, <a href="http://reviews.llvm.org/rL205029">r205029</a>.</p></li><li><p>In LLDB, JITed function can now have debug info and be debugged with debug and source info. <a href="http://reviews.llvm.org/rL204682">r204682</a>.</p></li><li><p>ThreadSanitizer vector clock operations have been optimized and are now O(1) for several important use cases. <a href="http://reviews.llvm.org/rL204656">r204656</a>.</p></li></ul>
- LLVM Weekly - #12, Mar 24th 2014https://blog.llvm.org/2014/03/llvm-weekly-12-mar-24th-2014.htmlMon, 24 Mar 2014 07:47:00 +0000https://blog.llvm.org/2014/03/llvm-weekly-12-mar-24th-2014.html<p>Welcome to the twelfth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/12">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><ul><li><p>You may recall my previous coverage of efforts by Philip Reames and others to introduce necessary changes to LLVM to support a precise relocating garbage collector. Previously he <a href="http://www.philipreames.com/Blog/2014/02/21/why-not-use-gcroot/">described the issues of using the llvm.gcroot intrinsic</a>. True to his word, he's followed up that post with a description of '<a href="http://www.philipreames.com/Blog/2014/03/18/late-safepoint-placement-overview/">late safepoint placement</a>', which is the approach Philip and his colleagues are working on to address the problem. More updates are promised over the next few weeks.</p></li><li><p>musl libc 1.0.0 <a href="http://www.musl-libc.org/download.html">has been released</a>. It is an MIT-licensed libc aiming to compete with glibc. "musl is a new general-purpose implementation of the C library. It is lightweight, fast, simple, free, and aims to be correct in the sense of standards-conformance and safety."</p></li><li><p>The <a href="http://erllvm.softlab.ntua.gr/">LLVM backend for the HiPE Erlang compiler</a> has been <a href="https://github.com/erlang/otp/commit/9d46875b53ffb21bc55aec4a2c76472133ea5d1c">merged</a> in to the Erlang/OTP master branch.</p></li><li><p>The 'Mystical Programming blog' has an amusing article on <a href="http://mysticalprogramming.wordpress.com/2014/03/19/how-to-abuse-a-cpp-compiler/">non-terminating C++ template computations</a> along with information on how GCC and Clang handle each example.</p></li><li><p>Meeting C++ have written up a <a href="http://meetingcpp.com/index.php/br/items/looking-at-c14.html">list of things likely to make their way in to C++14</a>.</p></li><li><p><a href="http://www.ceemple.com/what-is-ceemple/">Ceemple</a>, an LLVM-based product for technical computing, has been released. It's marketed as offering a number of advantages over Python or MATLAB in this space.</p></li><li><p>The next Cambridge LLVM Social will <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71338">take place on the 26th March, 7.30pm</a>.</p></li></ul><h3>On the mailing lists</h3><ul><li><p>David Given is working on an architecture that uses integer registers to store floating point values, and <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71368">asks for advice</a> on how to represent this in tablegen without being stopped dead by "cannot infer all types in pattern" errors.</p></li><li><p>Renato Golin has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71340">kicked off another thread on unwinding and exception handling and function attributes</a>. He's done a fantastic job of summarising the issues and proposal on moving forward which means I don't have to feel lazy by suggesting you just go read the thread if you're interested.</p></li><li><p>Arch Robinson asks the list for <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71307">advice on improving the SLPVectorizer in order to help with Julia code he's looking at</a>. The <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71308">response</a> from Arnold Schwaighofer is worth a read for anyone interested in hacking in this area.</p></li><li><p>Discussion about a binary format for instrumentation-based profiling data has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71306">continued</a>, with the suggestion that the format written out by instrumentation need not be the same as the format read back by the compiler (it could be transformed by other tools). Justin Bogner has detailed <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71434">proposed requirements</a> for these formats.</p></li><li><p>Tim Hill started an interesting discussion by <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35755">sharing his experiences from switching to Clang</a>. Among the positives were excellent errors, the static analyzer, compatibility, and quality of generated code. The main negative is the lack of documentation for many compiler options. There's general agreement in the responses that this is a problem that should be fixed in the (hopefully not too distant) future.</p></li><li><p>Lang Hames has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71352">proposed an RFC on adding an empty method to <code>iterator_range</code></a>. If debating API design is your cup of tea, prepare to be entertained.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The MIPS64r2-based Octeon CPU has been added. <a href="http://reviews.llvm.org/rL204337">r204337</a>.</p></li><li><p>The ProfileData library, <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71179">discussed last week</a> was committed. <a href="http://reviews.llvm.org/rL204482">r204482</a>, <a href="http://reviews.llvm.org/rL204489">r204489</a>.</p></li><li><p>The constant hoisting pass saw some refactoring and improvements. <a href="http://reviews.llvm.org/rL204431">r204431</a>, <a href="http://reviews.llvm.org/rL204433">r204433</a>, <a href="http://reviews.llvm.org/rL204435">r204435</a>, <a href="http://reviews.llvm.org/rL204537">r204537</a>.</p></li><li><p>The ARM integrated assembler learned how to handle the <code>.thumb_set</code> directive. <a href="http://reviews.llvm.org/rL204059">r204059</a>.</p></li><li><p>Assembler directives were added to create version-min load commands for iOS or Mac OSX. e.g. <code>.ios_version_min 5,2,0</code>. <a href="http://reviews.llvm.org/rL204190">r204190</a>.</p></li><li><p>It is now possible to specify the 'noduplicate' attribution for intrinsics. <a href="http://reviews.llvm.org/rL204200">r204200</a>.</p></li><li><p>The TableGen backends documentation was fleshed out a bit. <a href="http://reviews.llvm.org/rL204479">r204479</a>.</p></li><li><p>Scheduling annotations have been added to NEON AArch64 instructions. <a href="http://reviews.llvm.org/rL204505">r204505</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Counters used in instrumentation-based profiling are now represented in a static array. This is the first commit of a larger project to reduce runtime overhead (initialization in particular) for instrumentation-based profiling. <a href="http://reviews.llvm.org/rL204080">r204080</a>. Other commits for instrumentation-based profiling include <a href="http://reviews.llvm.org/rL204186">r204186</a>, <a href="http://reviews.llvm.org/rL204379">r204379</a>, <a href="http://reviews.llvm.org/rL204390">r204390</a>. There's a matching set of commits in compiler-rt.</p></li><li><p>The deprecated <code>-faddress-sanitizer</code>, <code>-fthread-sanitizer</code>, and <code>-fcatch-undefined-behavior</code> flags were removed. Users whould use <code>-fsanitize=</code> instead. <a href="http://reviews.llvm.org/rL204330">r204330</a>.</p></li><li><p>Support for parsing the OpenMP safelen clause (for 'omp simd') was committed. <a href="http://reviews.llvm.org/rL204428">r204428</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>Support was added to MemorySanitizer for 'advanced origin tracking', which records all locations where an uninitialized value is stored to memory rather than just the creation point. <a href="http://reviews.llvm.org/rL204152">r204152</a>.</p></li><li><p>The lldb backtrace view has been changed to a process view where you can expand the process, its threads, and see all frames under each thread. <a href="http://reviews.llvm.org/rL204251">r204251</a>.</p></li><li><p>In compiler-rt, Google have re-licensed the Android ucontext implementation under the standard dual license of compiler-rt. <a href="http://reviews.llvm.org/rL204128">r204128</a>.</p></li></ul>
- LLVM Weekly - #11, Mar 17th 2014https://blog.llvm.org/2014/03/llvm-weekly-11-mar-17th-2014.htmlMon, 17 Mar 2014 08:23:00 +0000https://blog.llvm.org/2014/03/llvm-weekly-11-mar-17th-2014.html<p>Welcome to the eleventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>It seems an extra comma slipped in to my bio in <a href="http://www.amazon.co.uk/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058/">Learning Python with Raspberry Pi</a> (<a href="http://www.amazon.com/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058/">US</a>) meaning rather than being described as a "compiler hacker, ...", I am a "compiler, hacker, Linux geek, and Free Software enthusiast". It's therefore official, I am a compiler. Presumably this makes me uniquely suited to writing LLVM Weekly.</p><p>Previously I've only linked to internship opportunities rather than job ads. I'd be interested in how readers feel about linking to job ads looking for someone with LLVM experience? Do let me know via email or Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/11">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><ul><li><p>LLVM's popular <a href="http://llvm.org/docs/tutorial/">'Kaleidoscope' tutorial</a> on implementing a language with LLVM has been <a href="https://github.com/hobinjk/rusty-kaleidoscope">ported to Rust</a>.</p></li><li><p>The <a href="http://llvm.org/devmtg/2014-04/#callfor">programme for EuroLLVM 2014</a> has been announced. EuroLLVM will be taking place in Edinburgh, Scotland on the 7th and 8th of April. At the time of writing, there are still some spaces available.</p></li><li><p>The PNaCl 'canary' toolchain is <a href="https://groups.google.com/forum/#!topic/native-client-discuss/qkahSDf5lrM">now based on LLVM 3.4</a>.</p></li><li><p>The <a href="http://software.intel.com/sites/landingpage/IntrinsicsGuide/">Intel intrinsics guide</a> is a useful reference for the massive variety of specialised functionality available on modern Intel CPUs.</p></li><li><p>Broadcom Cambridge are <a href="http://jobs.broadcom.com/job/Cambridge-Engineer%2C-Principal-LLVM-Compiler-Engineer/30894500/">looking for an LLVM compiler engineer</a>. See the job ad for more details.</p></li></ul><h3>On the mailing lists</h3><ul><li><p>The optimization report functionality that was <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70998">discussed last week</a> now has a <a href="https://docs.google.com/document/d/1FYUatSjZZO-zmFBxjOiuOzAy9mhHA8hqdvklZv68WuQ/edit">more complete proposal</a> about exactly how it would work.</p></li><li><p>There's some useful information in <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71070">this thread about evaluating LLVM's register allocators</a>, in particular how to ensure all register allocators are linked in to the clang binary.</p></li><li><p>David Majinemer has posted on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71123">RFC on providing section declarations in LLVM IR</a>. Currently the section attribute can be used on GlobalVariables and Functions, but as pointed out in the RFC this has issues. Another key motivator is to support the representation of the Microsoft ABI's RTTI (runtime type information) data.</p></li><li><p>Justin Bogner has posted two profiling-related RFCs. The first is related to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71179">creating a LLVM library for reading and writing profile data</a>. He also proposes a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71190">binary format for instrumentation-based profiling data</a> as opposed to the naive textual format currently used. A library to work with a proposed binary profile data format was actually <a href="http://reviews.llvm.org/rL203703">commited this week</a>, but the commit was reverted in order for more discussion to take place.</p></li><li><p>Mike McFadden's <a href="https://github.com/BonzaiThePenguin/WikiSort">detailed write-up of his implementation of an in-place merge sort</a> has been making the rounds on Reddit and Hacker News this week. He <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35668">posted to the clang mailing list</a> to ask whether there's someone in particular to speak to about using his implementation to replace libcxx's current <code>inplace_stable_sort</code> (which his implementation beats by 3-15x). No responses to his <a href="http://article.gmane.org/gmane.comp.compilers.clang.scm/94723">post to cfe-commits</a> yet.</p></li><li><p>Mikael Persson has announced to the mailing list that <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35656">he has been continuing work on the Templight debugger</a>, and attaches a revised version of the Templight patch. <a href="http://plc.inf.elte.hu/templight/">Templight</a> is a debugger and profiler for C++ template meta-programming. The main addition to the previous official release is that Mikael has added a gdb-style debugger.</p></li><li><p>Rudolphe Suescun's question about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71138">whether lld is ready for his project</a> prompted some interesting replies detailing current status and gaps in the LLVM linker, lld. In particular, the current lack of support for linker scripts and lack of support for merge debug info when linking.</p></li></ul><h3>LLVM commits</h3><ul><li><p>I don't believe I made mention of this last week, but it's been decided that virtual methods that override their base class should be marked with the <code>override</code> keyword (and that the <code>virtual</code> keyword would then be considered redundant). <a href="http://reviews.llvm.org/rL203433">r203433</a>, <a href="http://reviews.llvm.org/rL203442">r203442</a>, and others.</p></li><li><p>Support for NaCl support on MIPS developed, with the addition of sandboxing for loads, stores, stack pointer changes, and function calls. <a href="http://reviews.llvm.org/rL203484">r203484</a>, <a href="http://reviews.llvm.org/rL203606">r203606</a>.</p></li><li><p>As discussed in an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71039">RFC last week</a>, cmpxchg now has a second ordering operand which describes the required semantics in case no exchange takes place. <a href="http://reviews.llvm.org/rL203559">r203559</a>.</p></li><li><p>An optimisation was added so that switch-to-lookup-table conversion can be done by adding a bitmask check. An example is given in the commit message. <a href="http://reviews.llvm.org/rL203694">r203694</a>.</p></li><li><p>The sample LLVM project has been removed. It has bitrotted over time and doesn't include CMake support at a time that LLVM is moving away from autoconf/automake. <a href="http://reviews.llvm.org/rL203728">r203729</a>.</p></li><li><p>The PowerPC backend learned basic support for the VSX instruction set extensions. <a href="http://reviews.llvm.org/rL203768">r203768</a>.</p></li><li><p>The merging of a patchset to improve MergeFunctions time complexity from <code>O(N*N)</code> to <code>O(N*log(N))</code>. <a href="http://reviews.llvm.org/rL203788">r203788</a>.</p></li><li><p>MachineRegisterInfo has been undergoing some major refactoring in order to allow the use of C++11 range-based for loops. <a href="http://reviews.llvm.org/rL203865">r203865</a>.</p></li><li><p>The <code>linker_private</code> and <code>linker_private_weak</code> linkage types were removed. <a href="http://reviews.llvm.org/rL203866">r203866</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Clang will now produce a warning when an invalid ordering is passed to one of the atomic builtins. <a href="http://reviews.llvm.org/rL203561">r203561</a>, <a href="http://reviews.llvm.org/rL203564">r203564</a>..</p></li><li><p>In the world of profile guided optimisation (PGO), PGO counters are now scaled down to 32 bits when necessary instead of just truncated. <a href="http://reviews.llvm.org/rL203592">r203592</a>.</p></li><li><p>The static analyzer gained support for detecting when passing pointers to const but uninitialized memory. <a href="http://reviews.llvm.org/rL203822">r203822</a>.</p></li><li><p>The <code>-Wunreachable-code</code> diagnostic has been broken up into different diagnostic groups to provide access to unreachable code checks for cases where the default heuristics of <code>-Wunreachable-code</code> aren't enough. <a href="http://reviews.llvm.org/rL203994">r203994</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lld now has a todo list containing a listing of missing GNU ld command line options. <a href="http://reviews.llvm.org/rL203491">r203491</a>.</p></li><li><p>lldb saw some reworking on how the ShouldStopHere mechanism works. This allows a mode where stepping out of a frame into a frame with no debug information will continue stepping until it arrives at a frame that does have deug information. <a href="http://reviews.llvm.org/rL203747">r203747</a>.</p></li><li><p>The Polly build system has been updated so the Makefile builds a single monolithic LLVMPolly.so. <a href="http://reviews.llvm.org/rL203952">r203952</a>.</p></li></ul>
- LLVM Weekly - #10, Mar 10th 2014https://blog.llvm.org/2014/03/llvm-weekly-10-mar-10th-2014.htmlMon, 10 Mar 2014 07:43:00 +0000https://blog.llvm.org/2014/03/llvm-weekly-10-mar-10th-2014.html<p>Welcome to the tenth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>This week the book I authored in collaboration with <a href="https://twitter.com/ben_everard">Ben Everard</a>, <a href="http://www.amazon.co.uk/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058">Learning Python with Raspberry Pi</a> (<a href="http://www.amazon.com/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058/">Amazon US</a>) is officially released.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/10">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>John Regehr has written a blog post detailing <a href="http://blog.regehr.org/archives/1109">some ideas for implementing a superoptimizer for LLVM</a>. There's some good stuff in the comments too.</p><p>Version 2.1 of the Capstone disassembly framework has <a href="http://www.capstone-engine.org/Version-2.1.html">been released</a>. Library size is about 40% smaller, memory usage is down 40% and there are performance improvements as well.</p><p>Facebook have released <a href="https://github.com/facebook/chisel">Chisel</a>, a collection of LLDB commands to assist debugging iOS apps.</p><p>A <a href="https://github.com/gilligan/vim-lldb">fork of vim-lldb</a>, the LLDB plugin for Vim included in the lldb repo has appeared. Changes so far have been relatively minor.</p><h3>On the mailing lists</h3><ul><li><p>Probably one of the most interesting discussions on the mailing list this week came from Mark Seaborn's <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70908">questions about upstreaming PNaCl's IR simplification passes</a>. Both PNaCl and the new Emscripten fastcomp backend make use of a series of out-of-tree IR-to-IR passes that simplify the IR by lowering complex to simpler features. The suggestion is to upstream these so that everyone can benefit. Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70918">raises concerns</a> that these passes might bitrot without any in-tree users, suggesting that the PNaCl and Emscripten communities could do more to contribute to upstream LLVM and that such a track record would help ease that concern. There are a number of people chiming in to say they would find the functionality useful.</p></li><li><p>Diego Novillo asks <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70998">whether people would be interested in an optimization report facility</a>. This would give useful information about the decisions taken by various optimisers, which might be useful when investigating why code doesn't perform as expected and in finding missed optimisations. Unsurprisingly, everyone thinks this would be a good feature. Diego promises to write some more detailed, concrete proposals in the coming days now it's clear people like the general idea.</p></li><li><p>Kev Kitchens <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70896">asks about cross-compiling compiler-rt</a>. Vadim Chugunov helpfully points to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70902">his work on Rust's fork of compiler-rt</a> to support this. It's also pointed out in the thread that support for unwinding actually lives in libc++abi rather than in a separate libunwind where you might expect to find it.</p></li><li><p>There's a pretty <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35446">long discussion on naming for reverse iterators and other issues</a> which should make entertaining reading for anyone who enjoys bikeshedding (not that there's anything wrong with it, there's some good discussion of API naming principles there).</p></li><li><p>Tim Northover has shared an RFC (with initial patch) on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/71039">adding a second ordering operand to cmpxchg</a> which which indicates the failure ordering.</p></li></ul><h3>LLVM commits</h3><ul><li><p>A new implementation of PBQP (partitioned boolean quadratic programming)-based register allocator landed. <a href="http://reviews.llvm.org/rL202735">r202735</a>. The original commit (<a href="http://reviews.llvm.org/rL202551">r202551</a>) message details the changes, including massively reduced memory consumption. Average memory reduction is claimed to be 400x. The tagline is "PBQP: No longer feasting upon every last byte of your RAM".</p></li><li><p>AArch64 gained a machine description for Cortex-A53, which involved giving all non-NEON instructions scheduling annotations. <a href="http://reviews.llvm.org/rL203125">r203125</a>. REVERTED</p></li><li><p>The SPARC backend gained support for the VIS SIMD instruction set extensions. <a href="http://reviews.llvm.org/rL202660">r202660</a></p></li><li><p>A whole bunch of classes moved around, with the intention that LLVM's support library will work when building with C++ modules. <a href="http://reviews.llvm.org/rL202814">r202814</a> and many others. InstIterator, GetElementPtrTypeIterator, CallSite, PatternMatch, ValueHandle, ValueMap, CFG, ConstantFolder, NoFolder, PredIteratorCache, ConstantRange, PassNameParser, and LeakDetector moved from Support to IR.</p></li><li><p>The <code>PROLOG_LABEL</code> TargetOpcode was replaced with <code>CFI_INSTRUCTION</code> which is intended to have simpler semantics and be less convoluted to use. See the commit message for more details. <a href="http://reviews.llvm.org/rL203024">r203204</a>.</p></li><li><p>Uses of <code>OwningPtr<T></code> were replaced with <code>std::unique_ptr<T></code>. <a href="http://reviews.llvm.org/rL203083">r203083</a>.</p></li><li><p>The <code>inalloca</code> grammar was cleaned up. <a href="http://reviews.llvm.org/rL203376">r203376</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The PGO (profile-guided optimisation) code got some minor refactoring in preparation for handling non-C/C++ code, and initial suport for Objective-C blocks. <a href="http://reviews.llvm.org/rL203073">r203073</a>, <a href="http://reviews.llvm.org/rL203157">r203157</a>.</p></li><li><p>Module dependences are now included in the dependency files created by <code>-MD/-MMD</code> etc. <a href="http://reviews.llvm.org/rL203208">r203208</a>.</p></li><li><p>The <code>-Wunreachable-code</code> option no longer warns about dead code guarded by a configuration value. <a href="http://reviews.llvm.org/rL202912">r202912</a>.</p></li><li><p>The MSVC mangling scheme is not used for statics or types which aren't visible. <a href="http://reviews.llvm.org/rL202951">r202951</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>LLDB now supported JIT debugging on Linux using the GDB JIT interface. <a href="http://reviews.llvm.org/rL202956">r202956</a>.</p></li><li><p>Polly started emitting llvm.loop metadata for parallel loops. <a href="http://reviews.llvm.org/rL202854">r202854</a>.</p></li><li><p>In compiler-rt, assembler implementations of <code>__sync_fetch_and_*</code> for ARM were committed. <a href="http://reviews.llvm.org/rL202812">r202812</a>.</p></li><li><p>The level of windows support in LLD has been documented. <a href="http://reviews.llvm.org/rL203017">r203017</a>.</p></li></ul>
- LLVM Weekly - #9, Mar 3rd 2014https://blog.llvm.org/2014/03/llvm-weekly-9-mar-3rd-2014.htmlMon, 03 Mar 2014 05:43:00 +0000https://blog.llvm.org/2014/03/llvm-weekly-9-mar-3rd-2014.html<p>Welcome to the ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>As well as growing another year older last week, I've also started publicising the book I authored with <a href="https://twitter.com/ben_everard">Ben Everard</a>, <a href="http://www.amazon.co.uk/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058">Learning Python with Raspberry Pi</a> (<a href="http://www.amazon.com/Learning-Python-Raspberry-Alex-Bradbury/dp/1118717058/">Amazon US</a>) which should ship soon in paperback or is available right now for Kindle. Hopefully it should be available soon in DRM-free digital formats on oreilly.com. I will be putting more of my Raspberry Pi exploits and tutorials on <a href="http://muxup.com">muxup.com</a>, so if that interests you follow <a href="https://twitter.com/muxup">@muxup</a>.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/9">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The list of <a href="https://www.google-melange.com/gsoc/org/list/public/google/gsoc2014">mentoring organisations for Google Summer of Code 2014</a> has been released. LLVM is one of them, so any budding compiler engineers who qualify may want to check out the <a href="http://llvm.org/OpenProjects.html">ideas page</a>. Other organisations I spotted advertising relevant project ideas are <a href="http://llvm.linuxfoundation.org/index.php/GSoC">the Linux Foundation</a>, <a href="http://www.x.org/wiki/SummerOfCodeIdeas/">X.org</a> and of course <a href="http://gcc.gnu.org/wiki/SummerOfCode">GCC</a>.</p><p>At the end of last week, Broadcom made a major step forward in <a href="http://blog.broadcom.com/chip-design/android-for-all-broadcom-gives-developers-keys-to-the-videocore-kingdom/">announcing the release of full register level documentation for the VideoCore IV graphics engine</a> as well as full graphics driver source. The device most well-known for featuring VideoCore IV is the <a href="http://www.raspberrypi.org/archives/6299">Raspberry Pi</a>. The released documentation opens the door to producing something similar to the <a href="http://www.raspberrypi.org/archives/5934">GPU-accelerated FFT library</a> support that was recently released. Some readers of LLVM Weekly may of course be interested in using this information to produce an LLVM backend. Hopefully the following pointers will help. There are lots of resources linked to at the homepage of the <a href="https://github.com/hermanhermitage/videocoreiv">VideoCore IV reverse engineering project</a>. I'd draw particular attention to the <a href="https://github.com/hermanhermitage/videocoreiv-qpu">QPU reverse engineering effort</a> which contains good information despite the reverse engineering part of the work being made unnecessary by the Broadcom release. You may want to check out the <a href="http://www.freelists.org/archive/raspi-internals/">raspi-internals mailing list</a> and <code>#raspberrypi-internals</code> on Freenode. It's also worth looking at <a href="https://github.com/hermanhermitage/videocoreiv-qpu/tree/master/qpu-fft">the commented disassembly of the VideoCore FFT code</a> and Herman Hermitage's work in progress <a href="https://github.com/hermanhermitage/videocoreiv-qpu/tree/master/qpu-tutorial">QPU tutorial</a>.</p><p>Code for <a href="https://github.com/draperlaboratory/fracture">Fracture</a>, an architecture-independent decompiler to LLVM IR has been released.</p><p>Olivier Goffart has written about <a href="http://woboq.com/blog/moc-with-clang.html">his proof of concept reimplementation of Qt's moc using libclang</a>. It's actually from last year, but it's new to me.</p><p>Alex Denisov has written a <a href="http://railsware.com/blog/2014/02/28/creation-and-using-clang-plugin-with-xcode/">guide to writing a clang plugin</a>. He gives an example of a minimal plugin that complains about lowercased Objective C class names.</p><p>Coursera are re-running <a href="https://www.coursera.org/course/compilers">their compilers course</a> on March the 17th. See <a href="http://dirkjan.ochtman.nl/writing/2012/07/21/compilers-on-coursera.html">Dirkjan Ochtman's impressions of the course from the previous run</a>.</p><p>The Qualcomm LLVM team are <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70655">advertising for an intern</a>.</p><h3>On the mailing lists</h3><ul><li><p>Denis Steckelmacher <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70671">kicked off a discussion about the suggested GSoC project to use LLVM for code generation</a>. There are particularly interesting replies from <a href="http://article.gmane.org/gmane.comp.debugging.valgrind.devel/26122">Kirill Batuzov</a> and <a href="http://article.gmane.org/gmane.comp.debugging.valgrind.devel/26124">Julian Seward</a> who elaborate on why it's not a case of 'just use LLVM and it will be fast' as well as suggesting some changes that could be made to increase Valgrind's speed.</p></li><li><p>Chandler Carruth <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70836">announces he has flipped the switch for C++11 support on the build systems</a>. I, for one, welcome our new C++11 overloards.</p></li><li><p>For those interested in the issues of supporting precise GC on LLVM, see the discussion surrounding Philip Reames' <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70724">question on representing a safepoint</a>.</p></li><li><p>Alp Toker <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70714">proposed a way to move forward with the LLVM OpenMP runtime</a>. The main issue right now is there is no real test suite. Alp's suggestion is to organise a few days effort to adapt the libgomp test suite (to be hosted externally, due to licensing reasons).</p></li><li><p>Jasper Neumann <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70789">suggested a cunning optimisation</a> for checking the modulus. Benjamin Kramer explains the difficulty of integrating such an optimisation in to the peephole optimiser.</p></li><li><p>Nico Weber <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35267">suggests a Clang warning that fires on unexpected indentation levels</a>. He has <a href="http://llvm.org/bugs/show_bug.cgi?id=18938">prototype implementation</a> up on the bugtracker.</p></li><li><p>Saleem Abdulrasool has <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35268">suggested adding a macro that indicates the LLVM integrated assembler is being used</a>. Respondents to the thread so far aren't keen on the idea, pointing out that projects should really check whether a certain syntax or feature they need works rather than marking themselves incompatible with the LLVM integrated assembler which may of course improve compatibility in the future.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LLVM grew a big-endian AArch64 target <a href="http://reviews.llvm.org/rL202024">r202024</a>. Some might consider it a step back, but apparently there's a decent number of people interested in big-endian on AArch64. There's an interesting <a href="http://www.linux-kvm.org/wiki/images/c/c4/Kvm-forum-2013-crossing-the-endianness-bridge.pdf">presentation from ARM</a> about running a virtualised BE guest on a LE host.</p></li><li><p>The flipping of the C++11 switch has allowed a number of simplifications to start to make their way in to the LLVM codebase. For instance, turning simple functors in to lambdas. Like or loathe C++11 lambda syntax, they're certainly less verbose. <a href="http://reviews.llvm.org/rL202588">r202588</a>. <code>OwningPtr<T></code> gained support for being converted to and from <code>std::unique_ptr<T></code>, which lays the ground for LLVM moving to using <code>std::unique_ptr</code> in the future. <a href="http://reviews.llvm.org/rL202609">r202609</a>.</p></li><li><p>The coding standards document was updated to reflect the C++11 features that can now be used in the LLVM/Clang codebase and to provide guidance on their use. <a href="http://reviews.llvm.org/rL202497">r202497</a>, <a href="http://reviews.llvm.org/rL202620">r202620</a>.</p></li><li><p>The loop vectorizer is now included in the LTO optimisation pipeline by default. <a href="http://reviews.llvm.org/rL202051">r202051</a>.</p></li><li><p>DataLayout has been converted to be a plain object rather than a pass. A DataLayoutPass which holds a DataLayout has been introduced. <a href="http://reviews.llvm.org/rL202168">r202168</a>.</p></li><li><p>The PowerPC backend learned to track condition register bits, which produced measurable speedups (10-35%) for the POWER7 benchmark suite. <a href="http://reviews.llvm.org/rL202451">r202451</a>.</p></li><li><p>X86 SSE-related instructions gained a scheduling model. Sadly there is no indication whether this makes any measurable difference to common benchmarks. <a href="http://reviews.llvm.org/rL202065">r202065</a>.</p></li><li><p>The scalar replacement of aggregates pass (SROA) got a number of refactorings and bug fixes from Chandler Carruth, including some bug fixes for handling pointers from address spaces other than the default. <a href="http://reviews.llvm.org/rL202092">r202092</a>, <a href="http://reviews.llvm.org/rL202247">r202247</a>, and more.</p></li><li><p>An experimental implementation of an invalid-pointer-pair detector was added as part of AddressSanitizer. This attempts to identify when two unrelated pointers are compared or subtracted. <a href="http://reviews.llvm.org/rL202389">r202389</a>.</p></li><li><p>Shed a tear, for libtool has been removed from the LLVM build system. The commit says it was only being used to find the shared library extension and nm. The diffstat of 93 insertions and 35277 deletions speaks for itself. <a href="http://reviews.llvm.org/rL202524">r202524</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The initial changes needed for <code>omp simd</code> directive support were landed. <a href="http://reviews.llvm.org/rL202360">r202360</a>.</p></li><li><p>The <code>-Wabsolute-value</code> warning was committed, which will warn for several cases of misuse of absolute value functions. It will warn when using e.g. an int absolute value function on a float, or when using it one a type of the wrong size (e.g. using abs rather than llabs on a long long), or whn taking the absolute value of an unsigned value. <a href="http://reviews.llvm.org/rL202211">r202211</a>.</p></li><li><p>An API was added to libclang to create a buffer with a JSON virtual file overlay description. <a href="http://reviews.llvm.org/rL202105">r202105</a>.</p></li><li><p>The driver option <code>-ivfsoverlay</code> was added, which reads the description of a virtual filesystem from a file and overlays it over the real file system. <a href="http://reviews.llvm.org/rL202176">r202176</a>.</p></li><li><p>CFG edges have been reworked to encode potentially unreachable edges. This involved adding the AdjacentBlock class this encodes whether the block is reachable or not. <a href="http://reviews.llvm.org/rL202325">r202325</a>.</p></li><li><p>The 'remark' diagnostic type was added. This provides additional information to the user (e.g. information from the vectorizer about loops that have been vectorized). <a href="http://reviews.llvm.org/rL202475">r202475</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The compiler-rt subproject now has a <code>CODE_OWNERS.txt</code> to indicate who is primarily responsible for each part of the project. <a href="http://reviews.llvm.org/rL202377">r202377</a>.</p></li><li><p>A standalone deadlock detector was added to ThreadSanitizer. <a href="http://reviews.llvm.org/rL202505">r202505</a>.</p></li><li><p>The OpenMP runtime has been ported to FreeBSD. <a href="http://reviews.llvm.org/rL202478">r202478</a>.</p></li></ul>
- LLVM Weekly - #8, Feb 24th 2014https://blog.llvm.org/2014/02/llvm-weekly-8-feb-24th-2014.htmlMon, 24 Feb 2014 06:05:00 +0000https://blog.llvm.org/2014/02/llvm-weekly-8-feb-24th-2014.html<p>Welcome to the eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>I'll be at the <a href="http://www.raspberrypi.org/archives/6074">Raspberry Jamboree</a> at the end of the week, so if you're going as well be sure to say hi.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/8">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><ul><li><p>As a followup to the proposal that Philip Reames posted last week, where he described plans for contributing precise garbage collection support to LLVM, he has <a href="http://www.philipreames.com/Blog/2014/02/21/why-not-use-gcroot/">written a blog post about why the llvm.gcroot intrinsic is insufficient for this purpose</a>. A followup post is promised describing the approach they've decided to take. The article is is written so as to be accessible to those who may not be familiar with GC implementation. He also raises some interesting issues with gcroot, even when using it for a non-relocating collector.</p></li><li><p>Some may remember the <a href="http://dagger.repzret.org/">Dagger project</a> for decompilation of programs to LLVM IR from EuroLLVM 2013 (<a href="http://llvm.org/devmtg/2013-04/bougacha-slides.pdf">slides</a>). The promised source code release didn't happen, but the developers have <a href="http://dagger.repzret.org/update-feb-2014/">posted an update</a> detailing what they've been up to. There have been a lot of design changes, and some of the work has been submitted upstream as patches to LLVM MC. "At this point we don't really have a schedule; whenever we feel a patch is ready to go, we submit it to the community. The goal being, once we're done, our work becomes a full part of LLVM, where we and all contributors can continue to advance it!"</p></li><li><p>Tamás Szelei has written up a <a href="http://szelei.me/code-generator/">useful guide to implementing a code generator with libclang and Python</a>.</p></li><li><p>The Emscripten project is <a href="https://groups.google.com/forum/#!topic/emscripten-discuss/mZMkX3uBG4s">getting ready to use its 'fastcomp' LLVM backend by default</a>. Previously they had a series of passes written in Javascript to convert from LLVM IR to Javascript, but this is now implemented as a C++ LLVM backend. See <a href="https://github.com/kripken/emscripten/wiki/LLVM-Backend">their wiki</a> for more info.</p></li><li><p>Agner has <a href="http://agner.org/optimize/blog/read.php?i=311#311">updated his popular optimisation manuals</a> to include test results for AMD Steamroller processors, as well as adding some more AVX-512 information.</p></li><li><p>The <a href="http://dwarfstd.org">DWARF Debugging Information Format Committee</a> are welcoming comments, suggestions or proposals for changes to DWARF <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35175/">until March 31st</a>. Although DWARF Version 5 is 'nearing completion', it seems that no drafts have been published so you'll have to base your comments on DWARF 4. Do drop me a note if you know otherwise.</p></li><li><p>There have been <a href="http://sylvestre.ledru.info/blog/2014/02/22/some-updates-on-llvm-org">several updates</a> to <a href="http://llvm.org/apt/">http://llvm.org/apt/</a>. The upcoming Ubuntu 14.04 is now a supported distribution, and additionally both the stable and development versions of LLVM/Clang are built and can be installed side-by-side.</p></li></ul><h3>On the mailing lists</h3><ul><li><p>Renato Golin <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35229">reminds us</a> that although work is underway to update all buildbots to support C++11, the switch to use <code>-std=c++11</code> has not yet been flipped, so you'll have to hold off on using C++11 features in LLVM/Clang patches for just a little longer.</p></li><li><p>Saleem Abulrasool <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70584">points to an issue running recent Clang on the Linux kernel</a> related to the integrated assembler. As regular readers will know, the behaviour was recently changed so that for backends which have an integrated assembler, any inline assembly will be validated by it during compilation, even when compiling with <code>-S</code> (i.e. outputting assembly). The problem is that the Linux kernel is purposely including invalid assembly in some cases when outputting assembler files. Early responses are in favour of keeping current behaviour, people who are doing weird and wacky things can just use the <code>-no-integrated-as</code> switch.</p></li><li><p>In response to the earlier discussion about unwind behaviour in LLVM/Clang, Logan Chien has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70461">posted a detailed description of the problems he sees</a>.</p></li><li><p>Kevin Qin writes <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70511">asking about adding register allocation constraints</a>. Often the mailing list threads which get highlighted in LLVM Weekly are about particularly hairy problems that don't currently have a good solution. I'm happy to see this problem has a simple solution though, as Tim Northover and Quentin Colombet point out the <code>@earlyclobber</code> constraint can be used to ensure the output register allocated is different to the input registers.</p></li><li><p>While working on changes to CodeGenPrepare, Quentin Combet noted his patch would introduce a dependency from libLLVMScalarOpts (where CodeGenPrepare currently lives) to libLLVMCodeGen. He <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70528">writes to the list</a> asking for views on how to solve this problem. The forming consensus seems to be that it should just be moved to CodeGen. Potentially, any IR pass that depends directly on TargetLowering should be moved also. The move to CodeGenPrepare to lib/CodeGen has now <a href="http://reviews.llvm.org/rL201912">been committed</a>.</p></li><li><p>Per Viberg is <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35185">soliciting comments</a> on his design draft for improving the detection of uninitialized arguments.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The llvm-profdata tool was introduced. This tool will merge profile data generated by PGO instrumentation in Clang, though may later pick up more functionality. <a href="http://reviews.llvm.org/rL201535">r201535</a>.</p></li><li><p>In a long overdue cleanup, various member variables were renamed from TD to DL to match the renaming of TargetData to DataLayout. <a href="http://reviews.llvm.org/rL201581">r201581</a>, <a href="http://reviews.llvm.org/rL201827">r201827</a>, <a href="http://reviews.llvm.org/rL201833">r201833</a>. Additionally, DebugLoc variables which were named DL have now been renamed to DbgLoc so as not to be confused with DataLayout. <a href="http://reviews.llvm.org/rL201606">r201606</a>.</p></li><li><p>MCAsmParser now supports required parameters in macros, increasing GNU assembler compatibility. <a href="http://reviews.llvm.org/rL201630">r201630</a>.</p></li><li><p>A new TargetLowering hook, <code>isVectorShiftByScalarCheap</code> was added to indicate whether it's significantly cheaper to shift a vector by a scalar rather than by another vector with different values for different lanes. This is used by the new <code>OptimizeShuffleVectorInst</code> in CodeGenPrepare which tries to sink shufflevector instructions down to the basic block they're used so CodeGen can determine if the right hand of a shift is really a scalar. <a href="http://reviews.llvm.org/rL201655">r201655</a>.</p></li><li><p>Private linkage is now properly supported for MachO. <a href="http://reviews.llvm.org/rL201700">r201700</a>.</p></li><li><p>getNameWithPrefix and getSymbol were moved from TargetLowering to TargetMachine, which removes the dependency from Target to CodeGen. <a href="http://reviews.llvm.org/rL201711">r201711</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>The PGO instrumentation will now compute counts in a separate AST traversal. The reasons for and advantages of this change are documented in detail in the commit message. <a href="http://reviews.llvm.org/rL201528">r201528</a>.</p></li><li><p>Some initial work was committed on documenting available attributes in Clang. Attribute authors are encouraged to submit missing documentation (the method of documentation is described in the addition to the InternalManual.rst). <a href="http://reviews.llvm.org/rL201515">r201515</a>.</p></li><li><p>The IdenticalExprChecker has been extended to check the two branches of an if as well as logical and bitwise expressions. For those not familiar, this checker tries to warn about the unintended use of identical expressions. <a href="http://reviews.llvm.org/rL201701">r201701</a>, <a href="http://reviews.llvm.org/rL201702">r201702</a>.</p></li><li><p>CGRecordLayoutBuilder has been completely rewritten to remove cruft, simplify the implementation, and to work in one pass. <a href="http://reviews.llvm.org/rL201907">r201907</a>.</p></li><li><p>The CastSizeChecker was taught how to correctly deal with flexible array members. <a href="http://reviews.llvm.org/rL201583">r201583</a>.</p></li><li><p>A number of thread-safety attributes have been renamed (with their old name silently deprecated). e.g. <code>lockable</code> is now <code>capability</code>, <code>exclusive_locks_required</code> is now <code>requires_capability</code>. <a href="http://reviews.llvm.org/rL201585">r201585</a>. Additionally, the documentation was updated and greatly expanded. <a href="http://reviews.llvm.org/rL201598">r201598</a>.</p></li><li><p>Initial virtual file system support <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34941">discussed previously on the mailing list</a> has landed. <a href="http://reviews.llvm.org/rL201618">r201618</a>, <a href="http://reviews.llvm.org/rL201635">r201635</a>.</p></li><li><p>The vcvtX intrinsics were added for v8 ARM as opposed to only being recognised when targeting AArch64. <a href="http://reviews.llvm.org/rL201661">r201661</a>.</p></li><li><p>The hard-float ARM EABI (often known as gnueabihf) is now supported for FreeBSD. <a href="http://reviews.llvm.org/rL201662">r201662</a>.</p></li><li><p>Clang will now provide <code>max_align_t</code> in C11 and C++11 modes. Note the complaint in the commit message though that <code>max_align_t</code> as defined is not 'good' or 'useful'. <a href="http://reviews.llvm.org/rL201729">r201729</a>.</p></li><li><p>Again, there were a number of commits related to increasing compatibility with the MS ABI. None of them immediately leaped out at me as worth highlighting individually, so I recommend you have a flick through last weeks commits if you're particularly interested.</p></li></ul><h3>Other project commits</h3><ul><li><p>Rudimentary support for a standalone compiler-rt build system was added, which will allow the compiler-rt libraries to be built seperately from LLVM/Clang. <a href="http://reviews.llvm.org/rL201647">r201647</a>, <a href="http://reviews.llvm.org/rL201656">r201656</a>.</p></li><li><p>Assembly functions for AddressSanitizer on x86/amd64 were added. <a href="http://reviews.llvm.org/rL201650">r201650</a>.</p></li><li><p>LLDB gained a hardware watchpoint implementation for FreeBSD <a href="http://reviews.llvm.org/rL201706">r201706</a>.</p></li><li><p>Polly gained support for polyhedral dead code elimination. <a href="http://reviews.llvm.org/rL201817">r201817</a>.</p></li><li><p>A patch was added to lldb to provide initial support for the Hexagon DSP. <a href="http://reviews.llvm.org/rL201655">r201665</a>.</p></li></ul>
- LLVM Weekly - #7, Feb 17th 2014https://blog.llvm.org/2014/02/llvm-weekly-7-feb-17th-2014.htmlMon, 17 Feb 2014 04:19:00 +0000https://blog.llvm.org/2014/02/llvm-weekly-7-feb-17th-2014.html<p>Welcome to the seventh issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p><p>As always, apologies if I didn't pick up your favourite mailing list discussion or commits. Do drop me a line if you think I'm missing something interesting. There haven't been that many external news stories or blog posts (that I've found) in the last week, but it's been a particularly busy week on the mailing lists with a whole bunch of interesting discussions or RFCs.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/7">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The <a href="http://ellcc.org/">ELLCC Embedded Compiler Collection</a> now <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70441">has precompiled builds available</a> for ARM, i386, Mips, PowerPC and x86-64. Handily, these are all statically linked. The aim of ELLCC is to provide an easy to use multi-target cross compilation environment for embedded systems, and is of course based on LLVM and clang.</p><p>The next Waterloo Region LLVM Social <a href="http://article.gmane.org/gmane.comp.debugging.lldb.devel/3237/">has been announced for Feb 20th</a>.</p><p>The next Paris LLVM Social <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70330">will take place on Feb 24th</a>, hosted by Mozilla.</p><h3>On the mailing lists</h3><ul><li><p>Philip Reames contributed an RFC on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70430">using GetElementPtr as the canonical form for pointer addressing in LLVM IR before CodeGenPrepare</a>. The motivation behind this proposal will be interesting to many, particularly the Rust community and other language implementors looking to target LLVM. Philip and his colleagues (at Azul Systems I believe) are looking to support precise garbage collection in LLVM, and excitingly a complete upstreamable implementation should be coming "relatively shortly. (i.e. months, not weeks, not years)"</p></li><li><p>As a followup to last week's discussions on the GCC mailing list, Renato Golin has written a <a href="http://article.gmane.org/gmane.comp.gcc.devel/134419/">detailed proposal on how LLVM and GCC developers can co-operate</a>. He is welcoming responses <a href="http://developers.slashdot.org/comments.pl?sid=4769281&cid=46209457">on Slashdot</a>. Chris Lattner is very much in favour of the effort, though points out that there are some lists already used for this purpose (such as the 'Itanium ABI list', which I assume refers to <a href="http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev">cxx-abi-dev</a>) and perhaps other similar vendor-neutral mailing lists could be created.</p></li><li><p>Tom Roeder has posted an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70274">RFC on the integration of control-flow integrity techniques in to LLVM</a>. Control-flow integrity (CFI) helps to protect against a variety of attacks by ensuring control flow at run time matches a path determined ahead of time, and is described in <a href="http://research.microsoft.com/pubs/69217/ccs05-cfi.pdf">this 2005 paper</a>. Tom has an implementation that has been tested on Chromium, producing an overhead of ~4% for the dromaeo benchmark. JF Bastien responded indicating the PNaCl team would be interested in this work, while other respondents discussed representing a jump table in LLVM IR as opposed to inline assembly.</p></li><li><p>Jordan Rose kicked off a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35023">the future of the clang static analyzer</a>. One issue he raises is how to mark issues as false positives, hopefully in a more sophisiticated way than disabling checkers. He also mentions long term plans for adding a full-program analysis mode that would work across translation units. Ted Kremenek <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35025">follows up</a> with more details about treating reported diagnostics as 'issues' which might be suppressed individually.</p></li><li><p>Andrew Bokhanko from Intel initiated a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34995">discussion on adding some sort of SIMD pragma to Clang</a>. Options include upstreaming the implementation of OpenMP 4's <code>#pragma omp simd</code> from <a href="http://clang-omp.github.com">clang-omp</a>.</p></li><li><p>Mahdi Hamzeh writes to the mailing list with a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70348">query about if-converting before register allocation</a>. Andrew Trick points to the EarlyIfConverter, which can be run before register allocation but only generates conditional moves rather than predicating instructions. He <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70354">suggests an approach</a> for implementing if-conversion as a target-specific pass.</p></li><li><p>Vadim Chugunov <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70280">kicks off a discussion on a compiler-rt roadmap</a>. Issues include a potential rename, whether libunwind should be removed, and ensuring that it builds for all platforms that LLVM can target.</p></li><li><p>Matt Arsenault is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70390">seeking ideas on solving a problem where loop induction variables are larger than they need to be</a>.</p></li><li><p>Howard Hinnant is stepping down as code owner of libc++ and it <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70419">looks like Marshall Clow</a> is going to take over. Many LLVM devs also drop by to thank Howard for his hard work on libc++.</p></li><li><p>Ted Kremenek gives a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/35049">great summary of the status of ArrayBoundChecker and ArrayBoundCheckerV2</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>AsmPrinter::EmitInlineAsm() will no longer use the EmitRawText() call for targets with mature MC (MachineCode) support. The MCASMInfo::UseIntegratedAS field was added. When true, the integrated assembler will parse inline assembly even when emitting assembly output. <a href="http://reviews.llvm.org/rL201333">r201237</a>.</p></li><li><p>The RTDyld API learned to precompute the amount of memory required for all sections in a module, and reserveAllocationSpace to reserve the given amount of space. <a href="http://reviews.llvm.org/rL201259">r201259</a>.</p></li><li><p>The LTO API gained <code>lto_module_create_from_memory_with_path</code>, which is mainly useful for emitting warning messages from the linker. <a href="http://reviews.llvm.org/rL201114">r201114</a>.</p></li><li><p>ScalarEvolution will now analyze the trip count of loops where there is a switch guarding the exit. <a href="http://reviews.llvm.org/rL201159">r201159</a>.</p></li><li><p>The notes on Phabricator now include a suggestion to provide a link to the Differential revision (the code review) on commits that have been reviewed in this way. Please do this! <a href="http://reviews.llvm.org/rL201160">r201160</a>.</p></li><li><p>The AArch64 backend now recognises Cortex-A53 and Cortex-A57. <a href="http://reviews.llvm.org/rL201305">r201305</a>.</p></li><li><p>The ARM integrated assembler gained partial support for the <code>.arch_extension</code> directive. <a href="http://reviews.llvm.org/rL201471">r201471</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>There have been yet more updates to Clang's Microsoft ABI compatibility. Clang now understands Microsoft's <code>pointers_to_members</code> pragma. <a href="http://reviews.llvm.org/rL201105">r201105</a> as well as the <code>vtordisp</code> pragma <a href="http://reviews.llvm.org/rL201274">r201274</a>. In other MS ABI developments, the <code>-vm{b,g,s,m,v}</code> are now supported too. <a href="http://reviews.llvm.org/rL201175">r201175</a>.</p></li><li><p>The command line option <code>-fstack-protector-strong</code> was added. <a href="http://reviews.llvm.org/rL2011120">r201120</a>. See also <a href="http://reviews.llvm.org/rL200601">r200601</a> for info on the sspstrong function attribute.</p></li><li><p>Frontend support for the OpenMP <code>if</code> clause was committed. <a href="http://reviews.llvm.org/rL201297">r201297</a>.</p></li><li><p>You can use the <code>--rtlib=compiler-rt</code> flag to attempt to link against compiler-rt rather than libgcc. <a href="http://reviews.llvm.org/rL201307">r201307</a>.</p></li><li><p>The <code>-Wignored-pragmas</code> diagnostic was added, that will warn in any case where a pragma would have a side effect but is ignored. <a href="http://reviews.llvm.org/rL201102">r201102</a>.</p></li><li><p>The name of the checker producing each diagnostic message is now available through <code>getCheckName()</code>. This can be used to enable/disable a specific checker. <a href="http://reviews.llvm.org/rL201186">r201186</a>.</p></li><li><p>Clang now understands the <code>-fbuild-session-timestamp=</code> and <code>-fmodules-validate-once-per-build-session</code> flags which allows you to make it verify source files for a module only once during a build. <a href="http://reviews.llvm.org/rL201224">r201224</a>, <a href="http://reviews.llvm.org/rL201225">r201225</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The sanitizer projects in compiler-rt gained the beginnings for a deadlock detector. <a href="http://reviews.llvm.org/rL201302">r201302</a>, <a href="http://reviews.llvm.org/rL201407">r201407</a>..</p></li><li><p>The original compiler-rt functions (i.e. those that act as a libgcc replacement) now live in the lib/builtins directory. <a href="http://reviews.llvm.org/rL201393">r201393</a>.</p></li><li><p>In lldb, the user can now specify trap-handler-names, a list of functions which should be treated as trap handlers. <a href="http://reviews.llvm.org/rL201386">r201386</a>.</p></li></ul>
- LLVM Weekly - #6, Feb 10th 2014https://blog.llvm.org/2014/02/llvm-weekly-6-feb-10th-2014.htmlMon, 10 Feb 2014 08:15:00 +0000https://blog.llvm.org/2014/02/llvm-weekly-6-feb-10th-2014.html<p>Welcome to the sixth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter. I've been keeping the <a href="https://twitter.com/llvmweekly">@llvmweekly Twitter account</a> updated throughout the week, so follow that if you want more frequent news updates.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/6">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Alexi Starovoitov has <a href="https://lkml.org/lkml/2014/2/5/743">published an LLVM backend</a> targeting an extended version of the Linux Kernel's BPF. An example of the sort of program that might be compiled and run via BPF can be found <a href="http://article.gmane.org/gmane.linux.kernel/1605783">here</a>.</p><p>There is now under a week to go to submit proposals for presentations, tutorials, posters, etc for the upcoming <a href="http://llvm.org/devmtg/2014-04/">EuroLLVM 2014</a>. Get writing!</p><p>LWN's coverage of the recent discussion about LLVM and its licensing on the GCC mailing list is <a href="http://lwn.net/Articles/582697/">now available</a> to non-subscribers.</p><p>Renato Golin <a href="http://gcc.gnu.org/ml/gcc/2014-02/msg00093.html">posted to the GCC mailing list</a> suggesting there be more collaboration where possible on issues such as standardisation of command line interfaces, language extensions, or just general technical discussion.I know a mailing list GCC developers who want to keep abreast of LLVM/Clang developments should subscribe to...</p><p>Phoronix has <a href="http://www.phoronix.com/scan.php?page=article&item=intel_haswell_gcclang34&num=1">published a benchmark</a> comparing GCC 4.8.2, a GCC 4.9 snapshot and Clang 3.4 on an Intel Core i5-4670 system.</p><h3>On the mailing lists</h3><ul><li><p>Sony Computer Entertainment America are <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70232">looking for an intern</a> for their compiler engineering team.</p></li><li><p>Venkatraman Govindaraju reports that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70033">Clang can now self host on Linux/sparc64 and FreeBSD/sparc64</a>.</p></li><li><p>Paul Vario <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70193">asks for more information on the algorithm used in RegionInfo</a>, noting that the algorithm implemented seems substantially different to the one referenced in the <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.5126">paper</a> in the header's comment. The original author of that code, Tobias Grosser follows up with an <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70198">explanation for differences from that paper</a>.</p></li><li><p>Gordon Keiser helpfully reminds us that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70179">clang will happily take LLVM bitcode as input</a>.</p></li><li><p>Stephen Kelly, an upstream CMake developer <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70022">dropped by</a> to offer advice on LLVM's current CMake usage and learn what problems with CMake the project is facing. A number of responses are interested in the ability to use CMake to build multiple LLVM subprojects at once, or to build clang against an installed LLVM tree.</p></li><li><p>Last week's <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70027">RFC questioning the use of BlockFrequency</a> has now had a number of followups. I won't summarise here for fear of mischaracterising people, but do take a look if the issue interests you.</p></li><li><p>Tom Stellard is <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70210">looking for bugfix patches</a> that should be merged in to a future 3.4.1 release.</p></li><li><p>Renato Goling started a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70186">discussion about unwind and exception handling behaviour</a> in LLVM/Clang, listing four problems he sees with the code as-is.</p></li><li><p>Vassil Vassilev asks whether anyone has implemented a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34882">copy and paste detector for Clang's static analyzer</a>. Nick Lewycky <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34921">shares his implementation</a> of something in that direction.</p></li><li><p>Ben Langmuir posted an <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34941">RFC on a virtual filesystem for clang</a>. This aims to "allow a build system to provide a file/directory layout to clang without having to construct it 'for real' on disk".</p></li></ul><h3>LLVM commits</h3><ul><li><p>The x86 backend was slightly simplified by moving some matching for x86 bit manipulation instructions from X86ISelLowering.cpp to X86InstrInfo.td. I mention this commit mainly as it's a useful reference for those of you working on LLVM backend code. <a href="http://reviews.llvm.org/rL200824">r200824</a>.</p></li><li><p>The register allocator gained a new 'last chance recoloring mechanism'. Sadly the commit message doesn't include any data of how this improves register allocation for a given codebase. <a href="http://reviews.llvm.org/rL200883">r200883</a>.</p></li><li><p>The old SmallPtrSetImpl was renamed to SmallPtrSetImplBase, and a new SmallPtrSetImpl was introduced. This new SmallPtrSetImpl doesn't require a specific set size to be specified in its templated parameter. <a href="http://reviews.llvm.org/rL200688">r200688</a>.</p></li><li><p>A whole bunch of code was added to CodeGenPrepare which attempts to move sign extensions away from loads in order to increase the chance that the address computation can be folded in to the load on architectures like x86 with complex addressing modes. <a href="http://reviews.llvm.org/rL200947">r200947</a>.</p></li><li><p><code>strchr(p, 0)</code> is now simplified to <code>p + strlen(p)</code>. <a href="http://reviews.llvm.org/rL200736">r200736</a>.</p></li><li><p>Information on handling minor ('dot') releases was added to the HowToReleaseLLVM documentation. <a href="http://reviews.llvm.org/rL200772">r200772</a>.</p></li><li><p>The MIPS assembler learned to understand <code>%hi(sym1 - sym2)</code> and <code>%hi(sym1 - sym2)</code> expressions. <a href="http://reviews.llvm.org/rL200783">r200783</a>.</p></li><li><p>Mips gained a NaCl target. <a href="http://reviews.llvm.org/rL200855">r200855</a>.</p></li><li><p>LLVM now assumes the assembler supports the <code>.loc</code> directive for specifying debug line numbers. <a href="http://reviews.llvm.org/rL200862">r200862</a>.</p></li><li><p>The inliner was modified to consider the cold attribute on a function when deciding whether to inline. <a href="http://reviews.llvm.org/rL200886">r200886</a>. A later commit set the inlinecold-threshold to the same as the inline-threshold so that current inlining behaviour is maintained for now. <a href="http://reviews.llvm.org/rL200898">r200898</a>.</p></li><li><p>Initial implementation for a lazy call graph analysis pass (for use with the upcoming new pass manager) was committed. <a href="http://reviews.llvm.org/rL200903">r200903</a>.</p></li><li><p>The allowsUnalignedMemoryAccess function in TargetLowering now takes an address space argument. This was added for architectures like the R600 where different address spaces have different alignment requirements. <a href="http://reviews.llvm.org/rL200887">r200887</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>More support was MS ABI-compatible mangling was added. <a href="http://reviews.llvm.org/rL200857">r200857</a>.</p></li><li><p>The behaviour suggested by the C++ Defect Report <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#329">329</a> was implemented. <a href="http://reviews.llvm.org/rL200673">r200673</a>.</p></li><li><p>The ARM target gained support for crypto intrinsics defined in <code>arm_neon.h</code>. <a href="http://reviews.llvm.org/rL200708">r200708</a>.</p></li><li><p>The forRangeStmt AST matcher gained a handy hasLoopVariable sub-matcher. <a href="http://reviews.llvm.org/rL200850">r200850</a>.</p></li><li><p>The -verify-pch CC1 option is now supported. <a href="http://reviews.llvm.org/rL200884">r200884</a>.</p></li><li><p>The -fhiding-week-vtables CC1 option has been removed. <a href="http://reviews.llvm.org/rL201011">r201011</a>.</p></li><li><p>LLVM's new diagnostic system is now wired into clang's diagnostic system. <a href="http://reviews.llvm.org/rL200931">r200931</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>The address sanitizer gained two functions that would allow implementation of C++ garbage collection to work with its fake stack. <a href="http://reviews.llvm.org/rL200908">r200908</a>.</p></li><li><p>In lldb, the the Mac OS X SystemRuntime plugin now uses the libBacktraceRecording library. <a href="http://reviews.llvm.org/rL200822">r200822</a>.</p></li></ul>
- LLVM Weekly - #5, Feb 3rd 2014https://blog.llvm.org/2014/02/llvm-weekly-5-feb-3rd-2014.htmlMon, 03 Feb 2014 07:36:00 +0000https://blog.llvm.org/2014/02/llvm-weekly-5-feb-3rd-2014.html<p>Welcome to the fifth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter. I've been keeping the <a href="https://twitter.com/llvmweekly">@llvmweekly Twitter account</a> updated throughout the week, so follow that if you want more frequent news updates.</p><p>I'm afraid my summary of mailing list activities is much less thorough than usual, as I've been rather busy this weekend both moving house and suffering from a cold. Do ping me if you think I've missed anything important.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/5">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>This weekend there was an LLVM devroom at FOSDEM 2014. Slides have <a href="http://llvm.org/devmtg/2014-02/">already been posted</a> for some of the talks. Hopefully videos will follow.</p><p>Pocl (Portable Computing Language) 0.9 has been <a href="http://portablecl.org/pocl-0.9.html">released</a>. Pocl aims to be an efficient MIT-licensed implementation of the OpenCL 1.2 standard.</p><p>Mike Ash has published a useful <a href="https://mikeash.com/pyblog/friday-qa-2014-01-24-introduction-to-libclang.html">introduction to libclang</a>.</p><p>Ever wanted to use LLVM from within Rust? This <a href="http://hydrocodedesign.com/2014/01/31/llvm-with-rust/">blog post will tell you how</a>.</p><p>Phoronix has published a <a href="http://www.phoronix.com/scan.php?page=article&item=amd_kaveri_gcc49clang34&num=1">benchmark of Clang 3.4 vs GCC 4.9.0 20140126 on AMD Kaveri</a>.</p><h3>On the mailing lists</h3><ul><li><p>A question about the status of <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34747">SEH support in LLVM/Clang</a> was quickly derailed after the expiration of a key patent on SEH in June was brought up. The conversation moved to LLVM's <a href="http://llvm.org/docs/DeveloperPolicy.html#patents">developer policy on patents</a> and whether the LLVM or Clang mailing lists are a suitable place for their discussion. In the end, Chris Lattner <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34810">chimes in to clarify the policy</a>. The technical discussion <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69945">moved to this thread</a>.</p></li><li><p>Pekka Jääskeläinen answers a bugpoint question with a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69807">useful guide on using bugpoint with a custom exec-command option</a>.</p></li><li><p>Nick Lewycky suggests <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69890">making datalayout a mandatory part of an LLVM module</a>.</p></li><li><p>Chandler Carruth has proposed in an RFC that <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/70027">BlockFrequency is the wrong metric</a> for profile info.</p></li><li><p>Sara Elshobaky asks for advice on finding the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69797">number of instructions executed when running LLVM bytecode under lli</a>. There are a number of suggestions including callgrind, Pin, and other similar tools.</p></li><li><p>Markus Timpl raises an interesting question about <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69852">describing a load instruction that changes the value of two registers</a>.</p></li><li><p>Baoshan Pang writes to the LLVM list asking <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69973">how to start getting involved in LLVM</a>. If you've emailed me suggesting you'd like more pointers on how to get stuck in to LLVM, this thread is for you.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The ARM exception handling ABI (<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038a/IHI0038A_ehabi.pdf">EHABI</a>) is now enabled by default. <a href="http://reviews.llvm.org/rL200388">r200388</a>.</p></li><li><p>TargetLowering gained a hook which targets can implement to indicate whether a load of a constant should be converted to just the constant. <a href="http://reviews.llvm.org/rL200271">r200271</a>.</p></li><li><p>Line table debug info is now supported for COFF files when targeting win32. <a href="http://reviews.llvm.org/rL200340">r200340</a>.</p></li><li><p>LLVM now has the beginnings of a line editor library, initially to be used by clang-query but possibly consumed by LLDB as well in the future. <a href="http://reviews.llvm.org/rL200595">r200595</a>.</p></li><li><p>The R600 backend learned intrinsics for <code>S_SENDMSG</code> and <code>BUFFER_LOAD_DWORD*</code> instructions. <a href="http://reviews.llvm.org/rL200195">r200195</a>, <a href="http://reviews.llvm.org/rL200196">r200196</a>.</p></li><li><p>The loop vectorizer gained a number of flags to help experiment with changing thresholds. It now also only unrolls by powers of 2. <a href="http://reviews.llvm.org/rL200212">r200212</a>, <a href="http://reviews.llvm.org/rL200213">r200213</a>.</p></li><li><p>The loop vectorizer now supports conditional stores by scalarizing (they are put behind an if). This improves performance on the SPEC libquantum benchmark by 4.15%. <a href="http://reviews.llvm.org/rL200270">r200270</a>.</p></li><li><p>MCSubtargetInfo is now explicitly passed to the <code>EmitInstruction</code>, <code>EmitInstTo*</code>, <code>EncodeInstruction</code> and other functions in the MC module. <a href="http://reviews.llvm.org/rL200345">r200345</a> and others.</p></li><li><p>llvm-readobj learned to decode ARM attributes. <a href="http://reviews.llvm.org/rL200450">r200450</a>.</p></li><li><p>Speculative execution of llvm.{sqrt,fma,fmuladd} is now allowed. <a href="http://reviews.llvm.org/rL200501">r200501</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Position Independent Code (PIC) is now turned on by default for Android targets. <a href="http://reviews.llvm.org/rL200290">r200290</a>.</p></li><li><p>The Parser::completeExpression function was introduced, which returns a list of completions for a given expression and completion position. <a href="http://reviews.llvm.org/rL200497">r200497</a>.</p></li><li><p>The default CPU for 32-bit and 64-bit MIPS targets is now mips32r2 and mips64r2 respectively. <a href="http://reviews.llvm.org/rL200222">r200222</a>.</p></li><li><p>The ARM and AArch64 backends saw some refactoring to share NEON intrinsics. <a href="http://reviews.llvm.org/rL200524">r200524</a> and others.</p></li></ul><h3>Other project commits</h3><ul><li><p>Compiler-rt gained a cache invalidation implementation for AArch64 <a href="http://reviews.llvm.org/rL200317">r200317</a>.</p></li><li><p>Compiler-rt now features an optimised implementation of <code>__clzdi2</code> and <code>__clzsi2</code> for ARM. <a href="http://reviews.llvm.org/rL200394">r200394</a>.</p></li><li><p>Compiler-rt's CMake files will now compile the library for ARM. Give it a go and see what breaks. <a href="http://reviews.llvm.org/rL200546">r200546</a>.</p></li><li><p>The iohandler LLDB branch was merged in. The commit log describes the benefits. <a href="http://reviews.llvm.org/rL200263">r200263</a>.</p></li></ul>
- LLVM Weekly - #4, Jan 27th 2014https://blog.llvm.org/2014/01/llvm-weekly-4-jan-27th-2014.htmlMon, 27 Jan 2014 05:46:00 +0000https://blog.llvm.org/2014/01/llvm-weekly-4-jan-27th-2014.html<p>Welcome to the fourth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. This marks the end of the first month of operation, here's to many more! LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter. I've been keeping the <a href="https://twitter.com/llvmweekly">@llvmweekly Twitter account</a> updated throughout the week, so follow that if you want more frequent news updates.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/4">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>The biggest compiler-related news this week has been the discussions on the GCC mailing list. Things kicked off with <a href="http://gcc.gnu.org/ml/gcc/2014-01/msg00176.html">Eric S. Raymond's post</a> suggesting that technical progress in GCC is being held back by concerns about reusing parts of GCC in a way that bypasses the copyleft license. Ian Lance Taylor <a href="http://gcc.gnu.org/ml/gcc/2014-01/msg00181.html">responded</a> to point out that GCC now has a plugin system, albeit with an unstable interface, which mostly put a stop to that line of discussion. However a <a href="http://gcc.gnu.org/ml/gcc/2014-01/msg00247.html">later post to the mailing list from Richard Stallman</a> has proved very controversial by claiming that "The existence of LLVM is a terrible setback for our community precisely because it is not copylefted and can be used as the basis for nonfree compilers". There's plenty of discussion of these comments around the web <a href="http://lwn.net/Articles/582242/">at LWN</a>, Hacker News, Reddit, Slashdot etc. Although many of us may have a preference for non-copyleft ('permissive') free software licenses, RMS has consistently and over a long period of time argued that copyleft licenses ultimately do a better job of spreading free software and preserving its freedom. As such, it's not clear to me why this mailing list post has come as a surprise to many. I'm personally surprised he didn't bring up the fact that the BSD-style license used by LLVM contains no explicit patent grant (though LLVM does have a <a href="http://llvm.org/docs/DeveloperPolicy.html#patents">patent policy</a> to help protect its users).</p><p>Rapidly moving away from controversial topics, an exciting milestone for the LLVM project was hit this week. The <a href="http://reviews.llvm.org/rL200000">200000th commit</a> has been applied. Takumi Nakamura was lucky enough to be the one to author that commit.</p><p>The Khronos group has <a href="https://www.khronos.org/news/press/khronos-releases-spir-1.2-specification-for-portable-encoding-of-opencl-dev">released the SPIR 1.2 specification</a>. SPIR is a standardised intermediate representation meant for use with OpenCL, and is based on LLVM 3.2 IR. With the release, the Khronos Group have open sourced a modified Clang 3.2 which can generate SPIR from OpenCL C programs as well as a module verifier.</p><p>JoaquÃn M López Muñoz has published a benchmark <a href="http://bannalia.blogspot.co.uk/2014/01/a-better-hash-table-clang.html">comparing hash table performance on Clang</a>. He compares GCC's libstdc++-v3 to the LLVM project's libc++.</p><p>The Cambridge (UK) LLVM socials <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34548">are starting up again</a>, with the next one on the 29th Jan at 7.30pm. Sadly I can't make it, hopefully the next one!</p><h3>On the mailing lists</h3><ul><li><p>Chandler Carruth asks <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69689">whether LoopPass and LoopPassManager can be removed</a>. He lists the confusion and issues they cause, most damning to me is that they reoutinely modify IR from outside of the loop thus breaking the implied contract of a 'loop pass'. The discussion ended up with the proposal that LoopSimplify, LCSSA, and LoopVectorizer become function passes. As you can see from the LLVM commit section below, Chandler quickly submitted patches to do this which have been applied.</p></li><li><p>Vadim asks for input on his idea of <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69727">using LLVM to generate code with position-independent stacks</a>. This would be usual for implementing something similar to Python greenlets. Mark Seaborn points to <a href="https://codereview.chromium.org/29743003/">some similar work</a> he has done which restricts memory access to a range of address space.</p></li><li><p>Tom Stellard has completed a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69778">suggested policy and process for LLVM minor releases</a>.</p></li><li><p>Shea Levy, a maintainer for nixpkgs writes to the list with <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69662">the issues he has encountered</a>packaging LLVM and Clang for Nix.</p></li><li><p>Raul Silvera <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69781">asks for opinions on removing the ReadOnly attribute from math intrinsics</a> on the grounds that changes to the floating point environment (such as rounding mode) aren't modelled anyway. As Raul points out in a later followup "We currently appear to be at the worst of both worlds as we do not have support for this environment but are always being constrained by it."</p></li><li><p>Sebastien Riou asks <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69670">how to force a MachineFunctionPass to be the last one</a>. Peter Cooper suggests that at the moment you can add the pass to the end of <code>X86PassConfig::addPreEmitPass</code> or add the pass after the call to preEmitBass and before the ASM printer is added.</p></li><li><p>Jasper Neumann has spotted various cases where <a href="http://thread.gmane.org/gmane.comp.compilers.llvm.devel/69601">LLVM leaves unnecessary register moves</a> in the generated code. Andrew Trick suggests copy-eliminating peepholes could be added after register allocation, but that in general there is reluctance to introduce extra complexity to optimise special cases involving multiple physical register copies due to the small impact they have on performance.</p></li><li><p>David Chisnall enquires whether <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69711">LLVM relies on the assumption that the stack is in address space 0</a>. Matt Arsenault notes that OpenCL local variables currently work by created globals rather than alloca'ing a nondefault address space. He suggests the limitation stems from the fact a number of places in the compiler assume the address space is 0 and never check by retrieving the address space of the relevant pointer.</p></li><li><p>Christian Schafmeister has posted <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34505">a preannouncement of his soon-to-be-released C++ refactoring tool</a>, written in Lisp. It makes use of clang's ASTMatcher/Refactoring library. I'm looking forward to the promised open source release.</p></li><li><p>David Fang has posted a <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34507">summary of the status of libc++ on powerpc-darwin</a>.</p></li></ul><h3>LLVM commits</h3><ul><li><p>LoopSimplify is no longer a LoopPass, instead it is both a utility function and a FunctionPass. The motivation was to be able to compute function analysis passes after running LoopSimplify, but the change has a bunch of other advantages described in detail in the commit message. <a href="http://reviews.llvm.org/rL199884">r199884</a>. Additionally, the LCSSA (loop-closed SSA) pass was made a utility with a function pass and the LoopVectorizer became a FunctionPass. <a href="http://reviews.llvm.org/rL200067">r200067</a>, <a href="http://reviews.llvm.org/rL200074">r200074</a>.</p></li><li><p>The Constant Hoisting Pass was born. <a href="http://reviews.llvm.org/rL200022">r200022</a>.</p></li><li><p>InstCombine learned how to deal with vectors for most fmul/fvid/add/sub/mul/div combines. <a href="http://reviews.llvm.org/rL199598">r199598</a>, <a href="http://reviews.llvm.org/rL199602">r199602</a>.</p></li><li><p>Type-based alias analysis has, for the time being, been disabled when using alias analysis in CodeGen due to two shortcomings described in the commit message. <a href="http://reviews.llvm.org/rL200093">r200093</a>.</p></li><li><p>LTO gained new methods which allows the user to parse metadata nodes, extract linker options, and extract dependent libraries from a bitcode module. <a href="http://reviews.llvm.org/rL199759">r199759</a>.</p></li><li><p>The Sparc backend now supports the inline assembly constraint 'I'. <a href="http://reviews.llvm.org/rL199781">r199781</a>.</p></li><li><p>The x86 backend allows segment and address-size overrides for movs/lods/outs, fixing <a href="http://llvm.org/bugs/show_bug.cgi?id=9385">bug 9385</a>. <a href="http://reviews.llvm.org/rL199803">r199803</a> and more.</p></li><li><p>llvm-ar no longer opens or fstats file twice. <a href="http://reviews.llvm.org/rL199815">r199815</a>.</p></li><li><p>When compiling a function with the minsize attribute, the ARM backend will now use literal pools even for normal i32 immediates. <a href="http://reviews.llvm.org/rL199891">r199891</a>.</p></li><li><p>There was a fair bit of activity on the R600 backend. I haven't had the time to properly summarise that activity or pick out the most important commits, so I recommend those interested take a look through the commit logs.</p></li><li><p>JIT is now supported for Sparc64. <a href="http://reviews.llvm.org/rL199977">r199977</a>.</p></li><li><p>llvm-readobj gained support for the PE32+ format (used for Windows 64-bit executables). <a href="http://reviews.llvm.org/rL200117">r200117</a>.</p></li></ul><h3>Clang commits</h3><ul><li><p>Registry::getCompletions was implemented. This returns a list of valid completions for a given context. <a href="http://reviews.llvm.org/rL199950">r199950</a>.</p></li><li><p>Clang gained basic support for the attribute <code>returns_nonnull</code>. <a href="http://reviews.llvm.org/rL199626">r199626</a>, <a href="http://reviews.llvm.org/rL199790">r199790</a>.</p></li><li><p>getResultType on function and method declarations was renamed to getReturnType which is a semantically more accurate name. <a href="http://reviews.llvm.org/rL200082">r200082</a>. Similarly, getResultLoc was renamed to getReturnLoc. <a href="http://reviews.llvm.org/rL200105">r200105</a>.</p></li><li><p>All applicable accessors in FunctionProtoType have been renamed from <code>*argument*</code> to <code>*parameter*</code>. <a href="http://reviews.llvm.org/rL199686">r199686</a>.</p></li><li><p>Clang was taught to look in its installation libdir for libraries such as libc++ when the installation is within the system root. <a href="http://reviews.llvm.org/rL199769">r199769</a>.</p></li><li><p>A module.map file is now required to load a module. <a href="http://reviews.llvm.org/rL199852">r199852</a>.</p></li></ul><h3>Other project commits</h3><ul><li><p>lldb learned the 'step-avoid-libraries' setting, which allows a user to list libraries to avoid. <a href="http://reviews.llvm.org/rL199943">r199943</a>.</p></li><li><p>In compiler-rt, support was added for intercepting and sanitizing arguments passed to printf functions in AddressSanitizer and ThreadSanitizer. <a href="http://reviews.llvm.org/rL1999729">r199729</a>.</p></li><li><p>A fix was committed to ThreadSanitizer to prevent deadlocking after a fork. <a href="http://reviews.llvm.org/rL1999993">r199993</a>.</p></li><li><p>Dragonegg can now be built with CMake. <a href="http://reviews.llvm.org/rL199994">r199994</a>.</p></li><li><p>Compiler-rt gained support in its udiv/umod implementations for ARMv4 which lacks bx and clz. Code changes also resulting in a 30%+ performance improvement on the Raspberry Pi (armv7, ARM1176) and 5-10% on a Cortex A9. <a href="http://reviews.llvm.org/rL200001">r200001</a>.</p></li><li><p>In AddressSanitizer on Android, all AddressSanitizer output is duplicated to the system log. <a href="http://reviews.llvm.org/rL1999887">r199887</a>.</p></li><li><p>lld gained support for emitting a PE32+ file header. <a href="http://reviews.llvm.org/rL200128">r200128</a>.</p></li><li><p>lldb now supports Haswell on x86-64. <a href="http://reviews.llvm.org/rL199854">r199854</a>.</p></li></ul>
- LLVM Weekly - #3, Jan 20th 2014https://blog.llvm.org/2014/01/llvm-weekly-3-jan-20th-2014.htmlMon, 20 Jan 2014 07:42:00 +0000https://blog.llvm.org/2014/01/llvm-weekly-3-jan-20th-2014.html<p>Welcome to the third issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter.</p> <p>The canonical home for this issue <a href="http://llvmweekly.org/issue/3">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Eli Bendersky has penned <a href="http://eli.thegreenplace.net/2014/01/15/some-thoughts-on-llvm-vs-libjit/">some thoughts on LLVM vs. libjit</a>. Eli describes libjit as being more limited, yet easier to understand and to get going with due to its focus. He also makes interesting claims such as "to be honest, I don't think it's possible to create a really fast JIT within the framework of LLVM, because of its modularity. The faster the JIT, the more youâll have to deviate from the framework of LLVM". As well as the comments directly on the blog post, there is some good discussion over <a href="http://www.reddit.com/r/programming/comments/1vf1lx/some_thoughts_on_llvm_vs_libjit/">at Reddit</a> .</p><p><a href="http://www.capstone-engine.org/Version-2.0-RC1.html">Version 2.0-RC1 Capstone disassembly framework has been released</a>. Capstone is built using code from LLVM. The new release features reduced memory usage, faster Python bindings, and support for PowerPC among other changes.</p><p><a href="http://planet.clang.org/">Planet Clang</a> has been <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34439">announced</a>. It is a news feed following blog posts from Clang and LLVM committers and contributors. The blog roll is fairly short right now, but you're welcome to submit your RSS feed via the email address in the announcement post.</p><p>The PDF of an upcoming paper to be presented at CGO next month has been released. <a href="http://www.cs.rutgers.edu/~santosh.nagarakatte/papers/cgo2014-final.pdf">WatchdogLite: Hardware-Accelerated Compiler-Based Pointer Checking</a> proposes instruction set extensions to accelerate pointer checking functions and achieves a performance overhead of 29% in return for memory safety. The compiler extends (and is compared to) <a href="http://acg.cis.upenn.edu/softbound/">SoftBound + CETS</a>.</p><h3>On the mailing lists</h3><ul><li><p>David Woodhouse has posted a <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69440">detailed update on the status of 16-bit x86 in LLVM</a>. David has successfully built the 16-bit startup code of the Linux kernel and invites people to start testing it on real code.</p></li><li><p>Tom Stellard opens a discussion on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69428">stable LLVM 3.4.x releases</a>. A number of people volunteer their assistance and there seems to be general agreement that any 3.4.1 release would include bug-fixes only with no ABI changes.</p></li><li><p>Diego Novillo is looking to boost the performance of the SPEC benchmark libquantum <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69494">using profile info and loop unrolling</a>. Sean Silva did us all a great service by asking for clarification on what a "runtime unroller" means in this context. The answer is that the trip count (the number of times the loop is executed) is not known at compile time. The thread is worth a read if you're interested in loop unrolling or vectorization.</p></li><li><p>Aaron Ballman has stepped up as <a href="http://article.gmane.org/gmane.comp.compilers.clang.scm/90431">code owner for the attribute subsystem</a> with unanimous approval.</p></li><li><p>Skye Wanderman-Milne was looking for help on <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69470">loop unrolling a single function using the C++ API</a>. Simply adding the LoopUnrollPass to a FunctionPassManager had no effect, but after some advice from the mailing list Skye did respond to confirm that the set of ScalarReplAggregates, LoopRotate, and LoopUnroll passes did have the desired effect.</p></li><li><p>Tobias Grosser asks why LLVM's LNT (used for performance tracking) defaults to <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69555">aggregating results by taking the minimum rather than an average</a>. Replies quickly hone on in the real problem at hand, which is that results are 'noisy' potentially due to other processes on the machine but also quantised to certain values due to the timer being relatively coarse-grained in comparison to the execution time for the benchmarks.</p></li><li><p>This week's unsolved question is from Keith Walker, who's noticed that on ARM, the function prologue generated in GCC and LLVM ends up with <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69514">the frame register pointing to a different address</a>. The LLVM prologue results in the frame pointer pointing to just after the pushed r11 register (the saved frame pointer) while on GCC the frame pointer points to just after the pushed link register. The difference makes it difficult to produce a generic stack walker.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The MCJIT remote execution protocol was heavily refactored and it was hoped fixed on ARM where it was previously non-functional. There are still some random failures on ARM though, see <a href="http://llvm.org/bugs/show_bug.cgi?id=18057">bug 18507</a>. <a href="http://reviews.llvm.org/rL199261">r199261</a></p></li><li><p>The cutoff on when to attempt to convert a switch to a lookup table was changed from 4 to 3. Experimentally, Hans Wennborg found that there was no speedup for two cases but three produced a speedup. When building Clang, this results in 480 new switches to be transformed and an 8KB smaller binary size. <a href="http://reviews.llvm.org/rL199294">r199294</a></p></li><li><p>Support for the <code>preserve_mostcc</code> and <code>preserve_allcc</code> calling conventions was introduced and implemented for x86-64. These are intend to be used by a future version of the ObjectiveC runtime in order to reduce overhead of runtime calls. <a href="http://reviews.llvm.org/rL199508">r199508</a></p></li><li><p>The configure script now checks for a sufficiently modern host compiler (Clang 3.1 or GCC 4.7) <a href="http://reviews.llvm.org/rL199182">r199182</a></p></li><li><p>More work on the new PassManager driver. Bitcode can now be written using the new PM and more preparation/cleanup work has been performed. <a href="http://reviews.llvm.org/rL199078">r199078</a>, <a href="http://reviews.llvm.org/rL199095">r199095</a>, <a href="http://reviews.llvm.org/rL199104">r199104</a></p></li><li><p>Dominators.h and Verifier.h moved from the Analysis directory to the IR directory. <a href="http://reviews.llvm.org/rL199082">r199082</a></p></li><li><p>The DAGCombiner learned to reassociate (i.e. change the order of) vector operations <a href="http://reviews.llvm.org/rL199135">r199135</a></p></li><li><p>dllexport and dllimport are no longer represented as linkage types <a href="http://reviews.llvm.org/rL199218">r199218</a></p></li><li><p>Parsing of the .symver directive in ARM assembly was fixed <a href="http://reviews.llvm.org/rL199339">r199339</a></p></li></ul><h3>Clang commits</h3><ul><li><p>The MS ABI is now used for Win32 targets by default <a href="http://reviews.llvm.org/rL199131">r199131</a></p></li><li><p>The MicrosoftMode language option was renamed to MSVCCompat and its role clarified (see the commit message for a description of MicrosoftExt vs MSVCCompat). <a href="http://reviews.llvm.org/rL199209">r199209</a></p></li><li><p>The <code>-cxx-abi</code> command-line flag was killed and is instead inferred depending on the target. <a href="http://reviews.llvm.org/rL199250">r199250</a></p></li><li><p>The analyzer learned that shifting a constant value by its bit width is undefined. <a href="http://reviews.llvm.org/rL199405">r199405</a></p></li><li><p>The <code>nonnull</code> attribute can now be applied to parameters directly. <a href="http://reviews.llvm.org/rL199467">r199467</a></p></li><li><p>Support for AArch64 on NetBSD was added to the compiler driver. <a href="http://reviews.llvm.org/rL199124">r199124</a></p></li></ul><h3>Other project commits</h3><ul><li><p>AddressSanitizer in compiler-rt gained the ability to start in 'deactivated' mode. It can later be activated when <code>__asan_init</code> is called in an instrumented library. <a href="http://reviews.llvm.org/rL199377">r199377</a></p></li><li><p>A number of patches were committed to lld for better MIPS support. <a href="http://reviews.llvm.org/rL199231">r199231</a> and many more. </p></li><li><p>lldb recognises Linux distribution in the vendor portion of the host triple. e.g. <code>x86_64-ubuntu-linux-gnu</code>. <a href="http://reviews.llvm.org/rL199510">r199510</a></p></li></ul>
- LLVM Weekly - #2, Jan 13th 2014https://blog.llvm.org/2014/01/llvm-weekly-2-jan-13th-2014.htmlMon, 13 Jan 2014 07:29:00 +0000https://blog.llvm.org/2014/01/llvm-weekly-2-jan-13th-2014.html<p>Welcome to the second issue of LLVM Weekly (and the first to appear on the LLVM blog). LLVM Weekly is a newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. Thank you to everyone who has given positive feedback or suggestions, I'm planning in future editions to integrate some sort of statistics of git activity and contributions as well as activity on Bugzilla. LLVM Weekly is brought to you by <a href="http://asbradbury.org">Alex Bradbury</a>. Subscribe to future issues at <a href="http://llvmweekly.org">http://llvmweekly.org</a> and pass it on to anyone else you think may be interested. Please send any tips or feedback to <a href="mailto:asb@asbradbury.org">asb@asbradbury.org</a>, or <a href="https://twitter.com/llvmweekly">@llvmweekly</a> or <a href="https://twitter.com/asbradbury">@asbradbury</a> on Twitter. </p><p>The canonical home for this issue <a href="http://llvmweekly.org/issue/2">can be found here at llvmweekly.org</a>. </p> <a name='more'></a> <h3>News and articles from around the web</h3><p>Stephen Diehl has published a <a href="http://www.stephendiehl.com/llvm/">Haskell adaptation of the 'Kaleidoscope' tutorials</a> on how to implement aJIT compiled language using LLVM. This was received very positively and prompted some <a href="https://news.ycombinator.com/item?id=7031998">discussion on HN</a>.</p><p>Registration for EuroLLVM is <a href="http://llvm.org/devmtg/2014-04/">now open</a>. There's still time to submit your talk, poster or workshop proposals too.</p><p><a href="https://github.com/mozilla/rust/blob/0.9/RELEASES.txt">Rust 0.9 has been released</a>. Rust is a systems programming language which targetting LLVM with a particular emphasis on type safety, memory safety and concurrency. One of the core Rust developers at Mozilla, Niko Matsakis, also gave a <a href="http://www.youtube.com/watch?v=gfCtbGiHcg0">talk at linux.conf.au introducing Rust</a>.</p><p>Coverity 7 <a href="http://www.prnewswire.com/news-releases/coverity-unveils-new-version-of-development-testing-platform-239056251.html">now includes Clang compiler support</a>.</p><h3>On the mailing lists</h3><ul><li><p>Apple are <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-January/069169.html">advertising for interns</a> with their LLVM compiler frontend and runtime teams this summer. Note internships are restricted to students.</p></li><li><p>Amara Emerson shares a <a href="article.gmane.org/gmane.comp.compilers.clang.devel/34199/">proposal on handling the removal of the -mfpu option for AArch64</a>. This proposal aims to match gcc, where instead of <code>-mfpu</code> to specify FPU/NEON, the same information will be passed using feature modifiers on <code>-march</code>. It was pointed out that GCC also has <code>-mcpu</code> to complicate things. It's hoped collaboration with the GCC devs will lead to a simplification that both can use.</p></li><li><p>Tobias Grosser has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69264">set up some new machines tracking performance at -O3</a> using <a href="http://llvm.org/docs/lnt/">LNT</a>, which is a framework used for performance tracking of LLVM over time. Tobias is asking for someone to step in and improve the LNT infrastructure to take advantage of this new data. LNT is written in Python, using Flask and SQLAlchemy so this would be an ideal project for someone interested in contributing to LLVM but perhaps doesn't match the typical profile of the LLVM contributor.</p></li><li><p>Timothy Baldridge asks whether <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69219">LLVM can inline external library functions in a JITted method</a>. Replies point out that for the specific example given (memcpy), LLVM is already able to inline. Kevin Modzelewski <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69236">describes a technique he's used</a>.</p></li><li><p>Rafael EspÃndola announces a new milestone, all in-tree backends <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69369">now use MCInst for printing assembly</a>. Out of tree targets will need to lower MachineInstr to MCInst to use the new printer and the recent <a href="http://reviews.llvm.org/rL198030">conversion of the Sparc backend</a> to do this is probably as good a guide as any.</p></li><li><p>As part of the effort to use C++11 inside the LLVM codebase, Chandler Carruth has asked anyone running build-bot to look at <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69242">upgrading to the new baseline compiler versions</a>. These are MSVC 2012, GCC 4.7, or Clang 3.1.</p></li><li><p>Jasper Neumann has been <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69383/">working on switch lowering using hashing</a> as an alternative to using a jump table. He later <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69389/">further elaborates on the technique</a> and points to an interesting looking paper, <a href="http://ols.fedoraproject.org/GCC/Reprints-2008/sayle-reprint.pdf">Multiway Branch Code Generation</a> by Roger Anthony Sayle.</p></li><li><p>Kevin Modzelewski is encountering <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69349">disappointing bitcode parsing performance</a>, in particular when debug info is present. The issue is not identified or solved yet, I'm hoping to be able to point to an explanation of the problem in next week's issue!</p></li><li><p>Chandler Carruth suggests that the <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69244">interprocedual analysis passes be merged in to the Analysis library</a>. Right now, various interprocedural analyses live in lib/Analysis/IPA and are built as the LLVMipa library. Chris Lattner agrees so we can expect the merge to happen in the not too distant future.</p></li><li><p>Chandler Carruth has <a href="http://article.gmane.org/gmane.comp.compilers.llvm.devel/69392">suggested</a> that the <a href="http://www.llvm.org/docs/CodingStandards.html">LLVM coding standards</a> be updated so that namespaces are never indented, as opposed to the current confusing mixture. Despite the fact that debating whitespace is a favourite pastime of most programmers, the thread has been fairly uncontroversial thus far.</p></li><li><p>Milian Wolff wonders about <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34168">using the clang C API to parse default values</a>.</p></li><li><p>Renato Golin is working towards <a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/34161">adding various pragmas to Clang</a> and is seeking feedback on how to implement it. A few people on the mailing list suggest it might be worth trying to instead implement these using <a href="http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/">C++11 generalized attributes</a> and perhaps enabling support for the syntax in C99.</p></li><li><p>The <code>__has_attribute</code> feature macro is commonly used to detect support for a particular attribute in the compiler. Aaron Ballman <a href="http://article.gmane.org/gmane.comp.compilers.clang.scm/90321">suggests extending it</a> so you can test for the precise form of attribute syntax you are after.</p></li></ul><h3>LLVM commits</h3><ul><li><p>The Sparc ASM parser has seen further development, learning to parse branch instructions, conditional moves, and floating point instructions and more. It also gained an initial disassembler implementation. <a href="http://reviews.llvm.org/rL198738">r198738</a>, <a href="http://reviews.llvm.org/rL199033">r199033</a>, <a href="http://reviews.llvm.org/rL198591">r198591</a></p></li><li><p>In SimplifyCFG will now understand that when building a lookup table for a switch with no holes that it doesn't need a default result. According to the commit message, this saves 164KB off the clang binary in a bootstrap build. <a href="http://reviews.llvm.org/rL199025">r199025</a></p></li><li><p>The new pass manager saw further developments. <a href="http://reviews.llvm.org/rL198998">r198998</a> and many others (prefixed with <code>[PM]</code> in the commit logs)</p></li><li><p>The SampleProfile pass saw further development. Profile samples are propagated through the CFG, heuristically converting instruction samples to branch weights. Work was done to extend and simplify the format of sample profile input files. <a href="http://reviews.llvm.org/rL198972">r198972</a>, <a href="http://reviews.llvm.org/rL198973">r198973</a></p></li><li><p>The LoopVectorizer can use versioning for strided memory access. <a href="http://reviews.llvm.org/rL198950">r198950</a></p></li><li><p>In DataLayout, 'w' is now used rather than 'c' for win32 name mangling. <a href="http://reviews.llvm.org/rL198938">r198938</a></p></li><li><p>The LLVM developer policy was updated to more clearly spell out how to submit patches to the project. <a href="http://reviews.llvm.org/rL198901">r198901</a></p></li><li><p>WriteAsOperand has been killed in favour of the the printAsOperand method. <a href="http://reviews.llvm.org/rL198836">r198836</a></p></li><li><p>The x86 backend learned some more AVX-512 intrinsics. <a href="http://reviews.llvm.org/rL198745">r198745</a></p></li></ul><h3>Clang commits</h3><ul><li><p>Support for the <code>enable_if</code> attribute was added. This can be placed on function declarations to control which overload is selected based on the values of the function's arguments. See the commitdiff (particularly the docs change) for more info. <a href="http://reviews.llvm.org/rL198996">r198996</a></p></li><li><p>More work on MS VC++ ABI compatibility was committed. <a href="http://reviews.llvm.org/rL198907">r198907</a>, <a href="http://reviews.llvm.org/rL198975">r198975</a>, <a href="http://reviews.llvm.org/rL198977">r198977</a>, <a href="http://reviews.llvm.org/rL198900">r198900</a> and more.</p></li><li><p><code>__has_attribute</code> now understands target-specific attributes. <a href="http://reviews.llvm.org/rL198897">r198897</a></p></li><li><p>The clang plugin infrastructure is now covered by at least some tests. <a href="http://reviews.llvm.org/rL198747">r198747</a></p></li><li><p>The documentation on clang internals was updated with more up to date information on adding new attributes. <a href="http://reviews.llvm.org/rL198705">r198705</a></p></li><li><p>An initial instrumentation-based profile guided optimisation implementation landed. <a href="http://reviews.llvm.org/rL198640">r198640</a></p></li></ul>
- Google Summer of Code: C++ Modernizer Improvementshttps://blog.llvm.org/2013/11/google-summer-of-code-c-modernizer.htmlMon, 18 Nov 2013 04:12:00 +0000https://blog.llvm.org/2013/11/google-summer-of-code-c-modernizer.html<div style="text-indent: 0;"><a href="http://www.google-melange.com/gsoc/homepage/google/gsoc2013">Google Summer of Code</a> (GSoC) offers students stipends to participate in open source projects during the summer. This year, I was accepted to work on the <a href="http://clang.llvm.org/extra/clang-modernize.html">Clang C++ Modernizer</a>, a project formerly known as the <i>C++11 Migrator</i>, driven by a team at Intel. The goals of the tool are to modernize C++ code by using the new features of new C++ standards in order to improve maintainability, readability and compile time and runtime performance. The project was featured in the April blog post â<a href="http://blog.llvm.org/2013/04/status-of-c11-migrator.html">Status of the C++11 Migrator</a>â and has been evolving since, both in terms of architecture and features.<br /><div><br /><div>This article presents the improvements made to the tool in the last few months, which include my work from this summer for GSoC. For a complete overview of the tool and how to install it, please visit the documentation: <a href="http://clang.llvm.org/extra/clang-modernize.html#getting-started">http://clang.llvm.org/extra/clang-modernize.html#getting-started</a>. For a demonstration of the tool you can take a look at the Going Native 2013 talk given by Chandler Carruth: <a href="http://channel9.msdn.com/Events/GoingNative/2013/The-Care-and-Feeding-of-C-s-Dragons">The Care and Feeding of C++'s Dragons</a>. clang-modernize is featured starting at ~33min.<br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="background-color: transparent; color: black; font-family: Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br /><a name='more'></a></div><h2>Transform <u>all</u> Files That Make up a Translation Unit</h2>A major improvement since the last version is the ability to transform every file that composes a translation unit not only the main source file. This means headers also get transformed if they need to be which makes the modernizer more useful.<br /><br />To avoid changing files that shouldnât be changed, e.g. system headers or headers for third-party libraries, there are a few options to control which files should be transformed:<br /><ul><li><a href="http://clang.llvm.org/extra/ModernizerUsage.html#cmdoption-include">-include</a> Takes a comma-separated list of paths allowed to be transformed. All files within the entire directory tree rooted at each given path are marked as modifiable. For safety, the default behaviour is that no extra files will be transformed.</li><li><a href="http://clang.llvm.org/extra/ModernizerUsage.html#cmdoption-exclude">-exclude</a> Takes a comma-separated list of paths forbidden to be transformed. Can be used to prune out subtrees from included directory trees.</li><li><a href="http://clang.llvm.org/extra/ModernizerUsage.html#cmdoption-include-from">-include-from</a> and <a href="http://clang.llvm.org/extra/ModernizerUsage.html#cmdoption-exclude-from">-exclude-from</a> Respectively equivalent to -include and -exclude but takes a filename as argument instead of a comma-separated list of paths. The file should contain one path per line.</li></ul>Example, assuming a directory hierarchy of:<br /><ul><li>src/foo.cpp</li><li>include/foo.h</li><li>lib/third-party.h</li></ul>to transform both <i>foo.cpp</i> and <i>foo.h</i> but leave <i>third-party.h</i> as is, you can use one of the following commands:<br /><div style="padding-left: 25px;"><pre style="color: #555555;">clang-modernize -include=include/ src/foo.cpp -- -std=c++11 -I include/ -I lib/</pre><pre style="color: #555555;">clang-modernize -include=. -exclude=lib/ src/foo.cpp -- -std=c++11 -I include/ -I lib/</pre></div><h2>The Transforms</h2>Right now there is a total of 6 transforms, two of which are new:<br /><ol><li><a href="http://clang.llvm.org/extra/AddOverrideTransform.html">Add-Override Transform</a><br />Adds the âoverrideâ specifier to overriden member functions.</li><li><a href="http://clang.llvm.org/extra/LoopConvertTransform.html">Loop Convert Transform</a><br />Makes use of for-ranged based loop.</li><li><a href="http://clang.llvm.org/extra/PassByValueTransform.html">Pass-By-Value Transform</a> [new]<br />Replaces const-ref parameters that would benefit from using the pass-by-value idiom.</li><li><a href="http://clang.llvm.org/extra/ReplaceAutoPtrTransform.html">Replace Auto-Ptr Transform</a> [new]<br />Replaces uses of the deprecated <tt>std::auto_ptr</tt> by <tt>std::unique_ptr</tt>.</li><li><a href="http://clang.llvm.org/extra/UseAutoTransform.html">Use-Auto Transform</a><br />Makes use of the auto type specifier in variable declarations.</li><li><a href="http://clang.llvm.org/extra/UseNullptrTransform.html">Use-Nullptr Transform</a><br />Replaces null literals and macros by nullptr where applicable.</li></ol><h3>Improvement to Add-Override</h3>Since the last article in April, the Add-Override Transform has been improved to handle user-defined macros. Some projects, like LLVM, use a macro that expands to the âoverrideâ specifier for backward compatibility with non-C++11-compliant compilers. clang-modernize can detect those macros and use them instead of the âoverrideâ identifier.<br /><br />The command line switch to enable this functionality is <b>-override-macros</b>.<br /><br />Example:<br /><br /><div style="padding-left: 25px;"><tt>clang-modernize <b>-override-macros</b> foo.cpp</tt></div><div><span style="font-size: 15px; white-space: pre-wrap;"></span><br /><div dir="ltr"><table style="border-collapse: collapse; border: none; width: 624px;"><colgroup><col width="*"></col><col width="*"></col></colgroup><tbody><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">Before</span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">After</span></div></td></tr><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">#define LLVM_OVERRIDE override</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #007020;"><br class="kix-line-break" /></span></span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">struct</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> A {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">virtual</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> foo();<br class="kix-line-break" />};</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">struct</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> B </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">:</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> A {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">virtual</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> foo();<br class="kix-line-break" />};</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"></span></span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">#define LLVM_OVERRIDE override</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">struct</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> A {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">virtual</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> foo();<br class="kix-line-break" />};</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">struct</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> B </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">:</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> A {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">virtual</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> foo() </span><span style="font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">LLVM_OVERRIDE</span><span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">;<br class="kix-line-break" />};</span></span></div></td></tr></tbody></table></div><h3>Improvement to Use-Nullptr</h3>This transform has also been improved to handle user-defined macros that behave like NULL. The user specifies which macros can be replaced by nullptr by using the command line switch <a href="http://clang.llvm.org/extra/ModernizerUsage.html#cmdoption-user-null-macros">-user-null-macros=<string></a>.<br /><br />Example:<br /><br /><div style="padding-left: 25px;"><tt>clang-modernize <b>-user-null-macros=MY_NULL</b> bar.cpp</tt></div><span style="font-size: 15px; white-space: pre-wrap;"></span><br /><div dir="ltr"><table style="border-collapse: collapse; border: none; width: 624px;"><colgroup><col width="*"></col><col width="*"></col></colgroup><tbody><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Arial; font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">Before</span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Arial; font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">After</span></div></td></tr><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 8pt; margin-top: 11pt;"><span style="color: #007020; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 1; white-space: pre-wrap;">#define MY_NULL 0</span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">bar</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">() {<br class="kix-line-break" /> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">*</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">p </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> MY_NULL;<br class="kix-line-break" />}</span></span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">#define MY_NULL 0</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">bar</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">() {<br class="kix-line-break" /> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">*</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">p </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">nullptr</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">;<br class="kix-line-break" />}</span></span></div></td></tr></tbody></table></div><h3> New Transform: Replace Auto-Ptr</h3>This transform was a result of GSoC work. The transform replaces uses of <tt>std::auto_ptr</tt> by <tt>std::unique_ptr</tt>. It also inserts calls to <tt>std::move()</tt> when needed.<br /><span style="font-size: 15px; white-space: pre-wrap;"></span><br /><div dir="ltr"><table style="border-collapse: collapse; border: none; width: 624px;"><colgroup><col width="*"></col><col width="*"></col></colgroup><tbody><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Arial; font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">Before</span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Arial; font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">After</span></div></td></tr><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 8pt; margin-top: 11pt;"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">#include <memory></span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">steal</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">(std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">auto_ptr</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">></span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> x);</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">foo</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">(</span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> i) {<br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">auto_ptr</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">></span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> p(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">new</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">(i));<br class="kix-line-break" /><br class="kix-line-break" /> steal(p);<br class="kix-line-break" />}</span></span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 8pt; margin-top: 11pt;"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">#include <memory></span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">steal</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">(std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">unique_ptr</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">></span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> x);</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">void</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">foo</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">(</span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> i) {<br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">unique_ptr</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">></span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> p(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">new</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #902000; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">int</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">(i));<br class="kix-line-break" /><br class="kix-line-break" /> steal(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">std</span><span style="color: #666666; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">move(</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">p</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">)</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">);<br class="kix-line-break" />}</span></span></div></td></tr></tbody></table></div><h3>New Transform: Pass-By-Value</h3>Also a product of GSoC this transform makes use of move semantics added in C++11 to avoid a copy for functions that accept types that have move constructors by const reference. By changing to pass-by-value semantics, a copy can be avoided if an rvalue argument is provided. For lvalue arguments, the number of copies remains unchanged.<br /><br />The transform is currently limited to constructor parameters that are copied into class fields.<br /><br />Example:<br /><br /><div style="padding-left: 25px;"><tt>clang-modernize pass-by-value.cpp</tt></div><br /><div><div dir="ltr" style="color: black; font-weight: normal;"><table style="border-collapse: collapse; border: none; width: 624px;"><colgroup><col width="*"></col><col width="*"></col></colgroup><tbody><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><b>Before</b></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><b>After</b><br /><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt;"></div></td></tr><tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 8pt; margin-top: 11pt;"><div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">#include <string></span></span></div><div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span></div><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">class</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #0e84b5; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">A</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> {</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #002070; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">public:</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /> A(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">const</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string &Copied,</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">const</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">&</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">ReadOnly)<br class="kix-line-break" /> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">:</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> Copied(Copied),</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> ReadOnly(ReadOnly) {}</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #002070; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #002070; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">private:</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string Copied;<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">const</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">&</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">ReadOnly;<br class="kix-line-break" />};</span></span></div></td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 8pt; margin-top: 11pt;"><span style="color: #007020; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 1; white-space: pre-wrap;">#include <string></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">#include <utility></span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><u><br class="kix-line-break" /></u></span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">class</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="color: #0e84b5; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">A</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> {</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #002070; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">public:</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /> A(</span><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">std</span><span style="color: #666666; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">string</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> Copied,</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;"> const</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">&</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">ReadOnly)<br class="kix-line-break" /> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">:</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> Copied(</span><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">std</span><span style="color: #666666; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">move(</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">Copied</span><span style="color: #007020; font-size: 13px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">)</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">),</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> ReadOnly(ReadOnly) {}</span></span><br /><span style="font-family: Courier New, Courier, monospace;"><span style="color: #002070; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span><span style="font-family: Courier New, Courier, monospace;"><span style="color: #002070; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">private:</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string Copied;<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">const</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">::</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">string </span><span style="color: #666666; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">&</span><span style="color: #007020; font-size: 13px; vertical-align: baseline; white-space: pre-wrap;">ReadOnly;<br class="kix-line-break" />};</span></span></div></td></tr></tbody></table></div></div><br /><tt>std::move()</tt> is a library function declared in <tt><utility></tt>. If need be, this header is added by clang-modernize.<br /><br />There is a lot of room for improvement in this transform. Other situations that are safe to transform likely exist. Contributions are most welcomed in this area! <br /><div><h2>Usability Improvements</h2>We also worked hard on improving the overall usability of the modernizer. Invoking the modernizer now requires fewer arguments since most of the time the arguments can be inferred. <br /><ul><li>If no compilation database or flags are provided, -std=c++11 is assumed.</li><li>All transforms are enabled by default.</li><li>Files donât need to be explicitly listed if a compilation database is provided. The modernizer will get files from the compilation database. Use -include to choose which ones.</li></ul>Two new features were also added.<br /><ol><li>Automatically reformat code affected by transforms using <a href="http://clang.llvm.org/docs/LibFormat.html">LibFormat</a>.</li><li>A new command line switch to choose transforms to apply based on compiler support.</li></ol><h3>Reformatting Transformed Code</h3><a href="http://clang.llvm.org/docs/LibFormat.html">LibFormat</a> is the library used behind the scenes by <a href="http://clang.llvm.org/docs/ClangFormat.html">clang-format</a>, a tool to format C, C++ and Obj-C code. <i>clang-modernize</i> uses this library as well to reformat transformed code. When enabled with -format, the default style is LLVM. The -style option can control the style in a way identical to clang-format.<br /><br />Example:</div><div><b><br /></b></div><div><b>format.cpp</b></div><div><div dir="ltr" style="margin-bottom: 8pt; margin-left: 36pt; margin-top: 11pt;"><div><span id="docs-internal-guid-65d203ed-13ad-2ddb-d832-4912cc50e162"><span style="background-color: transparent; color: black; font-family: Courier New, Courier, monospace; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1.15; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #007020; font-size: 13px; vertical-align: baseline;">#include <iostream></span><span style="font-size: 13px; vertical-align: baseline;"><br class="kix-line-break" /></span><span style="color: #007020; font-size: 13px; vertical-align: baseline;">#include <vector></span></span></span></div><div style="font-weight: normal; line-height: 1.15;"><span style="background-color: transparent; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span id="docs-internal-guid-65d203ed-13ad-2ddb-d832-4912cc50e162"><span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px; vertical-align: baseline;"><span style="color: #007020;"><br class="kix-line-break" /></span></span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">void</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline;">f</span><span style="color: black; font-size: 13px; vertical-align: baseline;">(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">const</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">vector</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">></span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">&</span><span style="color: black; font-size: 13px; vertical-align: baseline;">my_container) {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">for</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> (std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">vector</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">>::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">const_iterator I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> my_container.begin(),<br class="kix-line-break" /> E </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> my_container.end();<br class="kix-line-break" /> I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">!=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> E; </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">++</span><span style="color: black; font-size: 13px; vertical-align: baseline;">I) {<br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">cout </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><<</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">*</span><span style="color: black; font-size: 13px; vertical-align: baseline;">I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><<</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">endl;<br class="kix-line-break" /> }<br class="kix-line-break" />}</span></span></span></span></div></div><br /><b>Without reformatting</b><br /><br /><div style="padding-left: 10px;"><tt>$ clang-modernize -use-auto format.cpp</tt></div><div dir="ltr" style="margin-bottom: 8pt; margin-left: 36pt; margin-top: 11pt;"><div><span style="background-color: transparent; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span id="docs-internal-guid-65d203ed-13ad-2ddb-d832-4912cc50e162"><span style="font-family: Courier New, Courier, monospace;"><span style="color: #007020; font-size: 13px; vertical-align: baseline;">#include <iostream></span><span style="font-size: 13px; vertical-align: baseline;"><br class="kix-line-break" /></span><span style="color: #007020; font-size: 13px; vertical-align: baseline;">#include <vector></span></span></span></span></div><div style="font-weight: normal; line-height: 1.15;"><span style="background-color: transparent; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span id="docs-internal-guid-65d203ed-13ad-2ddb-d832-4912cc50e162"><span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px; vertical-align: baseline;"><span style="color: #007020;"><br class="kix-line-break" /></span></span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">void</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline;">f</span><span style="color: black; font-size: 13px; vertical-align: baseline;">(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">const</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">vector</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">></span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">&</span><span style="color: black; font-size: 13px; vertical-align: baseline;">my_container) {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">for</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> (</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">auto</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> my_container.begin(),<br class="kix-line-break" /> E </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> my_container.end();<br class="kix-line-break" /> I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">!=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> E; </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">++</span><span style="color: black; font-size: 13px; vertical-align: baseline;">I) {<br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">cout </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><<</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">*</span><span style="color: black; font-size: 13px; vertical-align: baseline;">I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><<</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">endl;<br class="kix-line-break" /> }<br class="kix-line-break" />}</span></span></span></span></div></div><br /><b>With reformatting</b><br /><br /><div style="padding-left: 10px;"><tt>$ clang-modernize -format -style=LLVM -use-auto format.cpp</tt></div><div dir="ltr" style="margin-bottom: 8pt; margin-left: 36pt; margin-top: 11pt;"><div><span id="docs-internal-guid-65d203ed-13ad-2ddb-d832-4912cc50e162"><span style="background-color: transparent; color: black; font-family: Courier New, Courier, monospace; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1.15; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="color: #007020; font-size: 13px; vertical-align: baseline;">#include <iostream></span><span style="font-size: 13px; vertical-align: baseline;"><br class="kix-line-break" /></span><span style="color: #007020; font-size: 13px; vertical-align: baseline;">#include <vector></span></span></span></div><div style="font-weight: normal; line-height: 1.15;"><span style="background-color: transparent; font-size: 15px; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span id="docs-internal-guid-65d203ed-13ad-2ddb-d832-4912cc50e162"><span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 13px; vertical-align: baseline;"><span style="color: #007020;"><br class="kix-line-break" /></span></span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">void</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #06287e; font-size: 13px; vertical-align: baseline;">f</span><span style="color: black; font-size: 13px; vertical-align: baseline;">(</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">const</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">vector</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><</span><span style="color: #902000; font-size: 13px; vertical-align: baseline;">int</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">></span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">&</span><span style="color: black; font-size: 13px; vertical-align: baseline;">my_container) {<br class="kix-line-break" /> </span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">for</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> (</span><span style="color: #007020; font-size: 13px; font-weight: bold; vertical-align: baseline;">auto</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> my_container.begin(), E </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> my_container.end(); I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">!=</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> E; </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">++</span><span style="color: black; font-size: 13px; vertical-align: baseline;">I) {<br class="kix-line-break" /> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">cout </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><<</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">*</span><span style="color: black; font-size: 13px; vertical-align: baseline;">I </span><span style="color: #666666; font-size: 13px; vertical-align: baseline;"><<</span><span style="color: black; font-size: 13px; vertical-align: baseline;"> std</span><span style="color: #666666; font-size: 13px; vertical-align: baseline;">::</span><span style="color: black; font-size: 13px; vertical-align: baseline;">endl;<br class="kix-line-break" /> }<br class="kix-line-break" />}</span></span></span></span></div></div><br />For more information about this option, take a look at the documentation: <a href="http://clang.llvm.org/extra/ModernizerUsage.html#formatting-command-line-options" style="vertical-align: baseline;">Formatting Command Line Options</a>.<br /><h3>Choosing Transforms based on Compiler Support</h3>Another useful command-line switch is: <a href="http://clang.llvm.org/extra/ModernizerUsage.html#for-compilers-option">-for-compilers</a>. This option enables all transforms the given compilers support.<br /><br />As an example, imagine that your project dropped a dependency to a âlegacyâ version of a compiler. You can automagically modernize your code to the new minimum versions of the compilers you want to support:<br /><br />To support Clang >= 3.1, GCC >= 4.6 and MSVC 11:<br /><br /><div style="padding-left: 25px;"><pre>clang-modernize -format -for-compilers=clang-3.1,gcc-4.6,msvc-11 foo.cpp</pre></div><br />For more information about this option and to see which transforms are available for each compilers, please read <a href="http://clang.llvm.org/extra/ModernizerUsage.html#cmdoption-for-compilers">the documentation</a>.<br /><h2> Whatâs next?</h2>The ability to transform many translation units in parallel will arrive very soon. Think of <i>clang-modernize -j</i> as in make and ninja. Modernization of large code bases will become much faster as a result.<br /><br />More transforms are coming down the pipe as well as improvements to existing transforms such as the pass-by-value transform.<br /><br />We will continue fixing bugs and adding new features. Our backlog is publically available: <a href="https://cpp11-migrate.atlassian.net/secure/RapidBoard.jspa?rapidView=1&view=planning">https://cpp11-migrate.atlassian.net/secure/RapidBoard.jspa?rapidView=1&view=planning</a><br /><h2>Get involved!</h2>Interested by the tool? Found a bug? Have an idea of a transform that can be useful to others? The project is Open Source and contributions are most welcomed!<br /><br />The modernizer has its own bug and project tracker. If you want to file or fix a bug just go to: <a href="https://cpp11-migrate.atlassian.net/">https://cpp11-migrate.atlassian.net</a><br /><br />A few other addresses to keep in mind: <br /><ul><li><a href="http://clang.llvm.org/extra/clang-modernize.html">Clang C++ Modernizer Userâs Manual</a></li><li>IRC channel: #llvm on irc.oftc.net</li><li>Mailing lists:</li><ul><li><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">cfe-dev</a> for questions and general discussions</li><li><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">cfe-commits</a> for patches</li></ul><li><a href="http://llvm-reviews.chandlerc.com/">Phabricator</a> to submit patches</li></ul><h2> Final word</h2>Finally I want to thank my mentor Edwin Vane and his team at Intel, Tareq Siraj and Ariel Bernal, for the great support they provided me. Also thanks to the LLVM community and Google Summer of Code team for giving me this opportunity to work on the C++ Modernizer this summer.<br /><br />-- Guillaume Papin</div></div></div></div></div>
- The clang-cl /fallback modehttps://blog.llvm.org/2013/11/the-clang-cl-fallback-mode.htmlTue, 05 Nov 2013 08:42:00 +0000https://blog.llvm.org/2013/11/the-clang-cl-fallback-mode.html<p>There has been a lot of work lately towards bringing an LLVM toolchain to the Windows platform (see <a href="http://blog.llvm.org/2013/09/a-path-forward-for-llvm-toolchain-on.html">A path forward for an LLVM toolchain on Windows</a>). One result of that work is a new driver mode for Clang: <a href="http://clang.llvm.org/docs/UsersManual.html#clang-cl">clang-cl</a>. This mode makes Clang understand the same kind of command-line arguments as Visual Studio's compiler, cl.exe. For example, a typical command to compile a file into an executable with Clang might be "clang hello.cc -o hello", whereas with cl.exe, one would use "cl.exe hello.cc /Fehello". Now one can use the latter syntax with Clang by substituting "cl.exe" with "clang-cl". This makes it easy to use Clang for existing projects in Visual Studio.</p> <p>For the most part, clang-cl accepts exactly the same arguments as cl.exe. However, it also accepts some Clang-specific options. One such option that was added recently is <a href="http://clang.llvm.org/docs/UsersManual.html#the-fallback-option">the /fallback flag</a>. The purpose of this flag is to make it easy to use clang-cl even in projects where Clang cannot yet compile all of the code. This post gives an example of how /fallback can be used.</p> <a name='more'></a> <p>The way clang-cl works in /fallback mode is that it first tries to compile the code with Clang, and if that fails for some reason it falls back to compiling with cl.exe. Consider the following two files, where main.cpp can be compiled by Clang, but printer.cpp cannot:</p> <pre style="text-indent: 0px;"><br />printer.cpp:<br /><br />#include <iostream><br />void print_hello(const char *s) {<br /> std::cout << "Hello from " << s << "!" << std::endl;<br />}<br /></pre> <pre style="text-indent: 0px;"><br />main.cpp:<br /><br />extern void print_hello(const char*);<br />int main(int argc, char **argv) {<br /> print_hello(argv[0]);<br /> return 0;<br />}<br /></pre> <p>clang-cl cannot compile printer.cpp since it includes iostream which uses language features that are not completely supported yet (hopefully they will be soon). However, clang-cl can still compile the two files in fallback mode:</p> <pre style="text-indent: 0px;">clang-cl /fallback /Fehello main.cpp printer.cpp</pre> <p>Clang will compile main.cpp successfully, print some error messages about the features it does not support for printer.cpp, and fall back to the cl.exe compiler for that file. The compiled files will be linked together into hello.exe.</p> <p>Note that this is not fool proof: even if clang-cl thinks it has compiled a file successfully, there can be bugs in the generated code that cause failures at link- or run-time.</p> <p>Currently, the fallback mode will cause clang-cl to fall back on any kind of error. Going forward, it will be changed to only fall back on certain kinds of internal errors, and as Clang's Windows support improves, the fallback mode will eventually become unnecessary and removed. It is still early days for clang-cl, but you can try it out for yourself by downloading the toolchain from the <a href="http://llvm.org/builds/">LLVM Snapshot Builds website</a>.</p>
- OpenMP* projecthttps://blog.llvm.org/2013/10/openmp-project.htmlTue, 08 Oct 2013 03:13:00 +0000https://blog.llvm.org/2013/10/openmp-project.html<div dir="ltr" style="text-align: left;" trbidi="on"><div class="MsoNormal"><span lang="EN-US">I am extremely glad to announce that Intel has decided to provide a copy of our Intel® open-source OpenMP* runtime as an LLVM sub-project (and the LLVM project has been kind enough to accept our contribution!). This gives the community a fully LLVM license compatible version of the OpenMP runtime for use in OpenMP development projects. <o:p></o:p></span>The complete source code is now available at <a href="http://openmp.llvm.org/">openmp.llvm.org</a>. </div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US">We open-sourced the Intel OpenMP runtime code to support the development of a full LLVM-based implementation of the OpenMP specification. Intelâs compiler team in Moscow has made outstanding progress in implementing the Clang changes to support the OpenMP language extensions (you can see their work at </span><a href="http://clang-omp.github.io/" style="font-family: 'Times New Roman', serif; font-size: 12pt;">http://clang-omp.github.io</a>), and now weâve reached a milestone where we can create an LLVM sub-project for some of the other components that are needed to build a complete OpenMP system.</div><div class="MsoNormal"><br /></div><div class="MsoNormal">Personally, I am very happy (and proud) to be associated with LLVM, and I look forward to a long and productive collaboration.</div><div class="MsoNormal"><span lang="EN-US"><br /></span></div><div class="MsoNormal"><span lang="EN-US">-- Jim Cownie</span></div></div>
- libc++ and C++1Yhttps://blog.llvm.org/2013/09/libc-and-c1y.htmlMon, 23 Sep 2013 12:44:00 +0000https://blog.llvm.org/2013/09/libc-and-c1y.htmlI am proud to announce that as of September 21, libc++ has a full implementation of the C++1Y standard library. <br /><br />In April of 2013, the C++ standards committee approved a draft version of the next revision of the C++ language, called "C++1Y". (C++11 was called "C++0x" while in development). We hope that this draft standard will be approved next year, and become C++14. <br /><br />The draft standard includes changes to both the language and the standard library. These changes are designed to correct some mistakes that have been discovered in the C++11 standard and to add new features.<br /><br />Both clang and libc++ are being enhanced to support this new standard, and they each have a web page to show their current progress: <a href="http://clang.llvm.org/cxx_status.html">clang C++1Y Status</a> and <a href="http://libcxx.llvm.org/cxx1y_status.html">libc++ C++1Y status</a>.<br /><br />The C++ standards committee is meeting this week (September 23-28) to consider comments and defect reports in the C++1Y draft standard, and there will certainly be changes made.<br /><br />We could have waited until the final version of the C++1Y standard was approved; that would certainly have been less work. The draft standard will to be revised in September (and probably in February), so the libc++ implementation will have to change to track the standard.<br /><br />However, by implementing the draft standard has several advantages.<br /><ul><li>We gain experience in working with the new standard.</li><li>We found several places where the changes to the draft standard "exposed" other places were improvements can be made. For example, while implementing the new <code>optional</code> feature made it clear that interface of the the comparison functions <code>plus</code>, <code>less</code> (and others) could be enhanced. The result of that was the new paper <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3749.htm">n3749</a>.</li><li>By implementating the standard, we can identify problems/inconsistencies in the draft standard. For example, when we implemented the new library feature <code>dynarray</code>, we discovered that the interfaces for the allocator-based constructors for the container were <em>wrong</em>; in particular there were cases where it was not possible for the compiler to determine the correct constructor to call. This was raised as <a href="http://cplusplus.github.io/LWG/lwg-active.html#2255">LWG Issue 2255</a>, and will have to be resolved before the standard becomes final.</li></ul>
- A path forward for an LLVM toolchain on Windowshttps://blog.llvm.org/2013/09/a-path-forward-for-llvm-toolchain-on.htmlThu, 05 Sep 2013 18:23:00 +0000https://blog.llvm.org/2013/09/a-path-forward-for-llvm-toolchain-on.html<p>Over the past several months, contributors from Google and elsewhere in the community have begun actively working on bringing an LLVM toolchain to Windows in a way that would support and enhance a fully native development experience. This toolchain works with Visual Studio and the Windows development process that Windows developers are already using, making LLVM tools and technologies available to them. We want to cross the streams (in the Ghostbuster proton-pack sense) of the Visual Studio IDE and the LLVM-based C++ tools to enable developers to build C++ software better.</p> <p>To that end, weâve been driving many of the efforts around compatibility with Visual Studio and native Windows C++ code in Clang and LLD (the LLVM linker). Today, as announced at <a href="https://learn.microsoft.com/en-us/events/goingnative-2013/care-feeding-of-c-s-dragons">my GoingNative 2013 talk</a>, we are able to build a trivial C++ application that in turn links against native C++ libraries and uses them in real, interesting ways. This is a huge milestone for the project, and something weâre really excited to be talking more about. Lots of folks in the LLVM project came together to get the open source project here. Thanks to every single one of you.</p> <p>Going forward, we would really like to see an increased level of involvement from Windows developers. Weâre launching an <a href="http://llvm.org/builds">alpha-build website</a> as part of llvm.org where you can get fresh builds of Clang, various Clang-based-tools, LLD, and the rest of the LLVM toolchain for Windows on a regular basis. These installable packages should make it dramatically easier to test and experiment with this new set of tools in your development environment. Please feel free to try it out, <a href="http://llvm.org/bugs">file bugs</a>, and even <a href="http://llvm.org/docs/DeveloperPolicy.html#making-a-patch">submit patches</a> to help move the toolchain forward on this new platform. Keep in mind, we are following the tried-and-true open source release mantra of releasing early and frequently. These are alpha-quality releases intended at developers interested in helping us track down and understand bugs.</p> <p>There is still a lot of exciting work left to make LLVM and the C++ toolchain built on top of LLVM fully support the Windows platform. Come join the fun, because this is one place where patches are truly welcome.</p> -Chandler Carruth
- Clang Warningshttps://blog.llvm.org/2013/09/clang-warnings.htmlWed, 04 Sep 2013 17:03:00 +0000https://blog.llvm.org/2013/09/clang-warnings.html<span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"></span><br />Clang has two types of diagnostics, errors and warnings. Errors arise when the code does not conform to the language. Such things as missing semi-colons and mismatched braces prevent compilation and will cause Clang to emit an error message.<br /><br />On the other hand, warnings are emitted on questionable constructs on language conforming code. Over time, certain patterns have been determined to have a strong likelihood of being a programming mistake. Some examples of these include: order of operations confusion, mistaking similarly named language features, and easily made typos that still result in valid code.<br /><br />Although warnings may have false positives, the utility of finding bugs early usually outweigh their downsides. Keep reading for a demonstration of Clang's warnings, as well as a comparison to GCC's warnings.<br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></span><br /><a name='more'></a><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The following code consists of < 200 lines of code, one library, and one header file, only used for printing. It is legitimate C++ code and can be compiled into a program. Take a few moments and see if you can spot any bugs in the following code.</span></span></div><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"></span><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></span></div><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"></span><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">main.cc</span></span></span></div><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"></span><br /><ol style="margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#include "sort.h"</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#include <iostream></span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">int main(int argc, char** argv) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int V[] = { 3, 4, 7, 10, 11, 1, 2, 0};</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << "Unsorted numbers:" << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> for( auto num : V )</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << " " << num << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> if (!sort(V, sizeof(V)/sizeof(V[0]))) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << "Sort failed." << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> return 1;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << "Sorted numbers:" << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> for( auto num : V )</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << " " << num << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> return 0;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li></span></ol><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></span><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">sort.h</span></span></span></div><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"></span><br /><ol style="margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#ifndef _EXPERIMENTAL_WARNINGS_SORT_H_</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#define _EXPERIMNETAL_WARNINGS_SORT_H_</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#include <iostream></span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#ifdef _NDEBUG</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#define ASSERT(cond) \</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> if(!cond) cout << __FILE__ << ":" << __LINE__ << " " << #cond << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#else</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#define ASSERT(cond) if (!cond) {}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#endif</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">enum SortType {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> unknown = 0,</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> min_invalid = 3,</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> bubble = 1,</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> quick,</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> insert</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">};</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">class Sort {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> public:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> Sort(int vec[], int size, bool sorted = false);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> bool IsSorted();</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> void Begin(SortType Type = unknown);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> private:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> void BubbleSort();</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> void QuickSort() { }; // Not implemented yet.</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> void InsertSort() { }; // Not implemented yet.</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int* vec_;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> bool sorted_;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int &size_;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">};</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">static bool sort(int vec[], int size) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> Sort sort(vec, size);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> sort.Begin(bubble);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> return sort.IsSorted();</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#endif // _EXPERIMENTAL_WARNINGS_SORT_H_</span></span></div></li></span></ol><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></span><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">sort.cc</span></span></span></div><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"></span><ol style="margin-bottom: 0pt; margin-top: 0pt;"><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#include <iostream></span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">#include "sort.h"</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">Sort::Sort(int vec[], int size, bool sorted)</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> : sorted_(sorted_), vec_(vec), size_(size) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> if (size > 50)</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ASSERT("!Vector too large. Number of elements:" + size);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int sum;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> for (unsigned i = 0; !i == size; ++i) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int sum = sum + vec_[i];</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ++i;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ASSERT(sum < 100 && "Vector sum is too high");</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">bool Sort::IsSorted() {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> return sort;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">static bool CheckSort(int V[]) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> bool ret;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> for (int i = 1; i != sizeof(V)/sizeof(V[0]); ++i)</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> if (V[i] > V[i - 1])</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ret = false;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> return ret;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">static const char* TypeToString(SortType Type) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> const char* ret;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> switch (Type) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> case bubble:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ret = "bubble";</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> case quick:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ret = "quick";</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> case insert:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ret = "insert";</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> return ret;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">void Sort::Begin(SortType Type) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << "Sort type: ";</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << Type == 0 ? "Unknown type, resorting to bubble sort"</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> : TypeToString(Type);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> cout << endl;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> switch (Type) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> default:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> bubble:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> BubbleSort(); break;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> quick:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> QuickSort(); break;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> insert:</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> InsertSort(); break;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> sorted_ = CheckSort(vec_);</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span style="vertical-align: baseline; white-space: pre-wrap;"></span></span></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">void Sort::BubbleSort() {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> for (int i = 0; i < size_; ++i) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> for (int j = 1; j < size_; ++i) {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int a = vec_[j-1];</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> int b = vec_[j];</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> if (a > b); {</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> vec_[j-1] = b;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> vec_[j] = a;</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> }</span></span></div></li><li dir="ltr" style="font-size: 15px; list-style-type: decimal; vertical-align: baseline;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">}</span></span></div></li></span></ol><span id="docs-internal-guid-64a5b270-651c-62fd-ef8a-a37c15d794b3"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" />Did you find any bugs? Many common problems are hard to spot from just reading the code. To make a better coding experience, Clang has many diagnostics that will flag these mistakes. The bugs in the code are detailed below.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">main.cc does not have any problems. It merely is a wrapper around the library so that a binary can be produced and run, although running it will not sort the array properly.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">sort.h is the header file to the library.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">1:#ifndef _EXPERIMENTAL_WARNINGS_SORT_H_</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">2:#define _EXPERIMNETAL_WARNINGS_SORT_H_</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The first warning triggers on the first two lines. Header guards are used by libraries to prevent multiple <span style="font-family: Courier New, Courier, monospace;">#include</span>âs of a file from producing redefinition errors. To work, the <span style="font-family: Courier New, Courier, monospace;">#ifndef</span> and <span style="font-family: Courier New, Courier, monospace;">#define</span> must use the same macro name.. The transposition of E and N produces different names and is an easy bug to overlook. Worse, this sort of bug can hide within headers and never produce a problem when singly included and then much later start producing problems when someone double includes this header. Clang has -Wheader-guard to catch this. GCC does not catch this.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Next, examine the custom ASSERT macro used:</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">7.#define ASSERT(cond) \</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">8. if(!cond) cout << ...</span></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The problem is treating the macro parameter as a function parameter. Macro arguments are not evaluated. Instead, they are substituted in as typed. Thus, code as </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">ASSERT(x == 5)</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> becomes </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">if(!x == 5) cout << ...</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> The proper fix is to enclose the macro parameter in parentheses, as </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">if (!(cond)) cout << ...</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> This is caught by -Wlogical-not-parentheses. Being inside a macro definition, the warning will trigger when the macros are used with a note pointing back here. GCC has no equivalent for -Wlogical-not-parentheses.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">13:enum SortType {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">14: unknown = 0,</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">15: min_invalid = 3,</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">16:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">17: bubble = 1,</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">18: quick,</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">19: insert</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">20:};</span></span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">In this enum, a few non-valid values are defined, then the valid enums listed. Valid enums use the auto increment to get their values. However, </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">min_invalid</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> and </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">insert</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> both have value 3. Luckily, -Wduplicate-enum will identify enums in this situation and point them out. GCC will not warn on this.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: inherit;">On to sort.cc</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><span style="font-family: inherit;">Class constructor:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">4:Sort::Sort(int vec[], int size, bool sorted)</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">5: : sorted_(sorted_), vec_(vec), size_(size) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: inherit; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Members from sort.h:</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">34: int* vec_;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">35: bool sorted_;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">36: int &size_;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><br /></div><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Checking the only constructor of the class, numerous problems can be seen here. First notice that the variables are declared <span style="font-family: Courier New, Courier, monospace;">vec_</span>, <span style="font-family: Courier New, Courier, monospace;">sorted_</span>, then <span style="font-family: Courier New, Courier, monospace;">size_</span>, but in the constructor, they are listed as <span style="font-family: Courier New, Courier, monospace;">sorted_</span>, <span style="font-family: Courier New, Courier, monospace;">vec_</span>, then <span style="font-family: Courier New, Courier, monospace;">size_</span>. The order of initialization is order they were declared, meaning <span style="font-family: Courier New, Courier, monospace;">vec_</span> is initialized before <span style="font-family: Courier New, Courier, monospace;">sorted_</span>. There is no order dependence here, but -Wreorder will warn that the orders donât match. GCC also has -Wreorder.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Next, <span style="font-family: Courier New, Courier, monospace;">sorted_</span> is initialized with itself instead of with sorted. This leads to uninitialized value in <span style="font-family: Courier New, Courier, monospace;">sorted_</span>, which is caught by the aptly named -Wuninitialized. For this case, GCC has -Wself-assign and -Wself-init.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Finally, notice that <span style="font-family: Courier New, Courier, monospace;">size_</span> is declared as a reference but size is not passed by reference. size only lives until the end of the constructor while the reference <span style="font-family: Courier New, Courier, monospace;">size_</span> will continue to point to it. -Wdangling-field catches this problem.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">7: ASSERT("!Vector too large. Number of elements:" + size);</span></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Two problems here. Adding an integer to a string literal does not concatenate the two together. Instead, since a string literal is a pointer of type <span style="font-family: Courier New, Courier, monospace;">const char *</span>, this actually performs pointer math. With a sufficiently integer, this can even cause the pointer to go past the end of the string into some other memory. -Wstring-plus-int warns on this case. GCC has no equivalent warning.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: Courier New, Courier, monospace;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">7: ASSERT("!Vector too large. More than 50 elements.");</span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">When fixed, another problem arises. A common pattern is to include a string literal describing the assert. If the assert is always to fire, then expression should evaluate to false. The string literal evaluates to true, so just negate it to get a false value, right? Well, a number of common typos can happen.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><b>These values evaluate true:</b></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">"true"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">"false"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">"!true"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">"!false"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">"any string"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><b>These values evaluate to false:</b></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">!"true"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">!"false"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-family: 'Courier New', Courier, monospace; font-size: 15px; line-height: 1.15; white-space: pre-wrap;">!"any string"</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">!"!any string"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Due to that, -Wstring-conversion will warn when a string literal is converted to a true boolean value. Use </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">ASSERT(false && âstringâ)</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> or </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">ASSERT(0 && âstringâ)</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> instead. GCC has no equivalent warning.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> 9: int sum;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">10: for (unsigned i = 0; !i == size; ++i) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">11: int sum = sum + vec_[i];</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">12: ++i;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">13: }</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">14:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">15: ASSERT(sum < 100 && "Vector sum is too high");</span></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">More bugs here. The obvious one is the that <span style="font-family: Courier New, Courier, monospace;">sum</span> is uninitialized on line 9. When it gets used on line 15, this causes undefined behavior. This gets caught by -Wuninitialized which suggests setting it to 0 to fix. GCC's -Wuninitialized also catches this.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">A poor negation causes a bad condition in the for-loop. </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">!i == size</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> is equivalent to </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">(!i) == size</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> due to order of operations. -Wlogical-not-parentheses will suggest </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">!(i == size)</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> to correct this. Again, GCC does not have a -Wlogical-not-parantheses equivalent.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">On line 10 and 12, for every loop iteration, two </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">++i</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> will increment the variable. A warning in -Wloop-analysis catches this. This warning is Clang-specific.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Two separate problems happen on line 11. Another -Wuninitialized warning here for using <span style="font-family: Courier New, Courier, monospace;">sum</span> in its own initialization. Also, -Wshadow will warn that the variable <span style="font-family: Courier New, Courier, monospace;">sum</span> inside the loop is different from the variable <span style="font-family: Courier New, Courier, monospace;">sum</span> outside the loop. Both GCC's and Clang's versions of these warning catches these problems.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">18:bool Sort::IsSorted() {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">19: return sort;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">20:}</span></span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The member variable is called <span style="font-family: Courier New, Courier, monospace;">sorted_</span>. <span style="font-family: Courier New, Courier, monospace;">sort</span> is a static function wrapper defined at sort.h line 39. Here, the function is automatically converted to a function pointer, then to true. Caught by -Wbool-conversion. GCC has function address to bool conversions placed under -Waddress.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">22:static bool CheckSort(int V[]) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">23: bool ret;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">24: for (int i = 1; i != sizeof(V)/sizeof(V[0]); ++i)</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">25: if (V[i] > V[i - 1])</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">26: ret = false;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">27: return ret;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">28:}</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">On line 23, <span style="font-family: Courier New, Courier, monospace;">ret</span> is not initialized. On line 26, a value may be assigned to it, but it is possible that no path will through the code will set it a value. The warning -Wsometimes-uninitialized will warn on this and give suggestions on how to fix. GCC will not catch this.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">On line 24 inside the for loop conditional, there is </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">i != sizeof(V)/sizeof(V[0])</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">, which is trying to keep </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">i</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> as a valid array index. However, the </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">sizeof</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> calculation produces the wrong result. This would be correct if </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">V</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> was declared inside the function. However, as a parameter, </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">V</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> has type </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">int*</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">, causing the </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">sizeof</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> to take the size of a pointer instead of the array. A separate size argument needs to be passed to the function. Caught by -Wsizeof-array-argument, a Clang specific warning.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">30:static const char* TypeToString(SortType Type) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">31: const char* ret;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">32: switch (Type) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">33: case bubble:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">34: ret = "bubble";</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">35: case quick:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">36: ret = "quick";</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">37: case insert:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">38: ret = "insert";</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">39: }</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">40: return ret;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">41:}</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">A simple enum to string converter function. Like the previous function, <span style="font-family: Courier New, Courier, monospace;">ret</span> is again uninitialized, and will be caught by -Wsometimes-uninitialized. Clang warns here because it can analyze all the paths through the switch and determine that at least one will not assign a value to <span style="font-family: Courier New, Courier, monospace;">ret</span>. GCC does not have -Wsometimes-uninitialized.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">On the switch statement, Clang and GCC notices that <span style="font-family: Courier New, Courier, monospace;">unknown</span> is not used, caught by the warning -Wswitch.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Clang also has a special attribute, </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">[[clang::fallthrough]];</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">, to mark intended fallthroughs in switch cases. By marking all cases intended uses of fallthrough, Clang can warn on the unintended cases, such as these three cases without break statements. Otherwise, the fallthrough will cause all three cases to return <span style="font-family: Courier New, Courier, monospace;">âinsertâ</span>. This is -Wimplicit-fallthrough, a Clang-specific warning.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">43:void Sort::Begin(SortType Type) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">44: cout << "Sort type: ";</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">45: cout << Type == 0 ? "Unknown type, resorting to bubble sort"</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">46: : TypeToString(Type);</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">47: cout << endl;</span></span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">While </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">cout</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> uses </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">operator<<</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> to stream various types to output, it still is an operator and C++ has a defined order of operations. Shifts (<< and >>) are evaluated before conditional operators (?:). To add some parentheses to clear up the order, this becomes:</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">45: ((cout << Type) == 0) ? "Unknown type, resorting to bubble sort"<br class="kix-line-break" />46: : TypeToString(Type);</span></span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">First, </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">Type</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> gets pushed to </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">cout</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">, via </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">operator<<</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">. </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">operator<<</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> returns the </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">cout</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> stream again. Streams are convertible to bools to check if they are valid, which is checked against false, converted from 0. The result of this comparison is used for the conditional operator, whose result is not used anywhere. GCC doesn't catch this, but Clang's -Woverloaded-shift-op-parentheses does.</span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">48: switch (Type) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">49: default:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">50: bubble:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">51: BubbleSort(); break;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">52: quick:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">53: QuickSort(); break;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">54: insert:</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">55: InsertSort(); break;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">56: }</span></span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Another switch statement, also triggers -Wswitch because none of the enum values are represented. Each of the enum values is missing a case, causing them to become labels instead. The warning -Wunused-label hints that something is wrong here. -Wunused-label is in both GCC and Clang.</span></div><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">61: for (int i = 0; i < size_; ++i) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">62: for (int j = 1; j < size_; ++i) {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"> ...</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">69: }</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">70: }</span></span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">This double nested loop gives bubble sort its n</span><span style="font-size: 9px; vertical-align: super; white-space: pre-wrap;">2</span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> running time. Rather, in this case, an infinite running time. Note the increment in both of the loops happen on </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">i</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">, even in the inner loop. </span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">j</span></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> is never touched, either here or inside the loop. -Wloop-analysis will give a warning when all the variables inside a for loop conditional does not change during the loop iteration. Only in Clang.</span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">63: int a = vec_[j-1];</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">64: int b = vec_[j];</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">65: if (a > b); {</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">66: vec_[j-1] = b;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">67: vec_[j] = a;</span></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">68: }</span></span></div><br /><span style="font-family: Consolas; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Then -Wempty-body warning will trigger on line 65. The semi-colon here become the entirety of the loop body while the value swap happens on every loop iteration, not only when the conditional is true. Both Clang and GCC has this warning.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">This is just a small sample of the warnings that Clang provides. Along with informative diagnostic messages, these warnings help programmers avoid common coding pitfalls. In particular, it saves the programmer time tracking down valid but not intended code later. These warnings make Clang an exceptional productivity and code quality booster for coders.</span><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">For reference, a list of warnings discussed above:</span><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Wbool-conversion</span><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Warns on implicit conversion of a function pointer to a true bool value. GCC has this warning as part of -Waddress.</span><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Wempty-body</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Warns when an if statement, while loop, for loop, or switch statement only has a semi-colon for the body, and is on the same line as the rest of the statement. Clang and GCC warning.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Wheader-guard</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Detects when the #ifndef and #define have different macro names. This causes the header guard to fail to prevent multiple inclusions. </span><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">This is a Clang-specific warning available in SVN trunk and slated for the 3.4 release.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">-Wimplicit-fallthrough</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">Enabling this warning will cause a diagnostic to be emitted for all fallthroughs in switch statements that have not been annotated. Requires compilation in C++11 mode. Clang-specific warning, available in the 3.2 release.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Wlogical-not-parentheses</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">This warning is part of the -Wparentheses. This group of warnings suggests parentheses in cases where users may read the code differently than the compiler. This warning in particular will trigger when the logical not operator ('!') is applied to the left hand side of a comparison when it was meant to apply to the whole conditional. "!x == y" is different from "!(x == y)" since "!x" will be evaluated before the equality comparison. </span><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">This is a Clang-specific warning available in SVN trunk and slated for the 3.4 release.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Wloop-analysis</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Detects questionable code in loops. It catches two interesting loop patterns: a for-loop has an increment/decrement in its header and has the same increment/decrement for the last statement in the loop body, which will execute only half the intended iterations, and when the variables in the for-loop comparison are not modified during the loop, possibly indicating an infinite loop. Clang-specific warning. Unmodified loop variables warning is available in 3.2 and onward. Detection of double increments/decrements is in SVN trunk and slated for the 3.4 release.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Woverloaded-shift-op-parentheses</span><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The overloaded shift operator is used mainly with streams, such as cin and cout. However, the shift operator has higher precedence than some operators, such as comparison operators, which may cause unexpected problems. This warning suggests parentheses to disambiguate the order of evaluation. Clang-specific warning available since the 3.3 release.</span><br /><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span><br /><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;">-Wshadow</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;">Variable names in an inner scope may take the same name as a variable in an outer scope, yet refer to different variables. Then the variable in the outer scope may be difficult or impossible to refer to while inside the inner scope. -Wshadow points out such variable name reuse. Both Clang and GCC has this warning.</span><br /><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;">-Wsizeof-array-argument</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;">Warns when attempting to take the sizeof() of an array that is a parameter. These arrays are treated as a pointer, which will return an unexpected size. Clang-specific warning.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 1.15; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">-Wstring-conversion</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">A literal string has type const char *. As a pointer, it is convertible to a bool, but in most cases, the conversion to bool is not intended. This warning will trigger on such conversions. Clang-specific warning.</span></div><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">-Wswitch</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">This warning detects when an enum type is used in the switch, and some values of the enum are not represented in the cases. Clang and GCC warning.</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">-Wuninitialized</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">When a variable is declared, its value is uninitialized. If its value is used elsewhere before being initialized, undefined behavior may result. Present in both Clang and GCC. Clang performs additional analysis, such as following multiple code paths. Some items caught by Clang's warning falls under different warnings in GCC, such as -Wself-assign and -Wself-init.</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">-Wunique-enum</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">Enum elements can either be declared explicitly to a value, or implicitly which gives it the value of the previous element plus one. Clang-specific warning available since the 3.3 release.</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;"><br /></span></div><div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">-Wunused-label</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">Warns when a label is present in code, but never called. Clang and GCC warning.</span><br /><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;"><br /></span><span style="font-size: 15px; line-height: 17px; white-space: pre-wrap;">* Edited September 10, 2013. Spelling corrections were made. Warnings which were first available in 3.2 or later are noted. If not marked, the warning has been around since before the 3.2 release.</span></div></div></span>
- Object Caching with the Kaleidoscope Example Programhttps://blog.llvm.org/2013/08/object-caching-with-kaleidoscope.htmlFri, 02 Aug 2013 11:00:00 +0000https://blog.llvm.org/2013/08/object-caching-with-kaleidoscope.htmlIn previous posts I described the process of porting the LLVM Kaleidoscope tutorial program to use MCJIT as its execution engine and introduced a lazy compilation implementation with the MCJIT engine. The lazy implementation produced similar, and in some cases better, performance when compared with an implementation based on the older JIT execution engine, but it used more memory.<br /><br />In this post, Iâm going to extend the new implementation to use MCJITâs object caching interface. This will give our interpreter a way to store pre-compiled versions of previously used function and retrieve them for execution in later runs of the program.<br /><a name='more'></a><br /><h3>Adding a Library Parsing Mechanism</h3>Iâm going to base the object caching on a library loading model. In theory we could cache any object that the execution engine generates, but to make effective use of the cache we need some way of knowing that what weâre loading matches something we previously stored. For simplicity, Iâm going to extend the Kaleidoscope tutorial to accept a command line argument that references an LLVM IR file to be loaded as a library. Once thatâs working, Iâll introduce the object caching mechanism.<br /><br />The IR loading is a fairly easy thing to add. Weâll use a standard LLVM command line parsing template:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">cl::opt<std::string></span><br /><span style="font-family: Courier New, Courier, monospace;">InputIR("input-IR",</span><br /><span style="font-family: Courier New, Courier, monospace;"> cl::desc("Specify the name of an IR file to load for function definitions"),</span><br /><span style="font-family: Courier New, Courier, monospace;"> cl::value_desc("input IR file name"));</span></blockquote>Then in the main() function, weâll add argc and argv parameters along with a call to parse the command line options.<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">int main(int argc, char **argv) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> InitializeNativeTarget();</span><br /><span style="font-family: Courier New, Courier, monospace;"> InitializeNativeTargetAsmPrinter();</span><br /><span style="font-family: Courier New, Courier, monospace;"> InitializeNativeTargetAsmParser();</span><br /><span style="font-family: Courier New, Courier, monospace;"> LLVMContext &Context = getGlobalContext();</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> cl::ParseCommandLineOptions(argc, argv,</span><br /><span style="font-family: Courier New, Courier, monospace;"> "Kaleidoscope example program\n");</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> if (!InputIR.empty()) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> parseInputIR(InputIR);</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> ...</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Happily, LLVM also gives us what we need to parse an IR file into a module:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">bool parseInputIR(std::string InputFile) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> SMDiagnostic Err;</span><br /><span style="font-family: Courier New, Courier, monospace;"> Module *M = ParseIRFile(InputFile, Err, getGlobalContext());</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (!M) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> Err.print("IR parsing failed: ", errs());</span><br /><span style="font-family: Courier New, Courier, monospace;"> return false;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> char ModID[256];</span><br /><span style="font-family: Courier New, Courier, monospace;"> sprintf(ModID, "IR:%s", InputFile.c_str());</span><br /><span style="font-family: Courier New, Courier, monospace;"> M->setModuleIdentifier(ModID);</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> TheHelper->addModule(M);</span><br /><span style="font-family: Courier New, Courier, monospace;"> return true; </span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Iâm setting an identifier that we can use to recognize that this module was loaded as an IR file. Weâll use that later for object caching, but right now it also lets us skip the function optimization passes when we compile this module.<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">// Get the ModuleID so we can identify IR input files</span><br /><span style="font-family: Courier New, Courier, monospace;">const std::string ModuleID = M->getModuleIdentifier();</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;">// If we've flagged this as an IR file, it doesn't need function passes run.</span><br /><span style="font-family: Courier New, Courier, monospace;">if (0 != ModuleID.compare(0, 3, "IR:")) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Create a function pass manager for this engine</span><br /><span style="font-family: Courier New, Courier, monospace;"> FunctionPassManager *FPM = new FunctionPassManager(M);</span><br /><span style="font-family: Courier New, Courier, monospace;"> ...</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Finally, we need to provide a function to add the newly created module to the list of modules handled by MCJITHelper.<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">void MCJITHelper::addModule(Module* M) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> Modules.push_back(M);</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Our lazy compilation mechanism will take care of compiling this module when any function it contains is called.<br /><br />When we build the program now, we need to add âirreaderâ to the list of libraries on the compile line.<br /><br />At this point, we can provide a complete IR file as input to our Kaleidoscope interpreter. You can generate an IR file by capturing the âdumpâ output of a module that has been created by our interpreter. Itâs easiest to do this using the old JIT-based implementation, since it keeps everything in one module. Because the particulars of where an input file will come from are likely to be implementation specific, Iâll just leave it at that for now.<br /><h3>Implementing Object Cache</h3>The mechanism above to load IR files can be used with either the JIT or MCJIT implementations of the Kaleidoscope interpreter. With the MCJIT implementation, there is a significant time hit for compilation the first time a library is accessed, but subsequent references will be very fast. With the JIT implementation, the module parsed from IR is compiled lazily and so its responsiveness will be more uniform.<br /><br />However, MCJIT provides a mechanism for caching generated object images. Once weâve compiled a module, we can store the image and never have to compile it again. This is not available with the JIT execution engine and gives MCJIT a significant performance advantage when a library is used in multiple invocations of the program.<br /><br />MCJIT uses a callback mechanism to allow clients to register a custom cache handler. The handler must be a subclass of the ObjectCache class defined in âllvm/ExecutionEngine/ObjectCache.h.â For this example, Iâm going to use a very simple scheme that uses the input IR filename as a key and stores cached files in a subdirectory relative to the current working directory. Obviously in a real product youâd want something more sophisticated, but for demonstration purposes this will work.<br /><br />Hereâs the implementation:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">//===----------------------------------------------------------------------===//</span><br /><span style="font-family: Courier New, Courier, monospace;">// MCJIT object cache class</span><br /><span style="font-family: Courier New, Courier, monospace;">//===----------------------------------------------------------------------===//</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;">class MCJITObjectCache : public ObjectCache {</span><br /><span style="font-family: Courier New, Courier, monospace;">public:</span><br /><span style="font-family: Courier New, Courier, monospace;"> MCJITObjectCache() {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Set IR cache directory</span><br /><span style="font-family: Courier New, Courier, monospace;"> sys::fs::current_path(CacheDir);</span><br /><span style="font-family: Courier New, Courier, monospace;"> sys::path::append(CacheDir, "toy_object_cache");</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> virtual ~MCJITObjectCache() {</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Get the ModuleID</span><br /><span style="font-family: Courier New, Courier, monospace;"> const std::string ModuleID = M->getModuleIdentifier();</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> // If we've flagged this as an IR file, cache it</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (0 == ModuleID.compare(0, 3, "IR:")) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::string IRFileName = ModuleID.substr(3);</span><br /><span style="font-family: Courier New, Courier, monospace;"> SmallString<128>IRCacheFile = CacheDir;</span><br /><span style="font-family: Courier New, Courier, monospace;"> sys::path::append(IRCacheFile, IRFileName);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (!sys::fs::exists(CacheDir.str()) && sys::fs::create_directory(CacheDir.str())) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> fprintf(stderr, "Unable to create cache directory\n");</span><br /><span style="font-family: Courier New, Courier, monospace;"> return;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::string ErrStr;</span><br /><span style="font-family: Courier New, Courier, monospace;"> raw_fd_ostream IRObjectFile(IRCacheFile.c_str(), ErrStr, raw_fd_ostream::F_Binary);</span><br /><span style="font-family: Courier New, Courier, monospace;"> IRObjectFile << Obj->getBuffer();</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> // MCJIT will call this function before compiling any module</span><br /><span style="font-family: Courier New, Courier, monospace;"> // MCJIT takes ownership of both the MemoryBuffer object and the memory</span><br /><span style="font-family: Courier New, Courier, monospace;"> // to which it refers.</span><br /><span style="font-family: Courier New, Courier, monospace;"> virtual MemoryBuffer* getObject(const Module* M) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Get the ModuleID</span><br /><span style="font-family: Courier New, Courier, monospace;"> const std::string ModuleID = M->getModuleIdentifier();</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> // If we've flagged this as an IR file, cache it</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (0 == ModuleID.compare(0, 3, "IR:")) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::string IRFileName = ModuleID.substr(3);</span><br /><span style="font-family: Courier New, Courier, monospace;"> SmallString<128> IRCacheFile = CacheDir;</span><br /><span style="font-family: Courier New, Courier, monospace;"> sys::path::append(IRCacheFile, IRFileName);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (!sys::fs::exists(IRCacheFile.str())) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // This file isn't in our cache</span><br /><span style="font-family: Courier New, Courier, monospace;"> return NULL;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> OwningPtr<MemoryBuffer> IRObjectBuffer;</span><br /><span style="font-family: Courier New, Courier, monospace;"> MemoryBuffer::getFile(IRCacheFile.c_str(), IRObjectBuffer, -1, false);</span><br /><span style="font-family: Courier New, Courier, monospace;"> // MCJIT will want to write into this buffer, and we don't want that</span><br /><span style="font-family: Courier New, Courier, monospace;"> // because the file has probably just been mmapped. Instead we make</span><br /><span style="font-family: Courier New, Courier, monospace;"> // a copy. The filed-based buffer will be released when it goes</span><br /><span style="font-family: Courier New, Courier, monospace;"> // out of scope.</span><br /><span style="font-family: Courier New, Courier, monospace;"> return MemoryBuffer::getMemBufferCopy(IRObjectBuffer->getBuffer());</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;"> return NULL;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span> <span style="font-family: Courier New, Courier, monospace;">private:</span><br /><span style="font-family: Courier New, Courier, monospace;"> SmallString<128> CacheDir;</span><br /><span style="font-family: Courier New, Courier, monospace;">};</span></blockquote>Iâm going to instantiate this cache as a member variable of the MCJITHelper class. Iâm also adding a command line option to enable cache use.<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">cl::opt<bool> </span><br /><span style="font-family: Courier New, Courier, monospace;">UseObjectCache("use-object-cache", </span><br /><span style="font-family: Courier New, Courier, monospace;"> cl::desc("Enable use of the MCJIT object caching"),</span><br /><span style="font-family: Courier New, Courier, monospace;"> cl::init(false));</span></blockquote>Activating the cache simply requires a single call to the ExecutionEngine object after it has been created in MCJITHelper::compileModule():<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">if (UseObjectCache)</span><br /><span style="font-family: Courier New, Courier, monospace;"> NewEngine->setObjectCache(&OurObjectCache);</span></blockquote>At this point the MCJIT engine itself manages use of the cache. When the MCJIT engine is about to compile a module, it will call the cacheâs getObject method. If this method returns an object image, MCJIT will prepare that object for execution rather than compiling a new version. When MCJIT does compile a module it calls the cacheâs NotifyObjectCompiled method, giving the cache a chance to store the object image.<br /><br />The implementation above uses the Module identifier as a key to identify matching modules, but clients are free to use any mechanism to make this identification.<br /><h3>Cache Performance</h3>Now that we have the object caching mechanism in place, letâs take a look and see how it impacts our performance.<br /><br />Iâve created a new set of test inputs based on the inputs I used for previous measurements, but I separated the function definitions and the immediate function calls into separate script files and then generated an IR file from the function definitions. Iâll use these files to execute a workload that is equivalent to the previous workload while using an IR input file and loading the resultant object from cache when possible.<br /><br />There is obviously some performance benefit just from having a ready-made IR file rather than having to parse Kaleidoscope input, so I also created a version of the JIT-based implementation which accepts the IR input library to provide a meaningful point of comparison.<br /><br />The chart below shows the 5000-function workloads Iâve been using run with multiple implementations of the Kaleidoscope interpreter. The first three bars in each group show the âlazyâ MCJIT implementation, the original JIT implementation and our first working MCJIT implementation with the original workload file. The next three bars show the new implementations using an IR input file for function definitions.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-XE698SRqneI/Ue228waFk_I/AAAAAAAABNs/nYc00U-dfCs/s1600/CacheTiming.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-XE698SRqneI/Ue228waFk_I/AAAAAAAABNs/nYc00U-dfCs/s1600/CacheTiming.jpg" /></a></div><br />As you can see, the non-cached run of the library-based MCJIT implementation is slightly faster than our first working implementation (because the IR is pre-made), but significantly slower than the âlazyâ MCJIT implementation. However, this performance hit is only incurred the first time the workload is run. When the workload is run with this same MCJIT implementation a second time the function library is loaded from cache and the performance is far and away better than any of the other implementations.<br /><h3>Conclusions</h3>So where does this leave us? Did you ever have one of those math professors in college who would get halfway through a tricky proof and then write âQEDâ on the board even though it wasnât at all obvious how he would finish it? Thatâs the part weâre at now.<br /><br />I began this exercise in an attempt to either prove or disprove that the MCJIT execution engine was suitable for use in a program that relied on true just-in-time compilation. I came up with a reference implementation that does that, though with a few lingering questions â particularly regarding memory consumption.<br /><br />At this point, Iâm satisfied that MCJIT is up to the task. <i>Quod erat demonstratum</i>.<br /><br />Of course, thereâs more work to be done. Any serious implementation using the techniques Iâve shown would require a lot of fine tuning. Some of what Iâve done, such as the multiple module management, can and should be moved into the MCJIT component itself. No doubt many of the opportunities for performance improvements and more efficient memory use will also be within the MCJIT component. Nevertheless, I think the way forward is reasonably well defined.<br /><br />Several active LLVM developers are committed to making MCJIT a top notch execution engine. I hope that the exploration Iâve presented here will help more developers make use of it now and will generate momentum to iron out whatever additional shortcomings remain.<br /><br />The full source code listing for this post along with the scripts for generating test input are available in the trunk of the LLVM source tree at <llvm_root>/examples/Kaleidoscope/MCJIT.
- Kaleidoscope Performance with MCJIThttps://blog.llvm.org/2013/07/kaleidoscope-performance-with-mcjit.htmlMon, 29 Jul 2013 12:11:00 +0000https://blog.llvm.org/2013/07/kaleidoscope-performance-with-mcjit.htmlIn a previous post I described the process of porting the LLVM Kaleidoscope tutorial program to use MCJIT as its execution engine. After navigating through a serious of road blocks we ended up with an implementation that was working as expected.<br /><br />So it works, but the next question is, âIs it any good?â<br /><br />A lot of people considering the transition from the older JIT execution engine to MCJIT have concerns about the possible performance implications, particularly related to the fact that MCJIT doesnât support lazy compilation. The older JIT engine will generate code for functions in an LLVM module one function at a time, delaying compilation of each function until it is about to be executed. The MCJIT engine operates on entire modules, generating code for all functions in a module at once. In the previous post, we modified the Kaleidoscope interpreter to create multiple modules as needed, but weâre still compiling the entire current module when a function is executed.<br /><br />So what does that look like in terms of performance?<br /><a name='more'></a><br />The Kaleidoscope interpreter operates on input from stdin. When youâre sitting at your keyboard typing functions and expressions, it seems perfectly responsive. It would take a lot of typing to create a module large enough to have a noticeable compilation time. Of course, we can also drive our interpreter by redirecting a file through stdin. This will be useful for measuring performance. Unfortunately, there arenât a lot of large Kaleidoscope programs available that we can use as a benchmark.<br /><br />Instead I wrote a Python script that will generate random Kaleidoscope functions and expressions. By varying a few script parameters you can change the characteristics of the generated Kaleidoscope script to simulate various workload scenarios (number of functions, operations per function, number of function definitions between execution and percentage of calls within functions). My Python script also generates a bash script that uses the Linux âtimeâ utility to get some crude performance and memory usage measurements. These results should not in any way be confused with accurate benchmark data, but they ought to at least give us a rough idea of where we are.<br /><br />I made some minor changes to add a divide operator and a new output function (printlf) and to eliminate unnecessary output to stderr so that we arenât timing the âdumpâ functions.<br /><br />Hereâs how my new MCJIT-based toy compares to a version built with the older JIT engine:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-N9hwOu6Jbfw/Ue2Atl--6gI/AAAAAAAABNY/6-joqx1C12Y/s1600/InitialTiming.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-N9hwOu6Jbfw/Ue2Atl--6gI/AAAAAAAABNY/6-joqx1C12Y/s1600/InitialTiming.jpg" /></a></div><br />The numbers across the bottom here give some indication of the input being used. The first number is the number of functions in the script, the second number is the number of functions called at least once and the third number is the total number of calls that will be executed.<br /><br />So it turns out that depending on the input the MCJIT version of the Kaleidoscope interpreter that weâve created is anywhere between 1.25 and 5.5 times slower. Thatâs disappointing but not really unexpected. Remember that the JIT version never compiles functions that arenât used, and thatâs really the weakness that this comparison was intending to quantify. The more functions are called, the closer our MCJIT version is to the JIT version, which is what weâd expect.<br /><br />Weâll talk about memory use later, but for now letâs just say that it follows a similar pattern.<br />The input sets I have are pretty trivial, so the actual code generated isnât particularly interesting for performance analysis. I can tell you from experience that where both engines are able to use the same processor features they generate nearly identical code. (Thereâs a lot shared under the hood.) There are some new processor features that arenât supported by the older JIT engine, but thatâs not relevant for our current comparison.<br /><h3>Making MCJIT Lazy</h3>Now that we have some idea of what weâre up against, letâs turn to the task of making a version of the MCJIT toy that attempts to mimic the lazy-compilation mode of the old JIT engine. In the version weâve created to this point weâre delaying creation of our execution engine until something needs to be executed, but when we do compile weâre compiling everything in the Module, not just the functions that will be executed. Thatâs an inherent part of MCJITâs design, so to get around it, weâre going to have to create a new module for each function and put off compiling each module until it is needed for linking. If you had a detailed knowledge of the code youâre compiling you could optimize function grouping, putting related functions together in a module and so forth, but for the current experiment weâll take the most general approach possible.<br /><br />Once again, this is easier than you might expect.<br /><br />Letâs start by moving the code that compiles a module into a new method in MCJITHelper().<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">ExecutionEngine *MCJITHelper::compileModule(Module *M) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::string ErrStr;</span><br /><span style="font-family: Courier New, Courier, monospace;"> ExecutionEngine *NewEngine = EngineBuilder(M)</span><br /><span style="font-family: Courier New, Courier, monospace;"> .setErrorStr(&ErrStr)</span><br /><span style="font-family: Courier New, Courier, monospace;"> .setUseMCJIT(true)</span><br /><span style="font-family: Courier New, Courier, monospace;"> .setMCJITMemoryManager(new HelpingMemoryManager(this))</span><br /><span style="font-family: Courier New, Courier, monospace;"> .create();</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (!NewEngine) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());</span><br /><span style="font-family: Courier New, Courier, monospace;"> exit(1);</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> // Create a function pass manager for this engine</span><br /><span style="font-family: Courier New, Courier, monospace;"> FunctionPassManager *FPM = new FunctionPassManager(M);</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> // Set up the optimizer pipeline. Start with registering info about how the</span><br /><span style="font-family: Courier New, Courier, monospace;"> // target lays out data structures.</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(new DataLayout(*NewEngine->getDataLayout()));</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Provide basic AliasAnalysis support for GVN.</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(createBasicAliasAnalysisPass());</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Promote allocas to registers.</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(createPromoteMemoryToRegisterPass());</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Do simple "peephole" optimizations and bit-twiddling optzns.</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(createInstructionCombiningPass());</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Reassociate expressions.</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(createReassociatePass());</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Eliminate Common SubExpressions.</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(createGVNPass());</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Simplify the control flow graph (deleting unreachable blocks, etc).</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->add(createCFGSimplificationPass());</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->doInitialization();</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> // For each function in the module</span><br /><span style="font-family: Courier New, Courier, monospace;"> Module::iterator it;</span><br /><span style="font-family: Courier New, Courier, monospace;"> Module::iterator end = M->end();</span><br /><span style="font-family: Courier New, Courier, monospace;"> for (it = M->begin(); it != end; ++it) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Run the FPM on this function</span><br /><span style="font-family: Courier New, Courier, monospace;"> FPM->run(*it);</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> // We don't need this anymore</span><br /><span style="font-family: Courier New, Courier, monospace;"> delete FPM;</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> Engines.push_back(NewEngine);</span><br /><span style="font-family: Courier New, Courier, monospace;"> NewEngine->finalizeObject();</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> return NewEngine;</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Now the code in MCJITHelper::getPointerToFunction() that compiles the current module will look like this:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">// If we didn't find the function, see if we can generate it.</span><br /><span style="font-family: Courier New, Courier, monospace;">if (OpenModule) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> ExecutionEngine * NewEngine = compileModule(OpenModule);</span><br /><span style="font-family: Courier New, Courier, monospace;"> return NewEngine->getPointerToFunction(F);</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>It will also be helpful to have a function that âclosesâ the current module.<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">void MCJITHelper::closeCurrentModule() {</span><br /><span style="font-family: Courier New, Courier, monospace;"> OpenModule = NULL;</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>We donât want to call this from MCJITHelper::getModuleForNewFunction as you might expect, because that is called for immediate expressions as well as function definitions. Instead, weâll call it from the beginning of HandleDefinition(). This will cause the current module to be closed each time a function with a body is defined, but will still allow immediate expressions to be included in the last open module. We also need to call closeCurrentModule from compileModule if the module being compiled is the current module in order to handle the case of two consecutive immediate expressions.<br /><br />So far so good, but the problem we now face is that our current implementation of MCJITHelper::getPointerToFunction() and MCJITHelper::getPointerToNamedFunction() both assume that they will find all functions either in the current open module or an execution engine that has already been used to compile a module.<br /><br />To fix that weâll need to change our data structures. Instead of keeping a vector of modules and a vector of execution engines, weâll use a map that correlates module pointers with execution engine pointers. If a module has no execution engine pointer in the map that will mean the module has not yet been compiled.<br /><br />In our helper class definition, we replace this:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">typedef std::vector<ExecutionEngine*> EngineVector;</span><br /><span style="font-family: Courier New, Courier, monospace;">EngineVector Engines;</span></blockquote>with this:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">std::map<Module *, ExecutionEngine *> EngineMap;</span></blockquote>And with that we can re-write our getPointerToFunction methods to look like this:<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">void *MCJITHelper::getPointerToFunction(Function* F) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Look for this function in an existing module</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator begin = Modules.begin();</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator end = Modules.end();</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator it;</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::string FnName = F->getName();</span><br /><span style="font-family: Courier New, Courier, monospace;"> for (it = begin; it != end; ++it) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> Function *MF = (*it)->getFunction(FnName);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (MF == F) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::map<Module*, ExecutionEngine*>::iterator eeIt = EngineMap.find(*it);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (eeIt != EngineMap.end()) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> void *P = eeIt->second->getPointerToFunction(F);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (P)</span><br /><span style="font-family: Courier New, Courier, monospace;"> return P;</span><br /><span style="font-family: Courier New, Courier, monospace;"> } else {</span><br /><span style="font-family: Courier New, Courier, monospace;"> ExecutionEngine *EE = compileModule(*it);</span><br /><span style="font-family: Courier New, Courier, monospace;"> void *P = EE->getPointerToFunction(F);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (P)</span><br /><span style="font-family: Courier New, Courier, monospace;"> return P;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> return NULL;</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;">void *MCJITHelper::getPointerToNamedFunction(const std::string &Name)</span><br /><span style="font-family: Courier New, Courier, monospace;">{</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Look for the functions in our modules, compiling only as necessary</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator begin = Modules.begin();</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator end = Modules.end();</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator it;</span><br /><span style="font-family: Courier New, Courier, monospace;"> for (it = begin; it != end; ++it) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> Function *F = (*it)->getFunction(Name);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (F && !F->empty()) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::map<Module*, ExecutionEngine*>::iterator eeIt = EngineMap.find(*it);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (eeIt != EngineMap.end()) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> void *P = eeIt->second->getPointerToFunction(F);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (P)</span><br /><span style="font-family: Courier New, Courier, monospace;"> return P;</span><br /><span style="font-family: Courier New, Courier, monospace;"> } else {</span><br /><span style="font-family: Courier New, Courier, monospace;"> ExecutionEngine *EE = compileModule(*it);</span><br /><span style="font-family: Courier New, Courier, monospace;"> void *P = EE->getPointerToFunction(F);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (P)</span><br /><span style="font-family: Courier New, Courier, monospace;"> return P;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> return NULL;</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Both of these functions work in the same way. They iterate through our vector of Modules looking for a Module that contains a function with the name we are looking for. In the first case, we also check to see if this is exactly the function weâre looking for. (It might be a prototype.) Once weâve found the right module, we check to see if the module has a corresponding execution engine. If it does, we ask that engine for a pointer to the function. If not, we compile the module and then ask the new execution engine for the pointer. This leaves modules in an uncompiled state until we need a function either for execution or to satisfy a linking request.<br /><br />Youâll notice that this code doesnât populate the EngineMap. Weâll do that in the compileModule() function instead, where we were previously adding the new engine to the Engines vector. Weâll also need to change our clean up code in the MCJITHelper destructor.<br /><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">MCJITHelper::~MCJITHelper()</span><br /><span style="font-family: Courier New, Courier, monospace;">{</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Walk the vector of modules.</span><br /><span style="font-family: Courier New, Courier, monospace;"> ModuleVector::iterator it, end;</span><br /><span style="font-family: Courier New, Courier, monospace;"> for (it = Modules.begin(), end = Modules.end();</span><br /><span style="font-family: Courier New, Courier, monospace;"> it != end; ++it) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // See if we have an execution engine for this module.</span><br /><span style="font-family: Courier New, Courier, monospace;"> std::map<Module*, ExecutionEngine*>::iterator mapIt = EngineMap.find(*it);</span><br /><span style="font-family: Courier New, Courier, monospace;"> // If we have an EE, the EE owns the module so just delete the EE.</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (mapIt != EngineMap.end()) {</span><br /><span style="font-family: Courier New, Courier, monospace;"> delete mapIt->second;</span><br /><span style="font-family: Courier New, Courier, monospace;"> } else {</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Otherwise, we still own the module. Delete it now.</span><br /><span style="font-family: Courier New, Courier, monospace;"> delete *it;</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;"> }</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span></blockquote>Note that once a module has been passed to an execution engine, the execution engine owns that module, so in each case we only need to delete a module or an execution engine, but never both.<br /><h3>Lazy Performance Analysis</h3>At this point, the MCJIT-based version of our Kaleidoscope interpreter should be compiling lazily just like the old JIT-based implementation did. Letâs re-run our test workloads and see how it stacks up.<br /><br />Here are the new results.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-2iD8rrxxxQI/Ue2A6LTlKlI/AAAAAAAABNg/5VPeiEOLVv0/s1600/LazyTiming.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-2iD8rrxxxQI/Ue2A6LTlKlI/AAAAAAAABNg/5VPeiEOLVv0/s1600/LazyTiming.jpg" /></a></div><br />That looks quite a bit better. The big spike in the fourth column is the case where each function is called immediately after it is defined. The MCJIT implementation is still about 1.3 times slower with 5000 functions in that case, but previously that was one of the better points of comparison for MCJIT. Now itâs the worst case scenario.<br /><br />Also notice that with the new âlazyâ MCJIT implementation there are a few cases where our MCJIT-based interpreter is quicker than the old JIT-based implementation.<br /><h3>Memory Consumption</h3>Now letâs talk about memory usage. You can probably see without measurements that our new âlazyâ implementation is going to consume more memory than the old implementation. Weâre creating a new Module instance for each and every function that gets defined and a bunch more execution engine related objects every time one of these things gets compiled. But how bad is it?<br /><br />Itâs bad. Iâm not sure how far to trust the memory statistics Iâm getting from the time utility, but assuming they at least reliable enough to be a rough guide the MCJIT implementation has some issues. In the cases where the MCJIT implementation has a performance advantage the memory consumption can be as little as 1.5 times the JIT implementation, but in the worst case scenario of each function being called immediately after it is defined the MCJIT implementation can take up to 10 times more memory than the JIT implementation.<br /><br />What are we to make of this? Well, letâs start with a sanity check. As the introduction to the Kaleidoscope tutorial says the tutorial isnât meant to be a good implementation -- âthe code leaks memory, uses global variables all over the place, doesnât use nice design patterns like visitors, etc... but it is very simple.â<br />There are some very basic things going on that waste a lot of memory, and those are amplified in our MCJIT implementation. For instance, when an immediate expression is used, we leave it in memory for the duration of program execution, even though we can be absolutely certain weâll never reference it again.<br /><br />Also, I donât really have a feel for whether or not the sample inputs Iâm using have any correspondence to a real world usage pattern. I havenât done a detailed analysis of memory use, but at first glance it appears that a large chunk of the memory is being used to generate relocation tables for each generated object image. In theory we could drop those tables as soon as the object is fixed in memory (that is, after the call to finalizeObject), but we donât. This problem is magnified by the fact that the workloads are heavily based on a network of random calls between functions, probably involving a disproportionately high number of cross module references. Iâve made no attempt to optimize that.<br /><br />As I said, I just generated a bunch of random code and threw it at the interpreter. Thatâs true of the performance numbers too, of course. Remember, my goal here was just to try to get a ballpark feel for what the implementation looked like.<br /><br />My ballpark feel is that with the âlazyâ implementation the performance is going to be just about as good as the old JIT implementation, but itâs going to use more memory.<br /><h3>Next Steps</h3>So what else can we do with this? Why would anyone want to go to the trouble of switching to MCJIT just to get something that performed just about as well but used more memory?<br /><br />I could say that youâll get better ongoing support and adoption of new LLVM enhancements with MCJIT. While thatâs true, it would probably leave you a bit frustrated.<br /><br />Instead, what Iâm going to tell you is that MCJIT has a great feature that will give it a huge leg up on the old JIT engine in many real world usage scenarios. But thatâs going to have to wait until my next postâ¦.<br /><br />The full source code listing for this post along with the scripts for generating test input are available in the trunk of the LLVM source tree at <llvm_root>/examples/Kaleidoscope/MCJIT.<br /><div><br /></div>
- Using MCJIT with the Kaleidoscope Tutorialhttps://blog.llvm.org/2013/07/using-mcjit-with-kaleidoscope-tutorial.htmlMon, 22 Jul 2013 11:49:00 +0000https://blog.llvm.org/2013/07/using-mcjit-with-kaleidoscope-tutorial.html<div class="MsoNormal">You may have noticed that there are two different JIT execution engines in the LLVM project. The older implementation (llvm::JIT) is a sort of ad hoc implementation that brings together various pieces of the LLVM code generation and adds its own glue to get dynamically generated code into memory one function at a time. The newer implementation (llvm::MCJIT) is heavily based on the core MC library and emits complete object files into memory then prepares them for execution.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">MCJIT has several advantages, including broader platform support and better tool integration. However, because it is designed to compile entire modules into object images the MCJIT engine doesnât directly support some key features of the older JIT implementation, such as lazy compilation. By lazy compilation, I mean deferring compilation of individual functions until just before the function is going to be executed.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">At this point you may find yourself saying, âWait a minute? Are you saying MC<b><i>JIT</i></b>doesnât do âjust-in-timeâ compilation?!?â Wellâ¦sort of. Itâs more of a dynamic code emitter than a true just-in-time compiler. That said weâd like it to become a long term replacement for the old JIT so that we can reap the benefits of ongoing development in core MC code generation.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">So the question becomes, can we make MCJIT do what the older JIT engine does? The current answer is, âI hope so.â As a means of exploring this question, I decided to try to convert the Kaleidoscope tutorial to use MCJIT.<o:p></o:p></div><div class="MsoNormal"><br /><a name='more'></a><br /></div><div class="MsoNormal">The Kaleidoscope tutorial demonstrates a simple interactive interpreter (âtoyâ) designed to teach developers how to implement a simple programming language using LLVM. Kaleidoscope is presented as a procedural language that supports floating point variables, function calls and a few basic operators. The tutorial uses the JIT execution engine to produce executable code from user input.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Since MCJIT was conceived as a drop in replacement for the older JIT engine, putting it into the Kaleidoscope tutorial should be easy, right? Ehâ¦.keep reading and you can judge for yourself. Along the way, youâll see firsthand some of the key differences between these two engines.<o:p></o:p></div><h3>First Steps</h3><h1><o:p></o:p></h1><div class="MsoNormal">Iâll be starting where the Kaleidoscope tutorial ends. If you want to follow along, you can grab the final Kaleidoscope source code from the LLVM source tree at<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;"><llvm_root>/examples/Kaleidoscope/Chapter7/toy.cpp</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">Thereâs a Makefile there too, but it is intended to build the program in place as part of a complete LLVM build, so weâll be using a command line approach. For now, you can just type the build command in the Kaleidoscope tutorial:</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">clang++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 âo toy</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">If you have the right tools in your path, that should build the tutorial for you.</div><div class="MsoNormal"><o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">The first change weâll need to make is to create an MCJIT execution engine instead of a JIT execution engine. This is pretty simple. The ExecutionEngine gets created in the main() function in toy.cpp using an EngineBuilder object with a call that looks like this:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">EngineBuilder creates a JIT engine by default, but you can request an MCJIT engine instead by calling the setUseMCJIT() function, as such:</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr)</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> .setUseMCJIT(true)</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> .create();</span></blockquote><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">Youâll also need to include âMCJIT.hâ to get the MCJIT static constructor linked in properly (you can replace âJIT.hâ) and add two new lines of component initialization at the top of main().</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">IntializeNativeTargetAsmPrinter();</span><span style="font-family: Courier New, Courier, monospace;">InitializeNatureTargetAsmParser();</span></blockquote><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">Another feature of MCJIT that I should mention at this point is that it is designed to allow generated code to be remapped for execution in external processes or even on remote systems. As such, it requires that we call ExecutionEngine::finalizeObject() to let it know weâre ready for the generated object to be put in its executable state. We can do that just before calling getPointerToFunction() in HandleTopLevelExpression:</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">TheExecutionEngine->finalizeObject();</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">Now build with the command above, substituting âmcjitâ for âjitâ in the library list.</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">clang++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core mcjit native` -O3 âo toy</span></blockquote><div class="Code"><o:p></o:p></div><h3>Handling Function Names</h3><h1><o:p></o:p></h1><div class="MsoNormal">At this point, youâre up and running with MCJIT. Unfortunately, nothing will work because the interpreter uses unnamed functions to evaluate immediate expressions and MCJIT doesnât like that.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">For the purposes of this experiment, Iâm going to work around that with a quick and dirty hack that generates a simple unique name for such anonymous functions, and while Iâm at it Iâll make sure any function names would be legal in C, because that we need that to handle the way our interpreter names operators. My hack looks like this:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">//===----------------------------------------------------------------------===//<br />// Quick and dirty hack<br />//===----------------------------------------------------------------------===//<br /><o:p> </o:p>// FIXME: Obviously we can do better than this<br />std::string GenerateUniqueName(const char *root)<br />{<br /> static int i = 0;<br /> char s[16];<br /> sprintf(s, "%s%d", root, i++);<br /> std::string S = s;<br /> return S;<br />}<br /><o:p> </o:p>std::string MakeLegalFunctionName(std::string Name)<br />{<br /> std::string NewName;<br /> if (!Name.length())<br /> return GenerateUniqueName("anon_func_");<br /><o:p> </o:p> // Start with what we have<br /> NewName = Name;<br /><o:p> </o:p> // Look for a numberic first character<br /> if (NewName.find_first_of("0123456789") == 0) {<br /> NewName.insert(0, 1, 'n');<br /> }<br /><o:p> </o:p> // Replace illegal characters with their ASCII equivalent<br /> std::string legal_elements = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";<br /> size_t pos;<br /> while ((pos = NewName.find_first_not_of(legal_elements)) != std::string::npos) {<br /> char old_c = NewName.at(pos);<br /> char new_str[16];<br /> sprintf(new_str, "%d", (int)old_c);<br /> NewName = NewName.replace(pos, 1, new_str);<br /> }<br /><o:p> </o:p> return NewName;<br />}</span></blockquote><div class="CodeCxSpFirst"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">We need to use this in three places. First, in PrototypeAST::Codegen() just before the call to Function::Create()<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">std::string FnName = MakeLegalFunctionName(Name);</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">Also replace subsequent references to âNameâ with âFnNameâ in this function. Changing the âNameâ member of the PrototypeAST object would have other unintended consequences, so here weâre just changing the name by which LLVM will know the function. To that end, we also need to update calls to getFunction in UnaryExprAST::Codegen() and BinaryExprAST::Codegen(). </div><div class="MsoNormal"><o:p></o:p></div><div class="MsoNormal"><br /></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">Function *F = TheModule->getFunction(MakeLegalFunctionName(std::string("unary")+Opcode));</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">and</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">Function *F = TheModule->getFunction(MakeLegalFunctionName(std::string("binary")+Opcode));</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">A new member variable wouldnât be a bad idea, but we wonât have to think about this again, so for now letâs just leave it simple.</div><div class="MsoNormal"><o:p></o:p></div><h3>Adding Multiple Module Support</h3><h2><o:p></o:p></h2><div class="MsoNormal">Now letâs compile again using the command line above and give this a try.<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">ready> def add(x y) x+y;</span><span style="font-family: Courier New, Courier, monospace;">[output omitted]</span><span style="font-family: Courier New, Courier, monospace;">ready> add(1, 2);</span><span style="font-family: Courier New, Courier, monospace;">ready> Evaluated to 3.000000</span><span style="font-family: Courier New, Courier, monospace;">Hurray! Itâs working! Letâs keep playing with it.</span><span style="font-family: Courier New, Courier, monospace;">ready> add(3, 4);</span><span style="font-family: Courier New, Courier, monospace;">ready> Segmentation fault (core dumped)</span></blockquote><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">Oops! What happened? Well, hereâs the thing. Our âtoyâ program creates a single module, uses that to create an execution engine, then keeps adding all the functions it creates to that same module. This works with JIT, which is just generating code for one function at a time. MCJIT, on the other hand, compiles the entire module and expects it to stay compiled. When you add something to it and call finalizeObject() again it will skip the compilation phase (because it thinks the module has already been compiled) and attempt to re-apply relocations. Since the MCJIT memory manager marked the code sections for this object as R-X in the previous call to finalizeObject, the attempt to re-write the relocation crashes. MCJIT should obviously handle this case more gracefully, but the relevant point here is that MCJIT wonât let you continue to modify a module after itâs been compiled.</div><div class="MsoNormal"><o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Weâll need to modify our program to spin off a new module and execution engine every time it compiles a previous module, but as it turns out thatâs not as painful to implement as it might sound. Our âtoyâ program uses three global variables (TheModule, TheFPM and TheExecutionEngine) to handle all the functionality weâre interested in. Weâll create a helper class to replace those three objects and coordinate their behavior.<o:p></o:p></div><div class="MsoNormal">The class will look like this:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">//===----------------------------------------------------------------------===//<br />// MCJIT helper class<br />//===----------------------------------------------------------------------===//<br /><o:p> </o:p>class MCJITHelper<br />{<br />public:<br /> MCJITHelper(LLVMContext& C) : Context(C), OpenModule(NULL) {}<br /> ~MCJITHelper();<br /><o:p> </o:p> Function *getFunction(const std::string FnName);<br /> Module *getModuleForNewFunction();<br /> void *getPointerToFunction(Function* F);<br /> void dump();<br /><o:p> </o:p>private:<br /> typedef std::vector<Module*> ModuleVector;<br /> typedef std::vector<ExecutionEngine*> EngineVector;<br /><o:p> </o:p> LLVMContext &Context;<br /> Module *OpenModule;<br /> ModuleVector Modules;<br /> EngineVector Engines;<br />};<br /><o:p> </o:p>MCJITHelper::~MCJITHelper()<br />{<br /> if (OpenModule)<br /> delete OpenModule;<br /> EngineVector::iterator begin = Engines.begin();<br /> EngineVector::iterator end = Engines.end();<br /> EngineVector::iterator it;<br /> for (it = begin; it != end; ++it)<br /> delete *it;<br />}<br /><o:p> </o:p>Function *MCJITHelper::getFunction(const std::string FnName) {<br /> ModuleVector::iterator begin = Modules.begin();<br /> ModuleVector::iterator end = Modules.end();<br /> ModuleVector::iterator it;<br /> for (it = begin; it != end; ++it) {<br /> Function *F = (*it)->getFunction(FnName);<br /> if (F) {<br /> if (*it == OpenModule)<br /> return F;<br /><o:p> </o:p> assert(OpenModule != NULL);<br /><o:p> </o:p> // This function is in a module that has already been JITed.<br /> // We need to generate a new prototype for external linkage.<br /> // Look for a prototype in the current module.<br /> Function *PF = OpenModule->getFunction(FnName);<br /> if (PF && !PF->empty()) {<br /> ErrorF("redefinition of function across modules");<br /> return 0;<br /> }<br /><o:p> </o:p> // If we don't have a prototype yet, create one.<br /> if (!PF)<br /> PF = Function::Create(F->getFunctionType(),<br /> Function::ExternalLinkage,<br /> FnName,<br /> OpenModule);<br /> return PF;<br /> }<br /> }<br /> return NULL;<br />}<br /><o:p> </o:p>Module *MCJITHelper::getModuleForNewFunction() {<br /> // If we have a Module that hasn't been JITed, use that.<br /> if (OpenModule)<br /> return OpenModule;<br /><o:p> </o:p> // Otherwise create a new Module.<br /> std::string ModName = GenerateUniqueName("mcjit_module_");<br /> Module *M = new Module(ModName, Context);<br /> Modules.push_back(M);<br /> OpenModule = M;<br /> return M;<br />}<br /><o:p> </o:p>void *MCJITHelper::getPointerToFunction(Function* F) {<br /> // See if an existing instance of MCJIT has this function.<br /> EngineVector::iterator begin = Engines.begin();<br /> EngineVector::iterator end = Engines.end();<br /> EngineVector::iterator it;<br /> for (it = begin; it != end; ++it) {<br /> void *P = (*it)->getPointerToFunction(F);<br /> if (P)<br /> return P;<br /> }<br /><o:p> </o:p> // If we didn't find the function, see if we can generate it.<br /> if (OpenModule) {<br /> std::string ErrStr;<br /> ExecutionEngine *NewEngine = EngineBuilder(OpenModule)<br /> .setErrorStr(&ErrStr)<br /> .setUseMCJIT(true)<br /> .create();<br /> if (!NewEngine) {<br /> fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());<br /> exit(1);<br /> }<br /> OpenModule = NULL;<br /> Engines.push_back(NewEngine);<br /> NewEngine->finalizeObject();<br /> return NewEngine->getPointerToFunction(F);<br /> }<br /> return NULL;<br />}<br /><o:p> </o:p>void MCJITHelper::dump()<br />{<br /> ModuleVector::iterator begin = Modules.begin();<br /> ModuleVector::iterator end = Modules.end();<br /> ModuleVector::iterator it;<br /> for (it = begin; it != end; ++it)<br /> (*it)->dump();<br />}</span></blockquote><div class="CodeCxSpFirst"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpLast">The one thing here that might require explanation is the implementation of getFunction. This is used when the interpreter wants to call an existing function. Since weâre dealing with multiple modules now, we need to look for this function in all of the modules our helper class is handling. If we find it in the module weâre currently working with, we can just use it, but if we find it in another module we need to create a prototype in the current module. The function declaration we found in the other module will provide the function type.</div><div class="MsoNormal"><o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Weâll create a new global variable (TheHelper) and get rid of the three previously mentioned. In main() weâll replace the code that creates and initializes those three objects with a single line of code:<o:p></o:p></div><div class="Code">TheHelper = new MCJITHelper(Context);<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Now we just need to go through the code and replace uses of those three global objects with calls to our helper. There arenât as many as you might expect. You can find references to TheModule in UnaryExprAST::Codegen(), BinaryExprAST::Codegen(), CallExprAST::Codegen(), and PrototypeAST::Codegen(). All of these except the last are just drop-in replacements. In PrototypeAST::Codegen() we need to add a call to TheHelper->getModuleForNewFunction() to get the last argument to Function::Create().<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">Module* M = TheHelper->getModuleForNewFunction();</span><span style="font-family: Courier New, Courier, monospace;">Function *F = Function::Create(FT, Function::ExternalLinkage, Name, M);</span></blockquote><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">TheExecutionEngine is used only in HandleTopLevelExpression() and a direct replacement is suitable there, plus we can eliminate the call to finalizeObject since that will happen inside MCJITHelper::getPointerToFunction.</div><div class="MsoNormal"><o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">TheFPM is used in FunctionAST::Codegen() but thatâs not where weâll want it for MCJIT purposes. Since we arenât creating an ExecutionEngine until we need to compile a Module, Iâm also going to put the FunctionPassManager creation there and optimize all the functions in a Module just before code generation. This isnât strictly necessary, but it makes the code generation phase go a bit faster. We can put the following in MCJITHelper::getPointerToFunction() just after the execution engine is created:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">// Create a function pass manager for this engine<br />FunctionPassManager *FPM = new FunctionPassManager(OpenModule);<br /><o:p> </o:p>// Set up the optimizer pipeline. Start with registering info about how the<br />// target lays out data structures.<br />FPM->add(new DataLayout(*NewEngine->getDataLayout()));<br />// Provide basic AliasAnalysis support for GVN.<br />FPM->add(createBasicAliasAnalysisPass());<br />// Promote allocas to registers.<br />FPM->add(createPromoteMemoryToRegisterPass());<br />// Do simple "peephole" optimizations and bit-twiddling optzns.<br />FPM->add(createInstructionCombiningPass());<br />// Reassociate expressions.<br />FPM->add(createReassociatePass());<br />// Eliminate Common SubExpressions.<br />FPM->add(createGVNPass());<br />// Simplify the control flow graph (deleting unreachable blocks, etc).<br />FPM->add(createCFGSimplificationPass());<br />FPM->doInitialization();<br /><o:p> </o:p>// For each function in the module<br />Module::iterator it;<br />Module::iterator end = OpenModule->end();<br />for (it = OpenModule->begin(); it != end; ++it) {<br /> // Run the FPM on this function<br /> FPM->run(*it);<br />}<br /><o:p> </o:p>// We don't need this anymore<br />delete FPM;</span></blockquote><div class="CodeCxSpFirst"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpLast"><o:p></o:p></div><h3>Cross Module Linking</h3><h1><o:p></o:p></h1><div class="MsoNormal">Letâs try what we have now. Recompile using the command line above and start the program:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">ready> def add(x y) x+y;<br />[output omitted]<br />ready> add(1, 2);<br />ready> Evaluated to 3.000000<br />ready> add(3, 4);<br />ready> LLVM ERROR: Program used external function âaddâ which could not be resolved!</span></blockquote><div class="CodeCxSpFirst"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">Do you see what happened there? Our program created a module, added the function âaddâ to it and then added a call to that function. At this point, the MCJITHelper compiled that module and started a new module. When we tried to call âaddâ a second time, the generated call went into the new module, which doesnât have a definition for âaddâ â only a prototype.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">To make this work weâre going to need some way to link our dynamic code against previously generated modules.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Hereâs how linking works in MCJIT. When code is generated from a Module, a complete object file image is generated into memory. As MCJITâs runtime loader is preparing this object for execution, it will create a list of external symbols that need to be resolved. It will then call the MCJIT memory managerâs getPointerToNamedFunction method in an attempt to resolve these external symbols. (Why the memory manager? Because thatâs the component that knows which address space the JITed code will be running in.) The default memory manager (SectionMemoryManager) uses sys::DynamicLibrary::SearchForAddressOfSymbol() to try to link this symbol against the current process. If it canât find the symbol, the symbol gets reported as unresolved.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">We could solve the problem of linking dynamically generated objects by iterating through all the symbols in an object as it is loaded and calling sys::DynamicLibrary::AddSymbol() for each one. In some circumstances that might be a good solution (as long as you arenât worried about name conflicts). However, Iâd like to demonstrate an alternative solution which can be adapted to more general purposes. Iâm going to create a custom memory manager for linking purposes.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">My new memory manager will inherit from SectionMemoryManager and use the base implementation for the actual memory management. It will also attempt to reuse the base symbol resolution, but if a symbol is not found, it will delegate symbol resolution to our MCJITHelper class, which can search other loaded objects.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Hereâs the code for the new memory manager:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">class HelpingMemoryManager : public SectionMemoryManager</span><br /><span style="font-family: Courier New, Courier, monospace;">{</span><br /><span style="font-family: Courier New, Courier, monospace;"> HelpingMemoryManager(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;</span><br /><span style="font-family: Courier New, Courier, monospace;"> void operator=(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;">public:</span><br /><span style="font-family: Courier New, Courier, monospace;"> HelpingMemoryManager(MCJITHelper *Helper) : MasterHelper(Helper) {}</span><br /><span style="font-family: Courier New, Courier, monospace;"> virtual ~HelpingMemoryManager() {}</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> /// This method returns the address of the specified function. </span><br /><span style="font-family: Courier New, Courier, monospace;"> /// Our implementation will attempt to find functions in other</span><br /><span style="font-family: Courier New, Courier, monospace;"> /// modules associated with the MCJITHelper to cross link functions</span><br /><span style="font-family: Courier New, Courier, monospace;"> /// from one generated module to another.</span><br /><span style="font-family: Courier New, Courier, monospace;"> ///</span><br /><span style="font-family: Courier New, Courier, monospace;"> /// If \p AbortOnFailure is false and no function with the given name is</span><br /><span style="font-family: Courier New, Courier, monospace;"> /// found, this function returns a null pointer. Otherwise, it prints a</span><br /><span style="font-family: Courier New, Courier, monospace;"> /// message to stderr and aborts.</span><br /><span style="font-family: Courier New, Courier, monospace;"> virtual void *getPointerToNamedFunction(const std::string &Name,</span><br /><span style="font-family: Courier New, Courier, monospace;"> bool AbortOnFailure = true);</span><br /><span style="font-family: Courier New, Courier, monospace;">private:</span><br /><span style="font-family: Courier New, Courier, monospace;"> MCJITHelper *MasterHelper;</span><br /><span style="font-family: Courier New, Courier, monospace;">};</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;">void *HelpingMemoryManager::getPointerToNamedFunction(const std::string &Name,</span><br /><span style="font-family: Courier New, Courier, monospace;"> bool AbortOnFailure)</span><br /><span style="font-family: Courier New, Courier, monospace;">{</span><br /><span style="font-family: Courier New, Courier, monospace;"> // Try the standard symbol resolution first, but ask it not to abort.</span><br /><span style="font-family: Courier New, Courier, monospace;"> void *pfn = SectionMemoryManager::getPointerToNamedFunction(Name, false);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (pfn)</span><br /><span style="font-family: Courier New, Courier, monospace;"> return pfn;</span><br /><span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: Courier New, Courier, monospace;"> pfn = MasterHelper->getPointerToNamedFunction(Name);</span><br /><span style="font-family: Courier New, Courier, monospace;"> if (!pfn && AbortOnFailure)</span><br /><span style="font-family: Courier New, Courier, monospace;"> report_fatal_error("Program used external function '" + Name +</span><br /><span style="font-family: Courier New, Courier, monospace;"> "' which could not be resolved!");</span><br /><span style="font-family: Courier New, Courier, monospace;"> return pfn;</span><br /><span style="font-family: Courier New, Courier, monospace;">}</span><br /><div><br /></div></blockquote><div class="CodeCxSpFirst"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><o:p></o:p></span></div><div class="MsoNormal">(Donât forget to add this to the class definition if youâre coding along.)<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Finally, we need to set the memory manager in MCJITHelper::getPointerToFunction where we use EngineBuilder to create a new execution engine.<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">ExecutionEngine *NewEngine = EngineBuilder(OpenModule)<br /> .setErrorStr(&ErrStr)<br /> .setUseMCJIT(true)<br /> .setMCJITMemoryManager(new HelpingMemoryManager(this))<br /> .create();</span></blockquote><div class="CodeCxSpFirst"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpMiddle"><o:p></o:p></div><div class="CodeCxSpLast"><o:p></o:p></div><div class="MsoNormal">If youâre building against the LLVM 3.3 release, you need to use setJITMemoryManager instead of the more recently added setMCJITMemoryManager call.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Finally, chances are youâve built LLVM with the default settings, which means you built it without runtime type information (RTTI). If that is the case, youâll also need to start building the sample program without RTTI to get the inheritance from SectionMemoryManager to link properly. If you do that, thereâs a place in BinaryExprAST::Codegen where youâll need to change a âdynamic_castâ to a âreinterpret_castâ to keep things working. You lose a little automatic error checking that way, but since this is just a demo program I think we can live with that. Alternatively, you could rebuild LLVM with RTTI enabled.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Hereâs the new command line weâll use for building our program:<o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">clang++ -g -fno-rtti toy.cpp `llvm-config --cppflags --ldflags --libs core mcjit native` -O3 âo toy</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal">Trying it out one more time:</div><div class="MsoNormal"><o:p></o:p></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">ready> def add(x y) x+y;</span><br /><span style="font-family: Courier New, Courier, monospace;">[output omitted]</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> add(1, 2);</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> Evaluated to 3.000000</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> add(3, 4);</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> Evaluated to 7.000000</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> def mul(x y) x*y;</span><br /><span style="font-family: Courier New, Courier, monospace;">[output omitted]</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> mul(5, 6);</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> Evaluated to 30.000000</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> mul(7, add(8, 9));</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> Evaluated to 119.000000</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> extern exit();</span><br /><span style="font-family: Courier New, Courier, monospace;">[output omitted]</span><br /><span style="font-family: Courier New, Courier, monospace;">ready> exit();</span></blockquote><div class="MsoNormal">Woo hoo! Itâs really working this time.<o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">BTW, you see how that call to exit() got linked against our app, right? The Kaleidoscope tutorial shows you something like that, but the tutorial is a bit out of date. You can link against symbols in shared libraries that our program uses this way, but to link against symbols defined in the main program module youâll need to build with the â-rdynamicâ flag.<o:p></o:p></div><div class="Code"><br /></div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">clang++ -g -fno-rtti -rdynamic toy.cpp `llvm-config --cppflags --ldflags --libs core mcjit native` -O3 âo toy</span></blockquote><div class="Code"><o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal">Anyway, now weâve got a functional Kaleidoscope interpreter built using MCJIT. In the next installment Iâll do some crude performance analysis and look at ways that we can make it a little better.<o:p></o:p></div><div class="MsoNormal"><br /></div>The full source code listing for this post is available in the trunk of the LLVM source tree at <llvm_root>/examples/Kaleidoscope/MCJIT.
- LLDB 3.3 and beyondhttps://blog.llvm.org/2013/06/lldb-33-and-beyond.htmlFri, 28 Jun 2013 12:20:00 +0000https://blog.llvm.org/2013/06/lldb-33-and-beyond.html<div class="MsoNormal">The LLVM project debugger (LLDB) has seen a recent upswing of activity around the LLVM 3.3 release. While the debugger has long been the default tool with Xcode, its potential beyond Darwin has had room to grow. Especially within the last year, the development community has grown beyond its roots with OS/X and iOS to include substantial contributions for Linux, Windows, and FreeBSD. In addition, experimental packages are available for a growing number of distributions including Debian, Ubuntu and Arch.</div><div class="MsoNormal"><br /><a name='more'></a><br /></div><div class="MsoNormal">Much of the potential draws from the architecture of LLDB. The debugger is well suited to debugging the latest C++ code because of its reuse of LLVM and Clang. This includes the LLVM dynamic execution engine (MCJIT) for expression evaluation, the LLVM disassembler and the use of the Clang AST parser. The reuse of LLVM project components has kept LLDB lightweight and has focused developer efforts on the core tasks of being a good debugger. </div><div class="MsoNormal"><br /></div><div class="MsoNormal">Overall, this modern debugger has been well designed from the ground up for multi-threaded debugging, lazy symbolication, versatile unwind, and a hierarchical command set including both C++ and Python interfaces. The availability of these core interfaces allows LLDB to fulfill its name as a low-level debugger. Developers can use the LLDB libraries for format-neutral access to information in object files such as debug information, symbols, types, functions, line tables and more. This information is useful to develop debuggers, symbolication tools, and analysis tools.</div><div class="MsoNormal"><br /></div><div class="MsoNormal">Python is currently embedded inside of LLDB and available through an interactive interpreter. The available command set allows arbitrary Python code to be run on breakpoints, watch-points, data summaries and formatters, and the like. The LLDB shared library can also be accessed in Python scripts on the command line. Overall, the ability to customize LLDB behavior using arbitrary Python code, write extensions using Python, and to evaluate arbitrary C++ expressions contribute to the versatility of this project.</div><div class="MsoNormal"><br /></div><div class="MsoNormal">Recent LLDB packages have closed some of the feature gap with LLDB on Linux relative to Darwin. This includes support for multi-threaded debugging, watch-points and vector register sets. In addition there have been many improvements to process control, expression evaluation, the build system and support of i386 targets. Upcoming features include JIT debugging, core file support and support of new processor features. Much of this work impacts any POSIX distribution including FreeBSD. Currently, x86-64 Linux builds and targets are tested on trunk (using GCC and Clang) with every commit to LLVM, Clang and LLDB.</div><div class="MsoNormal"><br /></div><div class="MsoNormal">The activity on Linux for x86-64 is just part of the picture. A Windows branch has been developed with the first port of remote debugging to a non-Darwin platform. Work is just underway to assess LLDB on FreeBSD, with ICC and for i386 targets. In fact, the number of active contributors to LLDB has more than doubled in the last year alone.</div><div class="MsoNormal"><br /></div><div class="MsoNormal">At this point in the growth of LLDB, feedback is very welcome, as we grow the test coverage and use the tool to debug increasingly more complex applications. Increasingly, LLDB is a responsive debugger that can handle some of the harder cases of multi-threaded C++ debugging effectively. </div><div class="MsoNormal"><br /></div><div class="MsoNormal">For more information about LLDB architecture, features, source code, packages, feature status or build information, visit <a href="http://lldb.llvm.org/">lldb.llvm.org</a>. If you have questions or comments about this release, please contact the <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">lldb-dev</a> mailing list!</div><br /><div class="MsoNormal"><br /></div>
- LLVM 3.3 Released!https://blog.llvm.org/2013/06/llvm-33-released.htmlWed, 19 Jun 2013 11:25:00 +0000https://blog.llvm.org/2013/06/llvm-33-released.htmlLLVM 3.3 is <a href="http://llvm.org/releases/">now available</a>! For details, you can read the <a href="http://llvm.org/releases/3.3/docs/ReleaseNotes.html">Release Notes</a>.<p> LLVM 3.3 is a big release: it adds new targets for the AArch64 and AMD R600 GPU architectures, adds support for IBM's z/Architecture S390 systems, and major enhancements for the PowerPC backend (including support for PowerPC 2.04/2.05/2.06 instructions, and an integrated assembler) and MIPS targets.<p> Performance of code generated by LLVM 3.3 is substantially improved: the <a href="http://blog.llvm.org/2013/05/llvm-33-vectorization-improvements.html">auto-vectorizer</a> produces much better code in many cases and is on by default at -O3, a new SLP vectorizer is available, and many general improvements landed in this release. Independent evaluations show that LLVM 3.3's performance exceeds that of LLVM 3.2 and of its primary competition on many benchmarks.<p> 3.3 is also a major milestone for the Clang frontend: it is now <a href="http://blog.llvm.org/2013/04/clang-support-for-c11-and-beyond.html">fully C++'11 feature complete</a>. At this point, Clang is the only compiler to support the full C++'11 standard, including important <a href="http://libcxx.llvm.org">C++'11 library</a> features like std::regex. Clang now supports Unicode characters in identifiers, the <a href="http://clang-analyzer.llvm.org">Clang Static Analyzer</a> supports several new checkers and can perform interprocedural analysis across C++ constructor/destructor boundaries, and Clang even has a nice "<a href="http://blog.llvm.org/2013/04/status-of-c11-migrator.html">C++'11 Migrator</a>" tool to help upgrade code to use C++'11 features and a "<a href="http://clang.llvm.org/docs/ClangFormat.html">Clang Format</a>" tool that plugs into vim and emacs (among others) to auto-format your code.<p> LLVM 3.3 is the result of an incredible number of people working together over the last six months, but this release would not be possible without our volunteer release team! Thanks to Bill Wendling for shepherding the release, and to Ben Pope, Dimitry Andric, Nikola Smiljanic, Renato Golin, Duncan Sands, Arnaud A. de Grandmaison, Sebastian DreÃler, Sylvestre Ledru, Pawel Worach, Tom Stellard, Kevin Kim, and Erik Verbruggen for all of their contributions pulling the release together.<p> If you have questions or comments about this release, please contact the <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVMdev mailing list</a>! Onward to LLVM 3.4!
- LLVM 3.3 Vectorization Improvementshttps://blog.llvm.org/2013/05/llvm-33-vectorization-improvements.htmlTue, 28 May 2013 07:05:00 +0000https://blog.llvm.org/2013/05/llvm-33-vectorization-improvements.htmlI would like to give a brief update regarding vectorization in LLVM. When LLVM 3.2 was released, it featured a new experimental <a href="http://blog.llvm.org/2012/12/new-loop-vectorizer.html">loop vectorizer</a> that was disabled by default. Since LLVM 3.2 was released, we have continued to work hard on improving vectorization, and we have some news to share. First, the loop vectorizer has new features and is now enabled by default on -O3. Second, we have a new SLP vectorizer. And finally, we have new clang command line flags to control the vectorizers.<br /><h4> <a name='more'></a>Loop Vectorizer </h4>The LLVM Loop Vectorizer has a number of new features that allow it to vectorize even more complex loops with better performance. One area that we focused on is the vectorization "cost model". When LLVM estimates if a loop may benefit from vectorization it uses a detailed description of the processor that can estimate the cost of various instructions. We improved both the X86 and ARM cost models. Improving the cost models helped the compiler to detect benefitting loops and improve the performance of many programs. During the analysis of vectorized programs, we also found and optimized many vector code sequences. <br /><br />Another important improvement to the loop vectorizer is the ability to unroll during vectorization. When the compiler unrolls loops it generates more independent instructions that modern out-of-order processors can execute in parallel. The loop below adds all of the numbers in the array. When compiling this loop, LLVM creates two independent chains of calculations that can be executed in parallel. <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br /><span style="color: maroon; font-weight: bold;">int</span> sum_elements<span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span>A<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> n<span style="color: #808030;">)</span> <span style="color: purple;">{</span><br /> <span style="color: maroon; font-weight: bold;">int</span> sum <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: purple;">;</span><br /> <span style="color: maroon; font-weight: bold;">for</span> <span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> i <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: purple;">;</span> i <span style="color: #808030;"><</span> n<span style="color: purple;">;</span> <span style="color: #808030;">+</span><span style="color: #808030;">+</span>i<span style="color: #808030;">)</span><br /> sum <span style="color: #808030;">+</span><span style="color: #808030;">=</span> A<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span><span style="color: purple;">;</span><br /> <span style="color: maroon; font-weight: bold;">return</span> sum<span style="color: purple;">;</span><br /><span style="color: purple;">}</span><br /></pre></body></html></pre>The innermost loop of the program above is compiled into the X86 assembly sequence below, which processes 8 elements at once, in two parallel chains of computations. The vector registers XMM0 and XMM1 are used to store the partial sum of different parts of the array. This allows the processor to load two values and add two values simultaneously. <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br />LBB0<span style="color: #808030;">_</span>4<span style="color: #808030;">:</span><br /> movdqu <span style="color: #008c00;">16</span><span style="color: #808030;">(</span><span style="color: #808030;">%</span>rdi<span style="color: #808030;">,</span><span style="color: #808030;">%</span>rax<span style="color: #008c00;">,4</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>xmm2<br /> paddd <span style="color: #808030;">%</span>xmm2<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>xmm1<br /> movdqu <span style="color: #808030;">(</span><span style="color: #808030;">%</span>rdi<span style="color: #808030;">,</span><span style="color: #808030;">%</span>rax<span style="color: #008c00;">,4</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>xmm2<br /> paddd <span style="color: #808030;">%</span>xmm2<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>xmm0<br /> addq $<span style="color: #008c00;">8</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>rax<br /> cmpq <span style="color: #808030;">%</span>rax<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>rcx<br /> jne LBB0<span style="color: #808030;">_</span>4<br /></pre></body></html></pre><br />Another important improvement is the support for loops that contain IFs, and the detection of the popular min/max patterns. LLVM is now able to vectorize the code below: <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br /><span style="color: maroon; font-weight: bold;">int</span> fins_max<span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span>A<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> n<span style="color: #808030;">)</span> <span style="color: purple;">{</span><br /> <span style="color: maroon; font-weight: bold;">int</span> mx <span style="color: #808030;">=</span> A<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span><span style="color: purple;">;</span><br /> <span style="color: maroon; font-weight: bold;">for</span> <span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> i <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: purple;">;</span> i <span style="color: #808030;"><</span> n<span style="color: purple;">;</span> <span style="color: #808030;">+</span><span style="color: #808030;">+</span>i<span style="color: #808030;">)</span><br /> <span style="color: maroon; font-weight: bold;">if</span> <span style="color: #808030;">(</span>mx <span style="color: #808030;">></span> A<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span><span style="color: #808030;">)</span><br /> mx <span style="color: #808030;">=</span> A<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span><span style="color: purple;">;</span><br /> <span style="color: maroon; font-weight: bold;">return</span> mx<span style="color: purple;">;</span><br /><span style="color: purple;">}</span><br /></pre></body></html></pre>In the last release, the loop vectorizer was able to vectorize many, but not all, loops that contained floating point arithmetic. Floating point operations are not associative due to the unique rounding rules. This means that the expression (a + b) + c is not always equal to a + (b + c). The compiler flag -ffast-math tells the compiler not to worry about rounding errors and to optimize for speed. One of the new features of the loop vectorizer is the vectorization of floating point calculations when -ffast-math mode is used. Users who decide to use the -ffast-math flag will notice that many more loops get vectorized with the upcoming 3.3 release of LLVM. <br /><h4> SLP Vectorizer </h4>The SLP vectorizer (short for superword-level parallelism) is a new vectorization pass. Unlike the loop vectorizer, which vectorizes consecutive loop iterations, the SLP vectorizer combines similar independent instructions in a straight-line code.<br />The SLP Vectorizer is now available and will be useful for many people.<br />The SLP Vectorizer can boost the performance of many programs in the LLVM test suite. In one benchmark, "Olden/Power", the SLP Vectorizer boosts the performance of the program by 16%. Here is one small example of a function that the SLP Vectorizer can vectorize. <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br /><span style="color: maroon; font-weight: bold;">void</span> foo<span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span> restrict A<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span> restrict B<span style="color: #808030;">)</span> <span style="color: purple;">{</span><br /> A<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008c00;">7</span><span style="color: #808030;">+</span><span style="color: #808030;">(</span>B<span style="color: #808030;">[</span><span style="color: #008c00;">0</span><span style="color: #808030;">]</span> <span style="color: #808030;">*</span> <span style="color: #008c00;">11</span><span style="color: #808030;">)</span><span style="color: purple;">;</span><br /> A<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008c00;">6</span><span style="color: #808030;">+</span><span style="color: #808030;">(</span>B<span style="color: #808030;">[</span><span style="color: #008c00;">1</span><span style="color: #808030;">]</span> <span style="color: #808030;">*</span> <span style="color: #008c00;">12</span><span style="color: #808030;">)</span><span style="color: purple;">;</span><br /> A<span style="color: #808030;">[</span><span style="color: #008c00;">2</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008c00;">5</span><span style="color: #808030;">+</span><span style="color: #808030;">(</span>B<span style="color: #808030;">[</span><span style="color: #008c00;">2</span><span style="color: #808030;">]</span> <span style="color: #808030;">*</span> <span style="color: #008c00;">13</span><span style="color: #808030;">)</span><span style="color: purple;">;</span><br /> A<span style="color: #808030;">[</span><span style="color: #008c00;">3</span><span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #008c00;">4</span><span style="color: #808030;">+</span><span style="color: #808030;">(</span>B<span style="color: #808030;">[</span><span style="color: #008c00;">3</span><span style="color: #808030;">]</span> <span style="color: #808030;">*</span> <span style="color: #008c00;">14</span><span style="color: #808030;">)</span><span style="color: purple;">;</span><br /><span style="color: purple;">}</span><br /></pre></body></html></pre>The code above is compiled into the ARMv7s assembly sequence below. Notice that the 4 additions and 4 multiplication operations became a single Multiply-Accumulate instruction "vmla". <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br /><span style="color: #808030;">_</span>foo<span style="color: #808030;">:</span><br /> adr r2<span style="color: #808030;">,</span> LCPI0<span style="color: #808030;">_</span>0<br /> adr r3<span style="color: #808030;">,</span> LCPI0<span style="color: #808030;">_</span>1<br /> vld1<span style="color: #008c00;">.32</span> <span style="color: #808030;">{</span>d18<span style="color: #808030;">,</span> d19<span style="color: #808030;">}</span><span style="color: #808030;">,</span> <span style="color: #808030;">[</span>r1<span style="color: #808030;">]</span><br /> vld1<span style="color: #008c00;">.64</span> <span style="color: #808030;">{</span>d16<span style="color: #808030;">,</span> d17<span style="color: #808030;">}</span><span style="color: #808030;">,</span> <span style="color: #808030;">[</span>r3<span style="color: #808030;">:</span><span style="color: #008c00;">128</span><span style="color: #808030;">]</span> <br /> vld1<span style="color: #008c00;">.64</span> <span style="color: #808030;">{</span>d20<span style="color: #808030;">,</span> d21<span style="color: #808030;">}</span><span style="color: #808030;">,</span> <span style="color: #808030;">[</span>r2<span style="color: #808030;">:</span><span style="color: #008c00;">128</span><span style="color: #808030;">]</span><br /> vmla<span style="color: #008c00;">.</span>i32 q10<span style="color: #808030;">,</span> q9<span style="color: #808030;">,</span> q8 <br /> vst1<span style="color: #008c00;">.32</span> <span style="color: #808030;">{</span>d20<span style="color: #808030;">,</span> d21<span style="color: #808030;">}</span><span style="color: #808030;">,</span> <span style="color: #808030;">[</span>r0<span style="color: #808030;">]</span><br /> bx lr<br /></pre></body></html></pre><h4> Command Line Flags </h4>We've also added new command line flags to clang to control the vectorizers. The loop vectorizer is enabled by default for -O3, and it can be enabled or disabled for other optimization levels using the command line flags: <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br />$ clang <span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span> <span style="color: #808030;">-</span>fvectorize <span style="color: #808030;">/</span> <span style="color: #808030;">-</span>fno<span style="color: #808030;">-</span>vectorize file<span style="color: #008c00;">.</span>c<br /></pre></body></html></pre>The SLP vectorizer is disabled by default, and it can be enabled using the command line flags: <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br />$ clang <span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span> <span style="color: #808030;">-</span>fslp<span style="color: #808030;">-</span>vectorize file<span style="color: #008c00;">.</span>c<br /></pre></body></html></pre>LLVM has a second basic block vectorization phase which is more compile-time intensive (BB vectorizer). This optimization can be enabled through clang using the command line flag: <br /><pre style="background: #ffffff; color: black;"><html><body style="background: #ffffff; color: black;"><pre><br />$ clang <span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span> <span style="color: #808030;">-</span>fslp<span style="color: #808030;">-</span>vectorize<span style="color: #808030;">-</span>aggressive file<span style="color: #008c00;">.</span>c<br /></pre></body></html></pre>We've made huge progress in improving vectorization during the development of LLVM 3.3. Special thanks to all of the people who contributed to this effort.
- EuroLLVM 2013, Paris, Francehttps://blog.llvm.org/2013/05/eurollvm-2013-paris-france.htmlMon, 06 May 2013 12:50:00 +0000https://blog.llvm.org/2013/05/eurollvm-2013-paris-france.html<a href="http://4.bp.blogspot.com/-ImeUwzkqcHs/UYLFH1m_E4I/AAAAAAAAA5o/PyXfOAmzQV8/s1600/paris.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="http://4.bp.blogspot.com/-ImeUwzkqcHs/UYLFH1m_E4I/AAAAAAAAA5o/PyXfOAmzQV8/s200/paris.jpg" width="132" /></a>Two days after the end of EuroLLVM 2013, I finally got the energy to write a piece about it. It was a lot of hard work by an amazing team of volunteer organizers lead by Tobias Grosser, Duncan Sands, Sylvestre Ledru and Arnaud de Grandmaison, plus the usual suspects of the previous events, and in the end there was very little that had gone wrong, even in the slightest.<br /><br /><a href="http://3.bp.blogspot.com/-dvRd-sZEf_c/UYLE66SPUgI/AAAAAAAAA48/xqzFSGbGKN8/s1600/ens-01.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="132" src="http://3.bp.blogspot.com/-dvRd-sZEf_c/UYLE66SPUgI/AAAAAAAAA48/xqzFSGbGKN8/s200/ens-01.jpg" width="200" /></a><br />This was our biggest event yet, with 187 attendees, 12 talks, 2 tutorials, 7 lightning talks and 10 posters! The posters, slides and videos are available on the <a href="http://llvm.org/devmtg/2013-04/" target="_blank">EuroLLVM 2013 website</a>, as well as some idea on the abstracts, location (ENS, in Paris) and the great dinner cruise on Monday.<br /><br />You can also find on the site the results of our questionnaire, distilled and anonymized.<br /><br /><a name='more'></a><br /><br /><b>The Talks</b><br /><br /><a href="http://2.bp.blogspot.com/-OKtTowghfrg/UYLE-pI7_oI/AAAAAAAAA5I/28IT74VB5n4/s1600/keynote-01.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="132" src="http://2.bp.blogspot.com/-OKtTowghfrg/UYLE-pI7_oI/AAAAAAAAA5I/28IT74VB5n4/s200/keynote-01.jpg" width="200" /></a>The two key notes received high approval ratings (90+% overall). The first was Chandler's, speaking about the missing optimizations still lurking, hinting which ones would be low-hanging fruit, and others that we just have to fix nonetheless. On the second day we had Jakob with a nice break-down of source code into machine code and how it's executed on modern CPUs. Despite their highly technical nature, the talks were delivered in an easy-to-understand format, which the audience didn't find daunting.<br /><br /><a href="http://4.bp.blogspot.com/-NXxIevmJbmM/UYLFPSe5JZI/AAAAAAAAA6Q/HuPC-bTHg8k/s1600/talks.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="132" src="http://4.bp.blogspot.com/-NXxIevmJbmM/UYLFPSe5JZI/AAAAAAAAA6Q/HuPC-bTHg8k/s200/talks.jpg" width="200" /></a>We also had many good talks, from Debug Information (Eric's) to PowerPC implementation (Ulrich's) to OpenMP support (Bokhanko & Bataev's), where the announcement that Intel had open sourced their OpenMP on a compatible BSD-license, which is always good news! There were also talks about tools (lld) and Clang usage (AST Tutorial, Pragma Handling).<br /><br /><br /><a href="http://1.bp.blogspot.com/-wXSqgpeGPKI/UYLFJMIBMdI/AAAAAAAAA54/i7KmbwLRR0A/s1600/parallel-track.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="132" src="http://1.bp.blogspot.com/-wXSqgpeGPKI/UYLFJMIBMdI/AAAAAAAAA54/i7KmbwLRR0A/s200/parallel-track.jpg" width="200" /></a>Since we had two parallel tracks, I was worried that we'd get people divided and not get much visibility on the second track. Some people mentioned it on the questionnaire, but the number of reviews on both tracks are compatible, which shows that there was enough space and content for all tastes.<br /><br />Other comments reinforced the idea to have more visibility on the official tools (lldb, bugpoint, lli) as well as more basic-level tutorials on how to use LLVM and tools, not just how to hack it. Let this be a lead to you (yes, you!) propose tutorials next time.<br /><br /><b>Lightning Talks and Posters</b><br /><br /><a href="http://1.bp.blogspot.com/-5_4ROuWX3JQ/UYLFNz7YbYI/AAAAAAAAA6A/DdBaB_LMYIY/s1600/posters.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="132" src="http://1.bp.blogspot.com/-5_4ROuWX3JQ/UYLFNz7YbYI/AAAAAAAAA6A/DdBaB_LMYIY/s200/posters.jpg" width="200" /></a>There were many interesting lightning talks, all very quick and efficiently exposed. Part of the reason why we had so many was that many of the talks that we couldn't fit were transformed into lightning talks, others in posters, others in both.<br /><br />The idea was that, since a lightning talk can convey only a limited meaning, having a poster and specifically a poster session, was important to promote discussions between interested parties. That was actually very relevant, because some of the feedback was that there was little extra time to reinforce or create new connections.<br /><br /><a href="http://4.bp.blogspot.com/-AMNAvjEukrs/UYLFC845YBI/AAAAAAAAA5g/OOX650oDlTk/s1600/lightning.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="132" src="http://4.bp.blogspot.com/-AMNAvjEukrs/UYLFC845YBI/AAAAAAAAA5g/OOX650oDlTk/s200/lightning.jpg" width="200" /></a>Again, there were topics from optimizations (like adaptive parallelization, user-defined optimization, FDO) to tools (MCLinker) to builds (Debian+LLVM), but perhaps the most unusual of the talks was Henning's audio signal processing using LLVM and Haskell, in which we had a live demonstration of the hardware at work. It reminded me of early works from Kraftwerk.<br /><br />Of the 91 questionnaires returned, 94% said lightning talks were important and 90% that they would want to have it again in future events. Part of this acceptance, I imagine, is due to the extra connection you have with the presenter <b>after</b> the presentation.<br /><br /><br /><b>The Social</b><br /><br /><a href="http://2.bp.blogspot.com/-aBh8EkiCleo/UYLEvkhFxBI/AAAAAAAAA4Y/Fc0a6n8jcEY/s1600/cruise-03.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="132" src="http://2.bp.blogspot.com/-aBh8EkiCleo/UYLEvkhFxBI/AAAAAAAAA4Y/Fc0a6n8jcEY/s200/cruise-03.jpg" width="200" /></a>As highlighted above, there wasn't much time to socialize in between the talks, but there were specific coffee times, where the queue forced people to connect and meet others, the lunch time at the cafeteria, where finding a place to sit wasn't easy, so you'd end up sitting with completely unrelated people, and the amazing (let me say it again: <b>amazing</b>!) cruise dinner.<br /><a href="http://1.bp.blogspot.com/-1yDJHmuvXSw/UYLEsNyCqfI/AAAAAAAAA4Q/aED2oI382Y0/s1600/cruise-02.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="132" src="http://1.bp.blogspot.com/-1yDJHmuvXSw/UYLEsNyCqfI/AAAAAAAAA4Q/aED2oI382Y0/s200/cruise-02.jpg" width="200" /></a><br />Floating easily through the Seine, admiring Paris' historical places from a very interesting point of view, we had a great meal and an enjoyable evening. I'd really like to thanks again our sponsors for providing such a great way to end a conference day.<br /><br /><a href="http://4.bp.blogspot.com/-kP7ckIEo7IU/UYLEyRBpYqI/AAAAAAAAA4o/PaT-skA9ZSM/s1600/cruise-04.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="132" src="http://4.bp.blogspot.com/-kP7ckIEo7IU/UYLEyRBpYqI/AAAAAAAAA4o/PaT-skA9ZSM/s200/cruise-04.jpg" width="200" /></a>As some have pointed out, the only down-side of the dinner was that the social part fell a bit short, since most people haven't left their tables for the duration of the trip (I have, but I was taking the pictures!), which hindered a bit the <i>social</i> part of the event.<br /><br /><br />But, to be honest, that wasn't so bad, since most (I really mean <i>most</i>) of the people decided to walk to the river, spending no less than 1 hour together, enjoying the scenery and each others company.<br /><br /><br /><b><br /></b><b>Prize Draw and Wrapping Up</b><br /><b><br /></b><a href="http://3.bp.blogspot.com/-dz9N87WcuhY/UYLFOHEbFuI/AAAAAAAAA6E/tL64Syw9xIg/s1600/prize-draw.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="http://3.bp.blogspot.com/-dz9N87WcuhY/UYLFOHEbFuI/AAAAAAAAA6E/tL64Syw9xIg/s200/prize-draw.jpg" width="183" /></a>After the last session, just before the event ended, a great Parot headphone was delivered to Ahmed, who won the lottery.<br /><br />From my point of view, this was a very successful event, proof that Europe also has interesting LLVM engineering going on. It's also getting in shape with what people hope to find at these events, following the acceptance rates of talks and organization issues.<br /><br />With offers to help all over Europe (and beyond!), I wonder where the next EuroLLVM will be... But one thing I know: it's going to be great! :-)
- Clang support for C++11 and beyondhttps://blog.llvm.org/2013/04/clang-support-for-c11-and-beyond.htmlSun, 21 Apr 2013 07:04:00 +0000https://blog.llvm.org/2013/04/clang-support-for-c11-and-beyond.htmlAs of <a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=179861">r179861</a>, Clang implements the <b>entirety</b> of the C++11 language standard. The following features have been implemented since the release of Clang 3.2, along with our plans for "C++1y".<br /><br /><a name='more'></a><br /><h3>Support for <tt>[[attributes]]</tt></h3>C++11's <tt>[[attribute]]</tt> syntax is now fully supported, including support for the standard <tt>[[noreturn]]</tt> and <tt>[[carries_dependency]]</tt> attributes (although <tt>[[carries_dependency]]</tt> does not provide improved code generation). This allows non-returning functions to be written with a standard syntax: <br /><br /><pre>[[noreturn]] void foo() {<br /> while (true) do_something();<br />}<br /></pre><pre></pre><br />Just like <tt>__attribute__((noreturn))</tt>, Clang will warn you if you use this attribute on a function which can return, and will optimize callers on the assumption that the function does not return. Unlike <tt>__attribute__((noreturn))</tt>, <tt>[[noreturn]]</tt> is never part of a function's type. <br /><br />As with g++'s implementation, <tt>__attribute__((foo))</tt> attributes which are supported by g++ can be written as <tt>[[gnu::foo]]</tt>. Clang-specific <tt>__attribute__((...))</tt>s are not available through this syntax (patches to add <tt>[[clang::...]]</tt> attribute names are welcome).<br /><br />Clang also now provides complete support for C++11's almost-attribute <tt>alignas(...)</tt>. <br /><h3>Inheriting constructors</h3>Clang now supports C++11's inheriting constructor syntax, which provides a simple mechanism to re-export all the constructors from a base class, other than default constructors, or constructors which would be copy or move constructors for either the base or derived class. Example: <br /><br /><pre>struct Base {<br /> Base(); // default constructor, not inherited<br /> Base(int, char);<br /> template<typename T> Base(T &x);<br />};<br />struct Derived : Base {<br /> using Base::Base;<br />};<br />Derived f(1, 'x');<br />Derived d("foo"); // ok, calls inheriting constructor template<br /></pre><h3><tt>thread_local</tt> variables</h3>Clang now supports C++11's <tt>thread_local</tt> keyword, including dynamic initialization and destruction of thread-local objects. Dynamic destruction requires a C++ runtime library which provides <tt>__cxa_thread_atexit</tt>, which is currently only provided by the g++4.8 C++ runtime library. <br /><h2>C++1y</h2>With C++11 out of the door, what's next? The C++ standardization committee voted yesterday to create the first Committee Draft for C++1y (which will very likely be C++14). Since this is only the first draft, there will probably be many minor changes before C++1y is done, but the rough feature set is unlikely to change much. This new language standard includes: <br /><ul><li>Generalized lambdas, allowing a templated call operator and arbitrary captures: <br /><br /><pre>auto apply = [v(21)] (auto &&fn) { fn(v); };<br />apply([] (int &n) { n += 21; });<br />apply([] (int n) { std::cout << n; });<br /><br /></pre></li><li>Return type deduction for (non-lambda) functions: <br /><br /><pre>auto fn(int n) { return something(n); }<br /><br /></pre></li><li>A more powerful <tt>constexpr</tt> feature, allowing variable mutation and loops: <br /><br /><pre></pre><pre>constexpr auto len(const char *str) {<br /> int k = 0;<br /> while (*str++) ++k;<br /> return k;<br />}<br />static_assert(len("foo") == 3, "hooray");<br /></pre></li></ul>The improved <tt>constexpr</tt> feature comes with a backwards-compatibility cost, however. In order to support variable mutation for user-defined types, those types need to have <tt>constexpr</tt> member functions which are not <tt>const</tt>, so the C++11 rule which made <tt>constexpr</tt> member functions implicitly <tt>const</tt> has been removed. This means that you will need to make the <tt>const</tt> explicit if you were previously relying on this shorthand. Rewrite: <br /><br /><pre></pre><pre>struct S {<br /> int n;<br /> constexpr int get() { return n; }<br />};<br /></pre><br />... as ... <br /><pre></pre><pre>struct S {<br /> int n;<br /> constexpr int get() const { return n; }<br />};<br /></pre><br />... and your code will work in both C++11 and C++14. Clang already has a warning for code which is relying on the implicit <tt>const</tt> rule, and will fix it for you if you run <tt>clang -fixit</tt>. Other compilers supporting C++11 <tt>constexpr</tt> are expected to start providing similar warnings soon. <br /><br />Several of the new features were prototyped in Clang prior to standardization, and we expect implementations of those to land in Clang SVN over the coming weeks. See the <a href="http://clang.llvm.org/cxx_status.html">Clang C++ status page</a> for the latest details on C++1y features and Clang's support for them. The implemented features can be enabled with the <tt>-std=c++1y</tt> command-line flag. <br /><br />If you find bugs in the C++11 support, please report them on <a href="http://llvm.org/bugs">our bug tracker</a>. If you want to get involved fixing bugs or working on C++1y support, <a href="http://clang.llvm.org/get_involved.html">our website</a> has details of how you can help.
- Euro LLVM 2013 in Parishttps://blog.llvm.org/2013/04/euro-llvm-2013-in-paris.htmlThu, 18 Apr 2013 04:44:00 +0000https://blog.llvm.org/2013/04/euro-llvm-2013-in-paris.html<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on">In two weeks, the <a href="http://llvm.org/devmtg/2013-04/">2013 edition of the Euro LLVM</a> conference will start in historic center of Paris, France. The schedule has just been published. Most of different aspects of the LLVM infrastructure will present at the event. See below for the full details!</div><h3 id="monday"><a name='more'></a></h3><h3 id="monday">Monday, April 29th</h3><table border="1"> <tbody><tr> <th>Time</th> <th>Room</th> <th>Subject</th> </tr><tr> <td>11:00 - 13:00</td> <td>Entrance</td> <td>Registration</td> </tr><tr> <td>12:30 - 13:15</td> <td>ENS restaurant</td> <td>Lunch</td> </tr><tr> <td>13:14 - 13:30</td> <td>Dussane</td> <td>Welcome - Day 1</td> </tr><tr> <td>13:30 - 14:30</td> <td>Dussane</td> <td>Keynote : <a href="http://llvm.org/devmtg/2013-04/#talk3">Optimization in LLVM - Numbers, A Case Study, and Looking Forward</a></td> </tr><tr> <td rowspan="2">14:30 - 15:15</td> <td>Dussane</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk2">Towards OpenMP Support in LLVM</a></td> </tr><tr> <td>Résistants</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk1">Dagger: decompilation to LLVM IR</a></td> </tr><tr> <td>15:15 - 15:45</td> <td></td> <td>Coffee break</td> </tr><tr> <td rowspan="2">15:45 - 16:30</td> <td>Dussane</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk14">LLVM on IBM POWER processors: a progress report</a></td> </tr><tr> <td>Résistants</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk9">Performing Source-to-Source Transformations with Clang</a></td> </tr><tr> <td rowspan="2">16:30 - 17:15</td> <td>Dussane</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk12">How to implement an LLVM Assembler</a></td> </tr><tr> <td>Résistants</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk4">clang-format - Automatic formatting for C++</a></td> </tr><tr> <td>20:00 - 23:00</td> <td></td> <td>Dinner cruise on the Seine river, in Paris, for those who registered to the dinner</td> </tr></tbody></table><h3 id="tuesday">Tuesday, April 30th</h3><table border="1"> <tbody><tr> <th>Time</th> <th>Room</th> <th>Subject</th> </tr><tr> <td>8:45 - 9:00</td> <td>Dussane</td> <td>Welcome - Day 2</td> </tr><tr> <td>9:00 - 10:00</td> <td>Dussane</td> <td>Keynote : <a href="http://llvm.org/devmtg/2013-04/#talk7">How Computers Work</a></td> </tr><tr> <td rowspan="2">10:00 - 10:45</td> <td>Dussane</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk10">LLVM Interpreter, a key component in validation of OpenCL compilers</a></td> </tr><tr> <td>Résistants</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk6">Run-time tracking of uninitialized data with MemorySanitizer</a></td> </tr><tr> <td>10:45 - 11:05</td> <td></td> <td>Coffee break</td> </tr><tr> <td>11:05 - 12:05</td> <td>Dussane</td> <td><a href="http://llvm.org/devmtg/2013-04/#ltalkabstract">Lightning talks</a></td> </tr><tr> <td rowspan="2">12:05 - 12:35</td> <td>Résistants</td> <td><a href="http://llvm.org/devmtg/2013-04/#posterabstract">Posters</a></td> </tr><tr> <td>Cavailles</td> <td><a href="http://llvm.org/devmtg/2013-04/#posterabstract">Posters</a></td> </tr><tr> <td>12:35 - 13:35</td> <td>ENS restaurant</td> <td>Lunch</td> </tr><tr> <td rowspan="2">13:35 - 14:20</td> <td>Dussane</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk8">lld - Solving the Linking Performance Problem</a></td> </tr><tr> <td>Résistants</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk13">An experimental framework for Pragma Handling in Clang</a></td> </tr><tr> <td rowspan="2">14:20 - 15:05</td> <td>Dussane</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk5">Debug Info - Status and Directions</a></td> </tr><tr> <td>Résistants</td> <td>Talk : <a href="http://llvm.org/devmtg/2013-04/#talk11">Implementing Data Layout Optimizations in LLVM Framework</a></td> </tr><tr> <td>15:05 - 16:05</td> <td>Dussane</td> <td>Tutorial : <a href="http://llvm.org/devmtg/2013-04/#tuto1">The Clang AST - a tutorial</a></td> </tr><tr> <td>16:05 - 16:20</td> <td>Dussane</td> <td>Closing word</td> </tr></tbody></table><br />The event is sponsored by <a href="http://www.arm.com/">ARM</a>, <a href="http://www.google.com/">Google</a>, <a href="http://www.irill.org/">IRILL</a>/<a href="http://www.inria.fr/">INRIA</a>, <a href="http://www.intel.com/">Intel</a>, <a href="http://www.parrot.com/">Parrot</a>, <a href="http://www.qualcomm.com/quicinc/">QuIC</a>, <a href="http://www.samsung.com/">Samsung</a><br />Edit: See the <a href="http://blog.llvm.org/2013/05/eurollvm-2013-paris-france.html">feedback from Renato Golin</a> on the event</div>
- Status of the C++11 Migratorhttps://blog.llvm.org/2013/04/status-of-c11-migrator.htmlMon, 15 Apr 2013 05:53:00 +0000https://blog.llvm.org/2013/04/status-of-c11-migrator.htmlSince the <a href="https://docs.google.com/document/d/1xXfpLPxXIlp3pUpASXC547sQFF-vvHhnQkRBogM9wX0/edit?usp=sharing" target="_blank">design document</a> for cpp11-migrate, the C++11 migrator tool, was first proposed in <a href="http://www.phoronix.com/scan.php?page=news_item&px=MTI0Mzc" target="_blank">early December 2012</a> development has been making steady progress. In this article I'll talk about what's been implemented in cpp11-migrate so far, what's coming up, and how you can get involved.<br /><br />The purpose of the C++11 Migrator is to do source-to-source translation to migrate existing C++ code to use C++11 features to enhance maintainability, readability, runtime performance, and compile-time performance. Development is still early and transforms fall mostly into the first two categories. The migrator is based on Clang's <a href="http://clang.llvm.org/docs/LibTooling.html" target="_blank">LibTooling</a> and the <a href="http://clang.llvm.org/docs/LibASTMatchers.html" target="_blank">AST Matching library</a>.<br /><br />Most of the development so far has been carried out by a small core group at Intel. Our focus so far has been to set up project infrastructure and testing, implement a few basic transforms, and make sure those transforms work well. Our aim is to make this tool useful to the community so we're always listening for transform ideas and feedback.<br /><h2><a name='more'></a>How to Get cpp11-migrate</h2>cpp11-migrate is located in the Extra Clang Tools repository. To build cpp11-migrate, you will need the LLVM and Clang sources as well. Follow the directions in Clang's <a href="http://clang.llvm.org/get_started.html" target="_blank">Getting Started instructions</a> making sure to perform the optional step of checking out the Extra Clang Tools repository. Once checked out into the correct directory the build system, after a reconfiguration, will automatically include the extra Clang tools as part of the next full build. If you're using the CMake build system, you can build just cpp11-migrate with the <span style="font-family: Courier New, Courier, monospace;">cpp11-migrate</span><span style="font-family: inherit;"> target</span><span style="font-family: Courier New, Courier, monospace;">.</span> The <span style="font-family: Courier New, Courier, monospace;">check-clang-tools</span> target provided by CMake will run all regression tests for extra Clang tools, including cpp11-migrate.<br /><h2>The Transforms So Far</h2>The C++11 Migrator currently supports four features of C++11:<br /><ul><li>Range-based for loops</li><li>The <span style="font-family: Courier New, Courier, monospace;">nullptr</span><span style="font-family: inherit;"> </span>literal for null pointers</li><li>The <span style="font-family: Courier New, Courier, monospace;">auto</span><span style="font-family: inherit;"> </span>type specifier</li><li><span style="font-family: Courier New, Courier, monospace;">override</span><span style="font-family: inherit;"> </span>virtual specifier</li></ul><span style="font-size: large;">The range-based for-loop transform</span> once existed as a stand-alone tool called <span style="font-family: Courier New, Courier, monospace;">loop-convert</span><span style="font-family: inherit;"> contributed by Sam Panzer. When development on more transforms started, the idea became to pull all transforms under the jurisdiction of a single tool and </span><span style="font-family: Courier New, Courier, monospace;">cpp11-migrate</span><span style="font-family: inherit;"> was born. The range-based for-loop transform replaces for-loops used in one of the following three common situations:</span><br /><ol><li>Loops over containers using iterators</li><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #406080;">></span> myVec<span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #406080;">></span><span style="color: #406080;">::</span><span style="color: #003060;">iterator</span> I <span style="color: #308080;">=</span> myVec<span style="color: #308080;">.</span>begin<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #308080;">,</span><br /> E <span style="color: #308080;">=</span> myVec<span style="color: #308080;">.</span>end<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /> I <span style="color: #308080;">!</span><span style="color: #308080;">=</span> E<span style="color: #406080;">;</span> <span style="color: #308080;">+</span><span style="color: #308080;">+</span>I<span style="color: #308080;">)</span><br /> llvm<span style="color: #406080;">::</span>outs<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #308080;"><</span><span style="color: #308080;"><</span> <span style="color: #308080;">*</span>I<span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #406080;">></span> myVec<span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">auto</span> <span style="color: #308080;">&</span> elem <span style="color: #406080;">:</span> myVec<span style="color: #308080;">)</span><br /> llvm<span style="color: #406080;">::</span>outs<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #308080;"><</span><span style="color: #308080;"><</span> elem<span style="color: #406080;">;</span><br /></pre></div></div><li>Loops over statically allocated arrays</li><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">int</span> arr<span style="color: #308080;">[</span><span style="color: #308080;">]</span> <span style="color: #308080;">=</span> <span style="color: #406080;">{</span><span style="color: #008c00;">1</span><span style="color: #308080;">,</span><span style="color: #008c00;">2</span><span style="color: #308080;">,</span><span style="color: #008c00;">3</span><span style="color: #308080;">,</span><span style="color: #008c00;">4</span><span style="color: #308080;">,</span><span style="color: #008c00;">5</span><span style="color: #406080;">}</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">int</span> i <span style="color: #308080;">=</span> <span style="color: #008c00;">0</span><span style="color: #406080;">;</span> i <span style="color: #308080;"><</span> <span style="color: #008c00;">5</span><span style="color: #406080;">;</span> <span style="color: #308080;">+</span><span style="color: #308080;">+</span>i<span style="color: #308080;">)</span><br /> llvm<span style="color: #406080;">::</span>outs<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #308080;"><</span><span style="color: #308080;"><</span> arr<span style="color: #308080;">[</span>i<span style="color: #308080;">]</span><span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">int</span> arr<span style="color: #308080;">[</span><span style="color: #308080;">]</span> <span style="color: #308080;">=</span> <span style="color: #406080;">{</span><span style="color: #008c00;">1</span><span style="color: #308080;">,</span><span style="color: #008c00;">2</span><span style="color: #308080;">,</span><span style="color: #008c00;">3</span><span style="color: #308080;">,</span><span style="color: #008c00;">4</span><span style="color: #308080;">,</span><span style="color: #008c00;">5</span><span style="color: #406080;">}</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">auto</span> <span style="color: #308080;">&</span> elem <span style="color: #406080;">:</span> arr<span style="color: #308080;">)</span><br /> llvm<span style="color: #406080;">::</span>outs<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #308080;"><</span><span style="color: #308080;"><</span> elem<span style="color: #406080;">;</span><br /></pre></div></div><li>Loops over array-like containers using operator[] or at().</li><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #406080;">></span> myVec<span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">int</span> i <span style="color: #308080;">=</span> <span style="color: #008c00;">0</span><span style="color: #406080;">;</span> i <span style="color: #308080;"><</span> myVec<span style="color: #308080;">.</span>size<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span> <span style="color: #308080;">+</span><span style="color: #308080;">+</span>i<span style="color: #308080;">)</span><br /> llvm<span style="color: #406080;">::</span>outs<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #308080;"><</span><span style="color: #308080;"><</span> v<span style="color: #308080;">[</span>i<span style="color: #308080;">]</span><span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #406080;">></span> myVec<span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">auto</span> <span style="color: #308080;">&</span> elem <span style="color: #406080;">:</span> myVec<span style="color: #308080;">)</span><br /> llvm<span style="color: #406080;">::</span>outs<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #308080;"><</span><span style="color: #308080;"><</span> elem<span style="color: #406080;">;</span><br /></pre></div></div></ol><span style="font-size: large;">The nullptr transform</span> uses the new <span style="font-family: Courier New, Courier, monospace;">nullptr</span> literal where pointers are being initialized with or assigned a null value. In cases where an explicit cast is used, the explicit cast is left behind to avoid introducing ambiguities into the code.<br /><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">void</span> foo<span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">int</span> <span style="color: #308080;">*</span>arg<span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">void</span> foo<span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">float</span> <span style="color: #308080;">*</span>arg<span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><br /><span style="color: #200080; font-weight: bold;">int</span> <span style="color: #308080;">*</span>IntPtr <span style="color: #308080;">=</span> <span style="color: #008c00;">0</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">float</span> <span style="color: #308080;">*</span>FloatPtr <span style="color: #308080;">=</span> <span style="color: #7d0045;">NULL</span><span style="color: #406080;">;</span><br />foo<span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">static_cast</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #308080;">*</span><span style="color: #406080;">></span><span style="color: #308080;">(</span><span style="color: #008c00;">0</span><span style="color: #308080;">)</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">void</span> foo<span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">int</span> <span style="color: #308080;">*</span>arg<span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">void</span> foo<span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">float</span> <span style="color: #308080;">*</span>arg<span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><br /><span style="color: #200080; font-weight: bold;">int</span> <span style="color: #308080;">*</span>IntPtr <span style="color: #308080;">=</span> nullptr<span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">float</span> <span style="color: #308080;">*</span>FloatPtr <span style="color: #308080;">=</span> nullptr<span style="color: #406080;">;</span><br />foo<span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">static_cast</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #308080;">*</span><span style="color: #406080;">></span><span style="color: #308080;">(</span>nullptr<span style="color: #308080;">)</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /></pre></div></div><br /><span style="font-size: large;">The auto type specifier transform</span> replaces the type specifier for variable declarations with the new <span style="font-family: Courier New, Courier, monospace;">auto</span> keyword. In general, such a replacement can be done whenever the type of the variable declaration matches the type of its initializer. However, the transform targets only a few specific useful situations with readability and maintainability in mind:<br /><ol><li>When the variable is an iterator for an STL container.</li><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">pair</span><span style="color: #406080;"><</span><span style="color: #200080; font-weight: bold;">int</span><span style="color: #308080;">,</span> <span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">string</span><span style="color: #406080;">></span> <span style="color: #406080;">></span><span style="color: #406080;">::</span><span style="color: #003060;">iterator</span> NameAgeI <span style="color: #308080;">=</span> People<span style="color: #308080;">.</span>begin<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #0066ee;">std</span><span style="color: #406080;">::</span><span style="color: #003060;">vector</span><span style="color: #406080;"><</span>MyType<span style="color: #406080;">></span><span style="color: #406080;">::</span><span style="color: #003060;">iterator</span> I <span style="color: #308080;">=</span> Container<span style="color: #308080;">.</span>begin<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #308080;">,</span><br /> E <span style="color: #308080;">=</span> Container<span style="color: #308080;">.</span>end<span style="color: #406080;">;</span><br /> I <span style="color: #308080;">!</span><span style="color: #308080;">=</span> E<span style="color: #406080;">;</span> <span style="color: #308080;">+</span><span style="color: #308080;">+</span>I<span style="color: #308080;">)</span> <span style="color: #406080;">{</span><br /> <span style="color: #595979;">// ...</span><br /><span style="color: #406080;">}</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">auto</span> NameAgeI <span style="color: #308080;">=</span> People<span style="color: #308080;">.</span>begin<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">for</span> <span style="color: #308080;">(</span><span style="color: #200080; font-weight: bold;">auto</span> I <span style="color: #308080;">=</span> Container<span style="color: #308080;">.</span>begin<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #308080;">,</span><br /> E <span style="color: #308080;">=</span> Container<span style="color: #308080;">.</span>end<span style="color: #406080;">;</span><br /> I <span style="color: #308080;">!</span><span style="color: #308080;">=</span> E<span style="color: #406080;">;</span> <span style="color: #308080;">+</span><span style="color: #308080;">+</span>I<span style="color: #308080;">)</span> <span style="color: #406080;">{</span><br /> <span style="color: #595979;">// ...</span><br /><span style="color: #406080;">}</span><br /></pre></div></div><li>When the initializer is an allocation using the <span style="font-family: Courier New, Courier, monospace;">new</span><span style="font-family: inherit;"> operator.</span></li><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;">MyType <span style="color: #308080;">*</span>VarPtr <span style="color: #308080;">=</span> <span style="color: #200080; font-weight: bold;">new</span> MyType<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br />MyType <span style="color: #308080;">*</span> <span style="color: #200080; font-weight: bold;">const</span> VarCPtr <span style="color: #308080;">=</span> <span style="color: #200080; font-weight: bold;">new</span> MyType<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">auto</span> VarPtr <span style="color: #308080;">=</span> <span style="color: #200080; font-weight: bold;">new</span> MyType<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">auto</span> <span style="color: #200080; font-weight: bold;">const</span> VarCPtr <span style="color: #308080;">=</span> <span style="color: #200080; font-weight: bold;">new</span> MyType<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /></pre></div></div></ol>Support for a third situation is in development: creating objects with factory functions.<br /><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;">MyType <span style="color: #308080;">*</span>FooPtr <span style="color: #308080;">=</span> makeObject<span style="color: #406080;"><</span>MyType<span style="color: #406080;">></span><span style="color: #308080;">(</span><span style="color: #595979;">/*...*/</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br />MyType <span style="color: #308080;">*</span>BarPtr <span style="color: #308080;">=</span> MyType<span style="color: #406080;">::</span>create<span style="color: #308080;">(</span><span style="color: #595979;">/*...*/</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">auto</span> FooPtr <span style="color: #308080;">=</span> makeObject<span style="color: #406080;"><</span>MyType<span style="color: #406080;">></span><span style="color: #308080;">(</span><span style="color: #595979;">/*...*/</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #200080; font-weight: bold;">auto</span> BarPtr <span style="color: #308080;">=</span> MyType<span style="color: #406080;">::</span>create<span style="color: #308080;">(</span><span style="color: #595979;">/*...*/</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /></pre></div></div>In each situation, the deduced type for the declared variable should be obvious to the reader. Iterators for standard containers are created by functions with specific names and are used in specific situations. For factory functions and operator <span style="font-family: Courier New, Courier, monospace;">new</span><span style="font-family: inherit;">, </span>the type is spelled out in the initializer so repeating it in the variable declaration is not necessary.<br /><br /><span style="font-size: large;">The <span style="font-family: inherit;">override </span>virtual specifier transform</span>, contributed by Philip Dunstan, is the migrator's fourth transform and the first to be contributed from outside the core group at Intel. This transform detects virtual member functions in derived classes that override member functions from parent classes and adds the <span style="font-family: Courier New, Courier, monospace;">override</span> virtual specifier to the function.<br /><div style="text-indent: 0; vertical-align: middle;"><div style="display: inline-block; vertical-align: middle; width: 50%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">class</span> Parent <span style="color: #406080;">{</span><br /><span style="color: #200080; font-weight: bold;">public</span><span style="color: #e34adc;">:</span><br /> <span style="color: #200080; font-weight: bold;">virtual</span> <span style="color: #200080; font-weight: bold;">int</span> getNumChildren<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #406080;">}</span><span style="color: #406080;">;</span><br /><br /><span style="color: #200080; font-weight: bold;">class</span> Child <span style="color: #406080;">{</span><br /><span style="color: #200080; font-weight: bold;">public</span><span style="color: #e34adc;">:</span><br /> <span style="color: #200080; font-weight: bold;">virtual</span> <span style="color: #200080; font-weight: bold;">int</span> getNumChildren<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #406080;">}</span><span style="color: #406080;">;</span><br /></pre></div><div style="display: inline-block; font-size: x-large; vertical-align: middle;">â </div><div style="display: inline-block; vertical-align: middle; width: 45%;"><pre style="background: #f6f8ff; color: #000020;"><span style="color: #200080; font-weight: bold;">class</span> Parent <span style="color: #406080;">{</span><br /><span style="color: #200080; font-weight: bold;">public</span><span style="color: #e34adc;">:</span><br /> <span style="color: #200080; font-weight: bold;">virtual</span> <span style="color: #200080; font-weight: bold;">int</span> getNumChildren<span style="color: #308080;">(</span><span style="color: #308080;">)</span><span style="color: #406080;">;</span><br /><span style="color: #406080;">}</span><span style="color: #406080;">;</span><br /><br /><span style="color: #200080; font-weight: bold;">class</span> Child <span style="color: #406080;">{</span><br /><span style="color: #200080; font-weight: bold;">public</span><span style="color: #e34adc;">:</span><br /> <span style="color: #200080; font-weight: bold;">virtual</span> <span style="color: #200080; font-weight: bold;">int</span> getNumChildren<span style="color: #308080;">(</span><span style="color: #308080;">)</span> <span style="color: #200080; font-weight: bold;">override</span><span style="color: #406080;">;</span><br /><span style="color: #406080;">}</span><span style="color: #406080;">;</span><br /></pre></div></div><br />More details on these transforms, what they can and can't do, how to adjust their behaviour, and known limitations can be found in the <a href="http://clang.llvm.org/extra/cpp11-migrate.html" target="_blank">cpp11-migrate User's Manual</a>.<br /><h2>Testing on Real Projects</h2><div>What better way to test the C++11 Migrator than to run it on entire real projects? We've set up a continuous integration server to build and run cpp11-migrate on two projects so far and have plans for at least three more. For each project, the goal is to build the transformed code and run that project's test suite to ensure semantics haven't changed.</div><div style="margin-top: 1em; text-indent: 0; width: 20em;"><div style="border-right: 1px solid grey; display: inline-block; padding-right: .5em; vertical-align: top;"><b>Implemented: </b><br /><ol><li><a href="http://www.llvm.org/" target="_blank">LLVM 3.1</a></li><li><a href="http://www.itk.org/" target="_blank">ITK 4.3.1</a></li></ol></div><div style="display: inline-block; padding-left: .5em; vertical-align: top;"><b>Planned: </b><br /><ol><li><a href="http://lldb.llvm.org/" target="_blank">LLDB</a></li><li><a href="http://opencv.org/" target="_blank">OpenCV</a></li><li><a href="http://pocoproject.org/" target="_blank">Poco</a></li></ol></div></div>Running the migrator on real code has been enormously helpful for finding bugs. Real code from varying projects often reveals code expressions not accounted for in the development and unit testing of the transforms. Every time a bug found from transforming these projects gets fixed, new test cases are added to the regression test suite and the migrator becomes more robust.<br /><h2>Future Work</h2><div>Fixing bugs found by migrating real code is of high priority right now since we want a good user experience for as many people as we can as soon as possible. Adding more transforms is another priority and those transforms with the most interest from the community will come first. Currently at the top of the list are:</div><div><ol><li>Use the standard library instead of TR1</li><li>Replace use of the deprecated <span style="font-family: Courier New, Courier, monospace;">auto_ptr</span> class.</li></ol>In addition to fixing bugs and adding transforms, there are also more general improvements to consider. One such improvement we're making progress on is to remove the restriction that only source files are transformed and not any of the headers they include. The restriction has been in place until now because the migrator needs to know which headers are safe to transform. System headers and third-party library headers clearly shouldn't be touched.</div><h2>Get Involved!</h2><div>If you want to get involved, the first thing you can do is try out cpp11-migrate on your code. Bugs can be logged with <a href="http://llvm.org/bugs/" target="_blank">LLVM's bug tracker</a> under the product <span style="font-family: Courier New, Courier, monospace;">clang-tools-extra</span>. Send an email to the <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">Clang Developer's Mailing List</a> if you need help or would like to get more involved. We look forward to hearing from you!<br /><br /></div>
- Static analysis tools: using Clang in CppDependhttps://blog.llvm.org/2013/04/static-analysis-tools-using-clang-in.htmlMon, 15 Apr 2013 03:39:00 +0000https://blog.llvm.org/2013/04/static-analysis-tools-using-clang-in.html<div dir="ltr" style="text-align: left;" trbidi="on"><br />Static analysis is a method of computer program debugging that is done by examining the code without executing the program. The process provides an understanding of the code structure, can help to ensure that the code adheres to industry standards, and can find bugs not easy to detect.<br /><br />To develop a C / C++ static analysis tool, a parser is needed to parse the source code. C++ is a very powerful language but its syntax is a little bit complicated, what makes the parser not easy to develop.<br /><br />When we began the development of <a href="http://www.cppdepend.com/">CppDepend </a>about four years ago we needed a reliable C / C++ parser. At that time, Clang was an option but was not widely used and we didnât know if it would ultimately develop into a fully-featured compiler frontend.<br /><br />Last year, for the major release of CppDepend 3.0, we re-evaluated our C / C++ parser with a goal of getting more reliable results. We checked Clang to see where its evolution went and were very surprised that it now implements virtually all C++'11 features and became very popular. Clang now provide solid infrastructure to write tools that need syntactic and semantic information about a program.<br /><br /><a name='more'></a><br /><br />Clang is designed to be modular, and like other compilers it has three phases: <br /><ul style="text-align: left;"><li>The front end that parses source code, checking it for errors, and builds a language-specific Abstract Syntax Tree (AST) to represent the input code.</li><li>The optimizer: its goal is to do some optimization on the AST generated by the front end.</li><li>The back end: generates the final code to be executed by the machine, it depends of the target architecture.</li></ul><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-WDcl2mtJ8Do/UWnL-S-FgiI/AAAAAAAAAn0/3LTWx4a32XY/s1600/clang.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-WDcl2mtJ8Do/UWnL-S-FgiI/AAAAAAAAAn0/3LTWx4a32XY/s1600/clang.gif" /></a></div><br /><br />In our case we needed only to use the front end parser, and we use the generated AST. For that we added our custom ASTFrontEndAction.<br />Each ASTFrontEndAction create one or many ASTConsumer as shown by the following dependency gaph:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-Fvq7jfoaiwY/UWnTLIOexFI/AAAAAAAAAoE/86hDIkA9OaQ/s1600/clang2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-Fvq7jfoaiwY/UWnTLIOexFI/AAAAAAAAAoE/86hDIkA9OaQ/s1600/clang2.png" /></a></div><br /><br />ASTConsumer is an abstract class, and we have to implement our AST consumer for our specific needs. And to do that we had take a look at the implementation of the existing AST Consumers to understand how they works, and here are all the classes inheriting from ASTConsumer:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-3I8Luf_nK8Y/UWnVKzU3ooI/AAAAAAAAAoQ/aBd4RBORAjM/s1600/clang3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-3I8Luf_nK8Y/UWnVKzU3ooI/AAAAAAAAAoQ/aBd4RBORAjM/s1600/clang3.png" /></a></div><br />And we took ASTPrinter and ASTDumpXML as examples to understand how to implements our specific AST consumer.<br /><br /> Thanks to all the developers behind LLVM and Clang for their big efforts to deliver a powerful compiler, and to thank all open source C / C++ contributors, we are giving you a CppDepend "Pro license" for free. CppDepend can be used to analyze a code base in order to:<br /><br />â¢<span class="Apple-tab-span" style="white-space: pre;"> </span>Improve the code base quality.<br />â¢<span class="Apple-tab-span" style="white-space: pre;"> </span>Help new contributors to understand the existing code base.<br />â¢<span class="Apple-tab-span" style="white-space: pre;"> </span>Automate the code review to be sure that all the coding rules specified by the manager are satisfied.<br />â¢<span class="Apple-tab-span" style="white-space: pre;"> </span>Generate custom reports for documentation purpose.<br /><br />To get your CppDepend Pro license, you can just send us a mail at [email protected] with the following infos:<br /><br />â¢<span class="Apple-tab-span" style="white-space: pre;"> </span>Name of the contributor.<br />â¢<span class="Apple-tab-span" style="white-space: pre;"> </span>Link to the patches that you have contributed.<br /><br />Thanks!</div>
- LLVM Recipient of the 2012 ACM System Software Awardhttps://blog.llvm.org/2013/04/llvm-recipient-of-2012-acm-system.htmlWed, 10 Apr 2013 07:39:00 +0000https://blog.llvm.org/2013/04/llvm-recipient-of-2012-acm-system.html The ACM <a href="http://www.acm.org/press-room/news-releases/2013/acm-tech-awards-2012">just announced</a> that the LLVM project is the recipient of the <a href="http://awards.acm.org/homepage.cfm?srt=all&awd=149">2012 ACM System Software Award</a>. This award recognizes a "software system that has had a lasting influence, reflected in contributions to concepts, in commercial acceptance, or both." Many important software systems are previous recipients of this award, including Eclipse, VMware, Eiffel, Make, Java, Apache, TCP/IP, PostScript, SMALLTALK, TeX, and UNIX (among others).<p> This is fantastic recognition for the impact LLVM has had on the compiler and languages industry, and is recognition that all LLVM Developers should feel proud of.
- LLVM Debian/Ubuntu nightly packageshttps://blog.llvm.org/2013/04/llvm-debianubuntu-nightly-packages.htmlWed, 03 Apr 2013 13:32:00 +0000https://blog.llvm.org/2013/04/llvm-debianubuntu-nightly-packages.html<div dir="ltr" style="text-align: left;" trbidi="on"><br />In order to facilitate testing and to improve the deployment of the LLVM toolchain, we are happy to <a href="http://llvm.org/apt/">publish LLVM Debian/Ubuntu nightly packages</a>. Read on for information about how it works and what we're building.<br /><br /><a name='more'></a>These packages provide LLVM, Clang, compiler-rt, polly and LLDB.<br />They are built for Debian:<br /><ul style="text-align: left;"><li>Wheezy (future stable)</li><li>Unstable</li></ul>and Ubuntu:<br /><ul style="text-align: left;"><li>Precise</li><li>Quantal</li><li>Raring</li></ul> For now, amd64 and i386 are supported.<br /><br />For example, installing the nightly build of clang 3.3 is as simple as:<br /><pre></pre><i>echo "deb http://llvm.org/apt/wheezy/ llvm-toolchain-wheezy main"> /etc/apt/sources.list.d/llvm.list</i><br /><i>apt-get update</i><br /><i>apt-get install clang-3.3</i><br /><i><br /></i>Packages are automatically built twice a day for every architecture and operating system in clean chroots. They are built by a <a href="http://llvm-jenkins.debian.net/">Jenkins instance</a> hosted by <a href="http://www.irill.org/">IRILL</a> and push the LLVM infrastructure.<br /><h2> </h2><h2>Repositories</h2><div class="rel_section"><h3 style="text-align: left;"><b>Debian</b></h3></div><div class="rel_boxtext">wheezy (currently testing)<small></small><br /><pre>deb http://llvm.org/apt/wheezy/ llvm-toolchain-wheezy main<br />deb-src http://llvm.org/apt/wheezy/ llvm-toolchain-wheezy main<br /></pre><br />sid (unstable)<small></small><br /><pre>deb http://llvm.org/apt/unstable/ llvm-toolchain main<br />deb-src http://llvm.org/apt/unstable/ llvm-toolchain main<br /></pre></div><div class="rel_section"></div><div class="rel_section" style="text-align: left;"><h3><b>Ubuntu</b></h3></div><div class="rel_boxtext">Precise (12.04)<small></small><br /><pre>deb http://llvm.org/apt/precise/ llvm-toolchain-precise main<br />deb-src http://llvm.org/apt/precise/ llvm-toolchain-precise main</pre><pre> </pre>Quantal (12.10)<br /><small></small> <br /><pre>deb http://llvm.org/apt/quantal/ llvm-toolchain-quantal main<br />deb-src http://llvm.org/apt/quantal/ llvm-toolchain-quantal main</pre><pre> </pre>Raring (13.04)<small></small><br /><pre>deb http://llvm.org/apt/raring/ llvm-toolchain-raring main<br />deb-src http://llvm.org/apt/raring/ llvm-toolchain-raring main</pre></div><h2> </h2><h2>Install</h2>The following commands will install all packages provided by the llvm-toolchain:<br /><br /><pre>apt-get install clang-3.3 clang-3.3-doc libclang-common-dev libclang-dev libclang1 libclang1-dbg libllvm-3.3-ocaml-dev libllvm3.3 libllvm3.3-dbg lldb-3.3 llvm-3.3 llvm-3.3-dev llvm-3.3-doc llvm-3.3-examples llvm-3.3-runtime<br /></pre><h2> </h2><h2>Technical workflow</h2>Twice a day, each jenkins job will checkout the debian/ directory necessary to build the packages. The repository is available on the Debian hosting infrastructure: <a href="http://anonscm.debian.org/viewvc/pkg-llvm/llvm-toolchain/branches/">http://anonscm.debian.org/viewvc/pkg-llvm/llvm-toolchain/branches/</a>. In the <i>llvm-toolchain-*-source</i>, the following tasks will be performed: <br /><ul><li>upstream sources will be checkout</li><li>tarballs will be created. They are named: <ul><li>llvm-toolchain_X.Y~svn123456.orig-lldb.tar.bz2</li><li>llvm-toolchain_X.Y~svn123456.orig-compiler-rt.tar.bz2</li><li>llvm-toolchain_X.Y~svn123456.orig.tar.bz2</li><li>llvm-toolchain_X.Y~svn123456.orig-clang.tar.bz2</li><li>llvm-toolchain_X.Y~svn123456.orig-polly.tar.bz2</li></ul></li><li>Debian .dsc package description is created</li><li>Start the jenkins job <i>llvm-toolchain-X-binary</i></li></ul>Then, the job <i>llvm-toolchain-X-binary</i> will: <br /><ul><li>Create a chroot using cowbuilder or update it is already existing</li><li>Install libisl >=0.11 if necessary (for polly)</li><li>Build all the packages</li><li>Launch lintian, the Debian static analyzer</li><li>Publish the result on the LLVM repository</li></ul>Note that a <a href="http://anonscm.debian.org/viewvc/pkg-llvm/llvm-toolchain/branches/snapshot/debian/patches/">few patches</a> are applied over the LLVM tarballs (and should be merged upstream soon). <br /><h2>Future</h2>This versatile infrastructure allows some more interesting features like:<br /><ul style="text-align: left;"><li>Automatic launch of scan-build on the whole code</li><li>Full bootstrap of LLVM/Clang</li><li>Code coverage on the latest release</li></ul></div>
- Testing libc++ with -fsanitize=undefinedhttps://blog.llvm.org/2013/04/testing-libc-with-fsanitizeundefined.htmlMon, 01 Apr 2013 10:12:00 +0000https://blog.llvm.org/2013/04/testing-libc-with-fsanitizeundefined.html<i style="background-color: whitesmoke; font-family: 'Trebuchet MS', verdana, sans-serif; font-size: 13px; line-height: 22px; text-indent: 10px;">[This article is re-posted in a slightly expanded form <a href="http://cplusplusmusings.wordpress.com/2013/03/26/testing-libc-with-fsanitizeundefined/" style="border-bottom-color: red; border-bottom-style: dashed; border-bottom-width: 1px; color: purple; text-decoration: none;">from Marshall's blog</a>]</i><br /><br />After my last article, <a href="http://cplusplusmusings.wordpress.com/2013/03/20/testing-libc-with-address-sanitizer/">Testing libc++ with Address Sanitizer</a>, I thought "what other tests can I run?"<br /><br />Address Sanitizer (ASan) is not the only "sanitizer" that clang offers. There are "Thread Sanitizer" (TSan), "Undefined Behavior Sanitizer" (UBSan), and others. There's an integer overflow sanitizer which is called IOC coming in the 3.3 release of clang. The documentation for UBSan can be found <a href="http://clang.llvm.org/docs/UsersManual.html">on the LLVM site</a>.<br /><br />I have been looking at the results of running the libc++ test suite with UBSan enabled. Even if you're not interested in libc++ specifically, this post can be a useful introduction to useful Clang bug detectors, and shows several classes of problems they can find. <br /><h3><a name='more'></a></h3><h3>The mechanics</h3>Like ASan, UBSan is a compiler pass and a custom runtime library. You enable this by passing <code>-fsanitize=undefined</code> to the compiler and linker. I ran the libc++ test suite like this:<br /><pre><code><br /></code></pre><pre><code>cd $LLVM/libcxx/test<br />CC=/path/to/tot/clang OPTIONS="--std=c++11 -stdlib=libc++ -fsanitize=undefined" ./testit<br /></code></pre><br />Unfortunately, this failed; working with unreleased compilers and libraries, I needed updated versions of both libc++.dylib and libc++abi.dylib. So I built those from sources, and then used <code>DYLD_LIBRARY_PATH</code> to make sure that the test program used the libraries that I'd just built. (I didn't want to replace the ones in /usr/lib, because lots of things in the system depend on them)<br /><pre><code><br /></code></pre><pre><code>cd $LLVM/libcxx/test<br />DYLD_LIBRARY_PATH=$LLVM/libcxx/lib:$LLVM/libcxxabi/lib CC=/path/to/tot/clang OPTIONS="-std=c++11 -stdlib=libc++ -fsanitize=undefined -L $LLVM/libcxxabi/lib -lc++abi" ./testit<br /></code></pre><br />where, as before "/path/to/tot/clang" is the clang that I just built from source, and $LLVM is where I've checked out the various parts of LLVM from Subversion. <br /><h3>The results</h3>And the tests were off and running. In the last article, I noted that these tests take about 30 minutes to run on my MacBook Pro. The ASan tests took about 90 minutes. I was pleasantly surprised when the UBSan tests finished in about 42 minutes, or about 40% slower than the baseline tests. There were 12 tests (out of more than 4800) that failed under normal circumstances. Using UBSan, 49 tests failed, and there were about 48,463 different runtime errors reported by UBSan. <br /><h4>The failing tests</h4>Of the 37 tests that failed under UBSan, 34 of them were aborted because of <code>uncaught exception of type XXXX</code>, where XXX was from the standard library (<code>std::out_of_range</code>, for example). This is caused by a mismatch between libc++ and libc++abi, specifically by the fact that both my custom-built libc++ and my custom-built libc++abi contained typeinfo records for some of the standard exception classes. Getting this right and getting all the bits of the test infrastructure to use the right libraries turned into a big mess very quickly, and I still don't have a good solution here.<br /><br />However, I was able to convince myself that these failures were not the result of a bug in either libc++, the test suite or UBSan.<br /><br />The other three failures were in the <code>std::thread</code> test suite. When I investigated, it turned out that there was a race condition in some of the thread tests. <em>A race condition? In threading code? Inconceivable!</em><br /><br />Apparently the runtime environment under UBSan was different enough to trigger the (latent) race condition in these three tests. Looking at the test suite, I found the same race condition in 10 other tests as well. I committed revision 178029 to fix this in all 13 tests. <br /><h4>The error messages</h4>48K errors! I can't look at 48K error messages; so I decided to bin them.<br /><br />There were 37,675 messages of the form: <code>0x000106ae3fff: runtime error: value inf is outside the range of representable values of type 'xxxx' </code>where "xxxx" could be "double" or "float" (this also included "-inf" as well)<br /><br />and 10,693 messages of the form: <code>0x000101a8f244: runtime error: value nan is outside the range of representable values of type 'xxxx';</code> where "xxxx" could be "double" or "float".<br /><br />There were 52 messages of the form: <code>what.pass.cpp:24:9: runtime error: member call on address 0x7fff5e8f48d0 which does not point to an object of type 'std::logic_error'.</code><br /><br />There were 29 messages like this: <code>eval.pass.cpp:180:14: runtime error: division by zero</code><br /><br />There were 6 messages like this: <code>/Sources/LLVM/libcxx/include/memory:3163:25 runtime error: load of misaligned address 0x7fff569a85c6 for type 'const unsigned long', which requires 8 byte alignment</code><br /><br />There were 5 messages like this: <code>0x0001037a329e: runtime error: load of value 4294967294, which is not a valid value for type 'std::regex_constants::match_flag_type'</code><br /><br />There were 2 messages like this: <code>/Sources/LLVM/libcxx/include/locale:3361:48: runtime error: index 40 out of bounds for type 'char_type [10]'</code><br /><br /> There was one message like this: <code>runtime error: load of value 64, which is not a valid value for type 'bool'</code><br /><br />The first thing that I noticed is that sometimes UBSan will give you file and line number, and otherwise just a hex address. The file and line number is incredibly useful for tracking stuff down. <br /><h4>The Analysis</h4>Working from the bottom up:<br /><br />The <code>load of value 64, which is not a valid value for type 'bool'</code> message came out of one of the atomics tests, where it is trying to clear and set an atomic flag that has been default constructed. I don't know what the correct behavior is here; I'm still looking at this one.<br /><br />The <code>index 40 out of bounds for type 'char_type [10]'</code> errors came from the money formatting tests in libc++, and were failing only on "wide string" versions of the tests; i.e, with two (or four) byte characters. The offending line turned out to be:<br /><pre><code>*__nc = __src[find(__atoms, __atoms+sizeof(__atoms), *__w) - __atoms];</code></pre>and the problem was that sizeof(__atoms) was assumed to be the same as the number of entries in that array. Perfectly fine for character arrays, not so fine for wide character arrays. Fixed in revision 177694. <br /><br />The <code>load of value 4294967294, which is not a valid value for type 'std::regex_constants::match_flag_type'</code> errors turned out to be simple to fix as well, once we decided what the right fix was.<br /><br />This turned out to be complicated, because it involved a close reading of the standards document. The problem was that <code>match_flag_type</code> was an enum, emulating a bitmask. The type also had an <code>operator ~()</code>, which flipped all the bits in the type. But since the type was implemented as an enum, it had an underlying integer type that it was represented as, and the <code>operator ~</code> just flipped all the bits. This led to values that UBSan didn't like. A large discussion followed, with sentiments like "does it matter" and "can any code actually tell", and so on. Eventually, I just changed the <code>operator ~</code> to only flip the bits that are valid in the enumeration. Fixed in revision 177693.<br /><br />The <code>load of misaligned address 0x7fff569a85c6 for type 'const unsigned long', which requires 8 byte alignment</code> were in the hashing code for strings. They are a performance optimization, and I haven't tried to touch them. Whatever changes are made here will have to be done very carefully, since this will affect the performance of all the associative containers.<br /><br />The "division by zero" messages were in three different tests. There were 3 of them in the numeric limits tests, and they were there on purpose. There were 2 of them in the complex number tests, and they were also on purpose. The other 24 of them were in the random number test suite, where the tests were generating a bunch of random numbers (using various distributions) and checking to see that the mean, variance, standard deviation, skew, etc, were all what the programmer expected. The problem is in the last measurement: skew. It is some calculated value divided by the variance. If the variance is zero, then the skew should be infinity. Many of the tests in the random number suite are testing "edge cases" of the random number generators, and some of these edge cases will produce a sequence where all the numbers are the same (and thus, the variance == 0). We solved this by commenting out the calculation of the skew for these degenerate cases, and leaving a comment in the test source file. Howard fixed this in revision 177826.<br /><br />The <code>runtime error: member call on address 0x7fff5e8f48d0 which does not point to an object of type 'std::logic_error'</code> messages, as it turned out, were due to a bug in UBSan.<br /><br />I'm just getting started on the <code>inf</code>/<code>-inf</code>/<code>nan</code> messages (about 48K of those). Most of these come from the complex number regression tests. Since this is a test suite for a library that implements a bunch of numeric routines, a lot of the tests actually do generate and use nan/inf, so I expect that many of these will be "false positives". Richard Smith has pointed out:<br /><br /><blockquote>The C++ standardâs treatment of Inf and NaN values is highly underspecified, so for the most part itâs not clear what has defined behavior and what does not. </blockquote><blockquote>Anyway⦠Iâm updating UBSan to suppress the diagnostics for conversions of âInfâ and âNaNâ between floating-point types, and will probably split out a separate flag for finite overflow in conversions to floating-point types, so that users can turn it off as needed. I think thatâs the right compromise for the time being. </blockquote><h4>Conclusions</h4>This exercise, while not completed, has already turned up a set of bugs in the libc++ test suite, as well as a bug in libc++ and some undefined behavior in libc++. There's more to look at here, but I think this was a good exercise. There's kind of a mismatch of expectations here, especially in the complex and numeric test suites, because UBSan is looking for nan/inf/-inf and the libc++ test code is deliberately generating them.<br /><br />Thanks to Howard Hinnant for his patience and explanations about the C++ standard and libc++ and the libc++ test suite, and to Richard Smith for his help with UBSan and interpreting the C++ standard.
- Testing libc++ with Address Sanitizerhttps://blog.llvm.org/2013/03/testing-libc-with-address-sanitizer.htmlThu, 28 Mar 2013 14:02:00 +0000https://blog.llvm.org/2013/03/testing-libc-with-address-sanitizer.html<i>[This article is re-posted in a slightly expanded form <a href="http://cplusplusmusings.wordpress.com/2013/03/20/testing-libc-with-address-sanitizer/">from Marshall's blog</a>]</i><br />I've been running the libc++ tests off and on for a while. It's a quite extensive test suite, but I wondered if there were any bugs that the test suite was not uncovering. In the upcoming clang 3.3, there is a new feature named <a href="http://clang.llvm.org/docs/AddressSanitizer.html">Address Sanitizer</a> which inserts a bunch of runtime checks into your executable to see if there are any "out of bounds" reads and writes to memory.<br />In the back of my head, I've always thought that it would be nice to be able to say that libc++ was "ASan clean" (i.e, passed all of the test suite when running with Address Sanitizer).<br />So I decided to do that.<br /><br /><a name='more'></a> [ All of this work was done on Mac OS X 10.8.2/3 ] <h3> How to run the tests:</h3>There's a script for running the tests. It's called <code>testit</code>.<br /><pre><code> $ cd $LLVM/libcxx/test ; ./testit<br /></code></pre><pre><code><br /></code></pre>where $LLVM/libcxx is where libc++ is checked out. This takes about 30 minutes to run. Without Address Sanitizer, libc++ fails 12 out of the 4348 tests on my system. <h3>Running the tests with Address Sanitizer</h3><pre><code> $ cd $LLVM/libcxx/test ; CC=/path/to/tot/clang++ OPTIONS= "-std=c++11 -stdlib=libc++ -fsanitize=address" ./testit<br /></code></pre><em>Note: the default options are "-std=c++11 -stdlib=libc++", that's what you get if you don't specify anything</em>.This takes about 92 minutes; just a bit more than three times as long. With Address Sanitizer, libc++ fails 54 tests (again, out of 4348)<br /><br />What are the failures?<br /><br /><ul><li>In 11 tests, Address Sanitizer detected a one-byte write outside a heap block. All of these involve iostreams. I created a small test program that ASan also fires on, and sent it to Howard Hinnant (who wrote most of libc++), and he found a place where he was allocating a zero-byte buffer by mistake. One bug, multiple failures. He fixed this in revision <a href="http://llvm.org/viewvc/llvm-project?rev=177452&view=rev">177452</a>.</li><li>2 tests for std::random were failing. This turned out to be an off-by-one error in the test code, not in libc++. I fixed these in revisions <a href="http://llvm.org/viewvc/llvm-project?rev=177355&view=rev">177355</a> and <a href="http://llvm.org/viewvc/llvm-project?rev=177464&view=rev">177464</a>.</li><li>Address Sanitizer detected memory allocations failing in 4 cases. This is expected, since some of the tests are testing the memory allocation system of libc++. However, it appears that ASan does not call the user-supplied <code>new_handler</code> when memory allocation fails (and may not throw <code>std::bad_alloc</code>, ether). I have filed <a href="http://llvm.org/bugs/show_bug.cgi?id=15544">PR15544</a> to track this issue.</li><li>25 cases are failing where the program is failing to load, due to a missing symbol. This is most commonly <code>std::__1::__get_sp_mut(void const *)</code>, but there are a couple others. Howard says that this was added to libc++ after 10.8 shipped, so it's not in the dylib in /usr/lib. If the tests are run with a copy of libc++ built from source, they pass.</li><li>There are the 12 cases that were failing before enabling Address Sanitizer.</li></ul>Once Howard and I fixed the random tests and the bug in the iostreams code, I re-ran the tests using a recently build libc++.dylib.<br /><pre><code> $ cd $LLVM/libcxx/test ; DYLD_LIBRARY_PATH=$LLVM/libcxx/lib CC=/path/to/tot/clang++ OPTIONS= "-std=c++11 -stdlib=libc++ -fsanitize=address" ./testit<br /></code></pre>This gave us 16 failures: <br /><ul><li>The 4 failures that have to do with memory allocation failures.</li><li>The 12 failures that we started with.</li></ul><br /><h4>Conclusion</h4>I'm glad to see that there were so few problems in the libc++ code. It's a fundamental building block for applications on Mac OS X (and, as llvm becomes more popular, other systems). And now it's better than it was when we started this exercise.However, we did find a couple bugs in the test suite, and one heap-smashing bug in libc++. We also found a limitation in Address Sanitizer, too - which the developers are working on addressing.<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
- Instruction Relationship Framework in LLVMhttps://blog.llvm.org/2013/03/instruction-relationship-framework-in.htmlWed, 20 Mar 2013 13:42:00 +0000https://blog.llvm.org/2013/03/instruction-relationship-framework-in.htmlThe article provides an overview of the new Relationship framework of TableGen. This TableGen feature is used to describe user defined relationships between instructions. It was added to LLVM in October 2012. <a name='more'></a> <!-- ======================================================================= --><h3 id="Motivation">Motivation:</h3><!-- ======================================================================= --> The motivation for this feature stemmed from the Hexagon backend. Much like other processors, Hexagon provides multiple variations for many instructions. It is a common requirement in machine instruction passes to switch between various formats of the same instruction. For example, consider an <tt>Add</tt> instruction with predicated true (<tt>Add_pt</tt>) and predicated false (<tt>Add_pf</tt>) forms. Let's assume that a non-predicated <tt>Add</tt> instruction is selected during target lowering. However, during if-conversion, the optimization pass might decide to change the non-predicated <tt>Add</tt> into the predicated true <tt>Add_pt</tt> form. These transformations require a framework to relate non-predicated forms to the respective predicated forms. In the absence of such a framework, this transformation is typically achieved using large switch cases. There are many deficiencies in using a switch case based approach. The manual implementation of switch case clauses requires a very high maintenance cost. It also results in lost optimization opportunities due to incomplete implementation of switch cases. The lack of a relationship model resulted in around 15% of Hexagon backend code dedicated to switch cases with several of those functions growing to over thousands of lines of code.<br /><br />This problem inspired us to explore some alternatives. We started to look for a framework that was easy to maintain, flexible, scalable, and less error prone. After some initial discussions and brainstorming in the Hexagon group, we decided to modify TableGen to express instruction relations. The initial design was submitted to the LLVM-dev mailing list for review. Jakob Stoklund gave valuable suggestions and helped with the design of the relationship framework. The idea was to add a query language that can be used to define different kind of relationships between instructions. TableGen was extended to parse relationship models. It uses the information to construct tables which are queried to determine new opcodes corresponding to a relationship. The Hexagon backend relies heavily on the relationship framework and it has significantly improved the code quality of our target.<br /><br />Before getting into the implementation details, let's consider an API that takes an instruction opcode as input and returns its predicated true/false form. We'll first look at the switch-case based solution and then compare it with the relationship based implementation. <br \><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />short getPredicatedTrue(short opcode) {<br />switch (opcode) {<br />default:<br /> return -1;<br />case Hexagon::Add:<br /> return Hexagon::Add_pt;<br />case Hexagon::Sub:<br /> return Hexagon::Sub_pt;<br />case Hexagon::And:<br /> return Hexagon::And_pt;<br />case Hexagon::Or:<br /> return Hexagon::Or_pt;<br />case ... :<br /> return ...<br />}<br /><br />short getPredicatedFalse(short opcode) {<br />switch (opcode) {<br />default:<br /> return -1;<br />case Hexagon::Add:<br /> return Hexagon::Add_pf;<br />case Hexagon::Sub:<br /> return Hexagon::Sub_pf;<br />case Hexagon::And:<br /> return Hexagon::And_pf;<br />case Hexagon::Or:<br /> return Hexagon::Or_pf;<br />case ... :<br /> return ...<br />}<br /><br />short getPredicatedOpcode(short opcode, bool predSense) {<br />return predSense ? getPredicatedTrue(opcode)<br /> : getPredicatedFlase(opcode);<br />}<br /><br /></pre></div> The switch-case based approach becomes quite unwieldy because of the large number of cases. Also, it requires continuous maintenance as new instructions are added. The problem becomes more demanding when an instruction has multiple relations since each of these APIs must be updated.<br /><br />The relationship framework offers a very systematic solution to this problem. It requires instructions to model their attributes and categorize their groups. For instance, a field called 'PredSense' can be used to record whether an instruction is predicated or not and its sense of predication. Each instruction in the group has to be unique such that no two instructions can share all the same attributes. There must be at least one field with different value. The instruction groups are modeled by assigning a common base name to all the instructions in the group. One of the biggest advantages of this approach is that, by modeling these attributes and groups once, we can define multiple relationships with very little effort.<br /><br />With the relationship framework, the <tt>getPredicatedOpcode</tt> API can be implemented as below: <br /><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />short getPredicatedOpcode(short opcode, bool predSense) {<br />return predSense ? getPredicated(opcode, PredSenseTrue)<br /> : getPredicated(opcode, PredSenseFalse);<br />}<br /><br /></pre></div>Here, <tt>getPredicated()</tt> function is automatically generated by the relationship framework. It performs a query into the corresponding relationship table, also generated by the framework, and returns the matching predicated opcode if found.<br /> <!-- ======================================================================= --><h3 id="architecture">Architecture:</h3><!-- ======================================================================= --> The entire framework is driven by a class called <tt>InstrMapping</tt>. The TableGen back-end has been extended to include a new parser for the relationship models implemented using <tt>InstrMapping</tt> class. Any relationship model must derive from this class and assign all the class members to the appropriate values. This is how the class looks like: <br \><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />class InstrMapping {<br /> // Used to reduce search space only to the instructions using this relation model<br /> string FilterClass;<br /><br /> // List of fields/attributes that should be same for all the instructions in<br /> // a row of the relation table. Think of this as a set of properties shared<br /> // by all the instructions related by this relationship.<br /> list<string> RowFields = [];<br /> // List of fields/attributes that are same for all the instructions<br /> // in a column of the relation table.<br /> list<string> ColFields = [];<br /><br /> // Values for the fields/attributes listed in 'ColFields' corresponding to<br /> // the key instruction. This is the instruction that will be transformed<br /> // using this relation model.<br /> list<string> KeyCol = [];<br /><br /> // List of values for the fields/attributes listed in 'ColFields', one for<br /> // each column in the relation table. These are the instructions a key<br /> // instruction will be transformed into.<br /> list<list string=""> > ValueCols = [];<br />}<br /><br /></list></string></string></string></pre></div>Now, let's revisit the <tt>getPredicated</tt> API. As mentioned earlier, this function can be auto-generated by the relationship framework. It requires us to define a relationship model that can relate non-predicated instructions with their predicated forms: <br \><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />def getPredicated : InstrMapping {<br /> // Choose a FilterClass that is used as a base class for all the instructions modeling<br /> // this relationship. This is done to reduce the search space only to these set of instructions.<br /> let FilterClass = "PredRel";<br /><br /> // Instructions with same values for all the fields in RowFields form a row in the resulting<br /> // relation table.<br /> // For example, if we want to relate 'Add' (non-predicated) with 'Add_pt'<br /> // (predicated true) and 'Add_pf' (predicated false), then all 3<br /> // instructions need to have a common base name, i.e., same value for BaseOpcode here. It can be <br /> // any unique value (Ex: XYZ) and should not be shared with any other instruction not related to 'Add'.<br /> let RowFields = ["BaseOpcode"];<br /><br /> // List of attributes that can be used to define key and column instructions for a relation.<br /> // Here, key instruction is passed as an argument to the function used for querying relation tables.<br /> // Column instructions are the instructions they (key) can transform into.<br /> //<br /> // Here, we choose 'PredSense' as ColFields since this is the unique attribute of the key<br /> // (non-predicated) and column (true/false) instructions involved in this relationship model.<br /> let ColFields = ["PredSense"];<br /><br /> // The key column contains non-predicated instructions.<br /> let KeyCol = ["none"];<br /><br /> // Two value columns - first column contains instructions with PredSense=true while the second<br /> // column has instructions with PredSense=false.<br /> let ValueCols = [["true"], ["false"]];<br />}<br /><br /></pre></div>This relationship model is processed and the information is used to construct a table along with the API to query. All this is emitted in the <tt>XXXInstrInfo.inc</tt> file. However, with the changes made so far, we may end up with an empty relation table since we haven't defined <tt>PredSense</tt> and <tt>BaseOpcode</tt> for any of the instructions yet. <br \><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />multiclass ALU32_Pred<string bit="" mnemonic="" prednot=""> {<br /> let <span style="color: royalblue; font-weight: bold;">PredSense = !if(PredNot, "false", "true")</span>, isPredicated = 1 in<br /> def NAME : ALU32_rr<(outs IntRegs:$dst),<br /> (ins PredRegs:$src1, IntRegs:$src2, IntRegs: $src3),<br /> !if(PredNot, "if (!$src1)", "if ($src1)")#<br /> " $dst = "#mnemonic#"($src2, $src3)",<br /> []>;<br />}<br /><br />multiclass ALU32_base<string baseop="" mnemonic="" opnode="" sdnode="" string=""> {<br /> let <span style="color: royalblue; font-weight: bold;">BaseOpcode = BaseOp</span> in {<br /> let isPredicable = 1 in<br /> def NAME : ALU32_rr<(outs IntRegs:$dst),<br /> (ins IntRegs:$src1, IntRegs:$src2),<br /> "$dst = "#mnemonic#"($src1, $src2)",<br /> [(set (i32 IntRegs:$dst), (OpNode (i32 IntRegs:$src1),<br /> (i32 IntRegs:$src2)))]>;<br /><br /> defm pt : ALU32_Pred<mnemonic 0="">; // Predicate true<br /> defm pf : ALU32_Pred<mnemonic 1="">; // Predicate false<br /> }<br />}<br /><br />let isCommutable = 1 in {<br /> defm Add : ALU32_base<"add", "ADD", add>, <span style="color: royalblue; font-weight: bold;">PredRel</span>;<br /> defm And : ALU32_base<"and", "AND", and>, <span style="color: royalblue; font-weight: bold;">PredRel</span>;<br /> defm Xor: ALU32_base<"xor", "XOR", xor>, <span style="color: royalblue; font-weight: bold;">PredRel</span>;<br /> defm Or : ALU32_base<"or", "OR", or>, <span style="color: royalblue; font-weight: bold;">PredRel</span>;<br />}<br />defm Sub : ALU32_base<"sub", "SUB", sub>, <span style="color: royalblue; font-weight: bold;">PredRel</span>;<br /><br /></mnemonic></mnemonic></string></string></pre></div>Fields highlighted in blue are solely for the purpose of Relationship framework. Here, <tt>PredRel</tt> is a filter class used to extract instructions that may be related using <tt>getPredicated</tt> relationship model. All the instructions using this model are expected to derive from <tt>PreRel</tt> class. <tt>BaseOpcode</tt> is used to group related instructions together. In the above example, all the variants of <tt>Add</tt> instruction, <tt>Add, Add_pt, Add_pf</tt> will have their BaseOpcode set to <tt>ADD</tt>. Similarly, <tt>BaseOpcode</tt> for all the variants for <tt>Sub</tt> is set to <tt>SUB</tt>. It can be any string unique across all groups. <tt>PredSense</tt> is used to identify instructions within each group.<br /><br />With the help of this extra information, TableGen is able to construct the following API. It offers the same functionality as switch-case based approach and significantly reduces the maintenance overhead: <br \><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />int getPredicated(uint16_t Opcode, enum PredSense inPredSense) {<br />static const uint16_t getPredicatedTable[][3] = {<br /> { Hexagon::Add, Hexagon::Add_pt, Hexagon::Add_pf },<br /> { Hexagon::And, Hexagon::And_pt, Hexagon::And_pf },<br /> { Hexagon::Or, Hexagon::Or_pt, Hexagon::Or_pf },<br /> { Hexagon::Sub, Hexagon::Sub_pt, Hexagon::Sub_pf },<br /> { Hexagon::Xor, Hexagon::Xor_pt, Hexagon::Xor_pf },<br />}; // End of getPredicatedTable<br /><br /> unsigned mid;<br /> unsigned start = 0;<br /> unsigned end = 5;<br /> while (start < end) {<br /> mid = start + (end - start)/2;<br /> if (Opcode == getPredicatedTable[mid][0]) {<br /> break;<br /> }<br /> if (Opcode < getPredicatedTable[mid][0])<br /> end = mid;<br /> else<br /> start = mid + 1;<br /> }<br /> if (start == end)<br /> return -1; // Instruction doesn't exist in this table.<br /><br /> if (inPredSense == PredSense_true)<br /> return getPredOpcodeTable[mid][1];<br /> if (inPredSense == PredSense_false)<br /> return getPredicatedTable[mid][2];<br /> return -1;<br />}<br /><br /></pre></div>Once instructions have been defined to appropriately model their properties, defining new instruction mappings become extremely easy. Now, say we want to have an API that allows us to transform a <tt>predicate-true</tt> instruction into its <tt>predicate-false</tt> form. This can be done by defining a new relationship model. For this model, we don't have to modify any of the instruction definitions as they already have all the necessary information present. <br \><div class="highlight" style="background: #ffffff;"><pre style="line-height: 150%;"><br /><br />//===------------------------------------------------------------------===//<br />// Generate mapping table to relate predicate-true instructions with their<br />// predicate-false forms<br />//<br />def getFalsePredOpcode : InstrMapping {<br /> let FilterClass = "PredRel";<br /> let RowFields = ["BaseOpcode"];<br /> let ColFields = ["PredSense"];<br /> let KeyCol = ["true"];<br /> let ValueCols = [["false"]];<br />}<br /><br /></pre></div> <!-- ======================================================================= --><h3 id="conclusion">Conclusion:</h3><!-- ======================================================================= --> I hope this article succeeds in providing some useful information about the framework. The Hexagon backend makes extensive use of this feature and can be used as a reference for getting started on relationship framework.
- New Loop Vectorizerhttps://blog.llvm.org/2012/12/new-loop-vectorizer.htmlFri, 07 Dec 2012 10:12:00 +0000https://blog.llvm.org/2012/12/new-loop-vectorizer.htmlI would like to give a brief update regarding the development of the Loop Vectorizer. LLVM now has two vectorizers: The Loop Vectorizer, which operates on Loops, and the <a href="http://llvm.org/devmtg/2012-04-12/Slides/Hal_Finkel.pdf">Basic Block Vectorizer</a>, which optimizes straight-line code. These vectorizers focus on different optimization opportunities and use different techniques. The BB vectorizer merges multiple scalars that are found in the code into vectors while the Loop Vectorizer widens instructions in the original loop to operate on multiple consecutive loop iterations. <br /><a name='more'></a><br />LLVMâs Loop Vectorizer is now available and will be useful for many people. It is not enabled by default, but can be enabled through clang using the command line flag <b>"-mllvm -vectorize-loops"</b>. We plan to enable the Loop Vectorizer by default as part of the LLVM 3.3 release. <br /><br />The Loop Vectorizer can boost the performance of many loops, including some loops that are not vectorizable by GCC. In one benchmark, Linpack-pc, the Loop Vectorizer boosts the performance of gaussian elimination of single precision matrices from 984 MFlops to 2539 MFlops - a 2.6X boost in performance. The vectorizer also boosts the âGCC vectorization examplesâ <a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/Vectorizer/">benchmark</a> by a geomean of 2.15X.<br /><br />The LLVM Loop Vectorizer has a number of features that allow it to vectorize complex loops. Most of the features described in this post are available as part of the LLVM 3.2 release, but some features were added after the cutoff date. Here is one small example of a loop that the LLVM Loop Vectorizer can vectorize. <br /><pre style="background: #ffffff; color: black;"><br /><span style="color: maroon; font-weight: bold;">int</span> foo<span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span>A<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span>B<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> n<span style="color: #808030;">)</span> <span style="color: purple;">{</span><br /> <span style="color: maroon; font-weight: bold;">unsigned</span> sum <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: purple;">;</span><br /> <span style="color: maroon; font-weight: bold;">for</span> <span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> i <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: purple;">;</span> i <span style="color: #808030;"><</span> n<span style="color: purple;">;</span> <span style="color: #808030;">+</span><span style="color: #808030;">+</span>i<span style="color: #808030;">)</span><br /> <span style="color: maroon; font-weight: bold;">if</span> <span style="color: #808030;">(</span>A<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span> <span style="color: #808030;">></span> B<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span><span style="color: #808030;">)</span><br /> sum <span style="color: #808030;">+</span><span style="color: #808030;">=</span> A<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span> <span style="color: #808030;">+</span> <span style="color: #008c00;">5</span><span style="color: purple;">;</span><br /> <span style="color: maroon; font-weight: bold;">return</span> sum<span style="color: purple;">;</span><br /><span style="color: purple;">}</span><br /></pre><br />In this example, the Loop Vectorizer uses a number of non-trivial features to vectorize the loop. The âsumâ variable is used by consecutive iterations of the loop. Normally, this would prevent vectorization, but the vectorizer can detect that âsumâ is a reduction variable. The variable âsumâ becomes a vector of integers, and at the end of the loop the elements of the array are added together to create the correct result. We support a number of different reduction operations, such as multiplication.<br/><br/> Another challenge that the Loop Vectorizer needs to overcome is the presence of control flow in the loop. The Loop Vectorizer is able to "flatten" the IF statement in the code and generate a single stream of instructions. Another important feature is the vectorization of loops with an unknown trip count. In this example, ânâ may not be a multiple of the vector width, and the vectorizer has to execute the last few iterations as scalar code. Keeping a scalar copy of the loop increases the code size. <br/>The loop above is compiled into the ARMv7s assembly sequence below. Notice that the IF structure is replaced by the "vcgt" and "vbsl" instructions.<br /><br /><pre style='color:#000000;background:#ffffff;'><span style='color:#e34adc; '>LBB0_3:</span><br /> vld1.32 <span style='color:#808030; '>{</span>d26<span style='color:#808030; '>,</span> d27<span style='color:#808030; '>}</span><span style='color:#808030; '>,</span> <span style='color:#808030; '>[</span>r3<span style='color:#808030; '>]</span><br /> vadd.i32 q12<span style='color:#808030; '>,</span> q8<span style='color:#808030; '>,</span> q9<br /> subs r2<span style='color:#808030; '>,</span> #<span style='color:#008c00; '>4</span><br /> add.w r3<span style='color:#808030; '>,</span> r3<span style='color:#808030; '>,</span> #<span style='color:#008c00; '>16</span><br /> vcgt.s32 q0<span style='color:#808030; '>,</span> q13 <span style='color:#808030; '>,</span> q10<br /> vmla.i32 q12<span style='color:#808030; '>,</span> q13<span style='color:#808030; '>,</span> q11<br /> vbsl q0<span style='color:#808030; '>,</span> q12<span style='color:#808030; '>,</span> q8<br /> vorr q8<span style='color:#808030; '>,</span> q0<span style='color:#808030; '>,</span> q0<br /> bne <span style='color:#e34adc; '>LBB0_3</span><br /></pre> <br />In the second example below, the Loop Vectorizer must use two more features in order to vectorize the loop. In the loop below, the iteration start and finish points are unknown, and the Loop Vectorizer has a mechanism to vectorize loops that do not start at zero. This feature is important for loops that are converted from Fortran, because Fortran loops start at 1. <br />Another major challenge in this loop is memory safety. In our example, if the pointers A and B point to consecutive addresses, then it is illegal to vectorize the code because some elements of A will be written before they are read from array B.<br /><br />Some programmers use the 'restrict' keyword to notify the compiler that the pointers are disjointed, but in our example, the Loop Vectorizer has no way of knowing that the pointers A and B are unique. The Loop Vectorizer handles this loop by placing code that checks, at runtime, if the arrays A and B point to disjointed memory locations. If arrays A and B overlap, then the scalar version of the loop is executed. <br /><pre style="background: #ffffff; color: black;"><br /><span style="color: maroon; font-weight: bold;">void</span> bar<span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">float</span> <span style="color: #808030;">*</span>A<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">float</span> <span style="color: #808030;">*</span>B<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">float</span> K<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> start<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> end<span style="color: #808030;">)</span> <span style="color: purple;">{</span><br /> <span style="color: maroon; font-weight: bold;">for</span> <span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> i <span style="color: #808030;">=</span> start<span style="color: purple;">;</span> i <span style="color: #808030;"><</span> end<span style="color: purple;">;</span> <span style="color: #808030;">+</span><span style="color: #808030;">+</span>i<span style="color: #808030;">)</span><br /> A<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span> <span style="color: #808030;">*</span><span style="color: #808030;">=</span> B<span style="color: #808030;">[</span>i<span style="color: #808030;">]</span> <span style="color: #808030;">+</span> K<span style="color: purple;">;</span><br /><span style="color: purple;">}</span><br /></pre><br />The loop above is compiled into this X86 assembly sequence. Notice the use of the 8-wide YMM registers on systems that support AVX.<br /><br /><pre style="background: #ffffff; color: black;"><br /><span style="color: #e34adc;">LBB1_4:</span><br /> vmovups <span style="color: #808030;">(</span><span style="color: #808030;">%</span>rdx<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>ymm2<br /> vaddps <span style="color: #808030;">%</span>ymm1<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>ymm2<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>ymm2<br /> vmovups <span style="color: #808030;">(</span><span style="color: #808030;">%</span>rax<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>ymm3<br /> vmulps <span style="color: #808030;">%</span>ymm2<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>ymm3<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>ymm2<br /> vmovups <span style="color: #808030;">%</span>ymm2<span style="color: #808030;">,</span> <span style="color: #808030;">(</span><span style="color: #808030;">%</span>rax<span style="color: #808030;">)</span><br /> addq <span style="color: green;">$32</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>rax<br /> addq <span style="color: green;">$32</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>rdx<br /> addq $<span style="color: #008c00;">-8</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>r1<span style="color: #008c00;">1</span><br /><span style="color: maroon; font-weight: bold;"> jne</span> <span style="color: #e34adc;">LBB1_4</span><br /></pre><br />In the last example, we donât see a loop because it is hidden inside the "accumulate" function of the standard c++ library. This loop uses c++ iterators, which are pointers, and not integer indices, like we saw in the previous examples. The Loop Vectorizer detects pointer induction variables and can vectorize this loop. This feature is important because many C++ programs use iterators.<br /><pre style="background: #ffffff; color: black;"><br /><span style="color: maroon; font-weight: bold;">int</span> baz<span style="color: #808030;">(</span><span style="color: maroon; font-weight: bold;">int</span> <span style="color: #808030;">*</span>A<span style="color: #808030;">,</span> <span style="color: maroon; font-weight: bold;">int</span> n<span style="color: #808030;">)</span> <span style="color: purple;">{</span><br /> <span style="color: maroon; font-weight: bold;">return</span> std<span style="color: purple;">::</span>accumulate<span style="color: #808030;">(</span>A<span style="color: #808030;">,</span> A <span style="color: #808030;">+</span> n<span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: purple;">;</span><br /><span style="color: purple;">}</span><br /></pre>The loop above is compiled into this x86 assembly sequence. <br /><pre style="background: #ffffff; color: black;"><br /><span style="color: #e34adc;">LBB2_8:</span><br /> vmovdqu <span style="color: #808030;">(</span><span style="color: #808030;">%</span>rcx<span style="color: #808030;">,</span><span style="color: #808030;">%</span>rdx<span style="color: #808030;">,</span><span style="color: #008c00;">4</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span><span style="color: navy;">xmm1</span><br /> vpaddd <span style="color: #808030;">%</span><span style="color: navy;">xmm0</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span><span style="color: navy;">xmm1</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span><span style="color: navy;">xmm0</span><br /> addq <span style="color: green;">$4</span><span style="color: #808030;">,</span> <span style="color: #808030;">%</span>rdx<br /> cmpq <span style="color: #808030;">%</span>rdx<span style="color: #808030;">,</span> <span style="color: #808030;">%</span>rsi<br /><span style="color: maroon; font-weight: bold;"> jne</span> <span style="color: #e34adc;">LBB2_8</span><br /></pre><br/> The Loop Vectorizer is a target independent IR-level optimization that depends on target-specific information from the different backends. It needs to select the optimal vector width and to decide if vectorization is worthwhile. Users can force a certain vector width using the command line flag <b>"-mllvm -force-vector-width=X"</b>, where X is the number of vector elements. At the moment, only the X86 backend provides detailed cost information, while other targets use a less accurate method. <br/>The work on the Loop Vectorizer is not complete and the vectorizer has a long way to go. We plan to add additional vectorization features such as automatic alignment of buffers, vectorization of function calls and support for user pragmas. We also plan to improve the quality of the generated code. <br/> <br/>
- LLVM Developer Meeting 2012https://blog.llvm.org/2012/12/llvm-developer-meeting-2012.htmlWed, 05 Dec 2012 19:45:00 +0000https://blog.llvm.org/2012/12/llvm-developer-meeting-2012.htmlThe <a href="http://llvm.org/devmtg/2012-11/">2012 LLVM Developer Meeting</a> is now complete and was a great success. If you are interested in the talks, a complete set of <a href="http://llvm.org/devmtg/2012-11/">slides, videos, and posters</a> are now available. The LLVM Developer Meeting would not be possible without support from our sponsors. Many thanks to Apple, QuIC, Google, and Intel. -Chris
- Life of an instruction in LLVMhttps://blog.llvm.org/2012/11/life-of-instruction-in-llvm.htmlWed, 28 Nov 2012 15:31:00 +0000https://blog.llvm.org/2012/11/life-of-instruction-in-llvm.html<br />LLVM is a complex piece of software. There are several paths one may take on the quest of understanding how it works, none of which is simple. I recently had to dig in some areas of LLVM I was not previously familiar with, and this article is one of the outcomes of this quest.<br /><br />What I aim to do here is follow the various incarnations an "instruction" takes when it goes through LLVMâs multiple compilation stages, starting from a syntactic construct in the source language and until being encoded as binary machine code in an output object file.<br /><br />This article in itself will not teach one how LLVM works. It assumes some existing familiarity with LLVMâs design and code base, and leaves a lot of "obvious" details out. Note that unless otherwise stated, the information here is relevant to LLVM 3.2. LLVM and Clang are fast-moving projects, and future changes may render parts of this article incorrect. If you notice any discrepancies, please let me know and Iâll do my best to fix them.<br /><br /><a name='more'></a><br /><div class="section" id="input-code"><h3>Input code</h3>I want to start this exploration process at the beginning â C source. Hereâs the simple function weâre going to work with:<br /><br /><div class="highlight" style="background: #ffffff;"><pre style="line-height: 125%;"><span style="font-size: small;"><br /><span style="color: #00007f; font-weight: bold;">int</span> <span style="color: #00007f;">foo</span>(<span style="color: #00007f; font-weight: bold;">int</span> aa, <span style="color: #00007f; font-weight: bold;">int</span> bb, <span style="color: #00007f; font-weight: bold;">int</span> cc) {<br /> <span style="color: #00007f; font-weight: bold;">int</span> sum = aa + bb;<br /> <span style="color: #00007f; font-weight: bold;">return</span> sum / cc;<br />}</span><br /></pre></div><br />The focus of this article is going to be on the division operation.</div><div class="section" id="clang"><h3>Clang</h3>Clang serves as the front-end for LLVM, responsible for converting C, C++ and ObjC source into LLVM IR. Clangâs main complexity comes from the ability to correctly parse and semantically analyze C++; the flow for a simple C-level operation is actually quite straightforward.<br /><br />Clangâs parser builds an Abstract Syntax Tree (AST) out of the input. The AST is the main "currency" in which various parts of Clang deal. For our division operation, a <tt class="docutils literal">BinaryOperator</tt> node is created in the AST, carrying the <tt class="docutils literal">BO_div</tt> "operator kind". Clangâs code generator then goes on to emit a <tt class="docutils literal">sdiv</tt> LLVM IR instruction from the node, since this is a division of signed integral types.<br /><div class="section" id="llvm-ir"><h3>LLVM IR</h3>Here is the LLVM IR created for the function:<br /><br /><div class="highlight" style="background: #ffffff;"><pre style="line-height: 125%;">define i32 @foo(i32 %aa, i32 %bb, i32 %cc) nounwind {<br />entry:<br /> %add = add nsw i32 %aa, %bb<br /> %div = sdiv i32 %add, %cc<br /> ret i32 %div<br />}<br /></pre></div><br />In LLVM IR, <tt class="docutils literal">sdiv</tt> is a <tt class="docutils literal">BinaryOperator</tt>, which is a subclass of <tt class="docutils literal">Instruction</tt> with the opcode <tt class="docutils literal">SDiv</tt>. Like any other instruction, it can be processed by the LLVM analysis and transformation passes. For a specific example targeted at <tt class="docutils literal">SDiv</tt>, take a look at <tt class="docutils literal">SimplifySDivInst</tt>. Since all through the LLVM "middle-end" layer the instruction remains in its IR form, I wonât spend much time talking about it. To witness its next incarnation, weâll have to look at the LLVM code generator.<br /><br />The code generator is one of the most complex parts of LLVM. Its task is to "lower" the relatively high-level, target-independent LLVM IR into low-level, target-dependent "machine instructions" (<tt class="docutils literal">MachineInstr</tt>). On its way to a <tt class="docutils literal">MachineInstr</tt>, an LLVM IR instruction passes through a "selection DAG node" incarnation, which is what Iâm going to discuss next.</div></div><h3>SelectionDAG node</h3>Selection DAG nodes are created by the <tt class="docutils literal">SelectionDAGBuilder</tt> class acting "in the service of" <tt class="docutils literal">SelectionDAGISel</tt>, which is the main base class for instruction selection. <tt class="docutils literal">SelectionDAGISel</tt> goes over all the IR instructions and calls the <tt class="docutils literal"><span class="pre">SelectionDAGBuilder::visit</span></tt> dispatcher on them. The method handling a <tt class="docutils literal">SDiv</tt> instruction is <tt class="docutils literal"><span class="pre">SelectionDAGBuilder::visitSDiv</span></tt>. It requests a new <tt class="docutils literal">SDNode</tt> from the DAG with the opcode <tt class="docutils literal"><span class="pre">ISD::SDIV</span></tt>, which becomes a node in the DAG.<br /><br />The initial DAG constructed this way is still only partially target dependent. In LLVM nomenclature itâs called "illegal" â the types it contains may not be directly supported by the target; the same is true for the operations it contains.<br /><br />There are a couple of ways to visualize the DAG. One is to pass the <tt class="docutils literal"><span class="pre">-debug</span></tt> flag to <tt class="docutils literal">llc</tt>, which will cause it to create a textual dump of the DAG during all the selection phases. Another is to pass one of the <tt class="docutils literal"><span class="pre">-view</span></tt> options which causes it to dump and display an actual image of the graph (more details in the <a class="reference external" href="http://llvm.org/docs/CodeGenerator.html">code generator docs</a>). Hereâs the relevant portion of the DAG showing our <tt class="docutils literal">SDiv</tt> node, right after DAG creation (the <tt class="docutils literal">sdiv</tt> node is in the bottom):<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-SjbbSsuPKbo/ULTDEf2o5hI/AAAAAAAAAgM/CmQd_eeGowY/s1600/sdiv_initial_dag.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-SjbbSsuPKbo/ULTDEf2o5hI/AAAAAAAAAgM/CmQd_eeGowY/s1600/sdiv_initial_dag.png" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"></div><br /><br />Before the <tt class="docutils literal">SelectionDAG</tt> machinery actually emits machine instructions from DAG nodes, these undergo a few other transformations. The most important are the type and operation legalization steps, which use target-specific hooks to convert all operations and types into ones that the target actually supports.<br /><h3>"Legalizing" sdiv into sdivrem on x86</h3>The division instruction (<tt class="docutils literal">idiv</tt> for signed operands) of x86 computes both the quotient and the remainder of the operation, and stores them in two separate registers. Since LLVMâs instruction selection distinguishes between such operations (called <tt class="docutils literal"><span class="pre">ISD::SDIVREM</span></tt>) and division that only computes the quotient (<tt class="docutils literal"><span class="pre">ISD::SDIV</span></tt>), our DAG node will be "legalized" during the DAG legalization phase when the target is x86. Hereâs how it happens.<br /><br />An important interface used by the code generator to convey target-specific information to the generally target-independent algorithms is <tt class="docutils literal">TargetLowering</tt>. Targets implement this interface to describe how LLVM IR instructions should be lowered to legal <tt class="docutils literal">SelectionDAG</tt> operations. The x86 implementation of this interface is <tt class="docutils literal">X86TargetLowering</tt>. In its constructor it marks which operations need to be "expanded" by operation legalization, and <tt class="docutils literal"><span class="pre">ISD::SDIV</span></tt> is one of them. Hereâs an interesting comment from the code:<br /><br /><div class="highlight" style="background: #ffffff;"><pre style="line-height: 125%;"><span style="color: #007f00;"><br />// Scalar integer divide and remainder are lowered to use operations that</span><br /><span style="color: #007f00;">// produce two results, to match the available instructions. This exposes</span><br /><span style="color: #007f00;">// the two-result form to trivial CSE, which is able to combine x/y and x%y</span><br /><span style="color: #007f00;">// into a single instruction.</span><br /></pre></div> <br />When <tt class="docutils literal"><span class="pre">SelectionDAGLegalize::LegalizeOp</span></tt> sees the <tt class="docutils literal">Expand</tt> flag on a SDIV node it replaces it by <tt class="docutils literal"><span class="pre">ISD::SDIVREM</span></tt>. This is an interesting example to demonstrate the transformation an operation can undergo while in the selection DAG form.<br /><br />Here is the relevant portion of the DAG after legalization:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-4Hr-DU4FbR0/ULTCadxhrgI/AAAAAAAAAgE/hzLJ9YqVdT4/s1600/sdivrem_legal_dag.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-4Hr-DU4FbR0/ULTCadxhrgI/AAAAAAAAAgE/hzLJ9YqVdT4/s1600/sdivrem_legal_dag.png" /></a></div><br /><div class="section" id="instruction-selection-from-sdnode-to-machinesdnode"><h3>Instruction selection â from SDNode to MachineSDNode</h3>The next step in the code generation process is <i>instruction selection</i>. LLVM provides a generic table-based instruction selection mechanism that is auto-generated with the help of TableGen. Many target backends, however, choose to write custom code in their <tt class="docutils literal"><span class="pre">SelectionDAGISel::Select</span></tt> implementations to handle some instructions manually. Other instructions are then sent to the auto-generated selector by calling <tt class="docutils literal">SelectCode</tt>.<br /><br />The X86 backend handles <tt class="docutils literal"><span class="pre">ISD::SDIVREM</span></tt> manually in order to take care of some special cases and optimizations. The DAG node created at this step is a <tt class="docutils literal">MachineSDNode</tt>, a subclass of <tt class="docutils literal">SDNode</tt> which holds the information required to construct an actual machine instruction, but still in DAG node form. At this point the actual X86 instruction opcode is selected â <tt class="docutils literal"><span class="pre">X86::IDIV32r</span></tt> in our case.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-odnuGpLx3EA/ULTEEYSivqI/AAAAAAAAAgU/bcQZtTPOw2c/s1600/idiv_after_isel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-odnuGpLx3EA/ULTEEYSivqI/AAAAAAAAAgU/bcQZtTPOw2c/s1600/idiv_after_isel.png" /></a></div></div><h3>Scheduling and emitting a MachineInstr</h3>The code we have at this point is still represented as a DAG. But CPUs donât execute DAGs, they execute a linear sequence of instructions. The goal of the scheduling step is to linearize the DAG by assigning an order to its operations (nodes). The simplest approach would be to just sort the DAG topologically, but LLVMâs code generator employs clever heuristics (such as register pressure reduction) to try and produce a schedule that would result in faster code.<br />Each target has some hooks it can implement to affect the way scheduling is done. I won't dwell on this topic here, however.<br /><br />Finally, the scheduler emits a list of instructions into a <tt class="docutils literal">MachineBasicBlock</tt>, using <tt class="docutils literal"><span class="pre">InstrEmitter::EmitMachineNode</span></tt> to translate from <tt class="docutils literal">SDNode</tt>. The instructions here take the <tt class="docutils literal">MachineInstr</tt> form ("MI form" from now on), and the DAG can be destroyed.<br />We can examine the machine instructions emitted in this step by calling <tt class="docutils literal">llc</tt> with the <tt class="docutils literal"><span class="pre">-print-machineinstrs</span></tt> flag and looking at the first output that says "After instruction selection":<br /><br /><pre style="line-height: 125%;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"><br /># After Instruction Selection:<br /># Machine code for function foo: SSA<br />Function Live Ins: %EDI in %vreg0, %ESI in %vreg1, %EDX in %vreg2<br />Function Live Outs: %EAX<br /><br />BB#0: derived from LLVM BB %entry<br /> Live Ins: %EDI %ESI %EDX<br /> %vreg2<def> = COPY %EDX; GR32:%vreg2<br /> %vreg1<def> = COPY %ESI; GR32:%vreg1<br /> %vreg0<def> = COPY %EDI; GR32:%vreg0<br /> %vreg3<def,tied1> = ADD32rr %vreg0<tied0>, %vreg1, %EFLAGS<imp-def,dead>; GR32:%vreg3,%vreg0,%vreg1<br /> %EAX<def> = COPY %vreg3; GR32:%vreg3<br /> CDQ %EAX<imp-def>, %EDX<imp-def>, %EAX<imp-use><br /> IDIV32r %vreg2, %EAX<imp-def>, %EDX<imp-def,dead>, %EFLAGS<imp-def,dead>, %EAX<imp-use>, %EDX<imp-use>; GR32:%vreg2<br /> %vreg4<def> = COPY %EAX; GR32:%vreg4<br /> %EAX<def> = COPY %vreg4; GR32:%vreg4<br /> RET<br /><br /># End machine code for function foo.<br /></span></span></pre><pre style="line-height: 125%;"> </pre>Note that the output mentions that the code is in SSA form, and we can see that some registers being used are "virtual" registers (e.g. <tt class="docutils literal">%vreg1</tt>).<br /><div class="section" id="register-allocation-from-ssa-to-non-ssa-machine-instructions"><h3>Register allocation â from SSA to non-SSA machine instructions</h3>Apart from some well-defined exceptions, the code generated from the instruction selector is in SSA form. In particular, it assumes it has an infinite set of "virtual" registers to act on. This, of course, isnât true. Therefore, the next step of the code generator is to invoke a "register allocator", whose task is to replace virtual by physical registers, from the targetâs register bank.<br /><br />The exceptions mentioned above are also important and interesting, so letâs talk about them a bit more.<br /><br />Some instructions in some architectures require fixed registers. A good example is our division instruction in x86, which requires its inputs to be in the EDX and EAX registers. The instruction selector knows about these restrictions, so as we can see in the code above, the inputs to <tt class="docutils literal">IDIV32r</tt> are physical, not virtual registers. This assignment is done by <tt class="docutils literal"><span class="pre">X86DAGToDAGISel::Select</span></tt>.<br /><br />The register allocator takes care of all the non-fixed registers. There are a few more optimization (and pseudo-instruction expansion) steps that happen on machine instructions in SSA form, but Iâm going to skip these. Similarly, Iâm not going to discuss the steps performed after register allocation, since these donât change the basic form operations appear in (<tt class="docutils literal">MachineInstr</tt>, at this point). If youâre interested, take a look at <tt class="docutils literal"><span class="pre">TargetPassConfig::addMachinePasses</span></tt>.<br /><br />Here's the MIs dumped after register allocation:<br /><br /><pre style="line-height: 125%;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"><br /># After Virtual Register Rewriter:<br /># Machine code for function foo: Post SSA<br />Function Live Ins: %EDI in %vreg0, %ESI in %vreg1, %EDX in %vreg2<br />Function Live Outs: %EAX<br /><br />0B BB#0: derived from LLVM BB %entry<br /> Live Ins: %EDI %ESI %EDX<br />16B %ECX<def> = COPY %EDX<br />64B %EAX<def> = LEA64_32r %EDI<kill>, 1, %ESI<kill>, 0, %noreg<br />96B CDQ %EAX<imp-def>, %EDX<imp-def>, %EAX<imp-use><br />112B IDIV32r %ECX<kill>, %EAX<imp-def>, %EDX<imp-def dead="dead">, %EFLAGS<imp-def dead="dead">, %EAX<imp-use>, %EDX<imp-use><br />160B RET %EAX<imp-use><br /><br /># End machine code for function foo.<br /></imp-use></imp-use></imp-use></imp-def></imp-def></imp-def></kill></imp-use></imp-def></imp-def></kill></kill></def></def></span></span></pre><br /></div><div class="section" id="emitting-code"><h3>Emitting code</h3>So we now have our original C function translated to MI form â a <tt class="docutils literal">MachineFunction</tt> filled with instruction objects (<tt class="docutils literal">MachineInstr</tt>). This is the point at which the code generator has finished its job and we can emit the code. In current LLVM, there are two ways to do that. One is the (legacy) JIT which emits executable, ready-to-run code directly into memory. The other is MC, which is an ambitious object-file-and-assembly framework thatâs been part of LLVM for a couple of years, replacing the previous assembly generator. MC is currently being used for assembly and object file emission for all (or at least the important) LLVM targets. MC also enables "MCJIT", which is a JIT-ting framework based on the MC layer. This is why Iâm referring to LLVMâs JIT module as legacy.<br /><br />I will first say a few words about the legacy JIT and then turn to MC, which is more universally interesting.<br /><br />The sequence of passes to JIT-emit code is defined by <tt class="docutils literal"><span class="pre">LLVMTargetMachine::addPassesToEmitMachineCode</span></tt>. It calls <tt class="docutils literal">addPassesToGenerateCode</tt>, which defines all the passes required to do what most of this article has been talking about until now â turning IR into MI form. Next, it calls <tt class="docutils literal">addCodeEmitter</tt>, which is a target-specific pass for converting MIs into actual machine code. Since MIs are already very low-level, itâs fairly straightforward to translate them to runnable machine code. The x86 code for that lives in <tt class="docutils literal">lib/Target/X86/X86CodeEmitter.cpp</tt>. For our division instruction thereâs no special handling here, because the <tt class="docutils literal">MachineInstr</tt> itâs packaged in already contains its opcode and operands. It is handled generically with other instructions in <tt class="docutils literal">emitInstruction</tt>.</div><h3>MCInst</h3>When LLVM is used as a static compiler (as part of <tt class="docutils literal">clang</tt>, for instance), MIs are passed down to the MC layer which handles the object-file emission (it can also emit textual assembly files). Much can be said about MC, but that would require an article of its own. A good reference is <a class="reference external" href="http://blog.llvm.org/2010/04/intro-to-llvm-mc-project.html">this post from the LLVM blog</a>. I will keep focusing on the path a single instruction takes.<br /><br /><tt class="docutils literal"><span class="pre">LLVMTargetMachine::addPassesToEmitFile</span></tt> is responsible for defining the sequence of actions required to emit an object file. The actual MI-to-<tt class="docutils literal">MCInst</tt> translation is done in the <tt class="docutils literal">EmitInstruction</tt> of the <tt class="docutils literal">AsmPrinter</tt> interface. For x86, this method is implemented by <tt class="docutils literal"><span class="pre">X86AsmPrinter::EmitInstruction</span></tt>, which delegates the work to the <tt class="docutils literal">X86MCInstLower</tt> class. Similarly to the JIT path, there is no special handling for our division instruction at this point, and itâs treated generically with other instructions.<br /><br />By passing <tt class="docutils literal"><span class="pre">-show-mc-inst</span></tt> and <tt>-show-mc-encoding</tt> to <tt class="docutils literal">llc</tt>, we can see the MC-level instructions it creates with their encoding, alongside the actual assembly code:<br /><br /><pre style="line-height: 125%;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"><br />foo: # @foo<br /># BB#0: # %entry<br /> movl %edx, %ecx # encoding: [0x89,0xd1]<br /> # <MCInst #1483 MOV32rr<br /> # <MCOperand Reg:46><br /> # <MCOperand Reg:48>><br /> leal (%rdi,%rsi), %eax # encoding: [0x8d,0x04,0x37]<br /> # <MCInst #1096 LEA64_32r<br /> # <MCOperand Reg:43><br /> # <MCOperand Reg:110><br /> # <MCOperand Imm:1><br /> # <MCOperand Reg:114><br /> # <MCOperand Imm:0><br /> # <MCOperand Reg:0>><br /> cltd # encoding: [0x99]<br /> # <MCInst #352 CDQ><br /> idivl %ecx # encoding: [0xf7,0xf9]<br /> # <MCInst #841 IDIV32r<br /> # <MCOperand Reg:46>><br /> ret # encoding: [0xc3]<br /> # <MCInst #2227 RET><br />.Ltmp0:<br /> .size foo, .Ltmp0-foo<br /></span></span></pre><br /><br />The object file (or assembly code) emission is done by implementing the <tt class="docutils literal">MCStreamer</tt> interface. Object files are emitted by <tt class="docutils literal">MCObjectStreamer</tt>, which is further subclassed according to the actual object file format. For example, ELF emission is implemented in <tt class="docutils literal">MCELFStreamer</tt>. The rough path a <tt class="docutils literal">MCInst</tt> travels through the streamers is <tt class="docutils literal"><span class="pre">MCObjectStreamer::EmitInstruction</span></tt> followed by a format-specific <tt class="docutils literal">EmitInstToData</tt>. The final emission of the instruction in binary form is, of course, target-specific. Itâs handled by the <tt class="docutils literal">MCCodeEmitter</tt> interface (for example <tt class="docutils literal">X86MCCodeEmitter</tt>). While in the rest of LLVM code is often tricky because it has to make a separation between target-independent and target-specific capabilities, MC is even more challenging because it adds another dimension â different object file formats. So some code is completely generic, some code is format-dependent, and some code is target-dependent.<br /><h3>Assemblers and disassemblers</h3>A <tt class="docutils literal">MCInst</tt> is deliberately a very simple representation. It tries to shed as much semantic information as possible, keeping only the instruction opcode and list of operands (and a source location for assembler diagnostics). Like LLVM IR, itâs an internal representation will multiple possible encodings. The two most obvious are assembly (as shown above) and binary object files.<br /><br /><tt class="docutils literal"><span class="pre">llvm-mc</span></tt> is a tool that uses the MC framework to implement assemblers and disassemblers. Internally, <tt class="docutils literal">MCInst</tt> is the representation used to translate between the binary and textual forms. At this point the tool doesnât care which compiler produced the assembly / object file.<br /><br /><h3>Conclusion</h3><br />Presenting a "big picture" view of a complex system as LLVM isn't easy. I hope that this article succeeds in giving some clues about the internal workings of LLVM in a way that is useful for further exploration. <br /><pre style="line-height: 125%;"> </pre><i>[This article is re-posted in a slightly expanded form <a href="http://eli.thegreenplace.net/2012/11/24/life-of-an-instruction-in-llvm/">from here</a>]</i><br /><br /><br />
- LLVM Developer Meeting 2011https://blog.llvm.org/2012/01/llvm-developer-meeting-2011.htmlTue, 03 Jan 2012 12:44:00 +0000https://blog.llvm.org/2012/01/llvm-developer-meeting-2011.htmlThe <a href="http://www.llvm.org/devmtg/2011-11/">2011 LLVM Devloper Meeting</a> has come and gone, and it was a great event. It featured 17 great talks, several BOF sessions, a poster session, and lots of informal discussions between all sorts of people interested in LLVM and its subprojects. If you are interested in the talks, <a href="http://www.llvm.org/devmtg/2011-11/">slides and videos</a> are now available.<p> The Developer Meeting would not be possible without support from our sponsors. Many thanks to QuIC, Apple and Google.<p> Happy 2012!<p> -Chris
- NVIDIA CUDA 4.1 Compiler Now Built on LLVMhttps://blog.llvm.org/2011/12/nvidia-cuda-41-compiler-now-built-on.htmlMon, 19 Dec 2011 14:28:00 +0000https://blog.llvm.org/2011/12/nvidia-cuda-41-compiler-now-built-on.htmlFrom the NVIDIA CUDA compiler team:<p> <blockquote>CUDA is a parallel programming model and platform created by NVIDIA for harnessing the power of hundreds of cores in modern graphics processing units (GPUs). NVIDIA provides free support for CUDA C and C++ in the CUDA toolkit. The CUDA programming environment consists of a compiler targeting NVIDIA GPUs and has been adopted by thousands of developers.<p> At NVIDIA we have switched over to using LLVM inside the CUDA C/C++ compiler for Fermi and future architectures. We use LLVM for optimizations and PTX code generation and for generating debug information for CUDA debugging. From a developer's perspective the new compiler is functionally on par with the previous compilers and produces better code with better compile times. We have extended the LLVM core compiler to understand data parallel programming model. It is now available, as part of CUDA 4.1 and you can <a href="http://developer.nvidia.com/content/new-cuda-now-available">learn more here</a>.<p> Our experience with the use of LLVM has been very positive, starting with a modern compiler infrastructure and with high quality optimizations contributed by a large community of developers. The effort required to learn LLVM infrastructure is quite small and reasonable. </blockquote>
- LLVM 3.1 vector changeshttps://blog.llvm.org/2011/12/llvm-31-vector-changes.htmlMon, 19 Dec 2011 04:10:00 +0000https://blog.llvm.org/2011/12/llvm-31-vector-changes.htmlIntel uses the Low-Level Virtual Machine (LLVM) in a number of products, including the <a href="http://software.intel.com/en-us/articles/vcsource-tools-opencl-sdk/">Intel® OpenCL SDK</a>. The SDK's implicit vectorization module generates LLVM-IR (intermediate representation) which uses vector types.<p>LLVM-IR supports operations that use vector data types, and the LLVM code generator needs to do non-trivial work in order to efficiently compile vector operations into SIMD instructions. Recently, there were changes to the LLVM code generation that enabled better code generation for vector operations. In addition to many low level optimizations, this post talks about two major changes: the implementation of vector-select, and the support for vectors-of-pointers.<a name='more'></a><h2>The LLVM-IR select instruction</h2>The LLVM IR 'select' instruction is used to choose one value based on a condition. If the condition evaluates to 'True', the instruction returns the first value argument; otherwise, it returns the second value argument. For example:<pre> %X = select i1 true, i8 17, i8 42 ; yields i8:17</pre>The 'select' instruction also supports vector data types, where the condition is a vector of boolean data type. If the condition is a vector of booleans (see above), then the selection is done per element.<p>Vector-select instructions are very useful for vectorizing compilers, which use them to 'mask-out' inactive SIMD lanes. Until recently, the LLVM code generator did not support conditions with vector data types. Enabling them required enhancing several other areas of the code generator.<h2>SSE blends</h2>Intel's SSE4.1 instruction set features the PBLENDVB instruction. This instruction selects byte values from registers XMM1 and XMM2, using a mask specified in the high bit of each byte in XMM0, and stores the values into XMM1. There are also other instructions for handling larger data types, such as 32-bit integers, etc. It may seem odd for the selector bits to be the high bit, but the vector-compare machine instructions also set the high bits, so that the compare and blend instructions can work together efficiently.<p>As mentioned earlier, the LLVM-IR 'select' instruction represents the mask as a vector of booleans, which need to be translated into the high-bit of each SIMD vector element. This translation is done by the Type-Legalizer phase in the LLVM code generator.<h2>Type Legalization</h2>The Type Legalizer is a code generation phase that converts operations of any arbitrary data type which is represented by the LLVM-IR, into operations that use types which are supported by the target machine. For example, on x86 architecture, general purpose registers support the types i8, i16, i32 and i64. These types are 'Legal' because they fit into a machine register. The type i24 is 'Illegal' because it does not match a native x86 machine register. The Type-Legalizer has a complex set of rules for legalizing different types, and in many cases the type legalization takes multiple steps.The Type-Legalizer has a number of strategies for handling illegal vector types:<ul><li> Widening - The type-legalizer can widen vectors by adding additional elements. For example, the type <3 x float> would be widened to the legal type '<4 x float>'. </li><li> Splitting - The type-legalizer can split large vectors into smaller types. For example, a value of type <8 x float> can be split into two values of the legal type '<4 x float>'.</li><li> Scalarizing - The type-legalizer can break a vector into multiple scalars. For example, an operation of type <2 x i64> can be done on two 64-bit scalars using general purpose registers. </li></ul>Notice that none of the strategies above can translate the type '<4 x i1>' into the register-sized type '<4 x i32>'. To support the code-generation of vector-select, we added a new legalization kind which can support the promotion of each element in the vector, rather than increasing the number of elements in the vector.<p>LLVM already promotes small scalar integers into larger integers. For example, the type i8 is promoted to i32 on processors that do not support types smaller than 32 bits. Once the new type legalization technique was implemented, adding support for the select instruction was easy. Much like other instructions, a simple pattern in the TD file added support for different 'blend' instructions for different generations of the Intel Architecture (SSE4.1, AVX and AVX2). Processors that do not support the 'blend' instruction, lower the vector-select IR into a sequence of AND,XOR,OR with acceptable performance. <h2>Optimizations for Element Promotion</h2><a href="http://2.bp.blogspot.com/-iEM0ks4VajM/Tu8sGVUjBcI/AAAAAAAAEao/Hn4uRBVoK7s/s1600/PackedStore.png"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5687813341706388930" src="http://2.bp.blogspot.com/-iEM0ks4VajM/Tu8sGVUjBcI/AAAAAAAAEao/Hn4uRBVoK7s/s320/PackedStore.png" style="cursor: hand; cursor: pointer; float: right; height: 132px; margin: 0 0 10px 10px; width: 320px;" /></a>The new type-legalization method for vectors and the new vector-select implementation is open for new optimizations. For example, consider the problem of saving a vector of type '<4 x i8>' into memory. The in-memory representation of this type is that of four consecutive bytes, but the vector's in-register representation is '<4 x i32>'. Without any additional optimizations, the naive way of saving the vector would be to extract each one of the bytes into a general purpose register and to save them one by one into memory. One of the optimizations that we added recently is to shuffle all of the saved bytes into the lower part of the vector and save the four bytes into memory using a single scalar 32 bit store.<h2>Vectors of pointers</h2>Until recently, LLVM's vector type only contained elements which were integers or floating point. This abstraction matched the common SIMD instruction sets and enabled efficient code generation for many processors. In many cases vectorizing compilers wish to represent a vector of pointers, mainly for implementing scatter/gather memory operations. The lack of support in the IR made some vectorizing compilers worke around limitation by converting pointers to integers. This solution required the vectorizing compiler to implement address calculation manually, and added complexity to the software.<p>To solve this, LLVM now supports the pointer-vector type, as well as the instructions to manipulate it. Much like other vector instructions, the pointer-vector can be created and modified using the instructions 'insertelement', 'extractelement' and 'shufflevector'. However, pointer-vector types would not be so useful without vector 'getelementptr' instructions. We extended LLVM's GEP instruction to support vectors of pointers. The new pointer-vector abstraction enables better code generation, even for processors which do not support explicit gather/scatter instructions, since address calculation is now done on vectors.The following code is now legal in LLVM:<pre>define i32 @foo(<4 x i32*> %base, <4 x i32> %offset) nounwind { <br/> entry: <br/> %A2 = getelementptr <4 x i32*> %base, <4 x i32> %offset <br/> %k = extractelement <4 x i32*> %A2, i32 3 <br/> %v = load i32* %k <br/> ret i32 %v <br/> }</pre>We currently support only vectors of pointers to primitive types. In the future we may add additional capabilities and optimizations.<h2>Conclusion</h2>Intel® OpenCL SDK features an implicit vectorization module which uses the LLVM compiler toolkit for code generation. We are continuing to improve LLVM's code generation support for vectors, in order to support future Intel Architectures.<p>LLVM 3.1 will feature a number of changes that will enable vectorizing compilers to generate better code.
- LLVM 3.0 Exception Handling Redesignhttps://blog.llvm.org/2011/11/llvm-30-exception-handling-redesign.htmlMon, 28 Nov 2011 13:16:00 +0000https://blog.llvm.org/2011/11/llvm-30-exception-handling-redesign.htmlOne of the biggest IR changes in the LLVM 3.0 release is a redesign and reimplementation of the LLVM IR exception handling model. The old model, while it worked for most cases, fell over in some key situations, leading to obscure miscompilations, missed optimizations, and poor compile time. This post talks about the changes in LLVM 3.0 and how to move an existing LLVM front-end to the new design. It assumes some familiarity with the Itanium C++ ABI for exception handling.<a name='more'></a><h2>Goals of the exception handling system</h2>Exception handling needs to be a first-class citizen of the LLVM IR. This allows us to manipulate the exception handling information in an intelligent fashion (e.g., during inlining). Also, code generation needs to be able to reliably find a variety of information associated specific <tt>invoke</tt> call (e.g. the personality function for use with a call). Finally, we need to follow the established exception handling ABI to ensure binary compatibility with other compilers.<p>While there are a lot of details to get right for exception handling to work (with regards to the ABI), our goal is to keep LLVM IR as simple to generate and manipulate as possible. By making EH a first-class citizen, the new instructions will have a simple, easily understood syntax and constraints which can be tested to ensure that the IR is correct after each code transformation.<h2>The old exception handling system</h2>The old system used LLVM intrinsics to convey the exception handling information to the code generator. The primary problem with the old system is that there was nothing that bound these intrinsics to the invoke calls that could be unwound through, making code generation fragile, and optimizations like inlining impossible to represent (in the general case).<p>Further, the intrinsics were very difficult for code transformations to maintain and update correctly: we would frequently get exception tables which had incorrect information in them (e.g., specifying that a specific type couldn't propagate past that point when it wasn't specified in the original program). It also couldn't handle "cleanup" situations without a lot of work.<p>Because of normal code motion, the intrinsics, which held the information that the code generator needed to generate the correct tables, could be moved far away from the <tt>invoke</tt> instruction they were associated with. I.e., they could be moved out of the <tt>invoke</tt>'s landingpad. This made code generation of the previous exception handling constructs fragile, and sometimes caused miscompilations of exception handling code, which wasn't acceptable.<p>A final (somewhat theoretical) issue is that the old system only worked with standard personality functions. It would be nearly impossible to use custom personality functions (e.g. that returned 3 registers in a landing pad instead of 2) with it. While we had no specific use case for this, we were unable to use custom personality functions to optimize code size or performance of C++ exceptions.<h2>The LLVM 3.0 Exception Handling System</h2>The backbone of the new exception handling system are the two new instructions <tt>landingpad</tt> and <tt>resume</tt>:<dl><dt><tt><a href="http://llvm.org/docs/LangRef.html#i_landingpad">landingpad</a></tt></dt> <dd>Defines a landing pad basic block. It contains all of the information that's needed by the code generator to generate the correct EH tables. It's also required to be the first non-<tt>PHI</tt> instruction in the unwind destination of an invoke instruction. In addition, a landing pad may <em>only</em> be jumped to by the unwind edge of an <tt>invoke</tt> instruction. These constraints ensure that it is always possible to accurately match up the unwind information with an invoke call. It replaces the<tt>@llvm.eh.exception</tt> and <tt>@llvm.eh.selector</tt>intrinsics.</dd><dt><tt><a href="http://llvm.org/docs/LangRef.html#i_resume">resume</a></tt></dt> <dd>Causes the current exception to resume propagation up the stack. It replaces the <tt>@llvm.eh.resume</tt> intrinsic.</dd></dl><p>Here is a simple example of what the new syntax looks like. For this program:<p><br /><pre><br /> void bar();<br /> void foo() throw (const char *) {<br /> try {<br /> bar();<br /> } catch (int) {<br /> }<br /> }<br /></pre><br />The IR looks like this:<br /><pre><br /> @_ZTIPKc = external constant i8*<br /> @_ZTIi = external constant i8*<br /> define void @_Z3foov() uwtable ssp {<br /> entry:<br /> invoke void @_Z3barv()<br /> to label %try.cont unwind label %lpad<br /><br /> lpad:<br /> <b>%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)<br /> catch i8* bitcast (i8** @_ZTIi to i8*)<br /> filter [1 x i8*] [i8* bitcast (i8** @_ZTIPKc to i8*)]</b><br /> %1 = extractvalue { i8*, i32 } %0, 0<br /> %2 = extractvalue { i8*, i32 } %0, 1<br /> %3 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind<br /> %matches = icmp eq i32 %2, %3<br /> br i1 %matches, label %catch, label %filter.dispatch<br /><br /> filter.dispatch:<br /> %ehspec.fails = icmp slt i32 %2, 0<br /> br i1 %ehspec.fails, label %ehspec.unexpected, label %eh.resume<br /><br /> ehspec.unexpected:<br /> tail call void @__cxa_call_unexpected(i8* %1) no return<br /> unreachable<br /><br /> catch:<br /> %4 = tail call i8* @__cxa_begin_catch(i8* %1) nounwind<br /> tail call void @__cxa_end_catch() nounwind<br /> br label %try.cont<br /><br /> try.cont:<br /> ret void<br /><br /> eh.resume:<br /> <b>resume { i8*, i32 } %0</b><br /> }<br /></pre><br />The <tt>landingpad</tt> instruction specifies the <i>personality function</i>the EH runtime uses, a list of types which it can catch (<tt>int</tt>), and a list of types which <tt>foo</tt> is allowed to throw (<tt>const char *</tt>).<p>The <tt>resume</tt> instruction resumes propagation of the exception if it's not caught and of an allowed type.<h2>Converting to the LLVM 3.0 exception handling system</h2>Converting from the old EH API to the new EH API is rather simple because a lot of complexity has been removed. To generate the EH code in LLVM 2.9, you would have to do something akin to this:<br /><pre><br /> Function *ExcIntr =<br /> Intrinsic::getDeclaration(TheModule, Intrinsic::eh_exception);<br /> Function *SlctrIntr =<br /> Intrinsic::getDeclaration(TheModule, Intrinsic::eh_selector);<br /> Function *PersonalityFn =<br /> Function::Create(FunctionType::get(Type::getInt32Ty(Context), true),<br /> Function::ExternalLinkage,<br /> "__gxx_personality_v0", TheModule);<br /><br /> // The exception pointer.<br /> Value *ExnPtr = Builder.CreateCall(ExcIntr, "exn");<br /><br /> // The arguments to the @llvm.eh.selector instruction.<br /> std::vector<Value*> Args; Args.push_back(ExnPtr);<br /> Args.push_back(Builder.CreateBitCast(PersonalityFn,<br /> Type::getInt8PtrTy(Context)));<br /><br /> <i>// ... Complex code to add catch types, filters, cleanups, and catch-alls to Args ...</i><br /><br /> // The selector call.<br /> Value *Sel = Builder.CreateCall(SlctrIntr, Args, "exn.sel");<br /></pre><br />You should instead generate a <tt>landingpad</tt> instruction, that returns an exception object and selector value:<br /><pre><br /> LandingPadInst *LPadInst =<br /> Builder.CreateLandingPad(StructType::get(Int8PtrTy, Int32Ty, NULL),<br /> PersonalityFn, 0);<br /> Value *ExnPtr = Builder.CreateExtractValue(LPadInst, 0);<br /> Value *Sel = Builder.CreateExtractValue(LPadInst, 1);<br /></pre><br />It's now trivial to add the individual clauses to the <tt>landingpad</tt>instruction.<br /><pre><br /> <b><i>// Adding a catch clause</i></b><br /> Constant *TypeInfo = getTypeInfo();<br /> LPadInst->addClause(TypeInfo);<br /><br /> <b><i>// Adding a C++ catch-all</i></b><br /> LPadInst->addClause(Constant::getNullValue(Builder.getInt8PtrTy()));<br /><br /> <b><i>// Adding a cleanup</i></b><br /> LPadInst->setCleanup(true);<br /><br /> <b><i>// Adding a filter clause</i></b><br /> std::vector<Value*> TypeInfos;<br /> Constant *TypeInfo = getFilterTypeInfo();<br /> TypeInfos.push_back(Builder.CreateBitCast(TypeInfo, Builder.getInt8PtrTy()));<br /> ArrayType *FilterTy = ArrayType::get(Int8PtrTy, TypeInfos.size());<br /> LPadInst-<addClause(ConstantArray::get(FilterTy, TypeInfos));<br /></pre><br />Converting from using the <tt>@llvm.eh.resume</tt> intrinsic to the <tt>resume</tt> instruction is trivial. It takes the exception pointer and exception selector values returned by the <tt>landingpad</tt>instruction:<br /><pre><br /> Type *UnwindDataTy = StructType::get(Builder.getInt8PtrTy(),<br /> Builder.getInt32Ty(), NULL);<br /> Value *UnwindData = UndefValue::get(UnwindDataTy);<br /> Value *ExcPtr = Builder.CreateLoad(getExceptionObjSlot());<br /> Value *ExcSel = Builder.CreateLoad(getExceptionSelSlot());<br /> UnwindData = Builder.CreateInsertValue(UnwindData, ExcPtr, 0, "exc_ptr");<br /> UnwindData = Builder.CreateInsertValue(UnwindData, ExcSel, 1, "exc_sel");<br /> Builder.CreateResume(UnwindData);<br /></pre><br /><h4>Conclusion</h4>The new EH system now works much better than the old system. It is much less fragile and complex. This makes it easier to understand when you have to read the IR to figure out what's going on. More importantly, it allows us to follow the ABI more closely than before.<p>Better yet, it's rather straight-forward to convert from the old system to the new one. In fact, you may see your code become much simpler! If you're interested in more details and reference information, please see the <a href="http://llvm.org/docs/ExceptionHandling.html">Exception Handling in LLVM IR</a> document.
- LLVM 3.0 Type System Rewritehttps://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.htmlSat, 26 Nov 2011 09:04:00 +0000https://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.htmlOne of the most pervasive IR (and thus compiler API) changes in LLVM 3.0 was a complete reimplementation of the LLVM IR type system. This change was long overdue (the original type system lasted from LLVM 1.0!) and made the compiler faster, greatly simplified a critical subsystem of VMCore, and eliminated some design points of IR that were frequently confusing and inconvenient. This post explains why the change was made along with how the new system works. <a name='more'></a><h3>Goals of the type system</h3> The <a href="http://llvm.org/docs/LangRef.html#typesystem">LLVM IR type system</a> is a fairly straight-forward part of the IR. The type system consists of three major parts: primitive types (like 'double' and integer types), derived types (like structs, arrays and vectors), and a mechanism for handling forward declarations of types ('opaque').<p> The type system has several important requirements that constrains its design: we want to be able to use efficient pointer equality checks to determine structural type equality, we want to allow late refinement of types (e.g. when linking, one module should be able to complete types in another module), we want it to be easy to express many different source languages, and we want a simple and predictable system.<p> The only really difficult part of an IR type system is handling forward declarations of types. To see this, observe that the type system is actually represented with a complex graph of types (which is often cyclic). For example, a simple singly linked list of integers might be declared like this: <pre><br /> %intlist = type { %intlist*, i32 }<br /></pre> In this case, the type graph includes a StructType which points to an IntegerType and a PointerType. The PointerType points back to the StructType. In many real programs the graph is complex and heavily cyclic, particularly for C++ applications.<p> With this as background, lets start by talking about how LLVM 2.9 and earlier worked. <h3>The old type system</h3> The <a href="http://llvm.org/releases/2.9/docs/LangRef.html#typesystem">LLVM 2.9</a> type system has all of the straight-forward pieces and represents forward type declarations with an instance of <a href="http://llvm.org/releases/2.9/docs/LangRef.html#t_opaque">OpaqueType</a>. When this type is later resolved (e.g. at link time), a process know as "type refinement" <em>updates all pointers</em> to the old OpaqueType to point to the new definition, mutating the type graph on the fly, and then deletes the original OpaqueType. For example, if a module contained: <pre><br /> %T1 = type opaque<br /> %T2 = type %T1*<br /></pre> then T2 is a PointerType to an OpaqueType. If we resolve %T1 to {} (an empty struct), then %T2 <em>mutates</em> to be a PointerType to the empty StructType. For more information on this, please see the <a href="http://llvm.org/releases/2.9/docs/ProgrammersManual.html#TypeResolve ">type resolution section</a> of the LLVM 2.9 Programmer's Manual.<p> <h4>Ramifications of mutating and moving types</h4> Unfortunately, while conceptually simple, this type system had several problems. In order to guarantee that pointer equality checks work for structural type equivalence checks, VMCore is required to re-unique types whenever they are mutated during type resolution. This may not seem like such a big deal, but a single type refinement can cause hundreds of other types to be mutated, and it is quite common to refine hundreds or thousands of types (e.g. when linking an application for LTO). The performance of this was not acceptable, particularly because uniquing cyclic graphs requires full graphic isomorphism checks to be done, and our previous implementation was not algorithmically efficient.<p> Another problem is that more than just types need to be updated: anything that contains a pointer to a type has to be updated, or it gets a dangling pointer. This issue manifested in a number of ways: for example every Value has a pointer to a type. In order to make the system a bit more efficient, Value::getType() actually performed a lazy "union find" step to ensure that it always returned a canonicalized and uniqued type. This made Value::getType() (a very common call) more expensive than it should be.<p> An even worse problem that this "type updating" problem caused is when you were manipulating and building IR through the LLVM APIs. Because types could move, it was very easy to get dangling pointers, causing a lot of confusion and a lot of broken clients of the LLVM API. This was compounded by the fact that it was <em>required</em> to use type refinement to build <a href="http://llvm.org/releases/2.9/docs/ProgrammersManual.html#BuildRecType">simple recursive types</a>. We tried to make this simpler with the PATypeHolder and PATypeHandle classes, but they only worked if you used them exactly right and they were generally poorly understood.<p> <h4>Surprising behavior with type uniquing</h4> Many clients of LLVM, once they got things working, then quickly ran into a surprising aspect of type uniquing: type names were not part of the type system, they were an "on the side" data structure. The names were not taking into consideration during type uniquing, and you could have multiple names for one type (which led to a lot of confusion). For example, consider: <pre><br /> %T1 = type opaque<br /> @G1 = external global %T1*<br /><br /> %T2 = type {}<br /> @G2 = external global %T2*<br /></pre> If %T1 was later resolved to {}, then %T1 and %T2 would both become names for the same empty structure type, the type formerly known as "%T1*" would be unified with the type formerly known as "%T2*", and now the IR would print out as: <pre><br /> %T1 = type {}<br /> @G1 = external global %T1*<br /><br /> %T2 = type {}<br /> @G2 = external global %T1*<br /></pre> ... note that G2 now has type "%T1*"! This is because the names in the type system was just a hash table on the side, so that asmprinter would pick one of the arbitrarily large number of names for a type when printing. This was "correct", but highly confusing the folks who did not know the ins and outs of the type system, and not helpful behavior. It also made reading .ll dumps from a C++ compiler very difficult, because it is very common to have many structurally identical types with different names. <h4>Type Up-references</h4> A final problem (that I don't want to dwell on too much) is that we previously could have the situation where a type existed that had no name at all. While this is fine from the type system graph's perspective, this made printing types impossible if they were cyclic and had no names. The solution to this problem was a system known as <a href="http://llvm.org/releases/2.9/docs/LangRef.html#t_uprefs">type up-references</a>.<p> Type up-references were an elegant solution that allowed the asmprinter (and parser) to be able to represent an arbitrary recursive type in finite space, without requiring names. For example, the %intlist example above could be represented as "{\2*, i32}". It also allowed for construction of some nice (but surprising) types like "\1*" which was a pointer to itself!<p> Despite having some amount of beauty and elegance, type up-references were never well understood by most people and caused a lot of confusion. It is important to be able to strip the names out of an LLVM IR module (e.g. the -strip pass), but it is also important for compiler hackers to be able to understand the system! <h4>Preparing for the new type system</h4> With all of these problems, I realized that LLVM needed a newer and simpler type system. However, it is also important that new versions of LLVM be able to read old .bc and .ll files. To enable this, the big rewrite was carefully staged: the LLVM 2.9 asmprinter was enhanced to emit opaque types as numbered types instead of using up-references. Therefore, instead of emitting the %intlist example with up-references, LLVM 2.9 would emit it as: <pre><br /> %0 = type { %0*, i32 }<br /></pre> The plan for LLVM 3.0 was to drop compatibility with LLVM 2.8 (and earlier) files, so this made the "upgrade" logic needed in LLVM 3.0 much simpler. <h2>The LLVM 3.0 Type System</h2> To most clients, the new type system in LLVM 3.0 looks and smells a lot like the 2.9 type system. For example, .bc files and .ll files produced by LLVM 2.9 are readable and automatically upgraded to 3.0 features when read by the bitcode reader and .ll parser (though LLVM 3.1 will drop compatibility with 2.9). This is because the type system retains almost everything it had before: the primitive and derived types are the same, only OpaqueType has been removed and StructType has been enhanced.<p> In short, instead of a refinement based type system where types mutate in memory (requiring re-uniquing and moving/updating of pointers), LLVM 3.0 uses a type system very similar to what C has, based on type <em>completion</em>. Basically, instead of creating an opaque type and replacing it later, you now create an StructType with no body, then specify the body later. To create the %intlist type, you'd now write something like this: <pre><br /> StructType *IntList = StructType::create(SomeLLVMContext, "intlist");<br /> Type *Elts[] = { PointerType::getUnqual(IntList), Int32Type };<br /> IntList->setBody(Elts);<br /></pre> ... which is simple and to the point, much better than <a href="http://llvm.org/releases/2.9/docs/ProgrammersManual.html#BuildRecType">the 2.9 way</a>. There are a few non-obvious ramifications to this design though. <h4>Only struct types can be recursive</h4> In the previous type system, an OpaqueType could be resolved to any arbitrary type, allowing such oddities as "%t1 = type %t1*", which is a pointer to itself. In the new type system, only IR structure types can have their body missing, so it is impossible to create a recursive type that doesn't involve a struct. <h4>Literal and Identified structs</h4> In the new type system, there are actually two different kinds of structure type: a "literal" structure (e.g. "{i32, i32}") and an "identified" structure (e.g. "%ty = type {i32, i32}").<p> Identified structures are the kind we are talking about: they can have a name, and can have their body specified after the type is created. The identified structure is not uniqued with other structure types, which is why they are produced with StructType::create(...). Because identified types are potentially recursive, the asmprinter always prints them by their name (or a number like %42 if the identified struct has no name).<p> Literal structure types work similarly to the old IR structure types: they never have names and are uniqued by <em>structural</em> identity: this means that they must have their body elements available at construction time, and they can never be recursive. When printed by the asmprinter, they are always printed inline without a name. Literal structure types are created by the StructType::get(...) methods, reflecting that they are uniqued (the call may or may not actually allocate a new StructType).<p> We expect that identified structure types will be the most common, and that a frontend will only produce a literal structure type in special cases. For example, it is reasonable to use literal structure types for tuples, complex numbers, and other simple cases where a name would be arbitrary and would make the IR more difficult to read. The optimizer doesn't care one way or the other, so if you're the author of a front-end, just use whatever you prefer to see in your IR dumps. <h4>Identified structs have a 1-1 mapping with a name</h4> Where type names were kept as an "on the side" hash table before, they are now an intrinsic part of a type, and the only types that can be named are identified structs. This means that LLVM 3.0 doesn't exhibit the previous confusing behavior where two seemingly different structs would be printed with the same name. When stripping type names from a module, the identified structs just become anonymous: they are still 'identified', but they have no name. As with other anonymous entities in LLVM IR, they are asmprinted in a numeric form. <h4>Struct names are uniqued at the LLVMContext level</h4> Because StructType::create always returns a new identified type, we need some behavior for when you try to create two types with the same name. The solution is that VMCore detects the conflict and autorenames the later request by adding a suffix to the type: when you request a "foo" type, you may actually get back a type named "foo.42". This is consistent with other IR objects like instructions and functions, and the names are uniqued at the LLVMContext level. <h4>The Linker "links" types and retypes IR objects</h4> An interesting aspect of this design is that it makes the IR linker's job a bit more complex. Consider what happens when you link these two IR modules together: <pre><br />x.ll:<br /> %A = type { i32 }<br /> @G = external global %A<br />y.ll:<br /> %A = type { i32 }<br /> @G = global %A zeroinitializer<br /></pre> The first thing the linker does is load the two modules into the same LLVMContext. Since the two types named "A" <em>must be different</em> types, and since there can only be one type named %A, we actually get these two modules in memory: <pre><br />x.ll module:<br /> %A = type { i32 }<br /> @G = external global %A<br />y.ll module:<br /> %A.1 = type { i32 }<br /> @G = global %A.1 zeroinitializer<br /></pre> ... and now it is quite clear that the @G objects have different types. When linking these two global variables, it is now up to the linker to remap the types of IR objects into a consistent set of types, and rewrite things into a consistent state. This requires the linker to compute the set of identical types and solve the same graph isomorphism problems that VMCore used to (see the "remapType" logic in lib/Linker/LinkModules.cpp if you're interested).<p> Putting this logic in the IR linker instead of VMCore is better that the previous design on many levels: now the cost for this merging and uniquing is only paid by the IR linker, not by all bitcode reading and other IR creation code. The code is easier to understand and algorithmically optimize, because we're merging two complete graphs at once - instead of resolving types one at a time. Finally, this shrinks the size of VMCore by moving some complex logic out of it. <h4>Identifying magic IR types in the optimizer (or later)</h4> As in LLVM 2.9, type names are not really designed to be used as semantic information in IR: we expect everything to continue working if the -strip pass is used to remove all extraneous names from the IR. However, for research and other purposes, it can sometimes be a convenient hack to propagate information from a front-end into LLVM IR by using type names. This will work reliably in LLVM 3.0 (so long as you don't run the strip pass or something equivalent) because identified types aren't uniqued. However, be aware that the suffix can be added and write your code to tolerate it.<p> A more robust way to be able to identify a specific type in the optimizer (or some other point after the frontend has run) is to use a named metadata node to find the type. For example, if you want to find the %foo type, you could generate IR that looks like this: <pre><br /> %foo = type { ... }<br /> ...<br /> !magic.types = !{ %foo zeroinitializer }<br /></pre> Then to find the "foo" type, you'd just look up the "magic.types" named metadata, and get the type of the first element. Even if type names are stripped or types get auto-renamed, the type of the first element will always be correct and stable.<p> There seems to be some confusion around named metadata: unlike instruction-level metadata, they will <b>not</b> be dropped or invalidated by optimizer passes (so long as they don't point to functions or other IR objects that are modified by the optimizer). In general, named metadata is a much, much, better way to pass information from a frontend to an optimizer or backend than trying to play games with type names. <h2>Conclusion</h2> In conclusion, the new type system has solved a number of long-standing problems in LLVM IR. If you're upgrading some code from LLVM 2.x to 3.x, it is likely to be something that you'll run into. Hopefully, this helps answer some common questions about why we made the change and how it works!<p> -<a href="http://nondot.org/sabre/">Chris Lattner</a>
- Greedy Register Allocation in LLVM 3.0https://blog.llvm.org/2011/09/greedy-register-allocation-in-llvm-30.htmlSun, 18 Sep 2011 21:34:00 +0000https://blog.llvm.org/2011/09/greedy-register-allocation-in-llvm-30.htmlLLVM has two new register allocators: Basic and Greedy. When LLVM 3.0 is released, the default optimizing register allocator will no longer be linear scan, but the new greedy register allocator.<br />With its global live range splitting, the greedy algorithm generates code that is 1-2% smaller, and up to 10% faster than code produced by linear scan.<br /><br /><a name='more'></a><br /><h2> Lessons learned from linear scan</h2>Linear scan has been the default register allocator in LLVM since 2004. It has worked surprisingly well for such a simple algorithm. In fact, the simple design made it easier to tweak the algorithm in order to make small improvements to the generated code. More advanced register allocation algorithms often need to build expensive data structures, or they make assumptions about live ranges being invariant. That makes it difficult to, say, commute a two-address instruction on the fly, or rematerialize a constant pool load instead of spilling it to the stack.<br />A new register allocation algorithm needs to preserve this simplicity. It must be possible to change the machine code while the algorithm is running.<br />Linear scan depends on the virtual register rewriter to clean up the code after registers have been assigned. In theory, the rewriter should only rewrite virtual registers to their assigned physical registers, but it knows many other tricks. When linear scan does something silly like reloading a register from a stack slot twice, the rewriter will clean up the code by reusing the first register and eliminating the second reload. The algorithm is local, and it cannot clean up messes that extend beyond a single basic block. The rewriter always saves the day by removing obvious mistakes. It comes at a high price, though. It accounts for about half of the linear scan compile time, and its large collection of tricks makes the code very hard to maintain.<br />A new register allocator should avoid making obvious mistakes so the rewriter can concentrate on rewriting registers.<br />As the name implies, linear scan works by visiting live ranges in a linear order. It maintains an <em>active list</em> of live ranges that are live at the current point in the function, and this is how it detects interference without computing the full interference graph. The active list is the key to linear scan's speed, but it is also its greatest weakness.<br />When all physical registers are blocked by interfering live ranges in the active list, a live range is selected for spilling. Live ranges being spilled without being split first cause the mess that the rewriter is working so hard to clean up. We would much rather split them into smaller pieces that might be assignable, but this would require the linear scan algorithm to backtrack. This is very expensive, and full live range splitting isn't really feasible with linear scan.<br /><h2> Basic allocator</h2><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-wd-VjahgQ7s/Uf2yGLeR9QI/AAAAAAAAAAc/Rf-W3y1fKPA/s1600/rabasic.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://2.bp.blogspot.com/-wd-VjahgQ7s/Uf2yGLeR9QI/AAAAAAAAAAc/Rf-W3y1fKPA/s1600/rabasic.png" /></a></div>The new basic allocator does away with linear scan's dependence on visiting live ranges in linear order. Instead, it uses a priority queue to visit live range in order of decreasing spill weight. The active list used for interference checks is replaced with a set of <em>live interval unions</em>. Implemented as a B+ tree per physical register, they are an efficient way of checking for interference with already assigned live ranges. Unlike the active list, live interval unions work with any priority queue order.<br />When a live range cannot be assigned to any physical register in its register class, it is spilled. Because live ranges are assigned in order of decreasing spill weight, all the interfering live ranges in the live interval union have a higher spill weight. It is not necessary to look for a better spill candidate.<br />On CISC architectures, the spill slot memory accesses can often be folded into existing instructions. On RISC architectures, explicit load and store instructions must be inserted. This will also create new tiny live ranges between the spill code and the original instructions using the spilled live range. These new live ranges are put back on the priority queue with an infinite spill weightâthey cannot be spilled again.<br />Technically, these small live ranges with high spill weight should have been assigned first, but the basic allocator never backtracks. Therefore, it can happen that such a live range is blocked by already assigned live ranges with smaller spill weights. In that case, the allocator picks a physical register and spills the interfering live ranges assigned to that register instead.<br />The basic allocator produces code very similar to linear scan's output, and it also depends on the virtual register rewriter to clean up the code for good results. It doesn't offer significant advantages over linear scan, and it is intended mostly for testing the framework of priority queues and live interval unions. The basic algorithm is very simple, and it offers many opportunities for tweaking. Greedy does just that.<br /><h2> Greedy allocator</h2><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-4fMcjz5dFzE/Uf2yVe2AE5I/AAAAAAAAAAk/Jz0XiwrwHxA/s1600/ragreedy.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://4.bp.blogspot.com/-4fMcjz5dFzE/Uf2yVe2AE5I/AAAAAAAAAAk/Jz0XiwrwHxA/s1600/ragreedy.png" /></a></div>The first thing to notice about the basic algorithm is that its priority queue order doesn't work well for coloring registers optimally. Spill weights are computed as use densities, and small live ranges tend to have high spill weights. This means that all the tiny live ranges are allocated first. They use up the first registers in the register class, and the large live ranges get to fight over the leftovers. Most of them end up spilling.<br />Greedy avoids this problem by allocating the large live ranges first. This makes the full register class available for the large ranges, and the small ranges can often fit in the gaps. Some functions have too many large live ranges, so there is not enough room for all the small live ranges. It would be really bad to spill small live ranges with high spill weights, so instead already assigned live ranges with lower spill weight can be evicted from the live range union. Evicted live ranges are unassigned from their physical register and put back in the priority queue. They get a second chance at being assigned somewhere else, or they can move on to <em>live range splitting</em>.<br />When a live range cannot find interfering live ranges it is allowed to evict, it is not spilled right away. If possible, it is split into smaller pieces that are put back on the priority queue. This is a very important optimization. A large live range may be idle a lot of the time, but used intensively in a hot loop. By creating a separate live range covering the hot loop, there is a good chance it will be assigned a register. The remaining live range may spill outside the loop where it was idle anyway. A live range is only spilled when the splitter decides that splitting it won't help. That usually happens after all the busy regions have been separated, and the remaining live range only has a few copies to and from the busy registers.<br />The interaction between live range splitting and eviction creates a process of gradual refinement. As live ranges are split around busy regions, they get a higher spill weight. This may allow them to evict older live ranges that are less busy in that region. The evicted ranges are split, and so on.<br />The gradual process of splitting usually terminates before the live ranges become tiny, and the end result is a set of live ranges covering multiple instructions, or even multiple basic blocks. This means that there is nothing for the rewriter to clean up, and indeed greedy uses a completely trivial rewriter that is 85 lines of code compared to 2600 in the old rewriter.<br />The code generated by the greedy algorithm is almost always better than what linear scan can do. Usually this is because live range splitting was able to eliminate spill code from loops. Greedy does know some more tricks, though.<br /><h2> Tweaks</h2>It was an important design goal to make the algorithm as flexible as possible, and to avoid introducing arbitrary constraints. It is possible to change machine code and live ranges at any time. Simply evict the relevant live ranges, make the change, and put them back on the queue.<br />This flexibility allows many tweaks to the register allocator:<br /><ul><li>Register preferences. Function arguments are passed in specific physical registers defined by the ABI. LLVM represents this with copies between physical and virtual registers before and after function calls. The register allocator tries to assign the virtual registers to the same physical registers, so the copies can be eliminated. Linear scan was never really good at thisâthe preferred physical register had often been occupied by an earlier assignment. Greedy can simply evict the earlier assignment when that happens.</li><li>Prefer small encodings. On architectures like ARM Thumb2 and x86-64, some registers require a larger instruction encoding. Greedy will evict less important live ranges from the cheap registers before it assigns an expensive register. This means that the larger instruction encodings are used less often, and overall code size decreases.</li><li>Dead code elimination. Optimizations like rematerialization cause live ranges to be shorter, or even completely unused. Greedy will recompute the live ranges exactly, and recursively eliminate dead code.</li><li>Register class inflation. Live range splitting creates virtual registers that are used by fewer instructions. This sometimes lifts a constraint, so the virtual register can be moved to a larger register class. Depending on the architecture, this can double the number of registers available to the new live range.</li></ul>The greedy register allocator still has lots of room for improvement. That was the whole point of replacing linear scan.
- LLVM @ "The Architecture of Open Source Applications"https://blog.llvm.org/2011/05/llvm-architecture-of-open-source.htmlSun, 29 May 2011 20:37:00 +0000https://blog.llvm.org/2011/05/llvm-architecture-of-open-source.html<div class="separator" style="clear: both; text-align: center;"><a href="http://www.aosabook.org/images/cover1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://www.aosabook.org/images/cover1.jpg" height="250" width="190" /></a></div><br />LLVM is featured in <a href="http://www.aosabook.org/en/llvm.html">a chapter</a> of the new book <a href="http://www.aosabook.org/">The Architecture of Open Source Applications</a>. This chapter talks about the high-level design of LLVM, and how it differs from other contemporary compilers and JITs out there, why you might want to use it (if you're looking for compiler libraries), a simple example of writing an optimization, how the code is structured, a 10,000 foot view of how the code generator works, and some of the interesting capabilities LLVM has due to its design. If you're curious what this whole LLVM thing is, then this is a great place to start.<br /><br />This book is <a href="http://www.aosabook.org/en/index.html#purchase">available inexpensively</a> in dead tree or PDF form, and the author royalties are donated to charity. The content is <a href="http://www.aosabook.org/en/llvm.html">also available for free</a> under the creative commons license. Share and enjoy,<br /><br />-<a href="http://nondot.org/sabre/">Chris Lattner</a>
- C++ at Google: Here Be Dragonshttps://blog.llvm.org/2011/05/c-at-google-here-be-dragons.htmlMon, 23 May 2011 13:00:00 +0000https://blog.llvm.org/2011/05/c-at-google-here-be-dragons.htmlGoogle has one of the largest monolithic C++ codebases in the world. We have thousands of engineers working on millions of lines of C++ code every day. To help keep the entire thing running and all these engineers fast and productive we have had to build some unique C++ tools, centering around the Clang C++ compiler. These help engineers understand their code and prevent bugs before they get to our production systems.<br /><br /><a name='more'></a><i>(Cross-posted on the <a href="http://google-engtools.blogspot.com/2011/05/c-at-google-here-be-dragons.html">Google Engineering Tools Blog</a>)</i><br /><br />Of course, improving the speed of Google engineersâtheir productivityâdoesnât always correlate to <i>speed</i> in the traditional sense. It requires the holistic acceleration of Googleâs engineering efforts. Making any one tool faster just doesnât cut it; the entire process has to be improved from end to end.<br /><br />As a performance junkie, I like to think of this in familiar terms. Itâs analogous to an <b>algorithmic</b> performance improvement. You get âalgorithmicâ improvements in productivity when you reduce the total work required for an engineer to get the job done, or fundamentally shift the time scale that the work requires. However, improving the time a single task requires often runs afoul of all the adages about performance tuning, 80/20 rules, and the pitfalls of over-optimizing.<br /><br />One of the best ways to get these algorithmic improvements to productivity is to completely remove a set of tasks. Letâs take the task of triaging and debugging serious production bugs. If youâve worked on a large software project, youâve probably seen bugs which are somehow missed during code review, testing, and QA. When these bugs make it to production they cause a massive drain on developer productivity as the engineers cope with outages, data loss, and user complaints.<br /><br />What if we could build a tool that would find these exact kinds of bugs in software automatically? What if we could prevent them from ever bringing down a server, reaching a userâs data, or causing a pager to go off? Many of these bugs boil down to simple C++ programming errors. Consider this snippet of code:<br /><pre><br />Response ProcessRequest(Widget foo, Whatsit bar, bool *charge_acct) {<br /> // Do some fancy stuff...<br /> if (/* Detect a subscription user */) {<br /> charge_acct = false;<br /> }<br /> // Lots more fancy stuff...<br />}</pre><br /><br />Do you see the bug? Careful testing and code reviews catch these and other bugs constantly, but inevitably one will sneak through, because the code <b>looks fine</b>. It says that it shouldnât charge the account right there, plain as day. Unfortunately, C++ insists that âfalseâ is the same as â0â which can be a pointer just as easily as it can be a boolean flag. This code sets the pointer to NULL, and never touches the flag.<br /><br />Humans arenât good at spotting this type of devious typo, any more than humans are good at translating C++ code into machine instructions. We have tools to do that, and the tool of choice in this case is the compiler. Not just any compiler will do, because while the code above is <em>one</em> example of a bug, we need to teach our compiler to find lots of other examples. We also have to be careful to make certain that developers will act upon the information these tools provide. Within Googleâs C++ codebase, that means we break the build for every compiler diagnostic, even warnings. We continually need to enhance our tools to find new bugs in new code based on new patterns, all while maintaining enough precision to immediately break the build and have high confidence that the code is wrong.<br /><br />To address these issues we started a project at Google which is working with the <a href="http://llvm.org/">LLVM Project</a> to develop the <a href="http://clang.llvm.org/">Clang</a> C++ compiler. We can rapidly add warnings to Clang and customize them to emit precise diagnostics about dangerous and potentially buggy constructs. Clang is designed as a collection of libraries with the express goal of supporting diverse tools and application uses. These libraries can be directly integrated into IDEs and commandline tools while still forming the core of the compiler itself.<br /><br />Weâve been working on Clang for over a year now so that it can understand and reason about all of the C++ code at Google. But building the tools and technology to catch these bugs is only half the battle; we have to get engineers to <em>use</em> them as well. When other teams at Google respond to production bugs, our team will often begin working to enable any Clang diagnostics that might have caught the bug. Within one week of production issues, we can sweep the entire code base using these diagnostics to fix any latent bugs.<br /><br />Recently we enabled the Clang C++ compiler for every C++ build at Google in order to provide accurate and helpful warnings and diagnostics to engineers. Some examples of how Clang can help developers with bad code are discussed on <a href="http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html"> this post</a> to the LLVM blog. Beyond that, once we have swept the codebase with a bug-finding diagnostic, we can enable it for all our engineers to catch future bugs before theyâre committed. These diagnostics break the entire build of that piece of software to ensure that they arenât ignored and are acted on immediately. For the code sample above, the user gets an error message:<br /><pre><br /><b>example1.cc:4:17: error: initialization of pointer of type 'bool *' from literal 'false' [-Werror,-Wbool-conversions]</b><br /> charge_acct = false;<br /> <b>^</b></pre><br /><br />Here are two other classes of bugs weâve found::<br /><pre><br />long kMaxDiskSpace = 10 << 30; // Ten gigs ought to be enough for anybody.<br /><br />void SomeService() {<br /> // Setup task using external resource...<br /> while (/* Check if resource is available yet ... */) {<br /> sleep(0.5); // Yield the CPU<br /> }<br />}</pre><br /><br />Which now trigger the following errors:<br /><pre><br /><b>example2.cc:12:25: error: shift result (10737418240) requires 35 bits to represent, but 'int' only has 32 bits [-Werror,-Wshift-overflow]</b><br />long kMaxDiskSpace = 10 << 30;<br /> <b>~~ ^ ~~</b><br /><b>example2.cc:16:11: error: implicit conversion turns literal floating-point number into integer: 'double' to 'unsigned int' [-Werror,-Wliteral-conversion]</b><br /> sleep(0.5);<br /> <b>~~~~~ ^~~</b></pre><br /><br />All of these represent real bugs that we have found in our code, and that we are catching and fixing with the help of Clang today.<br /><br />Clang and its diagnostics donât in any way obviate the need for careful code review and thorough testing. Rather, they complement these practices, combining to help reduce the number of bugs in our code. This is the platform on which we are developing new and better diagnostics for engineers going forward. This is how we are providing an algorithmic improvement to their productivity, and accelerating Google.<br /><br />Stay tuned for more posts about how we rolled Clang out to Google engineers, how we have enhanced Clang to make it even more relevant for our code and our developersâ needs, and some of the exciting tools weâre building on top of this platform.
- What Every C Programmer Should Know About Undefined Behavior #3/3https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.htmlSat, 21 May 2011 00:48:00 +0000https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.htmlIn <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">Part 1</a> of the series, we took a look at undefined behavior in C and showed some cases where it allows C to be more performant than "safe" languages. In <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html">Part 2</a>, we looked at the surprising bugs this causes and some widely held misconceptions that many programmers have about C. In this article, we look at the challenges that compilers face in providing warnings about these gotchas, and talk about some of the features and tools that LLVM and Clang provide to help get the performance wins, while taking away some of the surprise.<br /><a name='more'></a><br /> Translation available in: <a href="http://blog-ja.intransient.info/2011/06/c-33.html">Japanese</a> <h2>Why can't you warn when optimizing based on undefined behavior?</h2><br />People often ask why the compiler doesn't produce warnings when it is taking advantage of undefined behavior to do an optimization, since any such case might actually be a bug in the user code. The challenges with this approach are that it is 1) likely to generate far too many warnings to be useful - because these optimizations kick in all the time when there is no bug, 2) it is really tricky to generate these warnings only when people want them, and 3) we have no good way to express (to the user) how a series of optimizations combined to expose the opportunity being optimized. Lets take each of these in turn:<br /><br /><b>It is "really hard" to make it actually useful</b><br /><br />Lets look at an example: even though invalid type casting bugs are frequently exposed by type based alias analysis, it would not be useful to produce a warning that "the optimizer is assuming that P and P[i] don't alias" when optimizing "zero_array" (from <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">Part #1 of our series</a>).<br /><br /><pre>float *P;<br /> void zero_array() {<br /> int i;<br /> for (i = 0; i < 10000; ++i)<br /> P[i] = 0.0f;<br />}<br /></pre><br />Beyond this "false positive" problem, a logistical problem is that the optimizer doesn't have enough information to generate a reasonable warning. First of all, it is working on an already-abstract representation of the code (<a href="http://llvm.org/docs/LangRef.html">LLVM IR</a>) which is quite different from C, and second, the compiler is highly layered to the point where the optimization trying to "hoist a load from P out of the loop" doesn't know that TBAA was the analysis that resolved the pointer alias query. Yes, this is "the compiler guy whining" part of the article :), but it really is a hard problem.<br /><br /><b>It is hard to generate these warnings <i>only</i> when people want them</b><br /><br />Clang implements numerous warnings for simple and obvious cases of undefined behavior, such as out of range shifts like "x << 421". You might think that this is a simple and obvious thing, but it turns out that this is hard, because <a href="http://llvm.org/bugs/show_bug.cgi?id=5544">people don't want to get warnings about undefined behavior in dead code</a> (see also <a href="http://llvm.org/bugs/show_bug.cgi?id=6933">the duplicates</a>).<br /><br />This dead code can take several forms: a macro that expands out in a funny way when when passed a constant, we've even had complaints that we warn in cases that would require <a href="http://llvm.org/bugs/show_bug.cgi?id=9322">control flow analysis</a> of switch statements to prove that cases are not reachable. This is not helped by the fact that switch statements in C are <a href="http://en.wikipedia.org/wiki/Duff's_device">not necessarily properly structured</a>.<br /><br />The solution to this in Clang is a growing infrastructure for handling "runtime behavior" warnings, along with code to prune these out so that they are not reported if we later find out that the block is unexecutable. This is something of an arms race with programmers though, because there are always idioms that we don't anticipate, and doing this sort of thing in the frontend means that it doesn't catch every case people would want it to catch.<br /><br /><b>Explaining a series of optimizations that exposed an opportunity</b><br /><br />If the frontend has challenges producing good warnings, perhaps we can generate them <em>from the optimizer</em> instead! The biggest problem with producing a useful warning here is one of data tracking. A compiler optimizer includes dozens of optimization passes that each change the code as it comes through to canonicalize it or (hopefully) make it run faster. If the inliner decides to inline a function, this may expose other opportunities for <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html#signed_overflow">optimizing away an "X*2/2"</a>, for example.<br /><br />While I've given <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html#optimizations">relatively simple and self-contained examples</a> to demonstrate these optimizations, most of the cases where they kick in are in code coming from macro instantiation, inlining, and other abstraction-elimination activities the compiler performs. The reality is that humans don't commonly write such silly things directly. For warnings, this means that in order to relay back the issue to the users code, the warning would have to reconstruct exactly how the compiler got the intermediate code it is working on. We'd need the ability to say something like:<br /><br /><blockquote><tt><br />warning: after 3 levels of inlining (potentially across files with Link Time Optimization), some common subexpression elimination, after hoisting this thing out of a loop and proving that these 13 pointers don't alias, we found a case where you're doing something undefined. This could either be because there is a bug in your code, or because you have macros and inlining and the invalid code is dynamically unreachable but we can't prove that it is dead.</tt></blockquote><br />Unfortunately, we simply don't have the internal tracking infrastructure to produce this, and even if we did, the compiler doesn't have a user interface good enough to express this to the programmer.<br /><br />Ultimately, undefined behavior is valuable to the optimizer because it is saying "this operation is invalid - you can assume it never happens". In a case like "*P" this gives the optimizer the ability to reason that P cannot be NULL. In a case like "*NULL" (say, after some constant propagation and inlining), this allows the optimizer to know that the code must not be reachable. The important wrinkle here is that, because it cannot solve the halting problem, the compiler cannot know whether code is actually dead (as the C standard says it must be) or whether it is a bug that was exposed after a (potentially long) series of optimizations. Because there isn't a generally good way to distinguish the two, almost all of the warnings produced would be false positives (noise).<br /><br /><h2>Clang's Approach to Handling Undefined Behavior</h2><br />Given the sorry state that we're in when it comes to undefined behavior, you might be wondering what Clang and LLVM are doing to try to improve the situation. I mentioned a couple of them already: the <a href="http://clang-analyzer.llvm.org/">Clang Static Analyzer</a>, <a href="http://klee.llvm.org/">Klee project</a>, and the <tt>-fcatch-undefined-behavior</tt> flag are useful tools for tracking down some classes of these bugs. The problem is that these aren't as widely used as the compiler is, so anything we can do directly in the compiler offers even higher goodness than doing it in these other tools. Keep in mind though that the compiler is limited by not having dynamic information and by being limited to what it can without burning lots of compile time.<br /><br />Clang's first step to improve the world's code is to turn on a whole lot more warnings by default than other compilers do. While some developers are disciplined and build with "<tt>-Wall -Wextra</tt>" (for example), many people don't know about these flags or don't bother to pass them. Turning more warnings on by default catches more bugs more of the time.<br /><br />The second step is that Clang generates warnings for many classes of undefined behavior (including dereference of null, oversized shifts, etc) that are obvious in the code to catch some common mistakes. Some of the caveats are mentioned above, but these seem to work well in practice.<br /><br />The third step is that the LLVM optimizer generally takes much less liberty with undefined behavior than it could. Though the standard says that any instance of undefined behavior has completely unbound effects on the program, this is not a particularly useful or developer friendly behavior to take advantage of. Instead, the LLVM optimizer handles these optimizations in a few different ways (the links describe rules of LLVM IR, not C, sorry!):<br /><br /><ol><li>Some cases of undefined behavior are silently transformed into implicitly trapping operations if there is a good way to do that. For example, with Clang, this C++ function:<br /><br /><pre>int *foo(long x) {<br /> return new int[x];<br />}<br /></pre><br />compiles into this X86-64 machine code:<br /><br /><pre>__Z3fool:<br /> movl $4, %ecx<br /> movq %rdi, %rax<br /> mulq %rcx<br /> movq $-1, %rdi # Set the size to -1 on overflow<br /> cmovnoq %rax, %rdi # Which causes 'new' to throw std::bad_alloc<br /> jmp __Znam<br /></pre><br />instead of the code GCC produces:<br /><br /><pre>__Z3fool:<br /> salq $2, %rdi<br /> jmp __Znam # Security bug on overflow!<br /></pre><br />The difference here is that we've decided to invest a few cycles in preventing a potentially <a href="http://cert.uni-stuttgart.de/advisories/calloc.php">serious integer overflow bug</a> that can lead to buffer overflows and exploits (operator new is typically fairly expensive, so the overhead is almost never noticable). The GCC folks have been aware of this <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19351">since at least 2005</a> but haven't fixed this at the time of this writing.</li><li>Arithmetic that <a href="http://llvm.org/docs/LangRef.html#undefvalues">operates on undefined values</a> is considered to produce a undefined value instead of producing undefined behavior. The distinction is that undefined values can't format your hard drive or produce other undesirable effects. A useful refinement happens in cases where the arithmetic would produce the same output bits given any possible instance of the undefined value. For example, the optimizer assumes that the result of "undef & 1" has zeros for its top bits, treating only the low bit as undefined. This means that ((undef & 1) >> 1) is defined to be 0 in LLVM, not undefined.</li><li>Arithmetic that dynamically executes an undefined operation (such as a signed integer overflow) generates a logical <a href="http://llvm.org/docs/LangRef.html#trapvalues">trap value</a> which poisons any computation based on it, but that does not destroy your entire program. This means that logic downstream from the undefined operation may be affected, but that your entire program isn't destroyed. This is why the optimizer ends up deleting code that operates on uninitialized variables, for example.</li><li>Stores to null and calls through null pointers are turned into a __builtin_trap() call (which turns into a trapping instruction like "ud2" on x86). These happen all of the time in optimized code (as the result of other transformations like inlining and constant propagation) and we used to just delete the blocks that contained them because they were "obviously unreachable".<br /><br />While (from a pedantic language lawyer standpoint) this is strictly true, we quickly learned that people do occasionally dereference null pointers, and having the code execution just fall into the top of the next function makes it very difficult to understand the problem. From the performance angle, the most important aspect of exposing these is to squash downstream code. Because of this, clang turns these into a runtime trap: if one of these is actually dynamically reached, the program stops immediately and can be debugged. The drawback of doing this is that we slightly bloat code by having these operations and having the conditions that control their predicates.</li><li>The optimizer does go to some effort to "do the right thing" when it is obvious what the programmer meant (such as code that does "*(int*)P" when P is a pointer to float). This helps in many common cases, but you really don't want to rely on this, and there are lots of examples that you might think are "obvious" that aren't after a long series of transformations have been applied to your code.</li><li>Optimizations that don't fall into any of these categories, such the zero_array and set/call examples in Part #1 are optimized as described, silently, without any indication to the user. We do this because we don't have anything useful to say, and it is very uncommon for (buggy) real-world code to be broken by these optimizations.</li></ol><br />One major area of improvement we can make is with respect to trap insertion. I think it would be interesting to add an (off-by-default) warning flag that would cause the optimizer to warn whenever it generates a trap instruction. This would be extremely noisy for some codebases, but could be useful for others. The first limiting factor here is the infrastructure work to make the optimizer produce warnings: it doesn't have useful source code location information unless debugging information is turned on (but this could be fixed).<br /><br />The other, more significant, limiting factor is that the warning wouldn't have any of the "tracking" information to be able to explain that an operation is the result of unrolling a loop three times and inlining it through four levels of function calls. At best we'll be able to point out the file/line/column of the original operation, which will be useful in the most trivial cases, but is likely to be extremely confusing in other cases. In any event, this hasn't been a high priority for us to implement because a) it isn't likely to give a good experience b) we won't be able to turn it on by default, and c) is a lot of work to implement.<br /><br /><h2>Using a Safer Dialect of C (and other options)</h2><br />A final option you have if you don't care about "ultimate performance", is to use various compiler flags to enable dialects of C that eliminate these undefined behaviors. For example, using the <tt>-fwrapv</tt> flag eliminates undefined behavior that results from signed integer overflow (however, note that it does <b>not</b> eliminate possible integer overflow security vulnerabilities). The <tt>-fno-strict-aliasing</tt> flag disables Type Based Alias Analysis, so you are free to ignore these type rules. If there was demand, we could add a flag to Clang that implicitly zeros all local variables, one that inserts an "and" operation before each shift with a variable shift count, etc. Unfortunately, there is no tractable way to <b>completely</b> eliminate undefined behavior from C without breaking the ABI and completely destroying its performance. The other problem with this is that you're not writing C anymore, you're writing a similar, but non-portable dialect of C.<br /><br />If writing code in a non-portable dialect of C isn't your thing, then the <tt>-ftrapv</tt> and <tt>-fcatch-undefined-behavior</tt> flags (along with the other tools mentioned before) can be useful weapons in your arsenal to track down these sorts of bugs. Enabling them in your debug builds can be a great way to find related bugs early. These flags can also be useful in production code if you are building security critical applications. While they provide no guarantee that they will find all bugs, they do find a useful subset of bugs.<br /><br />Ultimately, the real problem here is that C just isn't a "safe" language and that (despite its success and popularity) many people do not really understand how the language works. In its decades of evolution prior to standardization in 1989, C migrated from being a "low level systems programming language that was a tiny layer above PDP assembly" to being a "low level systems programming language, trying to provide decent performance by <em>breaking many people's expectations</em>". On the one hand, these C "cheats" almost always work and code is generally more performant because of it (and in some cases, <em>much</em> more performant). On the other hand, the places where C cheats are often some of the most surprising to people and typically strike at the worst possible time.<br /><br />C is much more than a portable assembler, sometimes in very surprising ways. I hope this discussion helps explain some of the issues behind undefined behavior in C, at least from a compiler implementer's viewpoint.<br /><br />-<a href="http://nondot.org/sabre/">Chris Lattner</a>
- What Every C Programmer Should Know About Undefined Behavior #2/3https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.htmlSat, 14 May 2011 12:33:00 +0000https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.htmlIn <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">Part 1</a>of our series, we discussed what undefined behavior is, and how it allows C and C++ compilersto produce higher performance applications than "safe" languages. This post talks about how"unsafe" C really is, explaining some of the highly surprising effects that undefined behaviorcan cause. In <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html">Part#3</a>, we talk about what friendly compilers can do to mitigate some of the surprise, evenif they aren't required to. <br /><br />I like to call this "<b>Why undefined behavior is often a scary and terrible thing for Cprogrammers</b>". :-)<br /><br /><a name='more'></a><br />Translation available in: <a href="http://blog-ja.intransient.info/2011/05/c-23.html">Japanese</a>,and <a href="https://chicksx.com/blog/c-programmer-part-2">Spanish</a>a>.<h2>Interacting Compiler Optimizations Lead to Surprising Results</h2><br />A modern compiler optimizer contains many optimizations that are run in specific orders, sometimes iterated, and change as the compiler evolves over time (e.g. new releases come out). Also, different compilers often have substantially different optimizers. Because optimizations run at different stages, emergent effects can occur due to previous optimizations changing the code.<br /><br />Lets take a look at a silly example (simplified from an exploitable bug that was found in the Linux Kernel) to make this more concrete:<br /><br /><pre>void contains_null_check(int *P) {<br /> int dead = *P;<br /> if (P == 0)<br /> return;<br /> *P = 4;<br />}<br /></pre><br />In this example, the code "clearly" checks for the null pointer. If the compiler happens to run "Dead Code Elimination" before a "Redundant Null Check Elimination" pass, then we'd see the code evolve in these two steps:<br /><br /><pre>void contains_null_check_after_DCE(int *P) {<br /> <strike>//int dead = *P;</strike> // deleted by the optimizer.<br /> if (P == 0)<br /> return;<br /> *P = 4;<br />}<br /></pre><br />and then:<br /><br /><pre>void contains_null_check_after_DCE_and_RNCE(int *P) {<br /> if (P == 0) // Null check not redundant, and is kept.<br /> return;<br /> *P = 4;<br />}<br /></pre><br />However, if the optimizer happens to be structured differently, it could run RNCE before DCE. This would give us these two steps:<br /><br /><pre>void contains_null_check_after_RNCE(int *P) {<br /> int dead = *P;<br /> if (<b>false</b>) // P was dereferenced by this point, so it can't be null <br /> return;<br /> *P = 4;<br />}<br /></pre><br />and then dead code elimination runs:<br /><br /><pre>void contains_null_check_after_RNCE_and_DCE(int *P) {<br /> <strike>//int dead = *P;</strike><br /> <strike>//if (false)</strike><br /> <strike>// return;</strike><br /> *P = 4;<br />}<br /></pre><br />To many (reasonable!) programmers, deleting the null check from this function would be very surprising (and they'd probably file a bug against the compiler :). However, both "contains_null_check_after_DCE_and_RNCE" and "contains_null_check_after_RNCE_and_DCE" are perfectly valid optimized forms of "contains_null_check" according to the standard, and both of the optimizations involved are important for the performance of various applications.<br /><br />While this is intentionally a simple and contrived example, this sort of thing happens all the time with inlining: inlining a function often exposes a number of secondary optimization opportunities. This means that if the optimizer decides to inline a function, a variety of local optimizations can kick in, which change the behavior of the code. This is both perfectly valid according to the standard, and important for performance in practice.<br /><br /><h2>Undefined Behavior and Security Don't Mix Well</h2><br />The C family of programming languages is used to write a wide range of security critical code, such as kernels, setuid daemons, web browsers, and much more. This code is exposed to hostile input and bugs can lead to all sorts of exploitable security problems. One of the widely cited advantages of C is that it is relatively easy to understand what is going on when you read the code.<br /><br />However, undefined behavior takes this property away. After all, most programmers would think that "contains_null_check" would do a null check above. While this case isn't too scary (the code will probably crash in the store if passed a null check, which is relatively easy to debug) there are a wide range of <i>very reasonable</i> looking C fragments that are completely invalid. This problem has bit many projects (including the Linux Kernel, OpenSSL, glibc, etc) and even led to CERT issuing a <a href="http://www.kb.cert.org/vuls/id/162289">vulnerability note</a> against GCC (though my personal belief is that all widely-used optimizing C compilers are vulnerable to this, not just GCC).<br /><br />Lets look at an example. Consider this carefully written C code:<br /><br /><pre>void process_something(int size) {<br /> // Catch integer overflow.<br /> if (size > size+1)<br /> abort();<br /> ...<br /> // Error checking from this code elided.<br /> char *string = malloc(size+1);<br /> read(fd, string, size);<br /> string[size] = 0;<br /> do_something(string);<br /> free(string);<br />}<br /></pre>This code is checking to make sure that the malloc is big enough to hold the data read from the file (because a nul terminator byte needs to be added), bailing out if an integer overflow error occurs. However, this is <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html#signed_overflow">exactly the example we gave before</a> in which the compiler is allowed to (validly) optimize out the check. This means that it is perfectly possible for the compiler to turn this into:<br /><br /><pre>void process_something(int *data, int size) {<br /> char *string = malloc(size+1);<br /> read(fd, string, size);<br /> string[size] = 0;<br /> do_something(string);<br /> free(string);<br />}<br /></pre><br />When being built on a 64-bit platform, it is quite likely that this is an exploitable bug when "size" is INT_MAX (perhaps the size of a file on disk). Lets consider how terrible this is: a code auditor reading the code would very reasonably think that a proper overflow check is happening. Someone testing the code would find no problem unless they specifically tested that error path. The secure code seems to work, until someone goes ahead and exploits the vulnerability. All in all, this is a surprising and quite scary class of bugs. Fortunately, the fix is simple in this case: just use "size == INT_MAX" or similar.<br /><br />As it turns out, integer overflow is a security problem for many reasons. Even if you are using fully defined integer arithmetic (either by using <tt>-fwrapv</tt> or by using unsigned integers), there is a <a href="http://en.wikipedia.org/wiki/Integer_overflow#Security_ramifications">wholly different class</a> of integer overflow bug possible. Fortunately, this class is visible in the code and knowledgable security auditors are usually aware of the problem.<br /><br /><br /><h2>Debugging Optimized Code May Not Make Any Sense</h2>Some people (for example, low level embedded programmers who like to look at generated machine code) do all of their development with optimizations turned on. Because code <b>frequently</b> has bugs when it is being developed, these folks end up seeing a disproportionate number of surprising optimizations that can lead to difficult-to-debug behaviors at runtime. For example, accidentally leaving out the "i = 0" in the "zero_array" example from the first article allows the compiler to completely discard the loop (compiling zero_array into "return;") because it is a use of an uninitialized variable.<br /><br />Another interesting case that bit someone recently happened when they had a (global) function pointer. A simplified example looks like this:<br /><br /><pre>static void (*FP)() = 0;<br />static void impl() {<br /> printf("hello\n");<br />}<br />void set() {<br /> FP = impl;<br />}<br />void call() {<br /> FP();<br />}<br /></pre>which clang optimizes into:<br /><br /><pre>void set() {}<br />void call() {<br /> printf("hello\n");<br />}<br /></pre>It is allowed to do this because calling a null pointer is undefined, which permits it to assume that set() must be called before call(). In this case, the developer forgot to call "set", did not crash with a null pointer dereference, and their code broke when someone else did a debug build.<br /><br />The upshot is that it is a fixable issue: if you suspect something weird is going on like this, try building at -O0, where the compiler is much less likely to be doing any optimizations at all.<br /><br /><br /><h2>"Working" code that uses undefined behavior can "break" as the compiler evolves or changes </h2>We've seen many cases where applications that "appear to be work" suddenly break when a newer LLVM is used to build it, or when the application was moved from GCC to LLVM. While LLVM does occasionally have a bug or two itself :-), this is most often because of latent bugs in the application that are now being exposed by the compiler. This can happen all sorts different ways, two examples are:<br /><br />1. an uninitialized variable which was zero initialized by luck "before", and now it shares some other register that isn't zero. This is commonly exposed by register allocation changes.<br /><br />2. an array overflow on the stack which starts clobbering a variable that actually matters, instead of something that was dead. This is exposed when the compiler rearranges how it packs things on the stack, or gets more aggressive about sharing stack space for values with non-overlapping lifetimes.<br /><br />The important and scary thing to realize is that just about *any* optimization based on undefined behavior can start being triggered on buggy code at any time in the future. Inlining, loop unrolling, memory promotion and other optimizations will keep getting better, and a significant part of their reason for existing is to expose secondary optimizations like the ones above.<br /><br />To me, this is deeply dissatisfying, partially because the compiler inevitably ends up getting blamed, but also because it means that huge bodies of C code are land mines just waiting to explode. This is even worse because...<br /><br /><h2>There is No Reliable Way to Determine if a Large Codebase Contains Undefined Behavior</h2>Making the landmine a much much worse place to be is the fact that there is <b>no good way</b> to determine whether a large scale application is free of undefined behavior, and thus not susceptible to breaking in the future. There are many useful tools that can help find <b>some</b> of the bugs, but nothing that gives full confidence that your code won't break in the future. Lets look at some of these options, along with their strengths and weaknesses:<br /><br />1. The <a href="http://valgrind.org/">Valgrind</a> <a href="http://valgrind.org/info/tools.html#memcheck">memcheck tool</a> is a fantastic way to find all sorts of uninitialized variables and other memory bugs. Valgrind is limited because it is quite slow, it can only find bugs that still exist in the generated machine code (so it <a href="http://blog.regehr.org/archives/519">can't find things the optimizer removes</a>), and doesn't know that the source language is C (so it can't find shift-out-of-range or signed integer overflow bugs).<br /><br />2. Clang has an experimental <tt>-fcatch-undefined-behavior</tt> mode that inserts runtime checks to find violations like shift amounts out of range, some simple array out of range errors, etc. This is limited because it slows down the application's runtime and it can't help you with random pointer dereferences (like Valgrind can), but it can find other important bugs. Clang also fully supports the <tt>-ftrapv</tt> flag (not to be confused with <tt>-fwrapv</tt>) which causes signed integer overflow bugs to trap at runtime (GCC also has this flag, but it is completely unreliable/buggy in my experience). Here is a quick demo of <tt>-fcatch-undefined-behavior</tt>:<br /><br /><pre>$ cat t.c<br />int foo(int i) {<br /> int x[2];<br /> x[i] = 12;<br /> return x[i];<br />}<br /><br />int main() {<br /> return foo(2);<br />}<br />$ clang t.c <br />$ ./a.out <br />$ clang t.c -fcatch-undefined-behavior <br />$ ./a.out <br />Illegal instruction<br /></pre>3. Compiler warning messages are good for finding some classes of these bugs, like uninitialized variables and simple integer overflow bugs. It has two primary limitations: 1) it has no dynamic information about your code as it executes, and 2) it must run very quickly because any analysis it does slows down compile time.<br /><br />4. <a href="http://clang-analyzer.llvm.org/">The Clang Static Analyzer</a> performs a much deeper analysis to try to find bugs (including use of undefined behavior, like null pointer dereferences). You can think of it as generating souped up compiler warning messages, because it is not bound by the compile time constraints of normal warnings. The primary disadvantages of the static analyzer is that it 1) doesn't have dynamic information about your program as it runs, and 2) is not integrated into normal workflows for many developers (though its integration into <a href="http://developer.apple.com/technologies/mac/snowleopard/static.html">Xcode 3.2 and later</a> is fantastic). <br /><br />5. The <a href="http://klee.llvm.org/">LLVM "Klee" Subproject</a> uses symbolic analysis to "try every possible path" through a piece of code to find bugs in the code and it <b>produces a testcase</b>. It is a great little project that is mostly limited by not being practical to run on large-scale applications.<br /><br />6. While I have never tried it, the <a href="http://code.google.com/p/c-semantics/">C-Semantics tool</a> by Chucky Ellison and Grigore Rosu is a very interesting tool that can apparently find some classes of bugs (such as sequence point violations). It is still a research prototype, but may be useful for finding bugs in (small and self-contained) programs. I recommend reading <a href="http://blog.regehr.org/archives/523">John Regehr's post about it</a> for more information.<br /><br />The end result of this is that we have lots of tools in the toolbox to find some bugs, but no good way to prove that an application is free of undefined behavior. Given that there are lots of bugs in real world applications and that C is used for a broad range of critical applications, this is pretty scary. In our <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html">final article</a>, I look at various options that C compilers have when dealing with undefined behavior, with a specific focus on <a href="http://clang.llvm.org/">Clang</a>.<br /><br />-<a href="http://nondot.org/sabre/">Chris Lattner</a>
- What Every C Programmer Should Know About Undefined Behavior #1/3https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.htmlFri, 13 May 2011 11:25:00 +0000https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.htmlPeople occasionally ask why LLVM-compiled code sometimes generates SIGTRAP signals when the optimizer is turned on.After digging in, they find that Clang generated a "ud2" instruction (assuming X86 code) - the same as is generatedby __builtin_trap(). There are several issues at work here, all centering around undefined behavior in C code andhow LLVM handles it.<br /><br />This blog post (the first in a series of three) tries to explain some of theseissues so that you can better understand the tradeoffs and complexities involved, and perhaps learn a few moreof the dark sides of C. It turns out that C is <i>not</i> a "high level assembler" like many experienced Cprogrammers (particularly folks with a low-level focus) like to think, and that C++ and Objective-C have directlyinherited plenty of issues from it.<br /><br /><a name='more'></a><br /><h2>Introduction to Undefined Behavior</h2><br />Translation available in: <a href="http://blog-ja.intransient.info/2011/05/c-13.html">Japanese</a> and<a href="https://chicksgold.com/blog/c-programmer-should-know">Spanish</a><br /><br />Both LLVM IR and the C programming language have the concept of "undefined behavior". Undefined behavior is abroad topic with a lot of nuances. The best introduction I've found to it is a post on<a href="http://blog.regehr.org/archives/213">John Regehr's Blog</a>. The short version of this excellent articleis that many seemingly reasonable things in C actually have undefined behavior, and this is a common source of bugsin programs. Beyond that, any undefined behavior in C gives license to the implementation (the compiler and runtime) to produce code that formats your hard drive, does completely unexpected things, <a href="http://www.catb.org/jargon/html/N/nasal-demons.html">or worse</a>. Again, I would highly recommend reading <a href="http://blog.regehr.org/archives/213">John's article</a>.<br /><br />Undefined behavior exists in C-based languages because the designers of C wanted it to be an extremely efficient low-level programming language. In contrast, languages like Java (and many other 'safe' languages) have eschewed undefined behavior because they want safe and reproducible behavior across implementations, and willing to sacrifice performance to get it. While neither is "the right goal to aim for," if you're a C programmer you really should understand what undefined behavior is.<br /><br />Before getting into the details, it is worth briefly mentioning what it takes for a compiler to get good performance out a broad range of C apps, because <b>there is no magic bullet</b>. At a very high level, compilers produce high performance apps by a) doing a good job at bread and butter algorithms like register allocation, scheduling, etc. b) knowing lots and lots of "tricks" (e.g. peephole optimizations, loop transformations, etc), and applying them whenever profitable. c) being good at eliminating unnecessary abstractions (e.g. redundancy due to macros in C, inlining functions, eliminating temporary objects in C++, etc) and d) not screwing anything up. While any of the optimizations below may sound trivial, it turns out that saving just one cycle out of a critical loop can make some codec run 10% faster or take 10% less power.<br /><br /><h2 id="optimizations">Advantages of Undefined Behavior in C, with Examples</h2><br />Before getting into the dark side of undefined behavior and LLVM's policy and behavior when used as a C compiler, I thought it would be helpful to consider a few specific cases of undefined behavior, and talk about how each enables better performance than a safe language like Java. You can look at this either as "optimizations enabled" by the class of undefined behavior or as the "overhead avoided" that would be required to make each case defined. While the compiler optimizer could eliminate some of these overheads some of the time, to do so in general (for every case) would require solving the halting problem and many other "interesting challenges".<br /><br />It is also worth pointing out that both Clang and GCC nail down a few behaviors that the C standard leaves undefined. The things I'll describe are both undefined according to the standard and treated as undefined behavior by both of these compilers in their default modes.<br /><br /><b>Use of an uninitialized variable:</b> This is commonly known as source of problems in C programs and there are many tools to catch these: from compiler warnings to static and dynamic analyzers. This improves performance by not requiring that all variables be zero initialized when they come into scope (as Java does). For most scalar variables, this would cause little overhead, but stack arrays and malloc'd memory would incur a memset of the storage, which could be quite costly, particularly since the storage is usually completely overwritten.<br /><br /><b id="signed_overflow">Signed integer overflow:</b> If arithmetic on an 'int' type (for example) overflows, the result is undefined. One example is that "INT_MAX+1" is not guaranteed to be INT_MIN. This behavior enables certain classes of optimizations that are important for some code. For example, knowing that INT_MAX+1 is undefined allows optimizing "X+1 > X" to "true". Knowing the multiplication "cannot" overflow (because doing so would be undefined) allows optimizing "X*2/2" to "X". While these may seem trivial, these sorts of things are commonly exposed by inlining and macro expansion. A more important optimization that this allows is for "<=" loops like this:<br /><br /><pre>for (i = 0; i <= N; ++i) { ... }<br /></pre><br />In this loop, the compiler can assume that the loop will iterate exactly N+1 times if "i" is undefined on overflow, which allows a broad range of loop optimizations to kick in. On the other hand, if the variable is defined to wrap around on overflow, then the compiler must assume that the loop is possibly infinite (which happens if N is INT_MAX) - which then disables these important loop optimizations. This particularly affects 64-bit platforms since so much code uses "int" as induction variables.<br /><br />It is worth noting that unsigned overflow is guaranteed to be defined as 2's complement (wrapping) overflow, so you can always use them. The cost to making signed integer overflow defined is that these sorts of optimizations are simply lost (for example, a common symptom is a ton of sign extensions inside of loops on 64-bit targets). Both Clang and GCC accept the "-fwrapv" flag which forces the compiler to treat signed integer overflow as defined (other than divide of INT_MIN by -1).<br /><br /><b>Oversized Shift Amounts:</b> Shifting a uint32_t by 32 or more bits is undefined. My guess is that this originated because the underlying shift operations on various CPUs do different things with this: for example, X86 truncates 32-bit shift amount to 5 bits (so a shift by 32-bits is the same as a shift by 0-bits), but PowerPC truncates 32-bit shift amounts to 6 bits (so a shift by 32 produces zero). Because of these hardware differences, the behavior is completely undefined by C (thus shifting by 32-bits on PowerPC could format your hard drive, it is <b>*not*</b> guaranteed to produce zero). The cost of eliminating this undefined behavior is that the compiler would have to emit an extra operation (like an 'and') for variable shifts, which would make them twice as expensive on common CPUs.<br /><br /><b>Dereferences of Wild Pointers and Out of Bounds Array Accesses:</b> Dereferencing random pointers (like NULL, pointers to free'd memory, etc) and the special case of accessing an array out of bounds is a common bug in C applications which hopefully needs no explanation. To eliminate this source of undefined behavior, array accesses would have to each be range checked, and the ABI would have to be changed to make sure that range information follows around any pointers that could be subject to pointer arithmetic. This would have an extremely high cost for many numerical and other applications, as well as breaking binary compatibility with every existing C library.<br /><br /><b>Dereferencing a NULL Pointer:</b> contrary to popular belief, dereferencing a null pointer in C is undefined. It is <i>not defined to trap</i>, and if you mmap a page at 0, it is <i>not defined to access that page</i>. This falls out of the rules that forbid dereferencing wild pointers and the use of NULL as a sentinel. NULL pointer dereferences being undefined enables a broad range of optimizations: in contrast, Java makes it invalid for the compiler to move a side-effecting operation across any object pointer dereference that cannot be proven by the optimizer to be non-null. This significantly punishes scheduling and other optimizations. In C-based languages, NULL being undefined enables a large number of simple scalar optimizations that are exposed as a result of macro expansion and inlining.<br /><br />If you're using an LLVM-based compiler, you can dereference a "volatile" null pointer to get a crash if that's what you're looking for, since volatile loads and stores are generally not touched by the optimizer. There is currently no flag that enables random NULL pointer loads to be treated as valid accesses or to make random loads know that their pointer is "allowed to be null".<br /><br /><b>Violating Type Rules:</b> It is undefined behavior to cast an int* to a float* and dereference it (accessing the "int" as if it were a "float"). C requires that these sorts of type conversions happen through memcpy: using pointer casts is not correct and undefined behavior results. The rules for this are quite nuanced and I don't want to go into the details here (there is an exception for char*, vectors have special properties, unions change things, etc). This behavior enables an analysis known as "Type-Based Alias Analysis" (TBAA) which is used by a broad range of memory access optimizations in the compiler, and can significantly improve performance of the generated code. For example, this rule allows clang to optimize this function:<br /><br /><pre>float *P;<br /> void zero_array() {<br /> int i;<br /> for (i = 0; i < 10000; ++i)<br /> P[i] = 0.0f;<br /> }<br /></pre><br />into "<tt>memset(P, 0, 40000)</tt>". This optimization also allows many loads to be hoisted out of loops, common subexpressions to be eliminated, etc. This class of undefined behavior can be disabled by passing the -fno-strict-aliasing flag, which disallows this analysis. When this flag is passed, Clang is required to compile this loop into 10000 4-byte stores (which is several times slower), because it has to assume that it is possible for any of the stores to change the value of P, as in something like this:<br /><br /><pre>int main() {<br /> P = (float*)&P; // cast causes TBAA violation in zero_array.<br /> zero_array();<br />}<br /></pre><br />This sort of type abuse is pretty uncommon, which is why the standard committee decided that the significant performance wins were worth the unexpected result for "reasonable" type casts. It is worth pointing out that Java gets the benefits of type-based optimizations without these drawbacks because it doesn't have unsafe pointer casting in the language at all.<br /><br />Anyway, I hope that this gives you an idea of some of the classes of optimizations enabled by undefined behavior in C. There are many other kinds of course, including sequence point violations like "foo(i, ++i)", race conditions in multithreaded programs, violating 'restrict', divide by zero, etc.<br /><br />In our <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html">next post</a>, we'll discuss why undefined behavior in C is a pretty scary thing if performance is not your only goal. In our final post in the series, we'll talk about how LLVM and Clang handle it.<br /><br />-<a href="http://nondot.org/sabre/">Chris Lattner</a>
- Regular Expression Commandshttps://blog.llvm.org/2011/04/regular-expression-commands.htmlFri, 22 Apr 2011 10:19:00 +0000https://blog.llvm.org/2011/04/regular-expression-commands.html<span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> Greetings LLDB users. I want to start writing regular blog posts for the new and cool features and things you can do in LLDB. Today I will start with one that was just added: regular expression commands.</span></span><br /><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span><br /><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"></span></span><br /><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><a name='more'></a></span></span><br /><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br />What is a regular expression command? It is a smart alias to other commands that you can define using the "</span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">command regex" </span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">command. You define a regular expression command by giving it a command name followed by a series of regular expression and substitution pairs. The regular expression and substitution pairs are supplied in a standard stream editor search and replace format:</span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></div><div><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"> </span></span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">s/<regex>/<subst>/</span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">When a command in later entered, it will strip off the regular expression command name and any spaces that follow, it and pass the raw argument string to be matched against your regular expression list in the order in which they were entered. The first </span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"><regex</span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">></span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> to match the raw argument string will then be allowed substitute in </span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">the command defined by </span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><span class="Apple-style-span" style="font-family: 'courier new';"><subst></span>.</span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">Lets supposed we want to use the </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"f"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> as a command to select a frame by frame index. The command to select a frame by the frame index is the </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"frame select <num></span></span><frame-idx><num><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"</span></span></num></frame-idx></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> command which you might not always want to type out. We can make this a bit easier this using a regular expression command:<br /></span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) command regex f 's/([0-9]+)/frame select %1/' </span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"command regex f"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> tells the interpreter to create a new regex command named </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"f"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">, and when a command is entered on the command line that starts with </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"f"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">, it will match the remaining command text against the regular expression </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"([0-9]+)"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">, and it if matches, it will substitute any parenthesized subexpressions. Here we enclosed the number regular expression </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"[0-9]+"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> in parentheses which will save the results in the first match and allow the matching string to be substituted into the match substitution text </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"frame select %1"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">. When we use our new regular expression command from the LLDB command line, it will show us what command resulted from our regular expression substitution:<br /></span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) f 12</span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">frame select 12</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><span class="Apple-style-span" style="font-family: 'courier new';"><br /></span><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">Any leading spaces that follow the regular expression command <span class="Apple-style-span" style="font-family: 'courier new';">"f"</span> will always be stripped prior to matching the regular expression, but there may be trailing spaces since we are processing the remaining raw command string that follows the initial </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"f"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> command name. The regular expression is also just looking for any sequence of one or more digits. Our current regular expression will actually match:<br /></span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) f 11 22 33<br />frame select 11</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><span class="Apple-style-span" style="font-family: 'courier new';"><br /></span><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">Since this isn't desired, we should make the regular expression more complete by checking for the start of the line (</span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">^</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">) and the end of the line (</span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">$</span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">) and also allow for zero or more spaces (</span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">[[:space:]]*</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">) to come after the number. Our newer and safer regular expression command line looks like:</span></span></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) command regex f 's/^([0-9]+)[[:space:]]*$/frame select %1/'</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">Now we can type in a command as </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"f 12 "</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> (note the trailing spaces), and still get correct substitutions, while our previous example of </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">"f 11 22 33"</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> will no longer match:<br /></span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) f 11 22 33<br />error: Command contents '11 22 33' failed to match any regular expression in the 'f' regex command.</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><span class="Apple-style-span" style="font-family: 'courier new';"><br /></span><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">Lets take this a bit further by also using the </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">f</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> command to emulate GDB's </span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">finish</span></span></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"> command when it is typed without any arguments. We will also modify this command to watch for a single "+" or "-" followed by a digit to signify a relative frame change using the frame select command with the --relative option:<br /></span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) frame select --relative </span></span><integer><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><offset></offset></span></span></integer></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /><br /></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">Multiple regular expressions can be entered in on the command line, or using the multi-line mode when typing in a live LLDB debug session. Below the text in bold is user entered:<br /></span></span><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br /></span></span></code></div><div><code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) </span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">commands regex f</span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"><br />Enter regular expressions in the form 's/</span></span><regex><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">/</span></span><subst><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">/' and terminate with an empty line:<br /></span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">s/^([0-9]+)[[:space:]]*$/frame select %1/<br />s/^([+-][0-9]+)[[:space:]]*$/frame select --relative=%1/<br />s/^[[:space:]]*$/finish/</span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><span class="Apple-style-span" style="font-family: 'courier new';"><br /></span><br /><span class="Apple-style-span" style="font-family: 'courier new';">(lldb) </span></span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">f</span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"><br />finish<br />...<br />(lldb) </span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">f -1</span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"><br />frame select --relative=-1<br />...<br />(lldb) </span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">f +1</span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"><br />frame select --relative=+1<br />...<br />(lldb) </span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">f 12</span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';"><br />frame select 12<br /></span></span></subst></regex></code><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';"><br />I hope you can see the possilbities in how you can customize your command line experience in LLDB using these commands. You can add any regular expression commands to your </span></span><b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'courier new';">~/.lldbinit</span><span class="Apple-style-span" style="font-family: 'lucida grande';"> </span></span></b><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'lucida grande';">file to always have your regular expression commands defined in your debug sessions.</span></span></div><div><span class="Apple-style-span" style="font-family: Times;"><br /></span></div>
- LLVM Developer Meeting 2010https://blog.llvm.org/2010/12/llvm-developer-meeting-2010.htmlThu, 23 Dec 2010 20:03:00 +0000https://blog.llvm.org/2010/12/llvm-developer-meeting-2010.htmlThe <a href="http://www.llvm.org/devmtg/2010-11/">2010 edition</a> of the <a href="http://www.llvm.org/devmtg/">LLVM Developer's Meeting</a> has come and gone, and it was a great event. It featured 17 great talks, several BOF sessions, and lots of informal discussions between all sorts of people interested in LLVM and its subprojects. Lang Hames wrote up a great summary of <a href="http://google-opensource.blogspot.com/2010/12/notes-from-2010-llvm-developers-meeting.html">his experience at the meeting</a>.<br /><br />Unfortunately, there was more people who wanted to attend than we were able to accomodate, but fortunately the slides and videos of all the talks are <a href="http://www.llvm.org/devmtg/2010-11/">available the web page</a>. Many thanks go our to our sponsors: Apple, QuIC, Google, Qualcomm.<br /><br />Happy holidays,<br /><br />-Chris
- LLVM in ClamAVhttps://blog.llvm.org/2010/09/llvm-in-clamav.htmlTue, 07 Sep 2010 21:05:00 +0000https://blog.llvm.org/2010/09/llvm-in-clamav.htmlNew in version 0.96, the ClamAV antivirus system extends its internal bytecode interpreter to support an LLVM JIT compiler. This JIT compiler allows for improved execution speeds, but also provides the ability to write virus checks directly in C code. For more details, see the <a href="http://vrt-sourcefire.blogspot.com/2010/09/introduction-to-clamavs-low-level.html">Sourcefire Vulnerability Research Team's Blog</a>.<br /><br />-Chris
- TCE project: Co-design of application-specific processors with LLVM-based compilation supporthttps://blog.llvm.org/2010/06/tce-project-co-design-of-application.htmlTue, 29 Jun 2010 08:38:00 +0000https://blog.llvm.org/2010/06/tce-project-co-design-of-application.html<a href="http://tce.cs.tut.fi/">TTA-based Codesign Environment</a> (TCE) is an application-specific instruction-set processor (ASIP) design toolset developed in <a href="http://www.tut.fi/">Tampere University of Technology</a> in several research projects since 2003. This blog post introduces the project and how LLVM is used in it to provide high-level language compiler support for the designed ASIPs.<br /><br /><a name='more'></a><br /><br /><br /><span style="font-size:medium;">The use case for application-specific processors</span><br /><br />Especially in embedded devices so called general purpose "off-the-shelf processors" are often not optimal for the application at hand. The readily available processors might be too large in chip area, might consume too much power, might be too expensive (for a mass product) or are not running the set of programs fast enough. In order to tackle the performance problem, a common design choice is to run parts of the application in software while speeding up the performance critical functions with a custom hand-tailored hardware accelerator or a co-processor implemented as an <a href="http://en.wikipedia.org/wiki/Application-specific_integrated_circuit">application-specific integrated circuit</a> (ASIC).<br /><br />The design, implementation and verification time of the hardware accelerators costs money and lengthens the time-to-market for the designed device. In addition, a fixed function hardware accelerator designed with an hardware description language (HDL) such as VHDL or Verilog has the problem of being "carved in stone", thus not providing programmability that enables late bug fixes and on-the-field updates to the supported set of functions.<br /><br /><a href="http://en.wikipedia.org/wiki/Fpga">Field-Programmable Gate Arrays</a> (FPGAs) allow reconfiguring the implemented hardware logic on the field. However, as FPGA is only an hardware design implementation technique, the "<a href="http://en.wikipedia.org/wiki/Non-recurring_engineering">non-recurring engineering cost</a>" of designing the hardware logic in an HDL is still there.<br /><br />Application-specific processors can be spotted in the "design space" between off-the-shelf processors, such as ARM products or Texas Instruments DSPs where functionality is described fully in software by the designer, and custom fixed function hardware accelerators where functionality is described fully in hardware description language by the designer. In case of ASIPs, the engineer is able to design both software and hardware at the same time (co-design) and is free to the choose the level of application specialization applied to the processor.<br /><br />What can be customized in an ASIP depends on the used processor template. A commonly customized part of the processor is the instruction set. Customizable instruction set allows the designer to define new application specific instructions for the processor to implement the desired functionality faster than a set of basic software operations such as additions or shifts can. Examples of such special instructions include complex arithmetic, non-standard floating point arithmetic, application-specific precision fixed point arithmetic, more than two input adders, etc.<br /><br />TCE places few restrictions on the types of custom instructions that can be added to the processor design. For example, there are no limits to the number of input operands or produced results nor the number of clock cycles the operation can execute. In addition to the custom operations, the number and size of the register files (RF), the number and type of the functional units (FU) and the connectivity between the RFs and FUs can be freely customized.<br /><br /><span style="font-size:medium;">About Transport Triggered Architectures</span><br /><br />TCE is based on a simple but scalable architecture template called <a href="http://en.wikipedia.org/wiki/Transport_triggered_architecture">Transport Triggered Architecture</a> (TTA, not to be confused with "Time Triggered Architecture"). TTA can be described as an exposed datapath VLIW architecture. The "exposed datapath" part means that the data transports that take place between the functional units (e.g. arithmetic logic unit or a multiplier) and the register files are explicitly visible to the programmer. In other words, while processors are commonly programmed by defining which operations to execute (including information of the sources of the operands and the destinations of the results), TTA is programmed by defining the transports of the operands and results. The name TTA comes from the way operations are executed: when operand data is moved to the triggering port of the functional unit, the operation starts executing. After a fixed latency (from the architecture point of view) the results can be read from the output ports of the functional unit to the next destination.<br /><br />The programming model can be illustrated more easily with an assembly code snippet example.<br /><br />1) <span style="font-style: italic;">Traditional "operation triggered" (first parameter is the destination)</span><br /><br /><ol><li>ADD R1, R2, R3</li><li>MUL R4, R1, R5<br /></li></ol><br />2) <span style="font-style: italic;">Transport triggered</span><br /><br /><ol><li>R2 -> ADD.OPERAND, R3 -> ADD.TRIGGER</li><li>ADD.RESULT -> R1</li><li>R1 -> MUL.OPERAND, R5 -> MUL.TRIGGER</li><li>MUL.RESULT -> R4<br /></li></ol>Transport programming enables some specific software optimizations such as software (register) bypassing which in turn can enable "dead result read elimination", that can be applied in case all result reads can be transported directly to the destination functional units. This can lead to reduced register (file) pressure. An example follows:<br /><br />3. <span style="font-style: italic;">Transport triggered with software bypassing and dead result read elimination</span><br /><br /><ol><li>R2 -> ADD.OPERAND, R3 -> ADD.TRIGGER</li><li>ADD.RESULT -> MUL.OPERAND, R5 -> MUL.TRIGGER</li><li>MUL.RESULT -> R4<br /></li></ol>Here the result from the adder is copied directly to the operand input port of the multiplier, thus removing the need for the general purpose register R1 used as a temporary storage. In addition to reducing register pressure, the freedom to schedule the movement of operand/result data in multiple cycles reduces the register file port pressure, which is one of the TTA's main motivations. In the traditional VLIW the number of RF ports needs to be scaled according to the number of connected functional units and their worst case RF port requirements (maximum simultaneous operand reads and result writes), leading to more complex RFs with higher delay and area.<br /><br /><span style="font-size:medium;">Toolset assisted processor design with TCE</span><br /><br />Designing new processors from the scratch is not a straightforward task. One needs to take care of the design, verification and porting a high level language programming toolchain for each of the processors so the programmers are happy (writing peculiar assembler syntax for a changing target would get quite depressing quickly!). Thus, the design process should be automated as fully as possible to make experimenting with different processor architecture alternatives feasible.<br /><br />The ultimate goal for an ASIP design toolset is to be as easy to use as taking a high-level language program as input and producing as a result an optimal processor implementation in VHDL or Verilog. It should parallelize the program for the processor's resources efficiently while exploiting custom instructions intelligently without any user intervention. In our experience, this type of fully automated "design space exploration" tends not to produce good enough results as the codesign process is often something that a human can do more efficiently. For example, sometimes the software needs to be refactored to a form that can exploit instruction level parallelism better. Sometimes it can be hard, or even impossible, for a software algorithm to realize that a complex-looking loop can be replaced with a simple single cycle custom instruction if implemented in hardware, and so on. Thus, we see that the realistic use case for an ASIP design toolset is to assist in the design task as much as possible while still leaving leeway for the engineer to exploit their knowledge in the field of algorithms or hardware design. This way, in case the engineer is skilled enough and the toolset assisting the ASIP design task is flexible enough, the processor design can eventually reach the performance of a fixed function hardware accelerator, while the design process can also be stopped at any point when the result is good enough.<br /><br />TCE is at a relatively mature state, providing graphical tools to design the TTA architectures, architecture description driven instruction set simulators, a retargetable compiler, and a processor implementation generator supporting VHDL output. Because TCE uses TTA, a static ILP architecture, as its processor template, the efficiency of the end result is highly dependent on an efficient compiler. The compiler has been our main focus in recent years and will most likely be in the future also.<br /><br /><span style="font-size:medium;">LLVM in TCE</span><br /><br />We were introduced to the LLVM project at about 2006. Until that point we used an old gcc v2.7.0 compiler ported from MOVE, the toolset preceeding TCE. It goes without saying that maintaining such an ancient piece of gcc code was quite a challenge and we actively tried to look for something easier to work with.<br /><br />In addition to a clean C++-based code base, one of the main things that lured us towards LLVM from a purely gcc-based compiler were the interprocedural optimizations. Interprocedural optimizations are very useful for us as we work with standalone (no operating system with a runtime linker assumed) fully linked programs. In fact, our compiler toolchain does not currently include any linker at all but inputs fully linked LLVM bitcodes to its code generation phase. This means that most programs benefit from the LLVM global optimizations such as aggressive inlining and dead code elimination as the externally visible interface in the compiled programs can be limited merely to the startup functions.<br /><br />After poking around and doing some experimental TTA code generation prototyping with LLVM (I think LLVM was at version 1.7 or so at that point) we noted that LLVM was getting more and more traction and started to look for a proper way for using LLVM for parts of the TCE code generation process.<br /><br />As described previously, our target, on top of being customizable, is transport triggered, thus nothing like any other architecture supported by LLVM. This caused some trial-and-error coding efforts while figuring out the best way of taking advantage of the existing code base of LLVM while still supporting instruction scheduling that exploits the special trickery and the extra scheduling freedom enabled by TTA. Another requirement, the automated retargeting of the LLVM backend for the resources of different designed processors caused some long work days to get functioning robustly.<br /><br />In the end, we came up with a plugin based backend approach. TCE code generation chain now includes a tool that generates LLVM backends from our XML-format architecture description files, compiles them with a C++ compiler to a dynamic library, and loads the generated LLVM backend on the fly during the code generation. At this point each TTA is modeled as a simple operation triggered architecture so the supported instruction set and registers can be described in the TableGen format. This way we could use the LLVM instruction selection and register allocation code, but the resulting sequential code is not yet something we can execute in a TTA. To finalize the code generation, after LLVM register allocation we convert the MachineInstructions to another internal representation (CFG+DDG with moves as the graph nodes) and do the rest of the code generation and TTA-specific optimizations on the TCE side.<br /><br />The main missing piece for us in LLVM code generation framework is a VLIW-type instruction scheduler. In case of TTA which is a statically scheduled architecture with programmer visible operation latencies, the compiler instruction scheduling is not merely an optimization that can be optionally executed to get more performance. It's fully up to the compiler to schedule the operations in such a way that the operations are not started too early (in case a previous operation is executing) nor the results read too soon (in case the operation has not yet finished). Thus, in our case, the instruction scheduling is actually mandatory to get correct results. Also, in order to exploit the instruction level parallelism in an architecture like TTA or VLIW, one needs a way to bundle multiple instructions (in our case data transport moves) in a single wide instruction (or "a cycle") to be executed in parallel. Finally, a way to model the processor resources (with resource tables or similar) during scheduling is needed to produce correct code in the absence of structural hazard detection.<br /><br />It would be really nice to have such a VLIW-style scheduling framework in LLVM so we could move more of our code generation to LLVM-side. Unfortunately due to a lack of time, we have not yet started to work on this as our existing instruction scheduler does the job well enough when starting from the "sequential RISC-like operation triggered" output from the LLVM code generation.<br /><br />In general, LLVM and it core developers have been a pleasure to work with and we hope to be able to contribute to the LLVM project more in the future. Keep up the good work!<br /><br /><span style="font-size:medium;">Future work and final words</span><br /><br />Currently we are looking into GPGPU-style workload compilation issues. We are experimenting with OpenCL to describe the applications for easier extraction of parallelism while still providing clean support for calling custom operations from the kernel code. There is also work ongoing to extend TCE to better support task level parallelism with multicore ASIP generation and compiler assisted multithreading.<br /><br />In case you got interested in the project or have questions to ask, please join the mailing list <a href="http://tce.cs.tut.fi/index.php/discussion">[email protected]</a>.<br /><br />I hope to see you there!<br /><br /><span style="font-style: italic;">--Pekka Jääskeläinen,</span><br /><span style="font-style: italic;font-size:x-small;" >a researcher that has been working in the TCE project from the start.</span><br /><br /><span style="font-size:medium;"></span>
- New "lldb" Debuggerhttps://blog.llvm.org/2010/06/new-lldb-debugger.htmlTue, 08 Jun 2010 21:00:00 +0000https://blog.llvm.org/2010/06/new-lldb-debugger.htmlI'm happy to announce a great new subproject of LLVM: LLDB. LLDB is a modern debugger infrastructure which is built (like the rest of LLVM) as a series of modular and reusable libraries. LLDB builds on existing LLVM technologies like the <a href="http://blog.llvm.org/2010/01/x86-disassembler.html">enhanced disassembler</a> APIs, the Clang ASTs and expression parser, the LLVM code generator and JIT compiler.<br /><br />While still in early development, LLDB supports basic command line debugging scenarios on the Mac, is scriptable, and has great support for multithreaded debugging. LLDB is already much faster than GDB when debugging large programs, and has the promise to provide a much better user experience (particularly for C++ programmers). We are excited to see the new platforms, new features, and enhancements that the broader LLVM community is interested in.<br /><br />If you'd like to try out LLDB and participate in its development, please visit <a href="http://lldb.llvm.org/">http://lldb.llvm.org/</a> and consider signing up for the <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev">lldb-dev</a> and <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits">lldb-commits</a> mailing lists.<br /><br />-Chris and the LLDB Team
- LLVM receives first ever SIGPLAN Software Systems Awardhttps://blog.llvm.org/2010/06/llvm-receives-first-ever-sigplan.htmlMon, 07 Jun 2010 23:37:00 +0000https://blog.llvm.org/2010/06/llvm-receives-first-ever-sigplan.htmlToday the <a href="http://www.acm.org/press-room/news-releases/2010/sigplan-software-award/view">ACM announced</a> that Chris Lattner and the LLVM Project are the recipient of the <a href="http://www.sigplan.org/award-software.htm">Programming Languages Software Award</a>.<br /><br />This award recognizes the impact that LLVM has had on the compiler research community, which can be seen in the large number of <a href="http://llvm.org/pubs/">research publications using LLVM</a> and the number of compiler courses that are using LLVM to teach compiler construction and optimization techniques. As part of this award, the ACM is donating $2500 to the LLVM project.
- Clang++ Builds Boost!https://blog.llvm.org/2010/05/clang-builds-boost.htmlThu, 20 May 2010 13:42:00 +0000https://blog.llvm.org/2010/05/clang-builds-boost.html<a href="http://www.boost.org/">Boost</a> is a collection of open-source, peer-reviewed C++ libraries that's well-known for having many good utility components for C++ programmers. It's also well-known for using bleeding-edge C++ techniques, such as extensive template and preprocessor metaprogramming, that have pushed many C++ compilers beyond their breaking point. Beyond just being a library, Boost has become a benchmark and a selling point for C++ compilers: is your compiler standards-confomant enough to build Boost?<br /><div><br /></div><div>Clang is.</div><div><br /><a name='more'></a><br /></div><div>This morning, Clang++ had its first fully-successful Boost regression test run, passing every applicable C++ test on the Boost release branch [*]. According to today's <a href="http://www.boost.org/development/tests/release/developer/summary.html">results</a>, Clang is successfully compiling more of Boost than other, established compilers for which Boost has historically been tailored (through various workarounds and configuration switches). In fact, Clang's <a href="http://svn.boost.org/svn/boost/branches/release/boost/config/compiler/clang.hpp">compiler configuration</a> in Boost is completely free of any of Boost's C++98/03 defect macros.</div><div><br /><div>As for the specifics: tests were run on Mac OS X 10.6 (Snow Leopard) with Clang targeting x86-64, debug build of Boost with the Clang toolset and a Release build of Clang from Subversion trunk.<br /><div><div><br /></div><div>If you want to try Boost with Clang, first <a href="http://clang.llvm.org/get_started.html">get Clang from Subversion</a> trunk and then <a href="https://svn.boost.org/trac/boost/wiki/BoostSubversion">get Boost from Subversion</a> (the release branch is most stable) and edit your <span class="Apple-style-span" style="font-family:'courier new';">~/user-config.jam</span> file by adding the following line:</div><div><br /></div><div><span class="Apple-style-span" style="font-family:'courier new';"> using clang ;</span></div><div><br /></div><div>assuming that "clang++" is in your path. Then, you can run</div><div><br /></div><div><span class="Apple-style-span" style="font-family:'courier new';">bjam toolset=clang</span></div><div><br /></div><div>to instruct Boost.Build to use Clang as its compiler.</div><div><br /></div><div><br /></div><div>[*] For those keeping score, the "build" results are build-system tests, not compiler tests, and the MPI tests are disabled due to <a href="https://svn.boost.org/trac/boost/ticket/4214">breakage</a> in the Serialization library. We are working with the library author to address the Serialization problems in Boost.</div></div></div></div>
- The Glasgow Haskell Compiler and LLVMhttps://blog.llvm.org/2010/05/glasgow-haskell-compiler-and-llvm.htmlMon, 17 May 2010 21:19:00 +0000https://blog.llvm.org/2010/05/glasgow-haskell-compiler-and-llvm.htmlIf you read the LLVM 2.7 release notes carefully you would have noticed that one of the new external users is the <a href="http://www.haskell.org/ghc">Glasgow Haskell Compiler</a> (GHC). As the author of the <a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Backends/LLVM">LLVM backend for GHC</a>, I have been invited to write a post detailing the design of the backend and my experiences with using LLVM. This is that post :).<br /><br /><a name='more'></a><br /><br />I began work on the backend around July last year, undertaking it as part of an honours thesis for my bachelor of Computer Science. Currently the backend is quite stable and capable on Linux x86, able to bootstrap GHC itself. Other platforms haven't received any attention yet.<br /><br /><h2>What is GHC and Haskell<br /></h2>GHC is a compiler for Haskell, a standardized, lazy, functional programming language. Haskell supports features such as static typing with type inference, lazy evaluation, pattern matching, list comprehension, type classes and type polymorphism. GHC is the most popular Haskell compiler, it compiles Haskell to native code and is supported of X86, PowerPC and SPARC.<br /><br /><h2>Existing pipeline</h2>Before the LLVM backend was added, GHC already supported two backends, a C code generator and a native code generator (NCG).<br /><br />The C code generator was the first backend implemented and it works pretty well but is slow and fragile due to its use of many GCC specific extensions and need to post processes the assembly code produced by GCC to implement optimisations which aren't possible to do in the C code. The native code generator was started later to avoid these problems. It is around 2-3x quicker than the C backend and generally reduces the runtime of a Haskell program by around 5%. GHC developers are hoping to depreciate the C backend in the next major release.<br /><br /><h2>Why an LLVM backend?</h2><ul><li><em>Offload work</em>: Building a high performance compiler backend is a huge amount of work, LLVM for example was started around 10 years ago. Going forward, the LLVM backend should be a lot less work to maintain and extend than either the C backend or NCG. It will also benefit from any future improvements to LLVM.</li><li><em>Optimisation passes</em>: GHC does a great job of producing fast Haskell programs. However, there are a large number of lower level optimisations (particularly the kind that require machine specific knowledge) that it doesn't currently implement. Using LLVM should give us most of them for free.</li><li><em>The LLVM Framework</em>: Perhaps the most appealing feature of LLVM is that it has been designed from the start to be a compiler framework. For researchers like the GHC developers, this is a great benefit and makes LLVM a very fun playground. For example, within a couple of days of the public release of the LLVM backend one developer, Don Stewart, wrote a genetic algorithm to find the best LLVM optimisation pipeline to use for various Haskell programs (you can find his blog post about this <a href="http://donsbot.wordpress.com/2010/03/01/evolving-faster-haskell-programs-now-with-llvm/">here</a>).</li></ul><br /><h2>Show me the speed</h2>That's enough reasoning for now though, lets instead jump right in and see GHC's LLVM backend in action. I'll also use this opportunity to do a little Haskell promoting as well, so you've been warned :).<br /><br />For a nice simple <a href="http://projecteuler.net/index.php?section=problems&id=14">problem</a> to solve lets find the starting number under 1 million that generates the longest <a href="http://en.wikipedia.org/wiki/Hailstone_sequence">hailstone sequence</a>. The hailstone sequence is a number sequence generated from a starting number n by the following rules:<br /><ul><li>if n is even, the next number is n/2</li><li>if n is odd, the next number is 3n + 1</li><li>if n is 1, stop.</li></ul>Here is a solution in both C and Haskell:<br /><pre><code><br />#include <stdio.h><br /><br />int main(int argc, char **argv) {<br /> int longest = 0, terms = 0, this_terms = 1, i;<br /> unsigned long j;<br /><br /> for (i = 1; i < 1000000; i++) {<br /> j = i;<br /> this_terms = 1;<br /><br /> while (j != 1) {<br /> this_terms++;<br /> j = j % 2 == 0 ? j / 2 : 3 * j + 1;<br /> }<br /><br /> if (this_terms > terms) {<br /> terms = this_terms;<br /> longest = i;<br /> }<br /> }<br /> printf("longest: %d (%d)\n", longest, terms);<br /> return 0;<br />}<br /><br />--------<br /><br />import Data.Word<br /><br />collatzLen :: Int -> Word32 -> Int<br />collatzLen c 1 = c<br />collatzLen c n | n `mod` 2 == 0 = collatzLen (c+1) $ n `div` 2<br /> | otherwise = collatzLen (c+1) $ 3*n+1<br /><br />pmax x n = x `max` (collatzLen 1 n, n)<br /><br />main = print . solve $ 1000000<br /> where solve xs = foldl pmax (1,1) [2..xs-1]<br /></code><br /></pre><br />Compiling the Haskell solution with the various backend gives the following runtime:<br /><ul><li><em>GHC-6.13 (NCG)</em>: 2.876s</li><li><em>GHC-6.13 (C)</em>: 0.576s</li><li><em>GHC-6.13 (LLVM)</em>: 0.516s</li><li><em>Clang-1.1</em>: 0.526s</li><li><em>GCC-4.4.3</em>: 0.335s</li></ul>Pretty great results for LLVM, it's the fastest backend of the three! The NCG performs quite badly in this case, despite my claim it usually outperforms the C backend. Recently when the GHC developers posted a message to the mailing list detailing plans to depreciate the C code generator due to the ongoing maintenance problems. A few GHC users responded, providing examples where the C code generator easily outperformed the native code generator as it does above. Thankfully for all those cases the LLVM backend does even better.<br /><br />One of the reasons I went with this example program is that I wanted to show off Haskell a little by demonstrating how easy it is to parallelize the solution:<br /><pre><br /><code><br />import Control.Parallel<br />import Data.Word<br /><br />collatzLen :: Int -> Word32 -> Int<br />collatzLen c 1 = c<br />collatzLen c n | n `mod` 2 == 0 = collatzLen (c+1) $ n `div` 2<br /> | otherwise = collatzLen (c+1) $ 3*n+1<br /><br />pmax x n = x `max` (collatzLen 1 n, n)<br />main = print soln<br /> where<br /> solve xs = foldl pmax (1,1) xs<br /> s1 = solve [2..500000]<br /> s2 = solve [500001..999999]<br /> soln = s2 `par` (s1 `pseq` max s1 s2)<br /></code><br /></pre><br />That's all! We simply divide the problem into two parts and combine them using Haskell's 'par' and 'pseq' constructs that tell the compiler to run the two parts 's1' and 's2' in parallel. And the run time (using LLVM of course):<br /><ul><li><em>GHC-6.13 (Parallel, LLVM)</em>: 0.312</li></ul>Great! We're even beating C here. Sure this is a very easy problem to parallelize but its still pretty cool.<br /><br />Finally, lets look at a bigger and more 'realistic' program and see how the LLVM backend performs. For this we will use HRay, a ray tracer implemented in Haskell. Using it to generate the image below we get the following run times:<br /><br /><a href="http://3.bp.blogspot.com/_Br4acuar1QM/S-OxB5nGI1I/AAAAAAAAAP4/qRIcxsMsx6Q/s1600/mirror.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="Ray Traced Image" border="0" id="BLOGGER_PHOTO_ID_5468409018760700754" src="http://3.bp.blogspot.com/_Br4acuar1QM/S-OxB5nGI1I/AAAAAAAAAP4/qRIcxsMsx6Q/s400/mirror.jpg" style="cursor: hand; cursor: pointer; display: block; height: 306px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br /><ul><li><em>GHC (NCG):</em> 29.499</li><li><em>GHC (C):</em> 29.043</li><li><em>GHC (LLVM):</em> 20.774</li></ul>A 30% reduction in run time with LLVM!<br /><br /><h2>Backend overview</h2>Lets look quickly at the job that the LLVM backend has to perform. GHC uses two major intermediate representations for compiling Haskell, the first being Core. Core is a functional language, basically a form of typed lambda calculus and its in this form that GHC does most of its optimisation work. There is also a IR called STG, its very similar to Core but is slightly easier to work with for procedural code generation.<br /><br /><a href="http://3.bp.blogspot.com/_Br4acuar1QM/S-OwnYREOZI/AAAAAAAAAPw/2ZELH-agCFU/s1600/pipeline.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" ghc="" id="BLOGGER_PHOTO_ID_5468408563133331858" pipeline"="" src="http://3.bp.blogspot.com/_Br4acuar1QM/S-OwnYREOZI/AAAAAAAAAPw/2ZELH-agCFU/s400/pipeline.png" style="cursor: hand; cursor: pointer; display: block; height: 98px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />The second major IR is C minus minus (Cmm), which is low level imperative language designed to act as an interface between the high level Haskell compiler parts and the low level code generation. Cmm as a language is quite similar to LLVM in terms of design and feature set (e.g both use bit types such as i32...). The syntax is quite different though with Cmm looking a little like C and LLVM looking like assembly. The similarity of the two shouldn't really come as much of a surprise since they are both positioned at the same point in a compiler pipeline and also because Cmm is mostly a subset of the <a href="http://www.cminusminus.org/">C--</a> language. C-- is a language designed by one of the primary GHC developers (Simon Peyton Jones) and others to act as a universal IR for compiler writers to target, very much like LLVM. (The research focus of C-- was quite different from LLVM though, C-- was designed to try to solve the problem of supporting high level language features like garbage collection and exceptions in a universal language with zero overhead. LLVM seems to be focused on supporting aggressive optimisation of a universal language). The C-- project never managed to take off like LLVM did though and so now Cmm simply serves as a good IR for GHC backends to work with.<br /><br />The LLVM backend fits into the GHC pipeline after Cmm, so its job is to compile from Cmm to LLVM Assembly. This is mostly straight forward because of the similarity of the two languages.<br /><br /><h2>The new calling convention</h2>There was one major challenge though in writing the backend where LLVM didn't provide the features needed to properly implement Haskell and so I needed to extend LLVM. This extension is the new calling convention I wrote of at the start of the post and to explain why its necessary we'll have to look very briefly at the execution model for Haskell used by GHC.<br /><br />GHC defines an abstract machine that implements the execution model for Haskell code. This is called the 'STG Machine' (or Spineless Tagless G-Machine) and its job is to evaluate the final, functional IR used by GHC, STG. The STG machine consists of three main parts, registers, a stack and a heap. For this stack, GHC doesn't use the standard C stack but implements its own. What we are concerned with though is just how the registers are implemented. The easiest method is to just store them all in memory as a structure and indeed GHC supports this method (its refereed to as 'unregistered mode' and is used for easier porting of GHC). However because of how often they are accessed a far more efficient way to implement them is to map them onto real hardware registers, which roughly halves the runtime of a typical Haskell program. So this is what GHC does, although as there are far too many STG machine registers to map onto real registers, it has to still store some of them in memory.<br /><br />This is a problem for the LLVM backend though as it has no control over the register allocation. We can still create a working backend by only supporting 'unregistered mode' but this isn't very useful due to the poor performance. Also we aren't just focused on performance, compatibility with the other backends is a major concern. We need to support the same register mapping as they use so that Haskell code compiled by LLVM will be able to link with code compiled by the other backends. Lets look quickly at how the other backends achieve this register mapping.<br /><br />With the native code generator its very straight forward since it has full control over the register allocation. How about the C backend though? Typically this would be a problem for C as well since it offers no control over register allocation. Thankfully GCC offers an extension, '<a href="http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Global-Reg-Vars.html#Global-Reg-Vars">Global Register Variables</a>', which allows you to assign a global variable to always reside in a specific hardware register. GCC implements this feature basically by removing the register specified from the list of known registers that its register allocator uses.<br /><br />So the solution for LLVM is a new calling convention but how does this work? Well the calling convention passes arguments in the hardware registers that GHC expects to find the STG machine registers in. So on entry to any function they're in the correct place. Unlike with the NCG or C backend this doesn't exclusively reserve the registers, so in the middle of a function we can't guarantee that the STG machine registers will still be in the hardware registers, they may have been spilled to the stack. This is fine, in fact its an improvement. It allows LLVM to generate the most efficient register allocation, having more registers and flexibility than the other backends, while still maintaining compatibility with them since on any function entry the STG machine registers are guaranteed to be in the correct hardware registers.<br /><br /><h2>Evaluation of the backend</h2>The two benchmarks at the start gave you a taste of the performance improvements that LLVM is able to bring to GHC. However, how does it perform across the board? The best way I have to test this at the moment is by using a benchmark suite included with GHC called 'nofib'. Currently this suite puts the native code generators in first place, with the LLVM code generator a close second at 3% behind in run time and the C code generator in last place at 6% behind. An important characteristic of the LLVM code generator though is that its consistent. At its best its able to beat the existing backends with a 2x speed-up in run time while at its worst its usually within 3 - 30% of the performance of the best of the NCG or C backend. So you don't get any cases like the NCG has where it really looses out. Its also worth noting that no work has been done yet on optimising the performance of the LLVM backend.<br /><br />The other great benefit of the LLVM code generator is its smaller size and simpler code base. The NCG clocks in at ~20,500 lines of code, the C backend at ~5,300 and the LLVM backend at ~3,100. For the C backend, around 2,000 lines of that code are Perl code which does the post processing of the GCC produced assembly, fragile and complex code full of regular expressions. For the LLVM backend around 1,200 lines of its code are a library for generating and printing out LLVM Assembly, so the complex code generation code is only at around 1,800 lines.<br /><br /><h2>Problems with backend</h2>There is one major issue remaining with the LLVM backend that I currently know of, its inability to implement a optimisation used by GHC called <em>'TABLES_NEXT_TO_CODE'</em> (TNTC).<br /><br />For functions, GHC needs to associate some meta-data with them, referred to as an info table. This table contains information about the function used by the run time system. Without the TNTC optimisation the linking of a table and function is done by having the info table contain a pointer to the function. With the TNTC optimisation the code and data is laid out so that the info table resides immediately before the function. This allows both the function and its info table to be accessed from the same pointer, which speeds up access of a function (one pointer lookup instead of two) and reduces the size of info tables.<br /><br /><a href="http://1.bp.blogspot.com/_Br4acuar1QM/S-OwSLPvitI/AAAAAAAAAPo/BSjScxNzjY8/s1600/heap_layout.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="GHC Code Layout Modes" border="0" id="BLOGGER_PHOTO_ID_5468408198860868306" src="http://1.bp.blogspot.com/_Br4acuar1QM/S-OwSLPvitI/AAAAAAAAAPo/BSjScxNzjY8/s400/heap_layout.png" style="cursor: hand; cursor: pointer; display: block; height: 191px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />How the other two backends handle this is the similar to the STG machine registers. The NCG can implement this with no problems, while the C backend is unable to do this in plain C. However, this time with no GCC extensions able to implement the optimisation either it resorts to post processing the assembly code produced by GCC. For LLVM we have the same problem as the C backend, LLVM doesn't provide a way to explicitly layout the code and data in the object file like we need. This optimisation is fairly significant, giving about a 5% reduction in run times when enabled, so its something I hope to fix up in the future either by adding support for it to LLVM or by post processing the assembly as the C backend does.<br /><br /><h2>Success of LLVM?</h2>When I asked for the GHC calling convention to be included in LLVM a price was asked of me, a blog post, this one. So I asked Chris what he felt I should write about. There is just one point left to cover to make sure I've paid in full.<br /><pre>> [Chris Lattner]: Talking about what you think is good and what you think should be improved in LLVM would also be great. :)</pre><br />I'd like to see LLVM gain the needed features to be able to implement the TNTC optimisation in the GHC backend. It would also be great if LLVM was better supported on Sparc as that's a platform GHC works reasonably well on where LLVM doesn't. As for what is good? When you look at the GHC LLVM backend, it achieves very close or better performance than existing backends that have been around for years, while having a smaller and simpler code base. I think you also gain a lot from the LLVM type system, it really helped catch most of the bugs fixed so far in the backend. Finally the great documentation. This is something I really appreciate and often is lacking in many projects. <br /><br /><h2>Future</h2>Since finishing my thesis at the end of 2009, I haven't been able to get much work done on the LLVM backend. However I was lucky enough to receive an internship with Microsoft Research in Cambridge, UK, where two of the primary GHC developers (Simon Marlow & Simon Peyton Jones) work. As part of this I'll be looking to implement the TNTC optimisation as well as general stabilisation and optimisation work. The backend only takes advantage of features offered in 2.5, so I also need to investigate and update it to use the newer 2.6 and 2.7 features. There is also a Google Summer of Code student, <a href="http://socghop.appspot.com/gsoc/student_project/show/google/gsoc2010/haskell/t127230760615">Alp Mestanogullari</a>, who is working on the backend. He is looking to improve the binding used by the backend to interface with LLVM. This binding currently works by producing LLVM assembly code in a temporary file. We want to change this to use the LLVM API instead as this should bring faster compile speeds and allow us to extend the API offered by GHC to include LLVM features. Should all this work go well, hopefully you'll see LLVM become the default backend for GHC in the next major release :)<br /><br />If you feel like looking into any of this in more detail, you can find my thesis paper on the backend <a href="http://docs.google.com/viewer?url=http%3A%2F%2Fwww.cse.unsw.edu.au%2F~pls%2Fthesis%2Fdavidt-thesis.pdf">here</a>.<br /><br />- David
- New "libc++" C++ Standard Libraryhttps://blog.llvm.org/2010/05/new-libc-c-standard-library.htmlTue, 11 May 2010 13:32:00 +0000https://blog.llvm.org/2010/05/new-libc-c-standard-library.htmlI'm happy to announce a new subproject of LLVM: "libc++". libc++ is an implementation of the C++ Standard Library, with a focus on standards compliance, highly efficient generated code, and with an aim to support C++'0x when the standard is ratified. libc++ is written and maintained by Howard Hinnant, but we look forward to contributions from the LLVM community.<br /><br />libc++ is approximately 85% complete at this point (including C++'0x features), and while it is intended to support and complement the Clang++ compiler, it can be ported to work with a broad variety of different C++ compilers. For more information, see the <a href="http://libcxx.llvm.org ">http://libcxx.llvm.org</a> web page.<br /><br />-Chris
- Extensible Metadata in LLVM IRhttps://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.htmlWed, 14 Apr 2010 00:23:00 +0000https://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.htmlA common request by front-end authors is to be able to add some sort of metadata to LLVM IR. This metadata could be used to influence language-specific optimization passes (for example, Type Based Alias Analysis in C), tag information for a custom code generator, or pass through information to link time optimization. LLVM 2.7 provides first-class support for this, and has switched debug information over to use it (improving debug info!). <br /><br />While the details of this feature can be found in the <a href="http://llvm.org/docs/LangRef.html">LLVM Language Reference</a> manual, sometimes it is hard to distill the big picture from the low-level details. This post tries to fill the gap by explaining some history, motivation and example use cases for this new LLVM 2.7 feature.<br /><br />This post was written by Devang Patel and myself.<br /><br /><a name='more'></a><br /><br />Before we dive into how metadata works, it is useful to describe how debug information was represented in LLVM 2.6 and earlier:<br /><br /><h2>Debug Information in LLVM 2.6</h2><br />Debugging information communicates source location information, type information and variable information to the debugger. This information is not used during the execution of program and does not result in executable code in the object file, but the code generator uses it to produce DWARF information. In this way, debug information is a sort of side channel from the front-end to the DWARF emitter in the code generator.<br /><br />For lack of a better mechanism, in LLVM 2.6 and earlier, debugging information is encoded using global variables tagged with a special "llvm.metadata" section. For example, we would generate something like this to describe C code like "int my_data;":<br /><br /><pre>@my_data = common global i32 0, align 4<br /><br />@llvm.dbg.global_variable = internal constant %llvm.dbg.global_variable.type { <br /> i32 458804, <br /> {}* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.global_variables to { }*), <br /> {}* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), <br /> i8* getelementptr ([8 x i8]* @.str4, i32 0, i32 0), <br /> i8* getelementptr ([8 x i8]* @.str4, i32 0, i32 0), <br /> i8* null, <br /> {}* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), <br /> i32 2, <br /> {}* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), <br /> i1 false, <br /> i1 true, <br /> {}* bitcast (i32* @my_data to {}*)<br />}, section "llvm.metadata"<br /><br />@.str4 = internal constant [8 x i8] c"my_data\00", section "llvm.metadata"<br /></pre><br />In this example, @my_data is the actual global variable generated for the C variable. This is what gets generated regardless of whether debug info is enabled or not.<br /><br />Here, @.str4 and @llvm.dbg.global_variable were interpreted by the code generator as descriptors holding information about @my_data, with various fields indicating the line number the global is declared, the compile unit, etc. You can see a full description of these fields in the <a href="http://llvm.org/releases/2.6/docs/SourceLevelDebugging.html#format_global_variables">LLVM2.6 Debug Info docs</a>. At code generation time, the dwarf writer would walk this and convert it to DWARF information. The LLVM globals would not get emitted as normal code because they are in the magic llvm.metadata section.<br /><br />While this did provide a basic level of functionality, it had a number of drawbacks. First, the @my_data global variable has an extra use in the IR, which may influence optimization of @my_data. For example the dead global elimination pass wouldn't delete it if dead, and the mod/ref analysis pass wouldn't analyze it because it appears that its address is taken. One major goal of debug information is that turning it on should not affect the executable code generated by the compiler. If it did, turning on debug info could hide the bug you're trying to track down!<br /><br />A second drawback of this implementation is that it has lots of pointless bitcast constant expressions. These extra objects bloat memory footprint, take time to allocate, unique and optimize, etc. The bitcasts also negatively impact readability of LLVM intermediate code, and are completely unnecessary: the dwarf emitter doesn't care about the types, it is walking this information as a data structure, not emitting it to memory.<br /><br /><h2>Motivation for LLVM IR Metadata</h2><br />Based on our experiences with debug info, and a desire to implement new cool things, we <a href="http://nondot.org/~sabre/LLVMNotes/EmbeddedMetadata.txt">designed</a> and implemented a brave new world where metadata was actually a first-class part of LLVM IR. The design aims to solve the issues mentioned above:<br /><br /><ol><li>Optimizations shouldn't be affected by metadata unless they explicitly try to look at it.</li><li>We want to reduce the memory footprint and cost of debug info.</li><li>Metadata shouldn't have LLVM IR types.</li><li>Ideally, the syntactic clutter should be reduced, improving the odds that someone can decode this stuff.</li></ol><br />Another important design point is that we want to be able to add new forms of metadata without the optimizers having to be updated to support them. This is a critical design point, because we want the metadata to be <em>extensible</em> by front-end authors to do whatever they want, and shouldn't require hacking the optimizers.<br /><br /><h2>Metadata in LLVM 2.7</h2><br />Metadata support includes several different related IR extensions: a new '<a href="http://llvm.org/docs/LangRef.html#t_metadata">metadata</a>' type in LLVM IR, new <a href="http://llvm.org/docs/LangRef.html#metadata">MDString</a>, <a href="http://llvm.org/docs/LangRef.html#metadata">MDNode</a>, and <a href="http://llvm.org/docs/LangRef.html#namedmetadatastructure">NamedMDNode</a> classes (all three of which derive from 'Value'), added support for referencing metadata from <a href="http://llvm.org/docs/LangRef.html#intrinsics">intrinsics</a>, and support for <a href="http://llvm.org/docs/LangRef.html#metadata">attaching it to instructions</a>. Metadata support is generally in the <a href="http://llvm.org/doxygen/Metadata_8h-source.html">llvm/Metadata.h</a> header. We'll walk through each of these constructs in turn:<br /><br />The new <b>'metadata' type</b> is the LLVM Type of each new IR object. This ensures that you can't use metadata as operands to random instructions, for example, you can't do '<tt>add i32 4, !"str"</tt>' since metadata is not a first-class type. The restrictions on metadata mean that it can only appear as an argument to an intrinsic, as an operand to another metadata, at top-level in a module (NamedMDNode), or be attached to an instruction.<br /><br />The new <b>MDString class</b> is used to represent string data in metadata, and it always has a metadata type. Since MDStrings are meant as metadata, not code, they are not null terminated in the .ll file. The MDString class allows C++ code walking the IR to access the arbitrary string data with a StringRef. In the .ll file, its syntax is something like:<br /><br /><pre>!"foo"<br /></pre><br />The new <b>MDNode class</b> is a tuple that can reference arbitrary LLVM IR values in the program as well as other metadata. In the .ll file, MDNodes are numbered and the syntax for referring to one is "!123" where 123 is the number of the node being referenced. An MDNode is declared with something like:<br /><br /><pre>!23 = !{ i32 4, !"foo", i32 *@G, metadata !22 }<br /></pre><br />In this case, the MDNode has four operands, the first is a ConstantInt, the second is a MDString, the third is a global variable, the fourth is another MDNode. MDNode's come in two flavors: one is a normal global MDNode which references global variables, constants etc. The second is a function-local MDNode, which can (potentially transitively) refer to instructions within a particular function. One important aspect of MDNodes is that they are not considered to be "uses" of a value: for example, they won't be found with use_iterator and aren't counted for predicates like Value::hasOneUse(). This prevents metadata from accidentally affecting code generation.<br /><br />The new <b>NamedMDNode class</b> provides named access to metadata at a module level, and each NamedMDNode contains a list of MDNode's. This gives clients of metadata (e.g. debug info) the ability to find all the metadata of a particular form (e.g. global variable debug descriptors). The Module class maintains a list of NamedMDNode instances just like it does global variables, functions, and aliases. In the .ll file, a NamedMDNode looks like this:<br /><br /><pre>!my_named_mdnode = !{ !1, !2, !4212 }<br /></pre><br />This defines a NamedMDNode with three referenced MDNodes.<br /><br /><b>LLVM intrinsics may reference metadata</b> as normal operands. More specifically, they can directly reference MDNode and MDString objects even though other calls and other operations cannot. In .ll files, this looks something like:<br /><br /><pre>!0 = metadata !{i32 524544, ...<br /><br />...<br /> %x = alloca i32<br /> call void @llvm.dbg.declare(metadata !{i32* %x}, metadata !0)<br /></pre><br />This passes the module-level !0 MDNode into the second argument and passes a function-local MDNode as the first argument (which, since it is an mdnode, does not count as a use of %X). In this case, the code generator uses this information to know that the metadata !0 is the variable descriptor for the alloca %X. Note that intrinsics themselves are not considered metadata, so they can affect code generation etc.<br /><br />Finally, <b>metadata can be attached to instructions</b>. Instructions can have an arbitrary list of MDNodes attached to them with string tags. For example:<br /><br /><pre>store i32 0, i32* %P, !nontemporal !2, !frobnatz !123<br /> ret void, !dbg !9<br /></pre><br />The first case is a store with two instruction-level metadata records attached to it, one named 'nontemporal' (which is <a href="http://llvm.org/docs/LangRef.html#i_store">implemented in LLVM 2.7</a>) and one named 'frobnatz' (which is a great new feature that might be in LLVM 2.8). The second is a return instruction with a debug location attached to it.<br /><br /><br /><h2>Using Extensible Metadata for Debug Info</h2><br />To contrast with the LLVM 2.6 debug info example above, in LLVM 2.7 we get something like this:<br /><br /><pre>@my_data = common global i32 0, align 4<br /> !llvm.dbg.gv = !{!0}<br /><br /> !0 = metadata !{<br /> i32 524340, i32 0, metadata !1, metadata !"my_data", metadata !"my_data",<br /> metadata !"", metadata !1, i32 2, metadata !3,<br /> i1 false, i1 true, i32* @my_data<br /> }<br /></pre><br />This replaces the global variables with an MDNode and MDString. This shrinks the IR by eliminating the pointless bitcasts, eliminating the irrelevant IR types, and the use of @my_data by !0 is no longer considered a "use". However, we still have lots of <a href="http://llvm.org/docs/SourceLevelDebugging.html#format_global_variables">magic fields that are documented elsewhere</a>.<br /><br />If you'd like to see more examples of debug info, you can see what the frontend generates by using something like "<tt>clang foo.c -g -S -o - -emit-llvm | less</tt>".<br /><br /><h2>What to use Metadata for</h2><br />A subtle point that was touched on above is that we don't want the optimizers to have to know about metadata. While it is very feasible to make optimizations preserve specific metadata (e.g. loop strength reduction could do some sort of fancy thing to update debug info it if wanted) by default, optimizations ignore and destroy it. For example, if an optimization deletes an instruction and there is a function-level MDNode referencing it, the reference in the MDNode will implicitly drop to null.<br /><br />This has some important implications on what it is safe to use metadata for: it can only be used for "value add" information, information that does not change the semantics of the program. To repeat this important point, <b>use of metadata is only safe if the program retains its semantics when the metadata is silently dropped</b>.<br /><br />For example, it is trivially safe for debug information to use metadata (though the dwarf emitter has to be careful to tolerate null pointers!): if metadata is dropped, it just means that debug information <em>quality</em> is reduced, it doesn't invalidate the debug info itself. In our example above, if the global "my_data" is deleted by the optimizer, the reference will drop to null and the debug info emitter won't generate a location for my_data.<br /><br />While this may sound limiting, there are lots of potential uses cases for metadata, you just have to be careful how you structure it. Lets run through a few examples:<br /><br /><h2>Current and Potential Clients of Metadata</h2><br />LLVM 2.7 supports generating <b>non-temporal <a href="http://llvm.org/docs/LangRef.html#i_load">loads</a> and <a href="http://llvm.org/docs/LangRef.html#i_store">stores</a></b> using the !nontemporal instruction-level modifier as documented in the LangRef manual. A non-temporal access is normal access with a hint to the CPU that it can avoid pulling data into the cache, as it won't be accessed again recently. This is safe because !nontemporal is an optimization hint: dropping the !nontemporal hint will result in the optimizer producing a normal load and store, which may have lower performance, but provides the same semantics as an actual non-temporal access.<br /><br />A potential future use case is to support <b>Type-Based Alias Analysis</b> (TBAA). TBAA is an optimization to know that "float *P1" and "int *P2" can never alias (in GCC, this is enabled with -fstrict-aliasing). The trick with this is that it isn't safe to implement TBAA in terms of LLVM IR types, you really need to be able to encode and express a type-subset graph according to the complex source-level rules (e.g. in C, "char*" can alias anything).<br /><br />An LLVM implementation of TBAA would encode the type-subset graph with MDNodes, and add type tags to load and store operations with a !tbaa instruction tag. A new <a href="http://llvm.org/docs/AliasAnalysis.html">AliasAnalysis</a> implementation would look for these tags on accesses and walk the type subset graph to determine if the two accesses might alias each other. This use of metadata is also safe, because it is an optimization: if the type tag gets dropped, it is always safe to assume that the access aliases everything for TBAA purposes.<br /><br />More broadly, metadata is a great way for a <b>front-end to communicate arbitrary information to custom language-specific optimization passes</b>. TBAA is one example, but this could equally apply to things like devirtualization (through class hierarchy analysis), doing locking and exception handling optimizations, even library-centric optimizations could be implemented with this.<br /><br />Since LLVM 2.7 is only the first release that supports metadata in its IR, we have yet to see how it will ultimately get used. If you end up using it in a novel or interesting way, please send me a link describing your use and I'll link to it from this post.<br /><br />-Chris and Devang
- Intro to the LLVM MC Projecthttps://blog.llvm.org/2010/04/intro-to-llvm-mc-project.htmlFri, 09 Apr 2010 23:27:00 +0000https://blog.llvm.org/2010/04/intro-to-llvm-mc-project.htmlThe LLVM Machine Code (aka MC) sub-project of LLVM was created to solve a number of problems in the realm of assembly, disassembly, object file format handling, and a number of other related areas that CPU instruction-set level tools work in. It is a sub-project of <a href="http://llvm.org/">LLVM</a> which provides it with a number of advantages over other compilers that do not have tightly integrated assembly-level tools.<br /><br />This blog post talks about how the MC project evolved, describes a few different aspects of it , talks about the improvements/capabilities it brings to LLVM, and finishes off with the current status of the project.<br /><br /><a name='more'></a><br /><br /><h2>History and Background</h2><br />Before MC came around, LLVM was already a mature compiler system that support both static compilation (through a normal assembler) and as well as JIT compilation (which emitted encoded instruction bytes directly to memory) on many different targets and sub-targets. However, despite these capabilities, the implementation of these subsystems was not designed wonderfully: why should the X86 instruction encoder (used by the JIT) have to know how to encode the weird pseudo instructions that the X86 code generator uses for its convenience? Why was this code emitter specific to the one code model used by the JIT?<br /><br />Beyond lack of elegance, it has been a goal for quite a while (for example, see <a href="http://llvm.org/devmtg/2009-10/">Bruno's 2009 devmtg talk</a>) to directly integrate an assembler into the compiler. Doing so would solve a number of problems: For fast compiles, it is incredibly wasteful for the compiler to carefully format a massive text file, then fork/exec an assembler, which then has to lex/parse/validate the file. In fact, since the rest of Clang is so fast, <a href="http://clang.llvm.org/performance.html">the assembler takes ~20% of compile time</a> for C code at -O0 -g. In addition to winning back this performance, not relying on an external assembler is attractive for several other reasons: the compiler doesn't have to worry about lots of different buggy assemblers which have similar but inconsistent syntax, Windows users typically don't have assemblers (and MASM is not fully-featured enough to be targeted by a compiler), some systems like FreeBSD have old versions of binutils that lack modern features, etc.<br /><br />Previously, we tried implementing a "<a href="http://wiki.llvm.org/Notes:Machine_Code_Emission_in_an_ideal_world">direct object emission</a>" system to allow the code generator to write .o files without an assembler, but this project hit a number of problems. One of the biggest problems is that it tried to re-implement all of the logic in AsmPrinter which handled "lowering" of the codegen IR to machine level constructs. This includes the logic that handled selection of linkage types, section selection, constant lowering and emission, lowering of debug info and exception info, etc. While these may not sound like a big deal, this logic is very delicate and having subtle differences between the .o file writer and .s file writer (e.g. one emitted a strong symbol and one emitting a weak symbol) wasn't acceptable. This previous project never even got to the interesting parts of an assembler, like relaxation support.<br /><br />Finally, beyond the previous scope of LLVM, there is a bigger toolchain out there that has to deal with things like assembly and disassembly of instructions. When a new instruction set extension comes around (e.g. SSE 4.2) the new instructions need to be added to the assembler, the disassembler, and the compiler. Since LLVM already had a JIT, it already knew how to do encoding of instructions, and we speculated that it might be reasonable to produce an assembler from the textual descriptions of the instructions in the code generator's tables. It would be great to be able to add an instruction description to one place and get the assembler, disassembler, and compiler backend support all at once.<br /><br /><h2>Primary MC Components</h2><br />You can break down the MC-related data structures and components into "that which operates on instructions" and "that which does other stuff". To provide a consistent abstraction we introduced the new <b><a href="http://llvm.org/doxygen/classllvm_1_1MCInst.html">MCInst</a></b> class to represent an instruction with operands (e.g. registers, immediates, etc) which is separate from the code generator's existing notion of an instruction (MachineInstr). The "other stuff" includes a variety of classes like <a href="http://llvm.org/doxygen/classllvm_1_1MCSymbol.html">MCSymbol</a> (which represents a label in a .s file), <a href="http://llvm.org/doxygen/classllvm_1_1MCSection.html">MCSection</a>, <a href="http://llvm.org/doxygen/classllvm_1_1MCExpr.html">MCExpr</a> etc. You can read the headers in the llvm/include/MC directory for more information on these.<br /><br />These MC classes live at a very low level in the LLVM system, depending only on the support and system libraries. The idea of this is that you can build something low-level (like a disassembler library) that doesn't have to link in the entire LLVM code generator (a disassembler doesn't need a register allocator :).<br /><br />Given this background, I'll talk about the major components of the MC project: the instruction printer, the instruction encoder, the instruction parser, the instruction decoder, the assembly parser, the assembler backend, and the compiler integration. LLVM already had these (except the instruction decoder and assembly parser), but the existing code has been refactored out and reworked substantially.<br /><br /><b>Instruction Printer</b><br /><br />The instruction printer is a very simple target-specific component that implements the MCInstPrinter API. Given a single MCInst, it formats and emits the textual representation of the instruction to a raw_ostream. Targets can have multiple MCInstPrinters, for example the X86 backend includes an AT&T and an Intel Syntax instruction printer. MCInstPrinters don't know anything about sections, directives, or other things like that so they are independent of object file format.<br /><br />Instruction printing is somewhat fiddly code (formatting all the operands exactly right, dealing with inconsistencies in the syntax of various instructions, etc) but LLVM already had a <a href="http://llvm.org/docs/TableGenFundamentals.html">TableGen</a> backend that auto-generated much of this from the .td files. Getting an old-style LLVM target to support this requires introducing a new MachineInstr -> MCInst lowering pass, which then passes the MCInst to the InstPrinter.<br /><br /><b><br />Instruction Encoder</b><br /><br />The instruction encoder is another target-specific component which transforms an MCInst into a series of bytes and a list of relocations, implementing the MCCodeEmitter API. The API is quite general, allowing any bytes generated to be written to a raw_ostream. Because the X86 instruction encoding is very complex (aka "completely insane"), the X86 backend implements this interface with custom C++ code that is driven from data encoded in the .td files. This is the only realistic way to handle all the prefix bytes, REX bytes etc, and is derived from the old JIT encoder for X86. We hope and expect that encoders for future RISC targets will be directly generated from the .td files. When used by the compiler, the same MachineInst -> MCInst lowering code is used as for the instruction printer.<br /><br /><b><br />Instruction Parser</b><br /><br />In order to parse instructions when reading a .s file, targets can implement lexers and parsers for their syntax, providing the TargetAsmParser API. The lexer is largely shared code that is parameterized based on common assembly syntax features (e.g. what is the comment character?), but the parser is all target-specific. Once an instruction opcode and its operands have been parsed, it goes through a 'matching' process which decides which concrete instruction is being specified. For example, on X86, "addl $4, %eax" is an instruction with a 1-byte immediate, but "addl $256, %eax" uses a 4-byte immediate field and is represented as a different MCInst.<br /><br />The output of an parsed instruction is an opcode + list of operands, and the parser also exposes the API for matching. Not all instructions can be matched as they are parsed from a .s file (for example, an immediate size might depend on the distance between two labels) so instructions can be held in a more abstract-than-MCInst representation until relaxation is performed if required.<br /><br /><b><br />Instruction Decoder</b><br /><br />As you might expect, the instruction decoder implements the MCDisassembler API and turns an abstract series of bytes (implemented with the MemoryObject API, to handle remote disassembly) into an MCInst and a size. As with previous components, a target may implement multiple different decoders (the X86 backend implements X86-16, X86-32, and X86-64 decoders). The decoder turns immediate fields into simple integer immediate operands, if there is a reference to a symbol, the relocation representing the symbol has to be handled by a client of the decoder.<br /><br /><b><br />Assembly Parser</b><br /><br />The assembly parser handles all the directives and other gunk that is in an .s file that is not an instruction (which may be generic or may be object-file specific). This is the thing that knows what .word, .globl etc are, and it uses the instruction parser to handle instructions. The input to the Assembly parser is a MemoryBuffer object (which contains the input file) and the assembly parser invokes actions of an MCStreamer interface for each thing it does.<br /><br /><b>MCStreamer is a very important API</b>: it is essentially an "assembler API" with one virtual method per directive and one "EmitInstruction" method that takes an MCInst. The MCStreamer API is implemented by the MCAsmStreamer assembly printer (which implements support for printing these directives to a .s file and uses the Instruction Printer to format the MCInsts) as well as the assembler backend (which writes out a .o file). It is impossible to overstate how important the MCStreamer API is for the overall MC picture to fit together as we'll see later. <br /><br /><b><br />Assembler Backend</b><br /><br />The assembler backend is one implementation of the MCStreamer API (along with the "MCAsmStreamer" text assembly code emitter) which implements all the "hard stuff" that assemblers do. For example, the assembler has to do "relaxation" which is the process that handles things like branch shortening, situations like "the size of this instruction depends on how far apart these two labels are, but the instruction is between the two labels, how do we break the cycle?" etc. It lays out fragments into sections, resolves instructions with symbolic operands down to immediates and passes this information off to object-file specific code that writes out (say) an ELF or MachO .o file.<br /><br /><b><br />Compiler Integration</b><br /><br />The final major piece of the puzzle is integrating this all into the compiler. In practice this meant making the compiler talk directly to the MCStreamer API to emit directives and instructions instead of emitting a text file. Converting over all the targets, debug info, eh emission, etc was a major project, and doubly so because it was taken as an opportunity to fix a bunch of major design issues in the AsmPrinter implementations (lots of copy and paste code etc). The new system is much better factored and lowers directly to MC constructs like MCSection and MCSymbol instead of passing around strings and using other ad-hoc data structures.<br /><br />The end result of this work is that the compiler backend now invokes the same MCStreamer interface to emit code that the stand-alone assembler parser does. This gives us high confidence that using the compiler backend to emit a text file (with the "MCAsmStreamer") and reading it back in with the asmparser will result in the same MCStreamer calls as when the code generator directly invokes them. <br /><br /><h2>Building on these Primitive Components</h2><br />Now that you know about the major components of the MC ecosystem, and you've seen how key data structures like MCInst and MCStreamer are used to communicate between the components, we can talk about building nice things out of them.<br /><br /><b><br />Disassembler Library</b><br /><br />One major high-level API built on this is the "enhanced disassembler" API, which uses these components in this sequence:<br /><br /><ol><li>It uses the Instruction Decoder to read machine code bytes in memory into an MCInst and determine instruction sizes.</li><li>It uses the Instruction Printer to print the textual form of the instruction to a buffer.</li><li>It uses the Instruction Parser to re-parse the textual form to find precise operand boundaries in the text and build a symbolic form of the operand.</li></ol><br />This library provides a number of great capabilities. Sean described it and the X86 implementation in <a href="http://blog.llvm.org/2010/01/x86-disassembler.html">his previous blog post</a>, and the interface is in the <tt>llvm/include/llvm-c/EnhancedDisassembly.h</tt> header.<br /><br />You can also access some of the functionality on the command line by using the llvm-mc tool:<br /><br /><pre>$ <b>echo "0xCD 0x21" | llvm-mc --disassemble -triple=x86_64-apple-darwin9</b><br /> int $33<br />$ <b>echo "0 0" | llvm-mc --disassemble -triple=x86_64-apple-darwin9</b><br /> addb %al, (%rax)<br />$ <b>echo "0 0" | llvm-mc --disassemble -triple=i386-apple-darwin9</b><br /> addb %al, (%eax)<br />$ <b>echo "0x0f 0x01 0xc2" | llvm-mc --disassemble -triple=i386-apple-darwin9</b><br /> vmlaunch<br /></pre><br /><b><br />Stand-alone Assembler</b><br /><br />If you combine the Assembly Parser, Instruction Parser, the Assembler Backend and the Instruction Encoder, you get a traditional stand-alone system assembler. The llvm-mc tool provides this capability with a command like:<br /><br /><pre>$ <b>llvm-mc foo.s -filetype=obj -o foo.o</b><br />$ <b>echo " invalid_inst _foo, %ebx" | llvm-mc -filetype=obj -o /dev/null</b><br /><stdin>:1:5: error: unrecognized instruction<br /> invalid_inst _foo, %ebx<br /> ^<br /></pre><br />The second example shows that the assembly parser gives nice caret diagnostics, not just "parse error on line 1" that many assemblers produce.<br /><br /><b><br />Really Complicated Assembly 'cat'</b><br /><br />If you want to, you can take the stand-alone assembler and hook the MCAsmStreamer interface up to the MCStreamer the assembler is calling. This allows you to read in a .s file (validating it) and then immediately print it back out. You can also play with options like -show-encoding and -show-inst (which shows MCInsts). Assembly cat is the default mode of llvm-mc for testing's sake, and you can play with it like this:<br /><br /><pre>$ <b>llvm-mc foo.s -o bar.s</b><br />$ <b>echo "addl %eax, %ebx" | llvm-mc -show-encoding -show-inst</b><br /> .section __TEXT,__text,regular,pure_instructions<br /> addl %eax, %ebx ## encoding: [0x01,0xc3]<br /> ## <MCInst #66 ADD32rr<br /> ## <MCOperand Reg:29><br /> ## <MCOperand Reg:29><br /> ## <MCOperand Reg:27>><br />$ <b>echo "xorl _foo, %ebx" | llvm-mc -show-encoding</b><br /> .section __TEXT,__text,regular,pure_instructions<br /> xorl _foo, %ebx ## encoding: [0x33,0x1c,0x25,A,A,A,A]<br /> ## fixup A - offset: 3, value: _foo, kind: FK_Data_4<br /></pre><br />The last example shows that the instruction encoder generates a fixup (aka relocation) as well as the data bytes for the instruction.<br /><br /><b><br />Assembly Generating Compiler</b><br /><br />Now that the compiler is wired up to emit all of its code through the MCStreamer API, we can connect various streamers to it. To get a "classic compiler", we can hook up an MCAsmStreamer to the and get a normal .s file out of the compiler:<br /><br /><pre>$ <b>clang foo.c -S -o foo.s</b><br /></pre><br />This uses the MCAsmStreamer and the Instruction Printers for the current target. One interesting observation is that .s file printing is very performance critical in the old world (when you don't have direct .o file writing support). Generating that huge text file requires a lot of detailed formatting and the compiler isn't doing a lot else at "-O0" mode, so it is a significant percentage of compile time.<br /><br />However, most build systems (e.g. makefiles) use the compiler in "-c" mode which asks for a .o file. If the compiler supports directly writing a .o file, the .s path isn't hot at all because it isn't being used. This means that we can reasonably make -S mode default to emitting a .s file with tons of helpful comments in it: this mode (e.g. gcc -fverbose-asm) is supported in some form by many compilers, but most people don't know it exists. The presence of direct .o file writing support means that we can turn this on by default! Also, the LLVM implementation of this is pretty nice, with information about spills, loop nests etc.<br /><br /><b><br />Compiler-Integrated Assembler</b><br /><br />As you might have guessed by now, LLVM also supports an integrated assembler. While this will eventually become the default for targets that support it, right now clang requires you to pass the -integrated-as flag:<br /><br /><pre>$ <b>clang foo.c -c -o foo.o -integrated-as</b><br /></pre><br />To the user, this works just like the non-integrated-as support. If you pass -v though, you'll see that the compiler is directly emitting the .o file and the assembler isn't run by the driver.<br /><br />This works very simply: the assembler backend is provided as the MCStreamer to the compiler, and it handles the various things the system assembler used to take care of. This means that the assembler never has to (for example) print out MCInsts to a textual representation and reparse them, it just passes the well-formed MCInsts the code generator is using directly to the assembler backend.<br /><br />This is all well and good except for one thing: inline assembly. With inline assembly, arbitrary assembly language can be included in the source file (optionally munged by the compiler to insert operand constraint information etc), and we have no choice but to parse this with the assembly parser. Fortunately, we have a nice clean and well decomposed system, so we the assembly handling code just creates a new temporary assembly parser to handle the inline asm, and has it talk to the same MCStreamer instance that the compiler is using. This means that the current state of the streamer is the same when the inline assembly is parsed as it would be if the system assembler is used.<br /><br />Using an integrated has other benefits as well: we can tightly integrate it with the clang diagnostics system instead of having the assembler detect the error late and report it with a foreign error. Beyond consistency, we can actually give really good information about where the error occurs, relaying it back to where in the <em>original source code</em> the problem is. Compare these examples with and without the integrated assembler:<br /><br /><pre>$ <b>cat t.c</b><br />int foo(int X) {<br /> __asm__ ("frob %0" : "+r" (X));<br /> return X;<br />}<br />$ <b>gcc t.c</b> <br />/var/folders/51/51Qw875vFdGa9KojoIi7Zk+++TM/-Tmp-//ccyXfgfZ.s:11:no such instruction: `frob %eax'<br />$ <b>clang t.c</b><br />/var/folders/51/51Qw875vFdGa9KojoIi7Zk+++TM/-Tmp-/cc-4zimMn.s:15:no such instruction: `frob %eax'<br />clang: error: assembler command failed with exit code 1 (use -v to see invocation)<br />$ <b>clang t.c -integrated-as</b><br /><b>t.c:2:11: <font color="red">error:</font> unrecognized instruction</b><br /> frob %eax<br /><font color="green"> ^</font><br /><b><inline asm>:1:2: note:</b> instantated into assembly here<br /> __asm__ ("frob %0" : "+r" (X));<br /><font color="green"> ^</font><br />1 error generated.<br /></inline></pre><br />I don't know about you, but I find it much more useful to know that line 2 of my C file is the problem than to find out that line 15 of a deleted file is. :) It is worth pointing out that it is incredibly important to show the code being parsed by the assembler, because after operand substitution etc it is not always clear from the source code what the problem is.<br /><br /><h2>Status and Open Projects!</h2><br />As described above, the architecture of the MC subsystems is already quite advanced and we have a lot of code written. However, not all of it is production quality and we don't yet have people signed up to do all the interesting work! As of this writing here is the high level status:<br /><br /><ol><li>All the clang-side work is done: the driver knows -integrated-as, the diagnostics subsystem can handle assembler errors, the code generator is fully switched over to use MCStreamer, etc.</li><li>The X86 and ARM <a href="http://blog.llvm.org/2010/01/x86-disassembler.html">disassemblers</a> are in good shape and considered to be at or near production quality.</li><li>The X86 instruction printer is done for both AT&T and Intel Syntax.</li><li>The MC components have been designed to be object file independent (e.g. work for MachO, ELF, PE-COFF etc) but only have an implementation for MachO (used on Mac OS/X systems). Adding support for ELF and/or PE-COFF should be reasonably straight-forward.</li><li>The X86 AT&T-syntax assembly parser is missing some important features, e.g. forward/backward labels, support for inferring suffixes on instructions (e.g. add -> addl), macros etc. However, it is sufficiently advanced to reliably parse everything generated by the LLVM X86 backend. Adding these missing features should be quite straight-forward.</li><li>The X86 Intel-syntax assembly parser doesn't exist.</li><li>The ARM assembly parser is not complete (probably 50% to useful), and the instruction printer is about 50% refactored from the old-style printer.</li><li>The assembler backend works quite well and currently tries to produces bitwise identical object files to the system assembler on the Mac (to allow validating through "/usr/bin/cmp"). That said, it's algorithms aren't all performance tuned, so it could probably be substantially faster.</li><li>The old JIT code path is still alive in LLVM, it should be killed off once it is replaced with a new MC implementation. One win of this is that the JIT will support inline assembly :)</li></ol><br />If you're interested in this level of the tool chain, this is a great area to get involved in, because there are lots of small to mid-sized projects just waiting to be tackled. I believe that the long term impact of this work is huge: it allows building new interesting CPU-level tools and it means that we can add new instructions to one .td file instead of having to add them to the compiler, the assembler, the disassembler, etc.<br /><br />-Chris
- ARM Advanced SIMD (NEON) Intrinsics and Types in LLVMhttps://blog.llvm.org/2010/04/arm-advanced-simd-neon-intrinsics-and.htmlWed, 07 Apr 2010 21:34:00 +0000https://blog.llvm.org/2010/04/arm-advanced-simd-neon-intrinsics-and.htmlLLVM now supports all the intrinsic functions defined by ARM for the Advanced SIMD (aka "NEON") instruction set, but if you are migrating from GCC to LLVM, there are some implementation differences that you may encounter. LLVM follows ARM's specification of the standard NEON types more closely than GCC. It is also more strict about checking types of arguments to the NEON intrinsics.<br /><br /><br />This post describes the NEON-related differences between LLVM and GCC and gives a few examples of how to adapt your code to work with LLVM.<br /><br /><br /><a name='more'></a><br /><h2>Background</h2><br />NEON is a vector processing extension to the ARM architecture. It is included in most recent ARM processors such as the Cortex A8 and A9. Some of the NEON instructions perform operations that are not simple to specify in C or C++, so ARM has defined a standard set of intrinsic functions for those operations. For example, the vqadd_s16 intrinsic performs a saturating add of two 64-bit vectors with elements that are 16-bit signed integers. ARM has also defined a standard set of NEON vector types to be used with these intrinsics. For example, the arguments and return value of the vqadd_s16 intrinsic have a type of int16x4_t. These intrinsics and types are declared in the <arm_neon.h> header file, which is provided by the compiler.<br /><br /><br />There are at least two prior implementations of these NEON intrinsics. ARM's RealView Compilation Tools (RVCT) compiler provides the full set of them, and not surprisingly, RVCT adheres closely to ARM's specification. GCC also has an implementation of NEON intrinsics, but it differs in some ways from RVCT and ARM's specification (at least in the 4.2.1 version from which llvm-gcc is derived).<br /><br /><br />The current status of NEON intrinsics in LLVM is that llvm-gcc has full support for them, although there is undoubtedly room for further performance tuning. Clang does not yet support NEON. Patches are welcome!<br /><br /><br /><h2>Different Types</h2><br />ARM defines the NEON vector types as opaque "containerized vectors". These types are defined in <arm_neon.h> as C structures. The user-visible type names are typedefs to these internal structures. For example, the type for a vector of 4 floats is defined as:<br /><br /><pre> typedef struct __simd128_float32_t float32x4_t;<br /></pre><br />The content of the internal structures is not specified, so the only thing you can portably do with values of these types is to pass them to NEON intrinsics.<br /><br /><br />GCC has its own syntax for specifying vector types. This syntax is not specific to NEON. A vector type is defined by adding a "__vector_size__" attribute with the total vector size in bytes. For example:<br /><br /><pre> typedef float float32x4_t __attribute__ ((__vector_size__ (16)));<br /></pre><br />Instead of using the opaque containerized vectors, GCC's implementation of the standard NEON types uses its own vector syntax.<br /><br /><br />So what about LLVM? We compromise and do both! The NEON types are defined as structures in <arm_neon.h>, following ARM's specification, but the contents of those structures are vectors defined with GCC's syntax. Each internal structure has a single element named "val" with a GCC vector type. The GCC vector types are defined with a "__neon_" prefix to the standard NEON type name. So, if you want to access the GCC vector type directly, you can do it with LLVM. That code won't be portable — it won't work with RVCT — but it may ease the transition from GCC.<br /><br /><br />What are the implications of this difference in the NEON types? The main thing is that the LLVM NEON types are aggregates, not scalars, so you can't do things like casting them to integer types. You also can't assign NEON variables to specific NEON registers using "asm" register attributes, since that is not supported for aggregates. See below for some related differences in the way you initialize vectors.<br /><br /><br /><h2>Stricter Type Checking</h2><br />Arguments to LLVM's NEON intrinsics are subject to much stricter type checking than with GCC. GCC's vector types can be cast to other vector types as long as the total size remains the same and you don't mix integer and floating-point vectors. The arguments to GCC's NEON intrinsics get this same treatment. You can pass a uint8x8_t value for a int32x2_t argument and GCC will not even warn you. LLVM requires the argument types to match exactly. If your code is sloppy with vector types, you will have to clean it up to compile with LLVM.<br /><br /><br />If you really want to cast NEON vector types, the right way to do it is with the vreinterpret intrinsics. For example, vreinterpret_s32_u8 will perform the cast from uint8x8_t to int32x2_t that was mentioned above.<br /><br /><br /><h2>How to Initialize a Vector?</h2><br />GCC's vector types can be directly assigned a brace-enclosed list of values corresponding to the vector elements. For example:<br /><br /><pre> int32x2_t vec = { 1, 2 };<br /></pre><br />initializes a vector with element values 1 and 2. This is convenient but not portable. In general, the best way to assign a vector value is to load it from memory with a NEON intrinsic. That is completely portable and often as fast or faster than the alternatives.<br /><br /><br />There are some special cases where you can do better. If all the vector elements have the same value, one of the vdup intrinsics would be a good solution. You can use the vcreate intrinsics to construct vectors from 64-bit values, and the vcombine intrinsics can put two of them together to form a 128-bit vector. However, moving values from general-purpose ARM registers to the NEON register file can be quite slow, so this may not be faster than a load. If the vector elements are floating-point values, then they are likely already in the right register file, and using vset_lane intrinsics to put them together into a vector may be faster. Generating the fastest code for these different cases is a work in progress, so you may need to experiment with different approaches to see which is fastest.
- What's wrong with this code?https://blog.llvm.org/2010/04/whats-wrong-with-this-code.htmlWed, 07 Apr 2010 11:49:00 +0000https://blog.llvm.org/2010/04/whats-wrong-with-this-code.htmlA user on IRC sent me this interesting KLEE example today, which I thought was cute enough I should post it.<br /><br /><div>If you aren't familiar with it, <a href="http://klee.llvm.org/">KLEE</a> is a tool for symbolic execution of LLVM code. It is way too complicated to explain here, but for the purposes of this example all you need to know is that it tries to explore all possible paths through a program.</div><div><br /><br /><a name='more'></a><br /><br /><br /></div><div>In this case, the user was actually talking to me because he thought there was a bug in KLEE, because it was only finding one path through the code. Here is the example:</div><div><pre>$ cat t.c<br />#include "klee/klee.h"<br /><br />int f0(int x) {<br />if (x * x == 1000)<br />return 1;<br />else<br />return 0;<br />}<br /><br />int main() {<br />return f0(klee_int("x"));<br />}<br /></pre>The idea here is that <tt>klee_int("x")</tt> creates a new symbolic variable, which can be <i>anything</i> (well, any possible <tt>int</tt>).</div><div><br /></div><div>The user was expecting that there would be two possible paths through this program, one returning 1 and one returning 0. But KLEE only finds one:</div><div><pre>$ clang -I ~/public/klee/include -flto -c t.c<br />$ ~/public/klee.obj.64/Debug/bin/klee t.o<br />KLEE: output directory = "klee-out-5"<br /><br />KLEE: done: total instructions = 24<br />KLEE: done: completed paths = 1<br />KLEE: done: generated tests = 1</pre><br /></div><div>Upon showing the example to me, I was also confused for a moment. However, since I happen to trust KLEE, I knew to look for a problem in the test case! And of course, the square root of 1000 isn't an integer, so there is no way this code can return 1. If we change the 1000 to 100, KLEE finds two paths as we would expect:</div><div><pre>$ cat t.c<br />#include "klee/klee.h"<br /><br />int f0(int x) {<br />if (x * x == 100)<br />return 1;<br />else<br />return 0;<br />}<br /><br />int main() {<br />return f0(klee_int("x"));<br />}<br />$ clang -I ~/public/klee/include -flto -c t.c<br />$ ~/public/klee.obj.64/Debug/bin/klee t.o<br />KLEE: output directory = "klee-out-6"<br /><br />KLEE: done: total instructions = 31<br />KLEE: done: completed paths = 2<br />KLEE: done: generated tests = 2</pre><br /></div>This example shows exactly what KLEE was designed for -- reasoning about code (or math) is hard, and it is great to let a machine do it for you!
- Amazing feats of Clang Error Recoveryhttps://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.htmlMon, 05 Apr 2010 23:20:00 +0000https://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.htmlIn addition to parsing and generating machine code for your source files when valid, a compiler frontend's job is also to detect invalid code and give you a hint that explains what is wrong so you can fix the problem. The bug could either be straight-up invalid (an error) or could just be something that is legal but looks really dubious (a warning). These errors and warnings are known as compiler 'diagnostics', and Clang aims to go above and beyond the call of duty to provide a really amazing experience.<br /><br />After the break, we show some examples of areas where Clang tries particularly hard. For other examples, the Clang web page also has <a href="http://clang.llvm.org/diagnostics.html">a page on diagnostics</a> and Doug showed how Clang diagnoses two-phase name lookup issues in <a href="http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.html">a prior blog post</a>.<br /><br /><b>Update</b>: Other people are starting to compare their favorite compiler. Here's the <a href="http://labs.hoffmanlabs.com/node/1540">OpenVMS Compiler</a>. Email Chris if you have a comparison you want posted.<br /><br /><a href="http://softdroid.net/udivitelnye-tryuki-vosstanovleniya-oshibok-clang">СекÑеÑÑ Ð²Ð¾ÑÑÑÐ°Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ (Russian Translation)</a> <span style="font-family: "helvetica"; font-size: 12px;"> provided by </span><a href="http://softdroid.net/" style="font-family: Helvetica; font-size: 12px;">Softdroid Recovery</a><span style="font-family: "helvetica";"><span style="font-size: 12px;">.</span></span><br /><span style="font-family: "helvetica";"><span style="font-size: 12px;"><a href="http://www.opensourceinitiative.net/edu/llvm/" target="_blank">Ukrainian Translation</a> provided by Sandi Wolfe.</span></span><br /><span style="font-family: "helvetica";"><span style="font-size: 12px;"><a href="https://www.autonvaraosatpro.fi/blogi/2018/04/23/hammastav-feats-ukskoik-error-recovery/" rel="nofollow" target="_blank">Estonian Translation</a> provided by Johanne Teerink.</span></span><br /><span style="font-family: "helvetica";"><span style="font-size: 12px;"><a href="https://studhilfe.de/translations/#Amazing-feats-of-Clang-Error-Recovery:DE">German Translation</a> provided by </span></span><span style="font-family: "helvetica";"><span style="font-size: 12px;">Philip Egger.</span></span><br /><span style="font-family: "helvetica";"><span style="font-size: 12px;"><a href="http://expereb.com/amazing-feats-of-clang-error-recovery/">Spanish Translation</a> provided by </span></span><span style="font-family: helvetica;"><span style="font-size: 12px;">Laura Mancini</span></span><br /><span style="font-family: "helvetica";"><span style="font-size: 12px;"><br /></span></span><br /><br /><a name='more'></a><br /><br />These examples use Apple GCC 4.2 as a comparison on these examples, but this isn't meant to bash (an old version of) GCC. Many compilers have these sorts of issues and we strongly encourage you to try the examples on your favorite compiler to see how it does. The examples all shown are necessarily small (reduced) examples that demonstrate a problem, when you see these in real life, they are often much more convincing :).<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="unknown_typenames">Unknown Typenames</a></h2><br />One annoying thing about parsing C and C++ is that you have to know what is a typename in order to parse the code. For example "(x)(y)" can be either a cast of the expression "(y)" to type "x" or it could be a call of the "x" function with the "(y)" argument list, depending on whether x is a type or not. Unfortunately, a common mistake is to forget to include a header file, which means that the compiler really has no idea whether something is a type or not, and therefore has to make a strongly educated guess based on context. Here are a couple examples:<br /><br /><pre>$ <b>cat t.m</b><br />NSString *P = @"foo";<br />$ <b>clang t.m</b><br />t.m:4:1: error: unknown type name 'NSString'<br />NSString *P = @"foo";<br />^<br />$ <b>gcc t.m</b><br />t.m:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token<br /></pre><br />and:<br /><br /><pre>$ <b>cat t.c</b><br />int foo(int x, pid_t y) {<br /> return x+y;<br />}<br />$ <b>clang t.c</b><br />t.c:1:16: error: unknown type name 'pid_t'<br />int foo(int x, pid_t y) {<br /> ^<br />$ <b>gcc t.c</b><br />t.c:1: error: expected declaration specifiers or '...' before 'pid_t'<br />t.c: In function 'foo':<br />t.c:2: error: 'y' undeclared (first use in this function)<br />t.c:2: error: (Each undeclared identifier is reported only once<br />t.c:2: error: for each function it appears in.)<br /></pre><br />This sort of thing also happens in C if you forget to use 'struct stat' instead of 'stat'. As is a common theme in this post, recovering well by inferring what the programmer meant helps Clang avoid emitting bogus follow-on errors like the three lines GCC emits on line 2. <br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="spell_checker">Spell Checker</a></h2><br />One of the <a href="http://zi.fi/shots/clang.png">more visible</a> things that Clang includes is a spell checker (also <a href="http://www.reddit.com/r/programming/comments/b8ws6/why_you_should_use_clang/">on reddit</a>). The spell checker kicks in when you use an identifier that Clang doesn't know: it checks against other close identifiers and suggests what you probably meant. Here are a few examples:<br /><br /><pre>$ <b>cat t.c</b><br />#include <inttypes.h><br />int64 x;<br />$ <b>clang t.c</b><br />t.c:2:1: error: unknown type name 'int64'; did you mean 'int64_t'?<br />int64 x;<br />^~~~~<br />int64_t<br />$ <b>gcc t.c</b><br />t.c:2: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x'<br /></pre><br />another example is:<br /><br /><pre>$ <b>cat t.c</b><br />#include <sys/stat.h><br />int foo(int x, struct stat *P) { <br /> return P->st_blocksize*2;<br />}<br />$ <b>clang t.c</b><br />t.c:4:13: error: no member named 'st_blocksize' in 'struct stat'; did you mean 'st_blksize'?<br /> return P->st_blocksize*2;<br /> ^~~~~~~~~~~~<br /> st_blksize<br />$ <b>gcc t.c</b><br />t.c: In function âfooâ:<br />t.c:4: error: 'struct stat' has no member named 'st_blocksize'<br /></pre><br />The great thing about the spell checker is that it catches a wide variety of common errors, and it also assists in later recovery. Code that later used 'x', for example, knows that it is declared as an int64_t, so it doesn't lead to other weird follow on errors that don't make any sense. Clang uses the well known <a href="http://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance function</a> to compute the best match out of the possible candidates.<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="typedef_tracking">Typedef Tracking</a></h2><br />Clang tracks the typedefs you write in your code carefully so that it can relate errors to the types you use in your code. This allows it to print out error messages in your terms, not in fully resolved and template instantiated compiler terms. It also uses its range information and caret to show you what you wrote instead of trying to print it back out at you. There are several examples of this on the Clang diagnostics page, but one more example can't hurt:<br /><br /><pre>$ <b>cat t.cc</b><br />namespace foo {<br /> struct x { int y; };<br />}<br />namespace bar {<br /> typedef int y;<br />}<br />void test() {<br /> foo::x a;<br /> bar::y b;<br /> a + b;<br />}<br />$ <b>clang t.cc</b><br />t.cc:10:5: error: invalid operands to binary expression ('foo::x' and 'bar::y' (aka 'int'))<br /> a + b;<br /> ~ ^ ~<br />$ <b>gcc t.cc</b><br />t.cc: In function 'void test()':<br />t.cc:10: error: no match for 'operator+' in 'a + b'<br /></pre><br />This shows that clang gives you the source names as you typed them ("foo::x" and "bar::y", respectively) but it also unwraps the y type with "aka" in case the underlying representation is important. Other compilers typically give completely unhelpful information which doesn't really tell you what the problem is. This is a surprisingly concise example from GCC, but it also seems to be missing some critical information (such as why there is no match). Also, if the expression was more than a single "a+b", you can imagine that pretty printing it back at you isn't the most helpful.<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="most_vexing_parse">The Most Vexing Parse</a></h2><br />One mistake many beginner programmers mistake is that they accidentally define functions instead of objects on the stack. This is due to an ambiguity in the C++ grammar which is resolved in an arbitrary way. This is an unavoidable part of C++, but at least the compiler should help you understand what is going wrong. Here's a trivial example:<br /><br /><pre>$ <b>cat t.cc</b><br />#include <vector><br /><br />int foo() {<br /> std::vector<std::vector<int> > X();<br /> return X.size();<br />}<br />$ <b>clang t.cc</b><br />t.cc:5:11: error: base of member reference has function type 'std::vector<std::vector<int> > ()'; perhaps you meant to call this function with '()'?<br /> return X.size();<br /> ^<br /> ()<br />$ <b>gcc t.cc</b><br />t.cc: In function âint foo()â:<br />t.cc:5: error: request for member âsizeâ in âXâ, which is of non-class type âstd::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > ()()â<br /></pre><br />I run into this thing when I originally declared the vector as taking some arguments (e.g. "10" to specify an initial size) but refactor the code and eliminate that. Of course if you don't remove the parentheses, the code is actually declaring a function, not a variable.<br /><br />Here you can see that Clang points out fairly clearly that we've gone and declared a function (it even offers to help you call it in case you forgot ()'s). GCC, on the other hand, is both hopelessly confused about what you're doing, but also spews out a big typename that you didn't write (where did std::allocator come from?). It's sad but true that being an experienced C++ programmer really means that you're adept at decyphering the error messages that your compiler spews at you.<br /><br />If you go on to try the more classical example where this bites people, you can see Clang try even harder:<br /><br /><pre>$ <b>cat t.cc</b><br />#include <fstream><br />#include <vector><br />#include <iterator><br /><br />int main() {<br /> std::ifstream ifs("file.txt");<br /> std::vector<char> v(std::istream_iterator<char>(ifs),<br /> std::istream_iterator<char>());<br /> <br /> std::vector<char>::const_iterator it = v.begin();<br /> return 0; <br />}<br />$ <b>clang t.cc</b><br />t.cc:8:23: warning: parentheses were disambiguated as a function declarator<br /> std::vector<char> v(std::istream_iterator<char>(ifs),<br /> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />t.cc:11:45: error: member reference base type 'std::vector<char> (*)(std::istream_iterator<char>, std::istream_iterator<char> (*)())' is not a structure or union<br /> std::vector<char>::const_iterator it = v.begin();<br /> ~ ^<br />$ <b>gcc t.cc</b><br />t.cc: In function âint main()â:<br />t.cc:11: error: request for member âbeginâ in âvâ, which is of non-class type<br />âstd::vector<char, std::allocator<char> > ()(std::istream_iterator<char, char, std::char_traits<char>, long int>, std::istream_iterator<char, char, std::char_traits<char>, long int> (*)())â<br /></pre><br />In this case, Clang's second error isn't particularly great (though it does give much more concise type names), but it gives a really critical warning, telling you that the parens in the example are declaring a function, not being used as parens for an argument.<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="missing_semicolons">Missing Semicolons</a></h2><br />One error that I frequently make (perhaps due to the wildly inconsistent grammar of C++, or perhaps because I am sloppy and have a short attention span...) is dropping a semicolon. Fortunately these are pretty trivial to fix once you know what is going on, but they can lead to some really confusing error messages from some compilers. This happens even in cases where it is immediately obvious what is going on to a human (if they are paying attention!). For example:<br /><br /><pre>$ <b>cat t.c</b><br />struct foo { int x; }<br /><br />typedef int bar;<br />$ <b>clang t.c</b><br />t.c:1:22: error: expected ';' after struct<br />struct foo { int x; }<br /> ^<br /> ;<br />$ <b>gcc t.c</b><br />t.c:3: error: two or more data types in declaration specifiers<br /></pre><br />Note that GCC emits the error on the thing that <em>follows the problem</em>. If the struct was the last thing at the end of a header, this means that you'll end up getting the error message <em>in a completely different file</em> than where the problem lies. This problem also compounds itself in C++ (as do many others), for example:<br /><br /><pre>$ <b>cat t2.cc</b><br />template<class t><br />class a{}<br /><br />class temp{};<br />a<temp> b;<br /><br />class b {<br />}<br />$ <b>clang t2.cc</b><br />t2.cc:2:10: error: expected ';' after class<br />class a{}<br /> ^<br /> ;<br />t2.cc:8:2: error: expected ';' after class<br />}<br /> ^<br /> ;<br />$ <b>gcc t2.c</b><br />t2.cc:4: error: multiple types in one declaration<br />t2.cc:5: error: non-template type âaâ used as a template<br />t2.cc:5: error: invalid type in declaration before â;â token<br />t2.cc:8: error: expected unqualified-id at end of input<br /></pre><br />In addition to emitting the confusing error "multiple types in one declaration", GCC goes on to confuse itself in other ways.<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="dot_arrow_thinko">. vs -> Thinko</a></h2><br />In C++ code, pointers and references often get used fairly interchangeably and it is common to use . where you mean ->. Clang recognizes this common sort of mistake and helps you out:<br /><br /><pre>$ <b>cat t.cc</b><br />#include <map><br /><br />int bar(std::map<int, float> *X) {<br /> return X.empty();<br />}<br />$ <b>clang t.cc</b><br />t.cc:4:11: error: member reference type 'std::map<int, float> *' is a pointer; maybe you meant to use '->'?<br /> return X.empty();<br /> ~^<br /> -><br />$ <b>gcc t.cc</b><br />t.cc: In function âint bar(std::map<int, float, std::less<int>, std::allocator<std::pair<const int, float> > >*)â:<br />t.cc:4: error: request for member âemptyâ in âXâ, which is of non-class type âstd::map<int, float, std::less<int>, std::allocator<std::pair<const int, float> > >*â<br /></pre><br />In addition to helpfully informing you that your pointer is a "non-class type", it goes out of its way to spell the full definition of std::map out, which is certainly not helpful.<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="scope_typo">:: vs : Typo</a></h2><br />Perhaps it's just me, but I tend to make this mistake quite a bit, again while in a hurry. The C++ :: operator is used to separate nested name specifiers, but somehow I keep typing : instead. Here is a minimal example that shows the idea:<br /><br /><pre>$ <b>cat t.cc</b><br />namespace x {<br /> struct a { };<br />}<br /><br />x:a a2;<br />x::a a3 = a2;<br />$ <b>clang t.cc</b><br />t.cc:5:2: error: unexpected ':' in nested name specifier<br />x:a a2;<br /> ^<br /> ::<br />$ <b>gcc t.cc</b><br />t.cc:5: error: function definition does not declare parameters<br />t.cc:6: error: âa2â was not declared in this scope<br /></pre><br />In addition to getting the error message right (and suggesting a fixit replacement to "::"), Clang "knows what you mean" so it handles the subsequent uses of a2 correctly. GCC, in contrast, gets confused about what the error is which leads it to emit bogus errors on every use of a2. This can be seen with a slightly elaborated example:<br /><br /><pre>$ <b>cat t2.cc</b><br />namespace x {<br /> struct a { };<br />}<br /><br />template <typename t><br />class foo {<br />};<br /><br />foo<x::a> a1;<br />foo<x:a> a2;<br /><br />x::a a3 = a2;<br />$ <b>clang t2.cc</b><br />t2.cc:10:6: error: unexpected ':' in nested name specifier<br />foo<x:a> a2;<br /> ^<br /> ::<br />t2.cc:12:6: error: no viable conversion from 'foo<x::a>' to 'x::a'<br />x::a a3 = a2;<br /> ^ ~~<br />t2.cc:2:10: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'foo<x::a>' to 'x::a const' for 1st argument<br /> struct a { };<br /> ^<br />$ <b>gcc t2.cc</b><br />t2.cc:10: error: template argument 1 is invalid<br />t2.cc:10: error: invalid type in declaration before â;â token<br />t2.cc:12: error: conversion from âintâ to non-scalar type âx::aâ requested<br /></pre><br />Here you can see that Clang's second error message is exactly right (and is explained). GCC gives a confusing follow on message about converting an "int" to x::a. Where did "int" come from?<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="near_hopeless">Helping out in near-hopeless situations</a></h2><br />C++ is a power tool that gives you plenty of rope to shoot yourself in the foot as well as mix your multi-paradigmed metaphors. Unfortunately, this power gives you plenty of opportunities to find yourself in a near hopeless situation where you know "something is wrong" but have no idea what the real problem is or how to fix it. Thankfully, Clang tries to be there for you, even in the toughest of times. For example, here's a case involving ambiguous lookup:<br /><br /><pre>$ <b>cat t.cc</b><br />struct B1 { void f(); };<br />struct B2 { void f(double); };<br /><br />struct I1 : B1 { };<br />struct I2 : B1 { };<br /><br />struct D: I1, I2, B2 {<br /> using B1::f; using B2::f;<br /> void g() {<br /> f(); <br /> }<br />};<br />$ <b>clang t.cc</b><br />t.cc:10:5: error: ambiguous conversion from derived class 'D' to base class 'B1':<br /> struct D -> struct I1 -> struct B1<br /> struct D -> struct I2 -> struct B1<br /> f(); <br /> ^<br />$ <b>gcc t.cc</b><br />t.cc: In member function âvoid D::g()â:<br />t.cc:10: error: âB1â is an ambiguous base of âDâ<br /></pre><br />In this case, you can see that not only does clang tell you that there is an ambiguity, it tells you <em>exactly the paths through the inheritance hierarchy that are the problems</em>. When you're dealing with a non-trivial hierarchy, and all the classes aren't in a single file staring at you, this can be a real life saver.<br /><br />To be fair, GCC occasionally tries to help out. Unfortunately, when it does so it's not clear if it helps more than it hurts. For example, if you comment out the two using declarations in the example above you get:<br /><br /><pre>$ <b>clang t.cc</b><br />t.cc:10:5: error: non-static member 'f' found in multiple base-class subobjects of type 'B1':<br /> struct D -> struct I1 -> struct B1<br /> struct D -> struct I2 -> struct B1<br /> f(); <br /> ^<br />t.cc:1:18: note: member found by ambiguous name lookup<br />struct B1 { void f(); };<br /> ^<br />$ <b>gcc t.cc</b><br />t.cc: In member function âvoid D::g()â:<br />t.cc:10: error: reference to âfâ is ambiguous<br />t.cc:2: error: candidates are: void B2::f(double)<br />t.cc:1: error: void B1::f()<br />t.cc:1: error: void B1::f()<br />t.cc:10: error: reference to âfâ is ambiguous<br />t.cc:2: error: candidates are: void B2::f(double)<br />t.cc:1: error: void B1::f()<br />t.cc:1: error: void B1::f()<br /></pre><br />It looks like GCC is trying here, but why is it emitting two errors on line 10 and why is it printing B1::f twice in each? When I get these sort of errors (which is pretty rare, since I don't use multiple inheritance like this often) I really value clarity when unraveling what is going on.<br /><br /><h2><a href="https://www.blogger.com/blogger.g?blogID=6088150582281556517" name="merge_conflicts">One more thing... Merge Conflicts</a></h2><br />Okay, this may be going a bit far, but how else are you going to fall completely in love with a compiler?<br /><br /><pre>$ <b>cat t.c</b><br />void f0() {<br /><<<<<<< HEAD<br /> int x;<br />=======<br /> int y;<br />>>>>>>> whatever<br />}<br />$ <b>clang t.c</b><br />t.c:2:1: error: version control conflict marker in file<br /><<<<<<< HEAD<br />^<br />$ <b>gcc t.c</b><br />t.c: In function âf0â:<br />t.c:2: error: expected expression before â<<â token<br />t.c:4: error: expected expression before â==â token<br />t.c:6: error: expected expression before â>>â token<br /></pre><br />Yep, clang actually detects the merge conflict and parses one side of the conflict. You don't want to get tons of nonsense from your compiler on such a simple error, do you?<br /><br />Clang: crafted for real programmers who make might make the occasional mistake. Why settle for less?<br /><br />-Chris
- Dragonegg Successfully Self-Hosts!https://blog.llvm.org/2010/02/dragonegg-successfully-self-hosts.htmlSun, 21 Feb 2010 05:07:00 +0000https://blog.llvm.org/2010/02/dragonegg-successfully-self-hosts.htmlThe <a href="http://dragonegg.llvm.org/">dragonegg GCC plugin</a> can host itself! Dragonegg lets you use the <a href="http://llvm.org/">LLVM</a> optimizers with <a href="http://gcc.gnu.org/">GCC-4.5</a>, much like <a href="http://llvm.org/cmds/llvmgcc.html">llvm-gcc</a>, but unlike llvm-gcc does not involve modifying GCC, thanks to the new GCC plugin infrastructure (currently one small patch is required). We built all of GCC-4.5, LLVM and dragonegg with dragonegg, then used the resulting binaries to build them all again. Why? Because we love to build! And because this was a great way of checking that nothing was miscompiled. The final dragonegg plugin was fully functional, successfully passing the entire dragonegg test suite.
- Clang Successfully Self-Hosts!https://blog.llvm.org/2010/02/clang-successfully-self-hosts.htmlThu, 04 Feb 2010 19:13:00 +0000https://blog.llvm.org/2010/02/clang-successfully-self-hosts.htmlToday, Clang completed its first complete self-host! We built all of LLVM and Clang with Clang (over 550k lines of C++ code). The resulting binaries passed all of Clang and LLVM's regression test suites, and the Clang-built Clang could then build all of LLVM and Clang again. The third-stage Clang was also fully-functional, completing the bootstrap.<div><br /></div><div>Congratulations to all of the Clang developers on this amazing achievement!</div>
- The x86 Disassemblerhttps://blog.llvm.org/2010/01/x86-disassembler.htmlWed, 06 Jan 2010 13:34:00 +0000https://blog.llvm.org/2010/01/x86-disassembler.htmlDisassemblers make binary analysis work. With a reliable disassembler, you can solve high-level problems like tracing back through a program's call stack or analyzing sample-based profiles to low-level problems like figuring out how your compiler unrolled a tight floating-point loop or what advantages declaring a variable const actually had at the other end of the optimization chain. A reliable disassembler, which takes sequences of bytes and prints human-readable instruction mnemonics, is a crucial part of any development platform. You're about to go on a whirlwind tour of the LLVM disassembler: why one should exist, what's great about this one, and how you can use it.<br /><br /><a name='more'></a><br /><h3>The case for an LLVM-based disassembler</h3>Disassemblers are all over the place. A disassembler you may well be familiar with is the disassembler from GNU gdb (<a href="http://opensource.apple.com/source/gdb/gdb-1346/src/include/dis-asm.h">source</a>). In fact, any debugger needs one: Sun mdb has a disassembler too (<a href="http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/cmd/mdb/common/mdb/mdb_disasm.h">source</a>). Some specialized applications like Dtrace need disassemblers as well (<a href="http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/intel/dtrace/fasttrap_isa.c">source</a>). So because this is well-traveled ground, there are several common properties you should expect from a disassembler:<br /><br /><ul><li>A large library can contain hundreds of thousands of instructions, so disassembly must be <em>fast</em>.<br /></li><li>A disassembler with a large memory footprint can steal memory and cache from analysis algorithms that need them more, so its code and data should be <em>compact</em>.<br /></li><li>Because disassemblers are used in a variety of applications, they should provide information about instructions in a <em>generic</em>, preferably even architecture-independent form.<br /></li><li>For the benefit of future code maintainers, disassemblers should be as <em>table-driven</em> as possible.</li></ul>Enter the LLVM MC architecture. In MC, instructions are represented using the architecture-independent <code>MCInst</code> class (<code>include/llvm/MC/MCInst.h</code>). The translation between MC instructions and machine code is specified by pre-existing <a href="http://llvm.org/docs/TableGenFundamentals.html">TableGen</a> tables (<code>lib/Target/X86/X86.td</code> for x86 platforms). Writing a disassembler inside the MC framework makes sense because it solves the generality and table-driven problems naturally, but we still need to solve two problems: speed and compactness.<br /><h3><span class="Apple-style-span" style="font-size: medium; font-weight: normal;"><h3>Quick Testdrive of the Disassembler</h3></span></h3><br />The llvm-mc tool provides a simple command line wrapper around the disassembler that we primarily use for testing (e.g. <span style="font-family: 'Courier New', Courier, monospace;">test/MC/Disassembler/simple-tests.txt</span>). It reads a text file containing input bytes and prints out the instructions that correspond to those bytes. For example, here's a simple transcript of using it:<br /><br /><pre>$ echo '1 2' | llvm-mc -disassemble -triple=x86_64-apple-darwin9<br />addl %eax, (%rdx)<br />$ echo '0x0f 0x1 0x9' | llvm-mc -disassemble -triple=x86_64-apple-darwin9<br />sidt (%rcx)<br />$ echo '0x0f 0xa2' | llvm-mc -disassemble -triple=x86_64-apple-darwin9<br />cpuid<br />$ echo '0xd9 0xff' | llvm-mc -disassemble -triple=i386-apple-darwin9<br />fcos<br /></pre><br /><div><span class="Apple-style-span" style="font-size: 19px; font-weight: bold;">Design of the decode process</span></div>Fast disassemblers can be classified into two categories, depending on the instruction format. On platforms with fixed-length instructions, it is possible to pull out all bits of the instruction at once and filter based on arbitrary ranges of those bits. In contrast, platforms with variable-length instructions require that the instruction be parsed byte by byte. In this article, I will discuss the variable-length case, and in particular the case of x86, which includes the <code>i386</code> and <code>x86_64</code> targets.<br />The structure of an x86 instruction is determined by several important factors, each of which is of vital importance when decoding:<br /><ul><li>The <em>context</em> of the instruction determines the meaning of the instruction and the size of its operands. The context includes the address and operand sizes of the instruction, as well as the presence (and position!) of prefixes such as the <code>REX.w</code> prefix on <code>x86_64</code> targets and the <code>f3</code> prefix on architectures with SSE.<br /></li><li>The <em>opcode</em> of the instruction is of varying size, and determines what operands are required. Opcodes come in four different types: one-byte opcodes of the form <code>xx</code>, two-byte opcodes of the form <code>0f</code> <code>xx</code>, three-byte opcodes of the form <code>0f</code> <code>38</code> <code>xx</code>, and three-byte opcodes of the form <code>0f</code><code>3a</code> <code>xx</code>.<br /></li><li>The <em>addressing bytes</em> of the instruction determine the addressing mode of the instruction's memory operand (there is only one memory operand possible with a selectable mode). The addressing bytes include the ModR/M (Modifier - Register/Memory) byte and the SIB (Scale - Index - Base) byte.</li></ul><table border="1"><tbody><tr> <td><b class="phase2"><span style="color: #339999;">Other prefixes?</span></b><br /></td> <td><b class="phase2"><span style="color: #339999;">Mandatory prefix?</span></b><br /></td> <td><b class="phase2"><span style="color: #339999;">REX prefix?</span></b><br /></td> <td><b class="phase1"><code><span style="color: #993399;">0f</span></code><span style="color: #993399;"> [</span><code><span style="color: #993399;">38</span></code><span style="color: #993399;">/</span><code><span style="color: #993399;">3a</span></code><span style="color: #993399;">]?</span></b><br /></td> <td><b class="phase3"><span style="color: #009900;">Opcode</span></b><br /></td> <td><b class="phase4"><span style="color: #3333ff;">ModR/M byte?</span></b><br /></td> <td><b class="phase5"><span style="color: #cc9933;">SIB byte?</span></b><br /></td> </tr></tbody></table><div class="caption"><em>Table 1:</em> Portions of an instruction relevant to decode<br /></div>You can read more about the meaning of all of these bytes in Chapter 2 of the Intel instruction manual, volume 2A (<a href="http://www.intel.com/Assets/PDF/manual/253666.pdf">large PDF</a>). The x86 disassembler is structured around hierarchical tables that assume a 5-phase decode process. You can follow along with this discussion by looking at <code>lib/Target/X86/Disassembler/X86DisassemblerDecoderCommon.h</code>, and the steps below are colored consistently with the data they access in Table 1.<br /><dl><dt><b class="phase1"><span style="color: #993399;">Phase 1</span></b></dt><dd>Record all prefixes but do not use them. Determine the type of the opcode, and obtain a <code>ContextDecision</code> on that basis: <code><span style="color: #cc9933;"><b>ONEBYTE_SYM</b></span></code>, <code><span style="color: #cc9933;"><b>TWOBYTE_SYM</b></span></code>, <code><b><span style="color: #cc9933;">THREEBYTE38_SYM</span></b></code>, and <code><b><span style="color: #cc9933;">THREEBYTE3A_SYM</span></b></code>. </dd><dt><b class="phase2"><span style="color: #339999;">Phase 2</span></b></dt><dd>Develop a context mask based on the prefixes that are present and the machine architecture being decoded for. Look up this mask in a lookup table (<code><b><span style="color: #cc9933;">CONTEXTS_SYM</span></b></code>) to get a context ID. Consult the <code><span style="color: #339999;"><b>ContextDecision</b></span></code> to find the <code><span style="color: #339999;"><b>OpcodeDecision</b></span></code> that corresponds to the context. As the comments in the header point out, the many possible contexts are boiled down to <code><span style="color: #339999;"><b>IC_max</b></span></code> distinct context IDs that actually matter when decoding. This saves a lot of space. </dd><dt><b class="phase3"><span style="color: #009900;">Phase 3</span></b></dt><dd>Read the opcode and use it to consult the <code><span style="color: #339999;"><b>OpcodeDecision</b></span></code> to find the right <code><span style="color: #339999;"><b>ModRMDecision</b></span></code>. </dd><dt><b class="phase4"><span style="color: #3333ff;">Phase 4</span></b></dt><dd>The ModR/M byte not only specifies the addressing mode, but also sometimes serves to identify the specific instruction intended. For example, extended opcodes and escape opcodes (often seen in SSE) use the Reg/Opcode field in the ModR/M byte as part of the opcode. You can see these oddities in Chapters A.4 and A.5 of the Intel instruction manual, volume 2B (<a href="http://www.intel.com/Assets/PDF/manual/253666.pdf">large PDF</a>). Given the value of the ModR/M byte, look up the LLVM opcode for the decoded instruction in the <code><span style="color: #339999;"><b>ModRMDecision</b></span></code>. </dd><dt><b class="phase5"><span style="color: #cc9933;">Phase 5</span></b></dt><dd>If the ModR/M byte indicates that an SIB byte is needed, read the SIB byte. This phase occurs as operands are read. </dd></dl>Once these five steps have been performed, the disassembler consumes the operands, whose forms are now completely specified.<br /><h3>Using the disassemblers in real code</h3>If you want to use a disassembler in your own code, then <code>tools/llvm-mc/Disassembler.cpp</code> is a good example of how to use one. You can instantiate a disassembler given a Target using the following code:<br /><pre><b class="namespace"><span style="color: #6600cc;">llvm</span></b>::<b class="identifier"><span style="color: #339999;">OwningPtr</span></b><<b class="keyword"><span style="color: #993399;">const</span></b> <b class="namespace"><span style="color: #6600cc;">llvm</span></b>::<b class="identifier"><span style="color: #339999;">MCDisassembler</span><span style="font-weight: normal;">></span></b><br /><b class="identifier"><span style="color: #339999;"> disassembler</span></b>(<b class="identifier"><span style="color: #339999;">target</span></b>.<b class="function"><span style="color: #336666;">createMCDisassembler</span></b>());<br /></pre>This disassembler works with <code><b><span style="color: #339999;">MemoryObject</span></b></code>s (<code>include/llvm/Support/MemoryObject.h</code>), and you will need to subclass <code><span style="color: #339999;"><b>MemoryObject</b></span></code> to perform the proper reading functions. A very <span style="color: #330033;">simple </span><code><span style="color: #339999;"><b>MemoryObject</b></span></code> subclass might look like this:<br /><pre><b class="keyword"><span style="color: #993399;">class</span></b> <b class="identifier"><span style="color: #339999;">BufferMemoryObject</span></b> : <span style="color: #993399;"><b>public</b></span> <b class="namespace"><span style="color: #6600cc;">llvm</span></b>::<b class="identifier"><span style="color: #339999;">MemoryObject</span></b> {<br /><b class="keyword"><span style="color: #993399;">private</span></b>:<br /><b class="keyword"><span style="color: #993399;"> const</span></b> <b class="identifier"><span style="color: #339999;">uint8_t</span></b> *<b class="identifier"><span style="color: #339999;">Bytes</span></b>;<br /><b class="identifier"><span style="color: #339999;"> uint64_t</span></b> <b class="identifier"><span style="color: #339999;">Length</span></b>;<br /><b class="keyword"><span style="color: #993399;">public</span></b>:<br /><b class="function"><span style="color: #339999;"> BufferMemoryObject</span></b>(<b class="keyword"><span style="color: #993399;">const</span></b> <b class="identifier"><span style="color: #339999;">uint8_t</span></b> *<b class="identifier"><span style="color: #339999;">bytes</span></b>, <b class="identifier"><span style="color: #339999;">uint64_t</span></b> <b class="identifier"><span style="color: #339999;">length</span></b>) :<br /><b class="identifier"><span style="color: #339999;">Bytes</span></b>(<b class="identifier"><span style="color: #339999;">bytes</span></b>), <b class="identifier"><span style="color: #339999;">Length</span></b>(<b class="identifier"><span style="color: #339999;">length</span></b>) {<br />}<br /><br /><b class="identifier"><span style="color: #339999;"> uint64_t</span></b> <b class="function"><span style="color: #336666;">getBase</span></b>() <b class="keyword"><span style="color: #993399;">const</span></b> { <b class="keyword"><span style="color: #993399;">return</span></b> <b class="literal"><span style="color: #3333ff;">0</span></b>; }<br /><b class="identifier"><span style="color: #339999;"> uint64_t</span></b> <b class="function"><span style="color: #336666;">getExtent</span></b>() <b class="keyword"><span style="color: #993399;">const</span></b> { <b class="keyword"><span style="color: #993399;">return</span></b> <b class="identifier"><span style="color: #339999;">Length</span></b>; }<br /><br /><b class="keyword"><span style="color: #993399;"> int</span></b> <b class="function"><span style="color: #336666;">readByte</span></b>(<b class="identifier"><span style="color: #339999;">uint64_t</span></b> <b class="identifier"><span style="color: #339999;">addr</span></b>, <b class="identifier"><span style="color: #339999;">uint8_t</span></b> *<b class="identifier"><span style="color: #339999;">byte</span></b>) <b class="keyword"><span style="color: #993399;">const</span></b> {<br /><b class="keyword"><span style="color: #993399;">if</span></b> (<b class="identifier"><span style="color: #339999;">addr</span></b> > <b class="function"><span style="color: #336666;">getExtent</span></b>())<br /><b class="keyword"><span style="color: #993399;">return</span></b> <b class="literal"><span style="color: #3333ff;">-1</span></b>;<br />*<b class="identifier"><span style="color: #339999;">byte</span></b> = <b class="identifier"><span style="color: #339999;">Bytes</span></b>[<b class="identifier"><span style="color: #339999;">addr</span></b>];<br /><b class="keyword"><span style="color: #993399;">return</span></b> <b class="literal"><span style="color: #3333ff;">0</span></b>;<br />}<br />};<br /></pre>Given a <code><span style="color: #339999;"><b>BufferMemoryObject</b></span></code>, all you have to do to extract <code><span style="color: #339999;"><b>MCInst</b></span></code> objects is to call the <code>getInstruction</code> method of the disassembler you got earlier:<br /><pre><b class="namespace"><span style="color: #6600cc;">llvm</span></b>::<b class="identifier"><span style="color: #339999;">MCInst</span></b> <b class="identifier"><span style="color: #339999;">Inst</span></b>;<br /><b class="identifier"><span style="color: #339999;">uint64_t</span></b> <b class="identifier"><span style="color: #339999;">Size</span></b>;<br /><b class="identifier"><span style="color: #339999;">disassembler</span></b>-><b class="function"><span style="color: #336666;">getInstruction</span></b>(<b class="identifier"><span style="color: #339999;">Inst</span></b>, <b class="identifier"><span style="color: #339999;">Size</span></b>, <b class="identifier"><span style="color: #339999;">BufferMObj</span></b>, <b class="literal"><span style="color: #3333ff;">0</span></b>, <b class="function"><b class="namespace"><span style="color: #6600cc;">llvm</span></b>::<span style="color: #336666;">nulls</span></b>()));<br /></pre>The last argument is an optional diagnostic stream, and the <code>0</code> indicates that the disassembler should start from address 0 in the buffer.<br /><h2>Where to look for more documentation</h2>For general information on how the disassembler's decode tables are generated from <code>lib/Target/X86/X86.td</code>, visit <code>utils/TableGen/DisassemblerEmitter.cpp</code>, which provides an overview of the TableGen side of the code. If you're interested in the gory, bit-for-bit details of how the disassembler dissects the various instruction bytes, you can go straight to <code>lib/Target/X86/Disassembler/X86Disassembler.h</code>, which describes the decode process in more detail and gives a guide to the implementation files.
- Address of Label and Indirect Branches in LLVM IRhttps://blog.llvm.org/2010/01/address-of-label-and-indirect-branches.htmlSun, 03 Jan 2010 00:11:00 +0000https://blog.llvm.org/2010/01/address-of-label-and-indirect-branches.htmlThe GCC Compiler supports a useful "<a href="http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html#Labels-as-Values">Label as Values</a>" extension, which allows code to take the address of a label and then later do an unconditional branch to an address specified as a void*. This extension is particularly useful for building efficient interpreters.<br /><br />LLVM has long supported this extension by lowering it to a "correct" but extremely inefficient form. New in LLVM 2.7 is IR support for taking the address of a label and jumping to it later, which allows implementing this extension much more efficiently. This post describes this new LLVM IR feature and how it works.<br /><br /><a name='more'></a><br /><br />In this discussion, I limit the scope to only considering "local" jumps. We don't talk about non-local jumps in the GCC extension sense: jumps from a nested function to an outer one.<br /><br /><span style="font-size: x-large;">The Address of Label Extension</span><br /><br />Before I dive into the new feature, I'll describe the GCC C extension along with how LLVM 2.6 and earlier used to compile it. Consider this code (from <a href="http://llvm.org/bugs/show_bug.cgi?id=3120">PR3120</a>):<br /><br /><pre>static int fn(Opcodes opcodes) {<br /> static const void *codetable[] =<br /> { &&RETURN, &&INCREMENT, &&DECREMENT, &&DOUBLE, &&SWAPWORD };<br /> int result = 0;<br /><br /> goto *codetable[*(opcodes++)];<br />RETURN:<br /> return result;<br />INCREMENT:<br /> result++;<br /> goto *codetable[*(opcodes++)];<br />DECREMENT:<br /> result--;<br /> goto *codetable[*(opcodes++)];<br />DOUBLE:<br /> result <<= 1;<br /> goto *codetable[*(opcodes++)];<br />SWAPWORD:<br /> result = (result << 16) | (result >> 16);<br /> goto *codetable[*(opcodes++)];<br />}<br /></pre><br />As you can see, the code initializes the 'codetable' array with the addresses of 5 labels, and later jumps through a computed pointer.<br /><br />An interesting aspect about this extension is that the only thing you are allowed to do with an address taken label is to jump to it. While it is widely misused for other things (e.g. the BUG macro in the linux kernel, which prints the address of a label on error), you are <b>really really</b> only allowed jump to it. You are not allowed to use it in an inline asm, inspect the value, or do anything else.<br /><br /><span style="font-size: x-large;">LLVM 2.6 and Earlier</span><br /><br />In LLVM 2.6 and earlier, LLVM took full advantage of the fact that you're not allowed to do anything with the value other than jump to the address of a label. Because this extension is only used rarely, we did not want to add direct support for this extension, because it would increase the complexity of LLVM IR. Instead, we took a very simple implementation approach, which faithfully implemented the extension, but did not require any new IR features. The approach was simple:<br /><ol><li>When the address of a label was taken, that label was assigned a unique integer ID (within its function) starting at 1. Taking the address of the label provided this integer ID, and not the actual address of the label.</li><li>When an indirect goto is seen, we lowered this construct as a standard LLVM <a href="http://llvm.org/docs/LangRef.html#i_switch">switch instruction</a>. For each uniquely assigned integer ID, the switch would jump to the corresponding label.</li></ol>The combination of these two elements meant that we could support this extension with no special support in LLVM IR. To give a more concrete example, this is how the example above was lowered. The "codetable" array was lowered as if it were written as:<br /><br /><pre>static const void *codetable[] =<br /> { (void*)1, (void*)2, (void*)3, (void*)4, (void*)5 };<br /></pre><br />This clearly doesn't provide the addresses of the specified labels, but it does provide unique ID numbers for each. With this, an indirect goto was lowered as if it were written as:<br /><br /><pre>switch (..) {<br /> default: __builtin_unreachable();<br /> case 1: goto RETURN;<br /> case 2: goto INCREMENT;<br /> case 3: goto DECREMENT:<br /> case 4: goto DOUBLE;<br /> case 5: goto SWAPWORD;<br /> }<br /></pre><br />Since code is only allowed to jump to the address of a label taken in the current function (again, not considering non-local gotos), we know all possible destinations, and we can codegen the indirect jump as a switch. To reiterate, the primary advantage of this approach was that it did not require any LLVM extension: switch statements required the LLVM IR switch instruction, so reusing it here was no problem.<br /><br />It is also worthwhile to point out that while this implementation fulfills the letter of the extension, it is fairly far from the intent of it. Beyond that, the major problem with the LLVM 2.6 implementation is that the generated code is quite slow.<br /><br /><span style="font-size: x-large;">LLVM 2.7 and Later: blockaddress and indirectbr</span><br /><br />While it is true that this extension is relatively rare, the cases where it is used are quite important. This extension is used in critical interpreter loops, where it can provide a fairly substantial win (around 15% is typical). Because of this, LLVM grew the ability to represent and codegen this in the intended form. This extension uses two new LLVM IR features:<br /><ol><li>First, taking the address of a label produces a new <a href="http://llvm.org/docs/LangRef.html#blockaddress">blockaddress</a> node (represented by the LLVM BlockAddress class).</li><li>Second, jumping through an address results in a new <a href="http://llvm.org/docs/LangRef.html#i_indirectbr">indirectbr</a> terminator instruction (the IndirectBrInst class).</li></ol>The two new features have a couple of interesting ramifications, but before we get into them, I'll show you how the example above compiles. First, the "codetable" array compiles into this pseudo IR:<br /><br /><pre>static const void *codetable[] =<br /> { blockaddress(@fn, %RETURN),<br /> blockaddress(@fn, %INCREMENT),<br /> blockaddress(@fn, %DECREMENT),<br /> blockaddress(@fn, %DOUBLE),<br /> blockaddress(@fn, %SWAPWORD)<br /> };<br /></pre><br />At codegen time, the new blockaddress constant actually lowered into a reference to the label for the LLVM BasicBlock that it correspond to. Next, instead of a switch, indirect gotos codegen into the new 'indirectbr' LLVM IR instruction like this:<br /><br /><pre>indirectbr i8* %address, [ label %RETURN, label %DOUBLE, label %INCREMENT, label %DECREMENT, label %SWAPWORD ]<br /></pre><br />While the blockaddress constant is relatively straightforward, you might be surprised to see all of the labels duplicated here. The 'indirectbr' is typically lowered to very simple machine code: a machine level jump through a register. Despite this underlying simplicity, the invariant on the "indirectbr" instruction is that it must include (possibly a superset of) all possible label targets in the list of labels in the instruction. Jumping to a label that is not included is undefined behavior. The order of labels in the instruction doesn't matter, but the presence or absence of a label is important.<br /><br /><span style="font-size: x-large;">Ramifications of this design</span><br /><br />When this feature was being added to LLVM, we considered many different approaches, which all had a variety of different tradeoffs. Instead of describing all possible implementation approaches, lets just talk about some of the ramifications of this approach by considering a set of questions you might have:<br /><br /><b>Why does indirectbr include a list of possible target blocks?</b><br /><br />One of the foremost concerns we had when implementing this new feature was that we wanted it to fit into the rest of the compiler with as little special case code as possible. One particularly important structure is the Control Flow Graph (CFG), which is the basis for all dataflow analysis in LLVM.<br /><br />In LLVM, the CFG is walked with the <a href="http://llvm.org/docs/ProgrammersManual.html#iterate_preds">pred_iterator and succ_iterator</a> iterators. <tt>succ_iterator</tt> is very simple, it just walks the BasicBlock operands of the <a href="http://llvm.org/docs/LangRef.html#terminators">terminator instruction</a> at the end of a block. <tt>pred_iterator</tt> is trickier: it walks the use-def chains of a BasicBlock, and reports any uses coming from terminators as predecessors.<br /><br />Clearly, for this extension to work with this scheme, we wanted to follow as closely as possible with the way the existing system works. This means that indirectbr having a list of possible targets makes the successor iterator very simple (it can just walk the list to get the possible destinations). A second major benefit is that this also fixes the predecessor iterator: since each operand is considered a 'use', walking the use list of a block that has its address taken will work correctly, because the indirectbr uses will be seen.<br /><br /><b>How does this extension interact with PHI nodes?</b><br /><br />PHI nodes are defined based on properties of the CFG, so they work normally as you'd expect based on the CFG behavior described above. Taking the address of a block itself doesn't cause it to have any PHI nodes. An address-taken block gets PHI node entries when an indirectbr jumps to it.<br /><br /><b>Why is blockaddress a constant?</b><br /><br />This is an easy one: the BlockAddress IR object inherits from Constant because it needs to be able to be used to initialize global variables. Global variable initializers must be Constant's.<br /><br /><b>Why does blockaddress take both a function and a basic block name?</b><br /><br />There are a couple answers to this. The most obvious one is that LLVM IR is not nested like C code is. When the address of a label is used to initialize a static variable, that static variable becomes an LLVM global variable like any other. If there were a reference to "foo" from a global variable, we need to know <i>which</i> "foo" label is being referenced (since each function has its own local namespace).<br /><br />A second and less obvious answer is that LLVM IR is more general than the GCC C extension: you are allowed to take the address of a block in a different function. This support falls out of the support we need to initialize global variables, and isn't obviously useful, but it is there nonetheless.<br /><br /><b>How does this extension interact with inlining?</b><br /><br />Simply put, LLVM currently refuses to inline a function containing an indirectbr (as does GCC). It is conceivably possible to relax this restriction in the future in some cases, but it would require a lot of analysis. The basic problem is that inlining an indirectbr is actually a pretty tricky thing to do: in addition to cloning the callee into the caller, we have to clone all blockaddress objects referring to block in the caller, and clone everything that refers to them. Here's a silly example in pseudo IR:<br /><br /><pre>static void *G = blockaddress(@foo, %bb);<br />void foo() {<br /> goto *G;<br />bb:<br /> return;<br />}<br />void bar() {<br /> foo();<br />}<br /></pre><br />Simply cloning foo into bar like this would not be correct:<br /><br /><pre>static void *G = blockaddress(@foo, %bb);<br />void foo() {<br /> goto *G;<br />bb: return;<br />}<br />void bar() {<br /> goto *G;<br />bb:<br /> return;<br />}<br /></pre><br />The problem is that 'bar' would jump through G to a label defined in 'foo'. It is not legal to jump from one function to another. To do this inlining, we'd actually have to clone G itself. Doing this is possible, but not worth it, particularly because most functions that use this extension are large interpreter loops.<br /><br /><b>How does this extension interact with critical edge splitting?</b><br /><br />Poorly.<br /><br />A critical edge in the CFG is an edge which comes from a block with multiple successors (e.g. a block that ends with a conditional branch) and goes to a block with multiple predecessors (like the merge point of an if/then/else). Critical edges are problematic for various code motion transformations. Prior to this extension, any critical edge in the CFG could be split by introducing a new intermediate block between the source and destination blocks. <br /><br />My biggest disappointment with this extension (and the reason I resisted implementing it for so long) centers around the fact that it inherently makes some edges un-splittable. Consider a simple little CFG like this:<br /><br /><pre>BB1:<br /> indirectbr i8* %P1, [ label %A, label %B ]<br />BB2:<br /> br label %A<br />A:<br /> ...<br /></pre><br />The edge "BB1->A" is critical because A has multiple predecessors (from both BB1 and BB2) and BB1 has multiple successors (to A and B). We could easily split the edge in this example by introducing a new intermediary block:<br /><br /><pre>BB1:<br /> indirectbr i8* %P1, [ label %A1, label %B ]<br />BB2:<br /> br label %A<br />A1:<br /> br label %A<br />A:<br /> ...<br /></pre><br />This is the normal critical-edge splitting transformation. Here we can see that the edge from BB1->A1 is not critical (because A1 has one predecessor) and the edge from A1->A is not critical either (because A1 has one predecessor). The problem with this is that we just broke an important invariant: since we didn't adjust places that took the address of A, we now have a situation where the CFG looks like BB1 jumps to A1 - but in reality, the pointer that the indirectbr gets will contain the address of A. This will cause us to do invalid dataflow analysis and lead to all sorts of problems.<br /><br />As with inlining, it is possible to teach the optimizer to be able to split some critical edges. However, this isn't enough. If there is a single critical edge that the optimizer may not be able to split it means that various LLVM optimizations have to assume that critical edge splitting can fail. This had some significant effects on the loop optimizer, for example, which assumed that it could split critical edges to form canonical loops.<br /><br /><b>Can we get an N^2 explosion of CFG edges?</b><br /><br />Absolutely. The issue here is that you can have N indirect branch instructions (in the example at the top, N = 5) and M labels with their addresses taken (in the example, M = 5). Since each indirectbr needs an edge to each label with its address taken, you get N*M edges, which is N^2. This can quickly become a big compile time problem, because it is fairly common for big interpreters to have hundreds of these things in their loops.<br /><br />Fortunately, the fix for this is pretty simple: while the optimizer can safely duplicate an indirectbr instruction, it decides that it isn't profitable to do so. By trying to maintain at most one indirectbr instruction per function, we effectively get a factoring of the edges. The llvm-gcc and clang frontends both generate IR which has at most one indirectbr instruction per function: all other indirect gotos are lowered as a branch to the communal indirectbr in a function.<br /><br />In order to produce efficient code, the code generator performs tail duplication to introduce the N^2 CFG. It does this early enough to get good code but late enough to not impact compile time too much. <br /><br /><b>What about labels whose address is taken but not branched to?</b><br /><br />Circling back to the Linux BUG macro and other abuses of this extension, it is natural to wonder whether we support these uses better than LLVM 2.6. The answer is "sort of". In cases where code takes the address of a block and has an indirectbr in a function, that address will persist and other uses will have the expected behavior: They will see the address of a block and not some magic block ID number.<br /><br />However, this typically isn't good enough. The issue is that taking the address of a block is not enough to prevent other optimizations (like block merging) from affecting it, it needs to have predecessors in the CFG. If we ever decide to better support abuses like this, we will need to extend our model to support them somehow. <br /><br />In any case, I hope this discussion about indirectbr is helpful and illuminating. Interpreter loops will be much more performant with LLVM 2.7 than with LLVM 2.6 and earlier!<br /><br />-Chris
- Clang Builds LLVMhttps://blog.llvm.org/2009/12/clang-builds-llvm.htmlThu, 24 Dec 2009 13:23:00 +0000https://blog.llvm.org/2009/12/clang-builds-llvm.htmlJust in time for the Christmas holiday, the Clang project has hit a major milestone: Clang can now build all of LLVM and Clang!<div><br /></div><div>The resulting Clang-built-Clang is not yet functional, so this "self-build" milestone is well short of full self-hosting. However, self-building indicates that C++ parsing, semantic analysis, and code generation is solid enough to compile the entirety of LLVM (~350k lines of C++ code) and Clang (~200k lines of C++ code) and produce object files that link together properly. To get to this point, we've fixed many bugs in Clang (when compiling C++ code), but also several bugs in LLVM and Clang that were found by Clang itself.</div><div><br /></div><div>We are tracking <a href="http://llvm.org/bugs/show_bug.cgi?id=5221">a number of Clang bugs</a> that manifest when building LLVM and Clang, as we make our way to the next big milestone: full self-hosting of Clang!</div>
- Advanced Topics in Redundant Load Elimination with a Focus on PHI Translationhttps://blog.llvm.org/2009/12/advanced-topics-in-redundant-load.htmlSat, 19 Dec 2009 14:45:00 +0000https://blog.llvm.org/2009/12/advanced-topics-in-redundant-load.htmlIn our <a href="http://blog.llvm.org/2009/12/introduction-to-load-elimination-in-gvn.html">previous post on GVN</a> we introduced some basics of load elimination. This post describes some advanced topics and focuses on PHI translation: what it is, why it is important, shows some nice things it can do, and describes the implementation in LLVM.<br /><a name='more'></a><br /><span style="font-size: x-large;">What is PHI Translation All About?</span><br /><br />When performing redundancy elimination on SSA form, PHI translation is required when we are walking through the CFG and the value being analyzed has an operand defined in the block we're walking through. In the case of load elimination, the operand of the value being analyzed is the pointer we're loading from. This means that PHI translation happens when the pointer we're loading is defined in a block. For example, consider this C code:<br /><br /><pre>if (...) {<br /> *A = 5;<br /> P = A;<br /> } else {<br /> *B = 9;<br /> P = B;<br /> }<br /> use(*P);<br /></pre><br />This compiles into LLVM IR that looks like this:<br /><br /><pre>BB1:<br /> store i32 5, i32* %A<br /> br label %Merge<br /><br />BB2:<br /> store i32 9, i32* %B<br /> br label %Merge<br /><br />Merge:<br /> %P = phi i32* [%A, %BB1], [%B, %BB2]<br /> %Y = load i32 *%P<br /> ...<br /> ... use %Y ...<br /></pre><br />In this example, GVN starts looking at the %Y load to see if it can eliminate it. It scans backwards up the block, looking for other things that provide the value of the memory address at %P. Unlike in the example in the previous post, here we actually find a definition of %P: what do we do?<br /><br />In LLVM 2.6 and before, memory dependence analysis would just give up and act as though the memory had been clobbered, preventing the load from being analyzed further (and eventually being eliminated in this case). New in LLVM 2.7, GVN is able to translate %P into each predecessor. In this case, it sees that %P has the value of %A in %BB1 (and then sees that %A is available there) and that %P has the value of %B in %BB2 (where it is also available). This allows GVN to optimize this example into:<br /><br /><pre>BB1:<br /> store i32 5, i32* %A<br /> br label %Merge<br /><br />BB2:<br /> store i32 9, i32* %B</pre><pre> br label %Merge<br /><br />Merge:<br /> %Y = phi i32 [5, %BB1], [9, %BB2]<br /> %P = phi i32* [%A, %BB1], [%B, %BB2]<br /> ...<br /> ... use %Y ...<br /></pre><br />which eliminates the load. This post talks about how this is done, the nuances involved in getting this right, and what this allows us to optimize.<br /><br /><span style="font-size: x-large;">Why is PHI Translation Required for Correctness?</span><br /><br />One thing that wasn't obvious to me when I dove into this is that PHI translation is actually required for correctness. This is the reason why memory dependence analysis must stop scanning if it finds the definition of the pointer. The cases where this happen are somewhat subtle and usually involve partial redundancy elimination. For example, consider this loop:<br /><br /><pre>Loop:<br /> %P = phi i32* [%A, %Entry], [%B, %Loop]<br /> %X = load i32* %P<br /> ...<br /> store i32 5, i32* %B<br /> store i32 4, i32* %P<br /> br i1 %cond, label %Loop, label %Out<br /></pre><br />Consider what would happen if PHI translation kept scanning for %P in predecessors as it went up the CFG: it would scan from the %X load up to the top of the Loop block. If not doing PHI translation correctly, it would continue scanning for %P in the Entry block (which we ignore in this example), then scan for %P in the Loop block (which is a predecessor of itself).<br /><br />Scanning for %P in the loop block finds the store of 4 to %P, so we'd consider 4 to be a live-in value on the edge from loop. However, this is <b>incorrect</b> and will lead to a miscompilation: the actual value live on that backedge is 5, which is provided by the previous store.<br /><br />This simple example is intended to show that PHI translation is not an optimization: it is required for correctness, and that the most simple form of PHI translation is to give up when you see a definition of the address. However, LLVM recently got smart enough to do much better than this or the simple pointer case above.<br /><br /><span style="font-size: x-large;">A More Interesting Case</span><br /><br />Consider this test case:<br /><br /><pre>struct S { int X, Y; };<br /><br />int foo(struct S *P1, struct S *P2, int C) {<br /> struct S *P;<br /> if (C) {<br /> P1->X = 4;<br /> P1->Y = 2;<br /> P = P1;<br /> } else {<br /> P2->X = 24;<br /> P2->Y = 2;<br /> P = P2;<br /> }<br /> return P->X + P->Y;<br />} <br /></pre><br />This code compiles down to IR that looks like this (using "<tt>clang t.c -S -o - -emit-llvm | opt -mem2reg -S</tt>":<br /><br /><pre>if.then:<br /> %tmp2 = getelementptr inbounds %struct.S* %P1, i32 0, i32 0<br /> store i32 4, i32* %tmp2<br /> %tmp4 = getelementptr inbounds %struct.S* %P1, i32 0, i32 1<br /> store i32 2, i32* %tmp4<br /> br label %if.end<br /><br />if.else: <br /> %tmp7 = getelementptr inbounds %struct.S* %P2, i32 0, i32 0<br /> store i32 24, i32* %tmp7<br /> %tmp9 = getelementptr inbounds %struct.S* %P2, i32 0, i32 1 <br /> store i32 2, i32* %tmp9<br /> br label %if.end<br /><br />if.end: <br /> %P = phi %struct.S* [ %P1, %if.then ], [ %P2, %if.else ] <br /> %tmp12 = getelementptr inbounds %struct.S* %P, i32 0, i32 0 <br /> %tmp13 = load i32* %tmp12 <br /> %tmp15 = getelementptr inbounds %struct.S* %P, i32 0, i32 1 <br /> %tmp16 = load i32* %tmp15 <br /> %add = add nsw i32 %tmp13, %tmp16 <br /> ret i32 %add<br />}<br /></pre><br />In this case, GVN looks to eliminate the %tmp13 and %tmp14 loads. Consider the %tmp13 load: it scans backwards from the load, looking for available values of %tmp12. As it goes, it immediately finds the definition of the pointer (%tmp12), so it needs to PHI translate the pointer or give up. Without getting into the details yet of how this is done, here is the intuition of what happens:<br /><br />In this case, the pointer is not a PHI node, but it <b>uses</b> a PHI node as an operand. Because of this, GVN needs to phi translate the entire symbolic expression "gep P, 0, 0" into the predecessors. It does this, forming the symbolic expression "gep P1, 0, 0" and it finds that the phi translated address is available as %tmp2 in the %if.then block. It then PHI translates the "gep P, 0, 0" expression into the %if.else forming the "gep P2, 0, 0" symbolic expression and finds that it is available as %tmp7. It scans those blocks for the pointers and finds that the values are, in fact, available. Because they are both available, it can use insert construct SSA form to eliminate the load.<br /><br />This allows it to see the both loads are in fact available in the predecessors. Here is the code after GVN (using "<tt>clang t.c -S -o - -emit-llvm | opt -mem2reg -S -gvn -die</tt>):<br /><br /><pre>if.then:<br /> %tmp2 = getelementptr inbounds %struct.S* %P1, i32 0, i32 0<br /> store i32 4, i32* %tmp2<br /> %tmp4 = getelementptr inbounds %struct.S* %P1, i32 0, i32 1<br /> store i32 2, i32* %tmp4<br /> br label %if.end<br /><br />if.else:<br /> %tmp7 = getelementptr inbounds %struct.S* %P2, i32 0, i32 0<br /> store i32 24, i32* %tmp7<br /> %tmp9 = getelementptr inbounds %struct.S* %P2, i32 0, i32 1<br /> store i32 2, i32* %tmp9<br /> br label %if.end<br /><br />if.end:<br /> %tmp13 = phi i32 [ 1, %if.then ], [ 2, %if.else ]<br /> %tmp16 = phi i32 [ 3, %if.then ], [ 4, %if.else ]<br /> %add = add nsw i32 %tmp13, %tmp16<br /> ret i32 %add<br />}<br /></pre><br />Here you can see that GVN found the available values, inserted PHI nodes, and eliminated the loads.<br /><br /><span style="font-size: x-large;">More Complex Address Expressions</span><br /><br />While the example above hopefully makes intuitive sense, it turns out that PHI translating expressions like this is actually a bit more difficult than it looks. It was so much so that it got split out into its own class, <a href="http://llvm.org/doxygen/classllvm_1_1PHITransAddr.html">PHITransAddr</a> (in <a href="http://llvm.org/doxygen/PHITransAddr_8h-source.html">llvm/Analysis/PHITransAddr.h</a>). Doing this was actually motivated by a few cute little examples like this:<br /><br /><pre>void test(int N, double* G) {<br /> for (long j = 1; j < 1000; j++)<br /> G[j] = G[j] + G[j-1];<br />}<br /></pre><br />This example (which was reduced from a larger example) has a loop carried redundancy where every iteration reads the previous iteration's value. In fact, the code could be rewritten like this, which only has one load in the loop:<br /><br /><pre>void test(int N, double* G) {<br /> double Prev = G[0];<br /> for (long j = 1; j < 1000; j++) {<br /> Prev = G[j] + Prev;<br /> G[j] = Prev;<br /> }<br />}<br /></pre><br />Some compilers have specific optimization passes that identify and eliminate these recurrences through dependence analysis. While this is a nice thing to do, sufficiently smart partial redundancy elimination of loads should also be able to eliminate this, and LLVM now does.<br /><br />The unoptimized code looks like this in LLVM IR:<br /><br /><pre>define void @test(i32 %N, double* %G) {<br />bb.nph:<br /> br label %for.body<br /><br />for.body:<br /> %indvar = phi i64 [ 0, %bb.nph ], [ %tmp, %for.body ] ; <b>indvar = [0 ... 999]</b><br /> %arrayidx6 = getelementptr double* %G, i64 %indvar<br /> %tmp = add i64 %indvar, 1<br /> %arrayidx = getelementptr double* %G, i64 %tmp<br /> %tmp3 = load double* %arrayidx ; <b>load G[indvar+1]</b><br /> %tmp7 = load double* %arrayidx6 ; <b>load G[indvar]</b><br /> %add = fadd double %tmp3, %tmp7<br /> store double %add, double* %arrayidx ; <b>store G[indvar+1]</b><br /> %exitcond = icmp eq i64 %tmp, 999<br /> br i1 %exitcond, label %for.end, label %for.body<br /><br />for.end:<br /> ret void<br />}<br /></pre><br />One interesting thing to be aware of here is that the -indvars<span style="font-family: 'Courier New', Courier, monospace;"> </span>pass rewrote the induction variable to count from 0 to 999 instead of from 1 to 1000. This is just a canonicalization, but it is why we see a store to indvar+1 instead of directly through indvar.<br /><br />In order to eliminate the redundant "<b>load G[indvar]</b>", GVN starts by looking for the dependencies of the %tmp7 load. It scans up the block, over several instructions that obviously don't modify the memory value, until it gets to the %arrayidx6 instruction, which defines the value. At this point it has to either stop phi translation (correct, but not very aggressive) or incorporate it into the scan and start looking for "gep %G, %indvar". It does this, until the next instruction, which defines %indvar. Since it found a definition of one of the inputs, it either has to phi translate (again, correct, not not very aggressive) or try to incorporate the value.<br /><br />In this case, PHITransAddr attempts to translate the "gep %G, %indvar" symbolic expression across the PHI for each predecessor. In the %for.body predecessor, it looks to see if there is an instruction that produces the value "gep %G, %tmp" (because %tmp is the value of the PHI in the %for.body predecessor), and finds that this expression exists as %arrayidx. Since PHI translation succeeded, it scans from the bottom of the block to see if there is a definition of the value at the address %arrayidx, and finds that the %tmp3 load produces the desired value.<br /><br />In the other predecessor (%bb.nph), PHITransAddr translates the symbolic "gep %G, %indvar" expression into "gep %G, 0" (which it uses InstSimplify to simplify down to "%G") and then checks to see if it is available as an address. "%G" is in fact a value address, so it scans from the bottom of the %bb.nph block to see if the value at address %G is available. In this case it isn't, so it records that the value is not available in the entry block, and that the phi translated address in that block is %G.<br /><br />At this point, the recursive walk of the CFG has completed, and GVN knows that the %tmp7 load is in fact available as the %tmp3 value in one predecessor, but it is not available in the other predecessor. This is a classic case of a partial redundancy. Since the value is redundant on one edge but not the other, GVN makes the value fully redundant by inserting the computation (a load of %G) into the %bb.nph block, constructs SSA and eliminates the original load.<br /><br />The final LLVM IR we get is:<br /><br /><pre>define void @test(i32 %N, double* %G) {<br />bb.nph:<br /> %tmp7.pre = load double* %G ; <b>Inserted by PRE</b><br /> br label %for.body<br /><br />for.body:<br /> %tmp7 = phi double [ %tmp7.pre, %bb.nph ],<br /> [ %add, %for.body ] ; <b>SSA Construction</b><br /> %indvar = phi i64 [ 0, %bb.nph ], [ %tmp, %for.body ]<br /> %arrayidx6 = getelementptr double* %G, i64 %indvar<br /> %tmp = add i64 %indvar, 1<br /> %arrayidx = getelementptr double* %G, i64 %tmp<br /> %tmp3 = load double* %arrayidx<br /> %add = fadd double %tmp3, %tmp7 ; <b>Now uses the PHI instead of a load</b><br /> store double %add, double* %arrayidx<br /> %exitcond = icmp eq i64 %tmp, 999<br /> br i1 %exitcond, label %for.end, label %for.body<br /><br />for.end:<br /> ret void<br />}<br /></pre><br />Through this, GVN and PHI translation have worked together to eliminate a load in the loop. If you're more comfortable reading X86 machine code, here is the before and after code for the loop:<br /><br />Before:<br /><pre>LBB1_1:<br /> movsd 8(%rsi,%rax,8), %xmm0 # Load<br /> addsd (%rsi,%rax,8), %xmm0 # Load<br /> movsd %xmm0, 8(%rsi,%rax,8) # Store<br /> incq %rax<br /> cmpq $999, %rax<br /> jne LBB1_1<br /></pre><br />After:<br /><span style="font-family: monospace; white-space: pre;">LBB1_1:</span><br /><pre>addsd 8(%rsi,%rcx,8), %xmm0 # Load<br /> movsd %xmm0, 8(%rsi,%rcx,8) # Store<br /> incq %rax<br /> incq %rcx<br /> cmpq $999, %rcx<br /> jne LBB1_1<br /></pre><br />If you're interested in other examples of PHI translation, take a look at test/Transforms/GVN/rle-phi-translate.ll and test/Transforms/GVN/rle.ll in the LLVM distribution.<br /><br /><span style="font-size: x-large;">Division of Labor</span><br /><br />Getting this to work requires a number of different LLVM subsystems to work together. Here are the major players:<br /><br /><b>PHI Translation</b><br /><br />The <a href="http://llvm.org/doxygen/classllvm_1_1PHITransAddr.html">PHITransAddr</a> class is the one that is responsible for building and translating symbolic expression like "gep %P, 1, (add %i, 1))" through PHI nodes. When the "instruction scan" finds a definition of an input to the current PHITransAddr expression, it either has to incorporate it into a (potentially larger and more complex) expression or give up. If it gives up, then PHI translation fails, otherwise it can keep scanning.<br /><br /><b>Memory Dependence Analysis</b><br /><br />"MemDep" is the pass that does the CFG and instruction scanning. It builds a lazy and cached representation that is morally similar to "Virtual SSA Form" used by some other compilers, but is significantly more efficient than the virtual SSA forms that I'm aware of.<br /><br />It exposes two major interfaces:<br /><br />1) "give me all the local dependences of this load". This query scans the block the load lives in for dependent instructions. If it does not find a dependent instruction it returns "nonlocal" to indicate that the loaded memory value is potentially live-in to the block.<br /><br />2) "give me all the non-local dependences for a load that is live in to a block". This query does the recursive upwards CFG scan that does PHI translation to find other definitions of the value.<br /><br />In the interesting cases for PHI translation, we end up doing a non-local query and get back a set of blocks where the value is available along with a set of blocks where the value isn't available.<br /><br /><b>Alias Analysis:</b><br /><br /><a href="http://llvm.org/docs/AliasAnalysis.html">Alias analysis</a> (in this case, the -basicaa pass) is the underlying analysis that tells us whether two pointers can point to the same memory location or whether an instruction can modify or read from a memory location. This is required to allow MemDep to scan beyond stores and calls that do not clobber the address we're interested in.<br /><br /><b>SSA Update:</b><br /><br />The <a href="http://llvm.org/doxygen/SSAUpdater_8h-source.html">SSAUpdater</a> class is used to insert PHI nodes based on the set of loads that we find are available.<br /><br /><b>GVN</b>:<br /><br />The GVN pass is the transformation sitting on top of all of these subsystems. Because it is based on these other facilities, its logic is relatively simple: First, do a non-local memdep query. If it returns a set of definitions with no clobbers, then the load is fully redundant and can be eliminated. Otherwise, if there are some definitions live in, we have a partially redundant case. GVN handles inserting the new computation to make the value fully redundant.<br /><br /><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="font-size: x-large;">Limitations</span><br /></div><br />While there is a lot of power here, there are still some significant limitations to this system. As of this writing, here are some of the most significant ones:<br /><br />First, an symbolic expression address must exist as an SSA value for PHI translation to succeed. In the last example, if we tried to phi translate "gep %G, %indvar" into a predecessor value which formed the symbolic expression of "gep %G, %xxx" and that symbolic expression did not actually exist in the code, PHI translation would fail. This happens because because after PHI translation occurs, we need MemDep to scan the block to find dependent instructions. Since MemDep queries are based on pointer values expressed as LLVM 'Value*'s, we have to have one to do the query.<br /><br />Second, critical edges currently block PRE of loads because we do not want to introduce the load on a control flow path where it would not exist before. In principle, we could do this by lazily splitting the edge, but this would require updating the other in-flight data structures that the GVN pass is maintaining and we don't do this yet.<br /><br />Finally, our PRE of loads can certainly be improved. Currently we only do PRE in cases where it would not grow the code and not introduce a computation on a path where it wouldn't exist before. Since we are deleting a load, this means that we only want to insert at most one load. The heuristic we use to determine whether this is the case is currently very local and can be improved.<br /><br />In any case, I hope this gives an useful overview of how this subsystem in LLVM works, and how it got better in what will be LLVM 2.7.<br /><br />-Chris
- The Dreaded Two-Phase Name Lookuphttps://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.htmlFri, 18 Dec 2009 14:17:00 +0000https://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.htmlC++ has more than its fair share of dark, dank corners, especially where templates are concerned. One of the most vexing is "two-phase name lookup", which involves lookup for any names that occur in the body of a template. As you might expect, there are two different phases of templates:<br /><br /><br /><a name='more'></a><br /><div><ol><li>Template definition time: when the template is initially parsed, long before it is instantiated, the compiler parses the template and looks up any "non-dependent" names. A name is "non-dependent" if the results of name lookup do not depend on any template parameters, and therefore will be the same from one template instantiation to another.</li><li>Template instantiation time: when the template is instantiated, the compiler looks up any "dependent" names, now that it has the full set of template arguments to perform lookup. The results of this lookup can (and often do!) vary from one template instantiation to another.</li></ol></div><div>Two-phase name lookup is not as complicated as its reputation implies. There are some non-obvious rules in the determination of what is a dependent vs. a non-dependent name, but otherwise the idea is simple. The problem with two-phase name lookup is that current compiler support for this feature is very poor. For example, GCC implements two-phase name lookup relatively well, but occasionally delays lookups that should have been done at template definition time (phase 1) until template instantiation time or performs lookups in both phases when it shouldn't. Visual C++, on the other hand, has a template parsing model that delays nearly every lookup to instantiation time (phase 2). By not implementing two-phase name lookup fully, both compilers tend to accept incorrect template code, and in some cases will end up compiling code differently from the mythical fully-conforming compiler. This is a portability issue, both between those two compilers (Visual C++ is more lenient) and to other, more pedantic compilers.<br /></div><div><br /></div><div>Like Clang. Clang was designed with complete support for two-phase name lookup, parsing template definitions (phase 1) as completely as possible and only performing name lookup at template instantiation time (phase 2) when required. Since we have chosen to make Clang C++ strict, we end up diagnosing template problems that other compilers miss. While that's generally good---correct code is more portable code---it also means that Clang needs to try extra-hard to produce decent diagnostics. Here's a recent problem Clang found within the LLVM code base (which compiled with GCC):<br /></div><div><div></div><blockquote><div>In file included from llvm/lib/Analysis/AliasAnalysisCounter.cpp:16:<br /></div><div>In file included from llvm/include/llvm/Pass.h:369:<br /></div><div>In file included from llvm/include/llvm/PassAnalysisSupport.h:24:<br /></div><div><b>llvm/include/llvm/ADT/SmallVector.h:317:7:</b><b><span style="color: red;"> error: <span style="color: black; font-weight: normal;">use of undeclared identifier 'setEnd'</span></span></b><br /></div><div>setEnd(this->end()+1);<br /></div><div><span style="color: #33ff33;"> ^</span><br /></div><div><span style="color: #33ff33;"> this-></span><br /></div><div>In file included from llvm/lib/Analysis/AliasAnalysisCounter.cpp:16:<br /></div><div>In file included from llvm/include/llvm/Pass.h:369:<br /></div><div><b>llvm/include/llvm/PassAnalysisSupport.h:56:14: note: <span style="font-weight: normal;">in instantiation of member function 'llvm::SmallVectorImpl llvm::PassInfo const *>::push_back' requested here</span></b><br /></div><div>Required.push_back(ID);<br /></div><div><span style="color: #33ff33;"> ^</span><br /></div><div>In file included from llvm/lib/Analysis/AliasAnalysisCounter.cpp:16:<br /></div><div>In file included from llvm/include/llvm/Pass.h:369:<br /></div><div>In file included from llvm/include/llvm/PassAnalysisSupport.h:24:<br /></div><div><b>llvm/include/llvm/ADT/SmallVector.h:105:8: note: </b><br /></div><div><b> must qualify identifier to find this declaration in dependent base class</b><br /></div><div>void setEnd(T *P) { this->EndX = P; }<br /></div><div><span style="color: #33ff33;"> ^</span><br /></div></blockquote><div></div><div>The problem itself is in SmallVectorImpl, in the call to setEnd(). The actual setEnd() function isn't in SmallVectorImpl, but in a base class, so we have a situation that looks like this:<br /></div><div><br /></div><div></div><blockquote><div>template<typename T><br /></div><div>class SmallVectorTemplateCommon {<br /></div><div>protected:<br /></div><div><span style="white-space: pre;"> </span> void setEnd(T *P);<br /></div><div>};<br /></div><div></div><div>template<typename T><br /></div><div>class SmallVectorImpl : public SmallVectorTemplateCommon<T> {<br /></div><div>public:<br /></div><div><span style="white-space: pre;"> </span> void push_back(const T& value) {<br /></div><div><span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span> // ...<br /></div><div><span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span> setEnd(this->end() + 1);<br /></div><div><span style="white-space: pre;"> </span> }<br /></div><div>};<br /></div></blockquote><div></div><div><br /></div><div>If we weren't in a template, this code would be fine, because we would find setEnd in our base class. However, because we're in a template we're dealing with two-phase name lookup. While parsing push_back(), the compiler performs name lookup for the name "setEnd" at phase 1: however, it can't find anything because it isn't allowed to look into the dependent base class SmallVectorTemplateCommon<T>. However, this code is still valid: "setEnd" is taken as the name of a non-member function, which could be found at instantiation time via Argument Dependent Lookup. Unfortunately, when we do get around to instantiating push_back, Argument Dependent Lookup doesn't look into our base class, so Clang gives us a "use of undeclared identifier" error.<br /></div><div><br /></div><div>By itself, that error would leave the programmer scratching her head. GCC and Visual C++ accepted this code, and setEnd() is <i>obviously</i> in the base class, so what gives? To help out a bit, Clang gives more detail:<br /></div><div><ol><li>The note at the very end, which reads "must qualify identifier to find this declaration in dependent base class," tells the programmer what declaration Clang could find... if only she were to qualify the name somehow so that Clang were allowed to look there.</li><li>The original error had a little hint below the caret diagnostic, in green, providing advice on how to fix this particular issue. By adding "this->", we tell the compiler that "setEnd" is in the current class or one of its (possibly dependent) base classes, to be found at template instantiation time.</li></ol></div><div>Clang C++ is designed to be a strict but helpful compiler, following the letter of the C++ standard to help programmers make sure that their code is portable. We also hope to make Clang a friendly compiler, that can use its knowledge of the program and the C++ language to help programmers get past portability problems like this one. And maybe, just maybe, Clang can shine a little light into the dark, scary corners of C++.<br /></div></div>
- Introduction to load elimination in the GVN passhttps://blog.llvm.org/2009/12/introduction-to-load-elimination-in-gvn.htmlThu, 17 Dec 2009 23:28:00 +0000https://blog.llvm.org/2009/12/introduction-to-load-elimination-in-gvn.htmlOne very important optimization that the GVN pass (opt -gvn) does is load elimination. Load elimination involves several subsystems (including alias analysis, memory dependence analysis, SSA construction, PHI translation) and has many facets (full vs partial redundancy elimination, value coercion, handling memset/memcpy, etc). In this post, I introduce and motivate the topic, which will let us expand on it in future posts.<br /><br /><a name='more'></a><br /><span style="font-size: x-large;">Basic Redundant Load Elimination</span><br /><br />GVN (which stands for "Global Value Numbering", though this detail has nothing to do with load elimination) is responsible for the form of load elimination known as <b>redundant</b> load elimination. This is the elimination of loads whose values are already available (other forms of load elimination includes deletion of <b>dead</b> loads). A simple example of a redundant load is:<br /><br /><pre> %x = load i32* %P<br /> %y = load i32* %P ; <- Redundant<br /></pre><br />Clearly in this example, we can delete the second load and "replace all uses" of %y with %x, because the value at address %p is already available as the value "i32 %x". Another simple form of redundant elimination comes about from stores, as in:<br /><br /><pre> store i32 4, i32* %P<br /> %a = load i32* %P</pre><br />In this example, we can replace %a with 4. This sort of transformation generalizes to support other operations: the GVN pass can forward memsets to loads, memcpy from constant globals to loads, etc. Note that GVN is not allowed to optimize away volatile loads.<br /><br />The implementation of this is pretty straight-forward: GVN (through the memdep class) scans backwards from the load that we are trying to eliminate up through the block until it gets an instruction that provides the value (as in these examples) or until it finds an instruction that might affect the memory in an unknown way like a call. If we find an instruction that potentially clobbers the memory location, we can't eliminate the load.<br /><br />However, straight-line code is pretty boring, lets look at more complex examples.<br /><br /><span style="font-size: x-large;">SSA Construction in GVN</span><br /><br />GVN can also eliminate non-local loads, which can require PHI node insertion. Here's a simple example:<br /><br /><pre>BB1:<br /> store i32 5, i32* %P<br /> br label %Merge<br /><br />BB2:<br /> %X = load i32* %P<br /> ... use %X ...<br /> br label %Merge<br /><br />Merge:<br /> %Y = load i32 *%P<br /> ...<br /> ... use %Y ...<br /></pre><br />In this case, GVN scans for available values of %P within the block (starting at the %Y load), and runs into the top of the %Merge block. Since it got to the top of the block, it starts scanning the predecessor blocks (%BB1 and %BB2) and it finds out that the value of the load is 5 in BB1 and %X in BB2. GVN then renames these values with the SSAUpdater class, producing:<br /><br /><pre>BB1:<br /> store i32 5, i32* %P<br /> br label %Merge<br /><br />BB2:<br /> %X = load i32* %P<br /> ... use %X ...<br /> br label %Merge<br /><br />Merge:<br /> %Y = phi i32 [5, %BB1], [%X, %BB2]<br /> ...<br /> ... use %Y ...<br /></pre><br />Replacing a load with a PHI node may not seem like a win, however the cost model we use in the LLVM optimizer assumes that PHI nodes will be coalesced away by the code generator, and are thus free. The logic that does PHI insertion is contained and maintained by the SSAUpdater class, which may be the subject of a future Blog post.<br /><br /><span style="font-size: x-large;">Pros and Cons of Redundant Load Elimination</span><br /><br />We always consider it profitable to eliminate a load in the optimizer when possible. Loads can be quite expensive (e.g. if they miss in the cache), and load/store traffic can hide other redundant or further simplifyable logic from the scalar optimizer. One idiom used to test alias analyses usually looks like this:<br /><br /><pre> %A = <b>load i32* %P</b><br /> store i32 1, i32* %Q<br /> %B = <b>load i32* %P</b><br /><br /> %C = sub i32 %A, %B<br /> ret i32 %C<br /></pre><br />If GVN + instcombine are able to turn this into "<span style="font-family: 'Courier New', Courier, monospace;">ret i32 0</span>" then we know that alias analysis was able to prove that P and Q did not alias. While somewhat unlikely in the real world, this is one example that shows a scalar optimization (X-X == 0) that can not be done unless the redundant loads are eliminated.<br /><br />The cost of eliminating redundant loads is that it creates longer live ranges that the code generator may not be able to cope with. This is a real issue that we don't currently have a good solution for. The ultimate answer is that improved rematerialization will be able to rematerialize the load further down in the code to reduce register pressure, we don't have great support for this yet though.
- 'lit' ithttps://blog.llvm.org/2009/12/lit-it.htmlThu, 17 Dec 2009 20:11:00 +0000https://blog.llvm.org/2009/12/lit-it.html<div>If you've been watching LLVM and Clang, you'll notice that there is a new testing tool we are using called <b>lit</b>. Clang has already moved to it, and LLVM has support for it (DejaGNU is still the default, but is being phased out). I thought I'd write a little bit about why I wrote <b>lit</b>, what it is, and how it will make your life better. :)<br /></div><div><br /><a name='more'></a><br /><br /></div><div>First, let me summarize the pre-<b>lit</b> background:<br /></div><div><ul><li>LLVM used <a href="http://www.gnu.org/software/dejagnu/">DejaGNU</a> and <a href="http://code.google.com/p/googletest/">googletest</a> unit tests. Our usage of DejaGNU was pretty limited though, what we really used was a test format which embedded shell scripts inside each test file. Our DejaGNU harness would interpret those commands, substitute a few variables, run them, and check the exit status. The googletest unit tests were run separately, and frequently forgotten.</li><li>Clang used a similar looking -- but completely different -- infrastructure which still had embedded shell scripts, but ran them via <b>make</b> and <b>sed</b>. It had the notable advantage of running tests in parallel and being significantly simpler, but not particularly flexible.</li></ul><div>One thing both systems had in common was that it was very easy to add a new test, usually a couple lines in a file in the appropriate directory. But there were some annoying cons:<br /></div><div><ul><li>There was no way to run tests via CMake or on Windows.</li><li>LLVM tests weren't run in parallel.</li><li>The UI to the tests was inconsistent and cumbersome (especially for DejaGNU, which would required invoking the LLVM Makefile via a shell script, which then invoked DejaGNU's runtest command).</li></ul><div>I didn't actually set out to write a new testing tool -- <b>lit </b>started because I had a need to run a very large number of "tests", which was just a fixed script to run with many different inputs. I hacked up a quick multithreaded Python test runner for it, and over time it grew a progress bar and more features. Later, when there was growing interest in having Clang work on Windows I wrote a Python based interpreter for the scripts (remember, they amounted to just shell scripts, so <b>lit</b> has what amounts to a little (ba)<b>sh</b> lexer and parser hiding in it). It didn't take a lot of imagination to put the two together and feature creep it until it could replace DejaGNU (yeah, it has a tiny Tcl parser too).<br /></div><div><br /></div><div>So, what <i>is </i><b>lit</b>? Strictly speaking, <b>lit</b> is a test running infrastructure, like DejaGNU. Its primary job is to find tests, execute them, and report the results to the user; it just happens to have built in support for the LLVM and Clang test formats. My number one design goal was that <b>lit</b> should "just work" whenever possible -- running a test should be as easy as<br /></div><pre><b>$ lit exprs.s</b><br />lit: lit.cfg:94: note: using out-of-tree build at '/Volumes/Data/ddunbar/llvm.obj.64'<br />-- Testing: 1 tests, 2 threads --<br />PASS: LLVM::MC/AsmParser/exprs.s (1 of 1)<br />Testing Time: 0.06s<br />Expected Passes : 1<br /></pre><div>no matter if you are using an in-tree or out-of-tree build, testing Clang or LLVM, a regression test or googletest based unit test, on Windows or Unix, and so on. And of course I also wanted it to be fast!<br /></div><div><br /></div><div>I'm not going to go into more detail on how to use <b>lit</b> (since it should be self explanatory or documented) but these are some of the features and benefits we've gotten from switching to <b>lit</b>:<br /></div><div><ul><li>LLVM tests run much faster, this improved our buildbot build/test cycle on a fast machine by about 25%, if I recall correctly. I still have a secret desire to make them even faster... one day...</li><li>Clang tests work on Windows and have been incorporated into our buildbot. There is still work to be done on LLVM tests.</li><li>LLVM/Clang tests work in CMake builds (with Makefiles, Xcode, and Visual Studio generators).</li><li><b>lit</b> integrates nicely into buildbot, so individual failures get split out into their own log. I hope to continue to improve the UI for diagnosing failures.</li><li>The LLVM googletest based unit tests are seamlessly integrated with the other tests. In fact, when using the standard LLVM Makefiles, its possibly to run all LLVM & Clang tests with just <tt>make check-all</tt>.</li><li>We're using some of the fancier <b>lit</b> features to help with C++ testing. For example, we have custom test suites which run <tt>clang -fsyntax-only</tt> over libstdc++ and the LLVM/Clang headers to test the parser, or which run <tt>clang -c</tt> over the LLVM and Clang C++ code to test Clang's C++ code generation. I secretly suspect Doug of having more <b>lit </b>test suites hiding on his hard drive.</li><li>And I have more improvements in store...</li></ul></div><div>You can read the <b>lit</b> man page <a href="http://llvm.org/cmds/lit.html">here</a>, and I hope to add more information to the LLVM <a href="http://llvm.org/docs/TestingGuide.html">Testing Guide</a> once all the pieces are fully in place. Try it out, I hope you like it!<br /></div><div><br /></div><div>- Daniel<br /></div><div><br /></div><div>p.s. <b>lit</b> stands for LLVM Integrated Tester, at least thats what I publicly claim. That, or it's the first three letter pronounceable name I came up with...<br /></div></div></div>
- Welcome to the LLVM Bloghttps://blog.llvm.org/2009/12/tag-specific-rss-feed.htmlMon, 14 Dec 2009 10:02:00 +0000https://blog.llvm.org/2009/12/tag-specific-rss-feed.htmlWelcome to the new and shiny LLVM Blog. We've noticed that while the greater LLVM community active and thriving, that it is very difficult for people who aren't hacking on it to follow interesting developments. A related problem is that the LLVM web page is really old and crufty, and various bits of it were true of some (long ago) time, but which aren't true anymore. This blog is an attempt to fix this problem, by providing a way for people to percolate interesting news out to the world, news that includes a date on it!<br /><br /><a name='more'></a><br /><br />My goal is that this blog will talk about the motivation and design of various subsystems in LLVM, including things that don't fit well in either code or permanent documentation, such as "why" we did things a certain way. Beyond the LLVM optimizer and code generator itself, I hope that this will eventually showcase ways that people are using LLVM, as well as details about what is going on in the various sub-projects of LLVM like <a href="http://clang.llvm.org/">Clang</a>, <a href="http://dragonegg.llvm.org/">DragonEgg</a>, etc.<br /><br />A final aspect of this Blog is that we intend to tag posts well and have tag-specific RSS feeds show up on the various subproject web pages. For example, here are some RSS feeds we have so far: [<a href="feed://blog.llvm.org/feeds/posts/default/-/meta">meta</a>] [<a href="feed://blog.llvm.org/feeds/posts/default/-/optimization">optimization</a>] [<a href="feed://blog.llvm.org/feeds/posts/default/-/testing">testing</a>] [<a href="feed://blog.llvm.org/feeds/posts/default/-/Clang">Clang</a>]. I'd like to have a tag for each subproject as well as (e.g.) a llvm-2.7 tag for features new in the 2.7 release.<br /><br />One decision so far is that we aren't going to allows comments on posts. We don't have the time or inclination to moderate comment spam, and we already have a great forum for discussions: various mailing lists. If you have comments on a post, ideas for future posts, or (better yet!) would like to contribute to this blog, please bring up your ideas on the relevant mailing lists.<br /><br />-Chris