Are you over 18 and want to see adult content?
More Annotations
![Download Gratis Download Aplikasi Dan software Gartis](https://www.archivebay.com/archive/f465eb17-f82c-4f36-87c8-f380282d856f.png)
Download Gratis Download Aplikasi Dan software Gartis
Are you over 18 and want to see adult content?
![vortiouscustomaccessories](https://www.archivebay.com/archive/af90531f-f334-47f0-af33-41697100d4c8.png)
vortiouscustomaccessories
Are you over 18 and want to see adult content?
![Είδη Κουζίνας - Είδη Μαγειρικής - Είδη Ζαχαροπλαστικής | GemoHouse.gr](https://www.archivebay.com/archive/a50f1268-a3e6-4518-bda3-54e0ac34ec1e.png)
Είδη Κουζίνας - Είδη Μαγειρικής - Είδη Ζαχαροπλαστικής | GemoHouse.gr
Are you over 18 and want to see adult content?
![ho.ua - VPS хостинг, бесплатный хостинг с php, платный хостинг](https://www.archivebay.com/archive/922b501e-a5ed-487e-ae52-9fa643eea6aa.png)
ho.ua - VPS хостинг, бесплатный хостинг с php, платный хостинг
Are you over 18 and want to see adult content?
![ATLUS Official website homepage | Atlus USA](https://www.archivebay.com/archive/a489b8a8-00af-428a-b70b-83dcabfe6721.png)
ATLUS Official website homepage | Atlus USA
Are you over 18 and want to see adult content?
![Steven Fallon - Scotland mountain guides, leaders and routes](https://www.archivebay.com/archive/2645d831-83f9-4fa0-a56b-b4f29b74c249.png)
Steven Fallon - Scotland mountain guides, leaders and routes
Are you over 18 and want to see adult content?
![Home - Parent Action on Drugs | Healthy youth, families and communities](https://www.archivebay.com/archive/5af26978-9981-4722-b673-2be3eef23667.png)
Home - Parent Action on Drugs | Healthy youth, families and communities
Are you over 18 and want to see adult content?
![Học tiếng Nhật Bản, Hàn Quốc, tiếng Anh, Trung tại Hà Nội](https://www.archivebay.com/archive/3e802562-f8f6-4bb4-b765-4fad0974e52a.png)
Học tiếng Nhật Bản, Hàn Quốc, tiếng Anh, Trung tại Hà Nội
Are you over 18 and want to see adult content?
Favourite Annotations
Text
Skip to content
Embedded in Academia John Regehr, Professor of Computer Science, University of Utah, USA A TOURIST’S GUIDE TO THE LLVM SOURCE CODEPosted byregehr
January 5, 2017January 7, 2017 10 Comments on A Tourist’s Guide to the LLVM Source Code In my Advanced Compilers course last fall we spent some time poking around in the LLVM source tree. A million lines of C++ is pretty daunting but I found this to be an interesting exercise and at least some of the students agreed, so I thought I’d try to write up something similar. We’ll be using LLVM 3.9, but the layout isn’t that different for previous (and probably subsequent) releases. I don’t want to spend too much time on LLVM background but here are a few things to keep in mind: * The LLVM core doesn’t contain frontends, only the “middle end” optimizers, a pile of backends, documentation, and a lot of auxiliary code. Frontends such as Clang live in separate projects. * The core LLVM representation lives in RAM and is manipulated using a large C++ API. This representation can be dumped to readable text and parsed back into memory, but this is only a convenience for debugging: during a normal compilation using LLVM, textual IR is never generated. Typically, a frontend builds IR by calling into the LLVM APIs, then it runs some optimization passes, and finally it invokes a backend to generate assembly or machine code. When LLVM code is stored on disk (which doesn’t even happen during a normal compilation of a C or C++ project using Clang) it is stored as “bitcode,” a compact binary representation. * The main LLVM API documentation is generated by doxygen and can be found here . This information is very difficult to make use of unless you already have an idea of what you’re doing and what you’re looking for. The tutorials (linked below) are the place to start learning the LLVM APIs. So now on to the code. Here’s the root directory, it contains:
* bindings
that
permit LLVM APIs to be used from programming languages other than C++. There exist more bindings than this, including C (which we’ll get to a bit later) and Haskell (out of tree).
* cmake :
LLVM uses CMake rather than autoconf now. Just be glad someone besidesyou works on this.
* docs in
ReStructuredText. See for example the Language Reference Manual that defines the meaning of each LLVM instruction (GitHub renders .rst files to HTML by default; you can look at the raw file here.)
The material in the tutorial subdirectory is particularly interesting, but don’t look at it there, rather go here . This is the best way to learn LLVM! * examples: This is the source code that goes along with the tutorials. As an LLVM hacker you should grab code, CMakeLists.txt, etc. from here whenever possible.* include
: The
first subdirectory, llvm-c,
contains the C bindings, which I haven’t used but look pretty reasonable. Importantly, the LLVM folks try to keep these bindings stable, whereas the C++ APIs are prone to change across releases, though the pace of change seems to have slowed down in the last few years. The second subdirectory, llvm, is
a biggie: it contains 878 header files that define all of the LLVM APIs. In general it’s easier to use the doxygen versions of these files rather than reading them directly, but I often end up grepping these files to find some piece of functionality.* lib
contains the real goodies, we’ll look at it separately below.* projects
doesn’t contain anything by default but it’s where you checkout LLVM components such as compiler-rt (runtime library for things like sanitizers), OpenMP support, and the LLVM C++ library that live inseparate repos.
* resources
:
something for Visual C++ that you and I don’t care about (but seehere ).
* runtimes
:
another placeholder for external projects, added only last summer, I don’t know what actually goes here.* test :
this is a biggie, it contains many thousands of unit tests for LLVM, they get run when you build the check target. Most of these are .ll files containing the textual version of LLVM IR. They test things like an optimization pass having the expected result. I’ll be covering LLVM’s tests in detail in an upcoming blog post.* tools :
LLVM itself is just a collection of libraries, there isn’t any particular main function. Most of the subdirectories of the tools directory contain an executable tool that links against the LLVM libraries. For example, llvm-dis is a disassembler from bitcode to the textual assembly format.* unittests
: More
unit tests, also run by the check build target. These are C++ files that use the Google Test framework to invoke APIs directly, as opposed to the contents of the “test” directory, which indirectly invoke LLVM functionality by running things like the assembler, disassembler, or optimizer.* utils :
emacs and vim modes for enforcing LLVM coding conventions; a Valgrind suppression file to eliminate false positives when running make check in such a way that all sub-processes are monitored by Valgrind; the lit and FileCheck tools that support unit testing; and, plenty of other random stuff. You probably don’t care about most of this. Ok, that was pretty easy! The only thing we skipped over is the“lib” directory
, which
contains basically everything important. Let’s look itssubdirectories now:
* Analysis
contains a lot of static analyses that you would read about in a compiler textbook, such as alias analysis and global value numbering. Some analyses are structured as LLVM passes that must be run by the pass manager; others are structured as libraries that can be called directly. An odd member of the analysis family is InstructionSimplify.cpp,
which is a transformation, not an analysis; I’m sure someone can leave a comment explaining what it is doing here (see this comment). I’ll do a
deep dive into this directory in a followup post.* AsmParser
:
parse textual IR into memory* Bitcode
:
serialize IR into the compact format and read it back into RAM* CodeGen
: the
LLVM target-independent code generator , basically a framework that LLVM backends fit into and also a bunch of library functions that backends can use. There’s a lot going on here (>100 KLOC) and unfortunately I don’t know very much about it.* DebugInfo
is
a library for maintaining mappings between LLVM instructions and source code locations. There’s a lot of good info in these slidesfrom a talk
at the 2014 LLVM Developers’ Meeting.* ExecutionEngine
:
Although LLVM is usually translated into assembly code or machine code, it can be directly executed using an interpreter. The non-jitting interpreter wasn’t quite working the last time I tried to use it, but anyhow it’s a lot slower than running jitted code. The latest JIT API, Orc , is inhere.
* Fuzzer
: this
is libFuzzer , a coverage-guided fuzzer similar to AFL . It doesn’t fuzz LLVM components, but rather uses LLVM functionality in order to perform fuzzing of programs that are compiled using LLVM.* IR :
sort of a grab-bag of IR-related code, with no other obvious unifying theme. There’s code for dumping IR to the textual format, for upgrading bitcode files created by earlier versions of LLVM, for folding constants as IR nodes are created, etc.* IRReader
,
LibDriver
,
LineEditor
:
almost nobody will care about these and they contain hardly any codeanyway.
* Linker
: An
LLVM module, like a compilation unit in C or C++, contains functions and variables. The LLVM linker combines multiple modules into a single, larger module.* LTO :
Link-time optimization, the subject of many blog posts and PhD theses, permits compiler optimizations to see through boundaries created by separate compilation. LLVM can do link-time optimization “for free” by using its linker to create a large module and then optimize this using the regular optimization passes. This used to be the preferred approach, but it doesn’t scale to huge projects. The current approach is ThinLTO,
which gets most of the benefit at a small fraction of the cost.* MC :
compilers usually emit assembly code and let an assembler deal with creating machine code. The MC subsystemin LLVM
cuts out the middleman and generates machine code directly. This speeds up compiles and is especially useful when LLVM is used as a JITcompiler.
* Object
:
Deals with details of object file formats such as ELF.* ObjectYAML
seems to support encoding object files as YAML . I do not know why this isdesirable.
* Option
:
Command line parsing* Passes
: part
of the pass manager, which schedules and sequences LLVM passes, taking their dependencies and invalidations into account.* ProfileData
:
Read and write profile data to support profile-guided optimizations* Support
:
Miscellaneous support code including APInts (arbitrary-precision integers that are used pervasively in LLVM) and much else.* TableGen
: A
wacky Swiss-army knife of a tool that inputs .td files (of which there are more than 200 in LLVM) containing structured data and uses a domain-specific backend to emit C++ code that gets compiled into LLVM. TableGen is used, for example, to take some of the tedium out of implementing assemblers and disassemblers.* Target
: the
processor-specific parts of the backends live here. There are lots of TableGen files. As far as I can tell, you create a new LLVM backend by cloning the one for the architecture that looks the most like yours and then beating on it for a couple of years.* Transforms
:
this is my favorite directory, it’s where the middle-end optimizations live. IPO contains interprocedural optimizations that work across function boundaries, they are typically not too aggressive since they have to look at a lot of code. InstCombine is LLVM’s beast of a peephole optimizer. Instrumentation supports sanitizers. ObjCARC supports this. Scalar
contains a pile of compiler-textbooky kinds of optimizers, I’ll try to write a more detailed post about the contents of this directory at some point. Utils are helper code. Vectorize is LLVM’s auto-vectorizer, the subject of much work in recent years. And that’s all for the high-level tour, hope it was useful and as always let me know what I’ve got wrong or left out.Posted byregehr
January 5, 2017January 7, 2017 Posted inCompilers, Computer
Science , Education
POST NAVIGATION
Previous Post Previous post: Undefined Behavior: Not Just for Programming Languages Next Post Next post:Testing LLVM
10 REPLIES ON “A TOURIST’S GUIDE TO THE LLVM SOURCE CODE”*
MATHIEU STUMPF GUNTZ says: January 6, 2017 at 2:29 am Hi, would you allow me to translate your article to French, preferably under a free lincense like CC-by-sa?*
TED MIELCZAREK says: January 6, 2017 at 2:54 am I don’t know for certain, but I highly suspect that ObjectYAML is used for the `tbd` files that Apple ships in newer OS X/iOS SDKs in place of dylibs. There seems to be precisely zero official documentation about this, but see: http://stackoverflow.com/a/32115656.
*
REGEHR says:
January 6, 2017 at 7:23 amTed, thanks!
Mathieu, certainly.
*
AL PETERSON says:
January 6, 2017 at 8:40 am Prof. Regehr, you rock! Thank you for this informative article!*
NICK LEWYCKY says:
January 6, 2017 at 9:02 am “An odd member of the analysis family is InstructionSimplify.cpp, which is a transformation, not an analysis; I’m sure someone can leave a comment explaining what it is doing here.” It doesn’t mutate the IR itself. The rule for llvm::SimplifyInstruction is that it may only return constants or existing Values in the program, which meets the requirements for an Analysis. The pass which calls SimplifyInstruction on every instruction is a transformation pass under lib/Transforms/Utils/SimplifyInstructions.cpp.*
PETER GOODMAN says:
January 6, 2017 at 9:26 am This is a great website for browsing the LLVM source code, as well as things like the Linux kernel: https://code.woboq.org/llvm/llvm/*
STIJN says:
January 6, 2017 at 2:03 pm Where it says “resources: something for Visual C++ that you and I don’t care about.”, I would rather have liked it said “resources: the version resource definition used for Windowsbinaries”.
*
REGEHR says:
January 6, 2017 at 5:58 pmAha, thanks Nick!
*
QUENTIN CARBONNEAUX says: January 7, 2017 at 1:16 pm Hi John, thanks for that great overview! This is my first comment but I’ve been enjoying your work and blog for now many months. I hop in because you mention that you use LLVM in a compiler class, it made me think that I should introduce my own work. For more than a year I have been developing (in parallel with my PhD work) a very small compiler backend in C . My goal was always educational (i.e. learn about ssa and more generally, state of the art compiler techniques), and it has been a very rich experience. As it is now, the compiler might not be suitable to study many advanced compiler techniques. However, I found it very convenient for experimentation, and it showed me many times what it takes to go from a research paper to a practical artifact. I would love to see this backend used in a compiler class. For example, LLVM could still be used as a model of serious industrial implementation, but for student projects my plainer C backend could lower the barrier of entry significantly and let them focus on the actual compiler techniques. For a concrete example of how little code a complex optimization pass might require, you can take a look at how copy elimination is implemented . As it is, it works on programs with cycles of copiesand phi nodes.
I look forward to hearing your thinking on this! If you have any suggestions on what could make it more fit for education, I’d be happy to incorporate them. http://c9x.me/compile/ http://c9x.me/git/?p=qbe.git;a=blob;f=copy.c;hb=HEAD PS: You might worry about the generation of the IL, but this will not be a problem for long as two projects close to an early release are using my backend for machine code generation.*
REGEHR says:
January 7, 2017 at 5:28 pm Quentin, QBE looks very cool! It is certainly something that I might use in a class. Along those same lines, I used Xv6 in a small Advanced OS class a few years ago and it worked really well. There’s something nice about understanding most of a small system instead of a tiny part of a huge system. Comments are closed.Search for:
ARCHIVES
Archives Select Month May 2021 (1) August 2020 (1) July 2020 (2) June 2020 (3) April 2020 (1) March 2020 (1) January 2020 (2) November 2019 (1) August 2019 (2) July 2019 (2) April 2019 (2) February 2019 (1) December 2018 (1) November 2018 (2) September 2018 (3) June 2018 (1) May 2018 (1) April 2018 (2) March 2018 (1) February 2018 (4) January 2018 (2) November 2017 (1) October 2017 (1) July 2017 (1) June 2017 (2) May 2017 (2) April 2017 (3) March 2017 (3) February 2017 (4) January 2017 (5) October 2016 (3) September 2016 (3) August 2016 (5) June 2016 (1) May 2016 (2) April 2016 (2) March 2016 (5) February 2016 (2) December 2015 (3) November 2015 (3) September 2015 (5) July 2015 (2) June 2015 (1) May 2015 (2) April 2015 (2) March 2015 (1) February 2015 (3) January 2015 (3) December 2014 (1) November 2014 (3) October 2014 (2) August 2014 (4) July 2014 (2) June 2014 (1) May 2014 (7) April 2014 (7) March 2014 (4) February 2014 (7) January 2014 (6) December 2013 (2) November 2013 (7) October 2013 (4) September 2013 (8) August 2013 (5) July 2013 (3) June 2013 (3) May 2013 (5) April 2013 (5) March 2013 (4) February 2013 (7) January 2013 (6) December 2012 (7) November 2012 (4) October 2012 (7) September 2012 (10) August 2012 (6) July 2012 (9) June 2012 (9) May 2012 (7) April 2012 (5) March 2012 (3) February 2012 (5) January 2012 (8) December 2011 (11) November 2011 (7) October 2011 (9) September 2011 (6) August 2011 (10) July 2011 (4) June 2011 (9) May 2011 (8) April 2011 (12) March 2011 (12) February 2011 (16) January 2011 (14) December 2010 (7) November 2010 (12) October 2010 (6) September 2010 (8) August 2010 (9) July 2010 (11) June 2010 (13) May 2010 (4) April 2010 (4) March 2010 (9) February 2010 (3) Embedded in Academia , Proudly powered byWordPress.
Details
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0