Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
LLVM
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Components== LLVM has become an umbrella project containing multiple components. ===Frontends=== LLVM was originally written to be a replacement for the extant [[Code generation (compiler)|code generator]] in the GCC stack,<ref>{{cite conference |last1=Lattner |first1=Chris |author1-link=Chris Lattner |last2=Adve |first2=Vikram |author2-link=Vikram Adve |title=Architecture For a Next-Generation GCC |url=http://llvm.org/pubs/2003-05-01-GCCSummit2003.html |conference=First Annual GCC Developers' Summit |date=May 2003 |access-date=September 6, 2009}}</ref> and many of the GCC frontends have been modified to work with it, resulting in the now-defunct LLVM-GCC suite. The modifications generally involve a [[GIMPLE]]-to-LLVM IR step so that LLVM optimizers and codegen can be used instead of GCC's GIMPLE system. Apple was a significant user of LLVM-GCC through [[Xcode]] 4.x (2013).<ref>{{cite web |title=LLVM Compiler Overview |url=https://developer.apple.com/library/archive/documentation/CompilerTools/Conceptual/LLVMCompilerOverview/index.html |website=developer.apple.com}}</ref><ref>{{cite web|url=https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc5_release_notes.html|title=Xcode 5 Release Notes|work=Apple Inc.}}</ref> This use of the GCC frontend was considered mostly a temporary measure, but with the advent of [[Clang]] and advantages of LLVM and Clang's modern and modular codebase (as well as compilation speed), is mostly obsolete. LLVM currently{{as of?|date=March 2023}} supports compiling of [[Ada (programming language)|Ada]], [[C (programming language)|C]], [[C++]], [[D (programming language)|D]], [[Delphi (software)|Delphi]], [[Fortran]], [[Haskell]], [[Julia (programming language)|Julia]], [[Objective-C]], [[Rust (programming language)|Rust]], and [[Swift (programming language)|Swift]] using various [[Semantic analysis (compilers)|frontends]]. Widespread interest in LLVM has led to several efforts to develop new frontends for many languages. The one that has received the most attention is Clang, a newer compiler supporting C, C++, and Objective-C. Primarily supported by Apple, Clang is aimed at replacing the C/Objective-C compiler in the GCC system with a system that is more easily integrated with [[integrated development environment]]s (IDEs) and has wider support for [[Thread (computing)|multithreading]]. Support for [[OpenMP]] directives has been included in [[Clang]] since release 3.8.<ref>{{cite web | url = http://llvm.org/releases/3.8.0/tools/clang/docs/ReleaseNotes.html#openmp-support-in-clan | title = Clang 3.8 Release Notes | access-date = August 24, 2016}}</ref> The [[Utrecht University|Utrecht]] [[Haskell]] compiler can generate code for LLVM. While the generator was in early stages of development, in many cases it was more efficient than the C code generator.<ref>{{cite web | url = http://www.cs.uu.nl/wiki/bin/view/Stc/CompilingHaskellToLLVM | title = Compiling Haskell To LLVM | access-date = February 22, 2009}}</ref> The [[Glasgow Haskell Compiler]] (GHC) backend uses LLVM and achieves a 30% speed-up of compiled code relative to native code compiling via GHC or C code generation followed by compiling, missing only one of the many optimizing techniques implemented by the GHC.<ref>{{cite web | url = http://blog.llvm.org/2010/05/glasgow-haskell-compiler-and-llvm.html | title = LLVM Project Blog: The Glasgow Haskell Compiler and LLVM | date = May 17, 2010 | access-date = August 13, 2010}}</ref> Many other components are in various stages of development, including, but not limited to, the [[Rust (programming language)|Rust]] compiler, a [[Java bytecode]] frontend, a [[Common Intermediate Language]] (CIL) frontend, the [[MacRuby]] implementation of Ruby 1.9, various frontends for [[Standard ML]], and a new [[graph coloring]] register allocator.{{citation needed|date=June 2012}} ===Intermediate representation=== [[File:Mesa layers of crap 2016.svg|thumb|LLVM IR is used e.g., by radeonsi and by llvmpipe. Both are part of [[Mesa 3D]].]] The core of LLVM is the [[intermediate representation]] (IR), a [[low-level programming language]] similar to assembly. IR is a strongly typed [[reduced instruction set computer]] (RISC) instruction set which abstracts away most details of the target. For example, the [[calling convention]] is abstracted through <code>call</code> and <code>ret</code> instructions with explicit arguments. Also, instead of a fixed set of registers, IR uses an infinite set of temporaries of the form %0, %1, etc. LLVM supports three equivalent forms of IR: a human-readable assembly format,<ref name=IRref>{{cite web |url=https://llvm.org/docs/LangRef.html |title=LLVM Language Reference Manual |author=<!-- Unstated staff writers --> |date=10 January 2023 |website=LLVM.org}}</ref> an in-memory format suitable for frontends, and a dense bitcode format for serializing. A simple [["Hello, world!" program]] in the human-readable IR format: <syntaxhighlight lang="llvm"> @.str = internal constant [14 x i8] c"Hello, world\0A\00" declare i32 @printf(ptr, ...) define i32 @main(i32 %argc, ptr %argv) nounwind { entry: %tmp1 = getelementptr [14 x i8], ptr @.str, i32 0, i32 0 %tmp2 = call i32 (ptr, ...) @printf( ptr %tmp1 ) nounwind ret i32 0 } </syntaxhighlight> The many different conventions used and features provided by different targets mean that LLVM cannot truly produce a target-independent IR and retarget it without breaking some established rules. Examples of target dependence beyond what is explicitly mentioned in the documentation can be found in a 2011 proposal for "wordcode", a fully target-independent variant of LLVM IR intended for online distribution.<ref>{{cite web |last1=Kang |first1=Jin-Gu |title=Wordcode: more target independent LLVM bitcode |url=https://llvm.org/devmtg/2011-09-16/EuroLLVM2011-MoreTargetIndependentLLVMBitcode.pdf |access-date=1 December 2019}}</ref> A more practical example is [[PNaCl]].<ref>{{cite web|url=http://nativeclient.googlecode.com/svn/data/site/pnacl.pdf |title=PNaCl: Portable Native Client Executables |access-date=25 April 2012 |url-status=dead |archive-url=https://web.archive.org/web/20120502135033/http://nativeclient.googlecode.com/svn/data/site/pnacl.pdf |archive-date=2 May 2012 |df=dmy-all}}</ref> The LLVM project also introduces another type of intermediate representation named [[MLIR (software)|MLIR]]<ref>{{Cite web |title=MLIR |url=https://mlir.llvm.org/ |access-date=2022-06-07 |website=mlir.llvm.org}}</ref> which helps build reusable and extensible compiler infrastructure by employing a plugin architecture named Dialect.<ref>{{Cite web |title=Dialects - MLIR |url=https://mlir.llvm.org/docs/Dialects/ |access-date=2022-06-07 |website=mlir.llvm.org}}</ref> It enables the use of higher-level information on the program structure in the process of optimization including [[Polytope model|polyhedral compilation]]. ===Backends=== At version 16, LLVM supports many [[instruction set]]s, including [[IA-32]], [[x86-64]], [[ARM architecture|ARM]], [[Qualcomm Hexagon]], [[Loongson#LoongArch|LoongArch]], [[Motorola 68000|M68K]], [[MIPS architecture|MIPS]], [[Nvidia|NVIDIA]] [[Parallel Thread Execution]] (PTX, also named ''NVPTX'' in LLVM documentation), [[PowerPC]], [[TeraScale (microarchitecture)|AMD TeraScale]],<ref>{{cite mailing list |url=http://lists.llvm.org/pipermail/llvm-dev/2012-March/048409.html |title=[LLVMdev] RFC: R600, a new backend for AMD GPUs |mailing-list=llvm-dev |first=Tom |last=Stellard |date=March 26, 2012}}</ref> most recent [[Advanced Micro Devices|AMD]] GPUs (also named ''AMDGPU'' in LLVM documentation),<ref>{{cite web |url=https://llvm.org/docs/AMDGPUUsage.html |title=User Guide for AMDGPU Backend β LLVM 15.0.0git documentation}}</ref> [[SPARC]], [[z/Architecture]] (also named ''SystemZ'' in LLVM documentation), and [[XCore]]. Some features are not available on some platforms. Most features are present for IA-32, x86-64, z/Architecture, ARM, and PowerPC.<ref>[http://llvm.org/docs/CodeGenerator.html#target-feature-matrix Target-specific Implementation Notes: Target Feature Matrix] // The LLVM Target-Independent Code Generator, LLVM site.</ref> [[RISC-V]] is supported as of version 7. In the past, LLVM also supported other backends, fully or partially, including C backend, [[Cell (microprocessor)|Cell SPU]], [[MicroBlaze|mblaze (MicroBlaze)]],<ref>{{cite web |title=Remove the mblaze backend from llvm |website=GitHub |date=July 25, 2013 |url=https://github.com/llvm/llvm-project/commit/729866670b05108c399221ca3908400d94ef9783 |access-date=January 26, 2020}}</ref> AMD R600, DEC/Compaq [[DEC Alpha|Alpha]] ([[Alpha AXP]])<ref>{{cite web |title=Remove the Alpha backend. |website=GitHub |date=October 27, 2011 |url=https://github.com/llvm/llvm-project/commit/4c9fca99c9a6734bb33c34aeaf40b71c4002757e |access-date=January 26, 2020}}</ref> and [[Nios II|Nios2]],<ref name=" llvm 2019">{{cite web |title=[Nios2] Remove Nios2 backend |website=GitHub |date=January 15, 2019 |url=https://github.com/llvm/llvm-project/commit/99fcbf67d04d488d819bffb8fda3bb9d5504b63b |access-date=January 26, 2020}}</ref> but that hardware is mostly obsolete, and LLVM developers decided the support and maintenance costs were no longer justified.{{citation needed|date=December 2021}} LLVM also supports [[WebAssembly]] as a target, enabling compiled programs to execute in WebAssembly-enabled environments such as [[Google Chrome]] / [[Chromium (web browser)|Chromium]], [[Firefox]], [[Microsoft Edge (series of web browsers)|Microsoft Edge]], [[Apple Safari]] or [[WAVM (virtual machine)|WAVM]]. LLVM-compliant WebAssembly compilers typically support mostly unmodified source code written in C, C++, D, Rust, Nim, Kotlin and several other languages. The LLVM machine code (MC) subproject is LLVM's framework for translating machine instructions between textual forms and machine code. Formerly, LLVM relied on the system assembler, or one provided by a toolchain, to translate assembly into machine code. LLVM MC's integrated assembler supports most LLVM targets, including IA-32, x86-64, ARM, and ARM64. For some targets, including the various MIPS instruction sets, integrated assembly support is usable but still in the beta stage.{{citation needed|date=December 2021}} ===Linker=== The lld subproject is an attempt to develop a built-in, platform-independent [[linker (computing)|linker]] for LLVM.<ref name="lld-home-page">{{cite web|title=lld - The LLVM Linker|url=http://lld.llvm.org/|publisher=The LLVM Project|access-date=May 10, 2017}}</ref> lld aims to remove dependence on a third-party linker. {{As of|2017|05}}, lld supports [[Executable and Linkable Format|ELF]], [[PE/COFF]], [[Mach-O]], and [[WebAssembly]]<ref>{{cite web|url=https://lld.llvm.org/WebAssembly.html|title=WebAssembly lld port}}</ref> in descending order of completeness. lld is faster than both flavors of [[GNU ld]].{{citation needed|date=December 2021}} Unlike the GNU linkers, lld has built-in support for [[link-time optimization]] (LTO). This allows for faster code generation as it bypasses the use of a linker plugin, but on the other hand prohibits interoperability with other flavors of LTO.<ref>{{cite web |title=42446 β lld can't handle gcc LTO files |url=https://bugs.llvm.org/show_bug.cgi?id=42446 |website=bugs.llvm.org}}</ref> ===C++ Standard Library=== The LLVM project includes an implementation of the [[C++ Standard Library]] named libc++, dual-licensed under the [[MIT License]] and the [[UIUC license]].<ref>{{cite web|url=http://libcxx.llvm.org|title="libc++" C++ Standard Library}}</ref> Since v9.0.0, it was relicensed to the [[Apache License 2.0]] with LLVM Exceptions.<ref name="License"/> ===Polly=== This implements a suite of cache-locality optimizations as well as auto-parallelism and [[Automatic vectorization|vectorization]] using a [[Polytope model|polyhedral model]].<ref>{{cite web|url=https://polly.llvm.org|title=Polly - Polyhedral optimizations for LLVM}}</ref> ===Debugger=== {{Main article|LLDB (debugger)}} ===C Standard Library=== llvm-libc is an incomplete, upcoming, ABI independent [[C standard library]] designed by and for the LLVM project.<ref>{{Cite web |title=llvm-libc: An ISO C-conformant Standard Library β libc 15.0.0git documentation |url=https://libc.llvm.org/ |access-date=2022-07-18 |website=libc.llvm.org}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)