What is LLVM and why is it needed?

Hello! I think many people immediately had another question - why do we need another article about LLVM at all, because there are more than a hundred of them on HabrΓ© ? My task was to write an "introduction to the topic" for the rest of us - professional developers who do not plan to create compilers and are not at all interested in the peculiarities of the LLVM IR device. As far as I know, this has not happened yet.



The main thing that interests almost everyone - and what I plan to talk about - is in the title of the article. Why do you need LLVM when you have GCC and Visual C ++? If you're not a C ++ programmer, should you worry? Is LLVM Clang anyway? Or not? And what do these four letters actually mean?



What's in a name?



Let's start with the last question. What's behind the letters LLVM? Once upon a time they were an acronym for "Low Level Virtual Machine", but nowadays they mean ... absolutely nothing.



LLVM was born as a research project by Chris Latner (then a master's student at the University of Illinois at Urbana-Champaign) and Vikram Adwe(then and to this day professors at the same university). The goal of the project was to create intermediate representation (IR) programs that allow for "aggressive optimization throughout the life of the application" - something like Java bytecode, only cooler. The main idea is to make a representation that is equally well suited for static compilation (when the compiler receives a program written in a high-level language, for example C ++, as input, translates it into LLVM IR, optimizes, and gets fast machine code as output), and dynamic (when the runtime system receives machine code as input along with LLVM IR stored in the object file during static compilation,optimizes it - taking into account the dynamic profile collected by this time - and gets even faster machine code at the output, for which you can continue to collect the profile, optimize, and so on ad infinitum).



? ? .



, " ":





, , LLVM β€” , "LLVM" . ! β€” llvm.org , LLVM , , .



? 2005 ...



Apple, Google --



Apple Objective-C ( ) LLVM. Apple ? , Apple , . , Apple PowerPC, (Symantec) , .



2005 Apple GCC, , GPL. GPLv3, GCC GCC 4.3. Apple , GCC, XCode, GCC 4.2. GPL , "": GCC, , , β€” ! LLVM "" ( UIUC, Apache 2.0), , .



Apple , " ", LLVM - GCC. "-" , ; "-" β€” , LLVM IR. GCC-- LLVM-- , β€” , , "". 2006 , "Clang".



"clang" β€” "C" "language". "C" C- , C C++ Objective-C. , "clang" "-", "-"! β€” !



- Clang - LLVM Clang/LLVM Clang. ( !) C++ .



LLVM Clang Google. Apple, Google LLVM β€” GCC , . Google β€” , , . Clang . Clang β€” Windows. GCC Windows, GCC , . , PDB, GCC β€” - .



Google , GCC; - Intel Microsoft. Google - Clang. Windows ( Google, - : Chromium Google Earth) LLVM Android. Android: " Android. , ( ) ."



, Google, LLVM . LLVM: ARM, IBM, Sony, Samsung, NXP, Facebook, Argonne National Lab… , " ". GCC, LLVM β€” , Intel Qualcomm. " " β€” LLVM , , , .



LLVM GCC



, : " , , Apple Google, … - ? LLVM? GCC ?"



β€” ! GCC , . , , , , , GPL , GCC β€” GCC, , ?



, GCC β€” GCC LLVM. "" ARM (Google, Samsung, Qualcomm ARM) LLVM β€” , ARM LLVM "" , GCC.



C++. , Google, ISO C++ β€” , , β€” - Clang. Clang / LLVM. , : C++ Clang'.



Clang β€” , Android LLVM β€” . , Clang warning', GCC, . , Clang' , Clang Static Analyzer, , , ++, .



LLVM , : "", - OpenMP ( ), lld (- ), libc++ ( C++). LLVM β€” GCC , . , LLVM β€” , .



Clang GCC, . β€” . , , C C++ " " β€” GCC Clang -.



, . , ?



    #include <stdio.h>

    static void die() {
      while(1)
        ;
    }

    int main() {
      printf("begin\n");
      die();
      printf("unreachable\n");
    }


"gcc -O2" "clang -O2" β€” . " " C ( ? β€” ). "", , β€” " "! ( C ). , Clang GCC . , ( ?) , .



"gcc" "clang" ( "g++" "clang++" C++) - . ? β€” ?



, , , ARM β€” , "" .



"" LLVM



LLVM C++. LLVM β€” , β€” . , LLVM "" . LLVM, LLVM , .



Clang Static Analyzer, , OpenMP, libc++ lld β€” , C++ . Rust LLVM β€” , Rust LLVM ! C++ Rust, LLVM ( , ) D, Fortran, Haskell, Julia, Kotlin, Lua, PHP, Python. -, LLVM IR, ! LLVM .



LLVM β€” , . ML β€” TensorFlow Google PyTorch Facebook β€” LLVM .



LLVM , . ML ( , ), - , LLVM.



LLVM β€” "core" LLVM ! LLVM Developers' Meeting " " IT. , , Huawei, β€” , LLVM .



, , LLVM . LLVM- ?



LLVM ( Intel, NXP Huawei), . ! β€” , : LLVM . ? β€” ? :)




All Articles