{"id":181743,"date":"2024-03-19T11:13:00","date_gmt":"2024-03-19T10:13:00","guid":{"rendered":"https:\/\/liora.io\/en\/?p=181743"},"modified":"2026-02-06T08:21:13","modified_gmt":"2026-02-06T07:21:13","slug":"llvm-everything-you-need-to-know-about-this-compiler","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/llvm-everything-you-need-to-know-about-this-compiler","title":{"rendered":"LLVM: Everything you need to know about this compiler"},"content":{"rendered":"<style>\n.elementor-heading-title{padding:0;margin:0;line-height:1}.elementor-widget-heading .elementor-heading-title[class*=elementor-size-]>a{color:inherit;font-size:inherit;line-height:inherit}.elementor-widget-heading .elementor-heading-title.elementor-size-small{font-size:15px}.elementor-widget-heading .elementor-heading-title.elementor-size-medium{font-size:19px}.elementor-widget-heading .elementor-heading-title.elementor-size-large{font-size:29px}.elementor-widget-heading .elementor-heading-title.elementor-size-xl{font-size:39px}.elementor-widget-heading .elementor-heading-title.elementor-size-xxl{font-size:59px}<\/style><p><strong>While it is common practice for developers to write programs in a &#8220;high-level&#8221; language such as Python or Java, these same programs need to be &#8220;compiled&#8221; in order to make direct use of the microprocessor&#8217;s capabilities. LLVM has been a major innovator in this field, promoting aspects such as modularity and real-time compilation.<\/strong><\/p>\t\t\n\t\t<p><strong>Developers<\/strong> know that writing a sequence of instructions in a language such as Python, Java or <a href=\"https:\/\/liora.io\/en\/c-what-is-this-computer-language-for\">C++<\/a> is just one step in the process leading to an executable program. The process that transforms the &#8220;source code&#8221; (what the developer writes) into code that can be used by the <strong>microprocessor is called compilation.<\/strong><\/p><p>Languages such as Python or Java are called high-level languages. They feature instructions that are easy for humans to understand, such as the famous IF, which is used to test a condition and is found in most languages<\/p><p>Developing a program in machine code is extremely arduous, so it&#8217;s compilation that converts instructions written in a high-level language into machine code.<\/p><p>Designed by computer scientist Chris Lattner around 2002, at the University of Illinois, as part of his doctoral thesis, <strong>LLVM<\/strong> was conceived with a view to renewing the approach to compilation and optimizing its use.<\/p>\t\t\n\t\t\t<h3>Optimizing the compilation process<\/h3>\t\t\n\t\t<p><strong>Optimizing compilers<\/strong> is nothing new. The GCC compiler &#8211; an integral part of the GNU (for Linux) operating system launched by Richard Stallman in 1984 &#8211; has over time incorporated numerous optimization options to <a href=\"https:\/\/liora.io\/en\/horizontal-scaling-definition-features-and-benefits\">improve the efficiency of the code it generates.<\/a><\/p><p><strong>LLVM<\/strong>, for its part, appeared in the early 2000s, at a time when multi-core<a href=\"https:\/\/liora.io\/en\/computational-resources-definition-operation-and-role\"> microprocessor<\/a> architectures were becoming commonplace, as were GPUs or computer graphics processors.<\/p><p>LLVM stands for Low Level <a href=\"https:\/\/liora.io\/en\/virtual-machine-definition-use-and-benefits\">Virtual Machine,<\/a> and this name partly sums up what it achieves: the creation of virtual machines (capable of emulating the behavior of given processors) at a low level (and therefore, close to the processor).<\/p>\t\t\n\t\t\t<style>\n.elementor-widget-image{text-align:center}.elementor-widget-image a{display:inline-block}.elementor-widget-image a img[src$=\".svg\"]{width:48px}.elementor-widget-image img{vertical-align:middle;display:inline-block}<\/style>\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/09\/llvm1.jpg\" title=\"\" alt=\"\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption><\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/cloud-dev\/devops-engineer\">Find out more about our DevOps training<\/a><\/div><\/div>\n\n\t\t\t<h3>LLVM&#8217;s innovative approach<\/h3>\t\t\n\t\t<p>LLVM has proposed a number of innovative approaches:<\/p><ul><li>modular architecture ;<\/li><li>JIT compilation ;<\/li><li>IR Intermediate Representation;<\/li><li>a whole ecosystem of reusable tools.<\/li><\/ul><p>Let&#8217;s take a look at these various points.<\/p>\t\t\n\t\t\t<h3>Modular architecture<\/h3>\t\t\n\t\t<p>Traditionally, most <strong>compilers consisted of a single program, making it difficult to optimize or extend their capabilities.<\/strong><\/p><p>One of the main objectives for <strong>LLVM<\/strong> was to create a modular compiler architecture, in other words, to get different components to work harmoniously together. This has brought many benefits.<\/p><p>Compiler development can be entrusted to different teams, each responsible for developing one or more specific modules. This reduces development time and increases overall efficiency. The code produced by a team is usually cleaner and easier to understand by those who would be in charge of maintaining it.<\/p><p>When a<strong> compiler<\/strong> comes in the form of a series of modules, it is possible to optimize any one of them separately. And since maintenance can be carried out on this isolated module. The result is greater flexibility.<\/p><p>If, over the months, it turns out that a major function is missing from the compiler, it can be added, either by modifying one of the existing modules or by creating a new one.<\/p><p>In this way, the modular structure encourages experimentation and the implementation of new capabilities.<br>Modular <a href=\"https:\/\/liora.io\/en\/distributed-architecture-definition-and-relationship-to-big-data\">architecture<\/a> facilitates the integration of external tools.<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/09\/llvm2.jpg\" title=\"\" alt=\"\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption><\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/cloud-dev\/devops-engineer\">Discover our DevOps training<\/a><\/div><\/div>\n\n\t\t\t<h3>JIT or &#8220;on-the-fly&#8221; compilation<\/h3>\t\t\n\t\t<p>In the traditional compilation process, the conversion is produced in its entirety before the program is executed, producing definitive, uneditable machine code.<\/p><p>With <strong>LLVM&#8217;s JIT (Just-In-Time) compilation,<\/strong> the source code written by the developer is converted into executable machine code at the very moment of execution.<\/p><p>JIT compilation takes place just before the execution of a sequence of machine code. This is known as &#8220;selective compilation&#8221;. Optimization takes place dynamically (in real time), according to the program&#8217;s behavior.<\/p><p>LLVM is not the only tool to use JIT compilation. The same is true of Microsoft&#8217;s .Net and many Java implementations.<\/p>\t\t\n\t\t\t<h3>IR or intermediate representation<\/h3>\t\t\n\t\t<p>As we saw above, LLVM stands for <strong>&#8220;low-level virtual machines&#8221;<\/strong>. And here we have another key to LLVM: it doesn&#8217;t generate code adapted to a particular microprocessor, but rather intermediate code, close to machine language but independent of a given computing unit.<\/p><p>This &#8220;intermediate representation&#8221; (IR) can be adapted to all kinds of processors, from computing units to graphics processors. Once again, this approach has a number of advantages:<\/p><ul><li>IR can be optimized independently of the final, processor-specific code.<\/li><li>IR code is easier to analyze and debug than machine language.<\/li><li>When a new processor is released, it&#8217;s easy to get the compiler to integrate the corresponding machine language type.<\/li><\/ul>\t\t\n\t\t\t<h3>A rich ecosystem<\/h3>\t\t\n\t\t<p>LLVM also benefits from a vast ecosystem of tools and extensions capable of extending its capabilities. This is due in part to the presence of high-quality user communities. For example, the Clang compiler (based on LLVM for languages such as C, C++ and Objective-C) is actively supported by employees from Google, Apple, Mozilla and ARM. Similarly, recent high-performance languages such as Rust and Swift, similarly based on LLVM, have large, participative communities.<\/p>\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/liora.io\/app\/uploads\/2023\/09\/llvm3.jpg\" title=\"\" alt=\"\" loading=\"lazy\">\t\t\t\t\t\t\t\t\t\t\t<figcaption><\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/cloud-dev\/devops-engineer\">DevOps training<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>While it is common practice for developers to write programs in a &#8220;high-level&#8221; language such as Python or Java, these same programs need to be &#8220;compiled&#8221; in order to make direct use of the microprocessor&#8217;s capabilities. LLVM has been a major innovator in this field, promoting aspects such as modularity and real-time compilation. Developers know [&hellip;]<\/p>\n","protected":false},"author":76,"featured_media":181744,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2434],"class_list":["post-181743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-dev"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/181743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/76"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=181743"}],"version-history":[{"count":1,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/181743\/revisions"}],"predecessor-version":[{"id":205953,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/181743\/revisions\/205953"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/181744"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=181743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=181743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}