Questions tagged [llvm]

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. The llvm tag is mostly for writing C++ code (or another language via the C bindings) to interface with the LLVM library, not about any of the (growing amount of) tools that have LLVM under the hood. See the `llvm-codegen` tag for questions about machine code generated by LLVM.

Welcome to the LLVM Project.

The LLVM Core libraries provide a modern source- and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones!).

These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR").

The LLVM Core libraries are well documented, and it is particularly easy to invent your own language (or port an existing compiler) to use LLVM as an optimizer and code generator.

As much as everything else, LLVM has a broad and friendly community of people who are interested in building great low-level tools. If you are interested in getting involved, a good first place is to skim the LLVM Blog and to sign up for the LLVM Developer mailing list.

What not to ask: user-level questions about XCode are off-topic, please only use the tag for those. The tag is mostly for writing C++ code (or another language via the C bindings) to interface with the LLVM library, not about any of the (growing amount of) tools that have LLVM under the hood.

Books

6394 questions
26
votes
1 answer

Syscall/sysenter on LLVM

How do I write the LLVM bitcode required to emit an architecture-specific system call instruction? More specifically, clang supports inline assembly, and clearly supports emitting system calls (otherwise libc and vdso could not be compiled). How…
Zach Riggle
  • 2,975
  • 19
  • 26
26
votes
1 answer

LLVM's integer types

The LLVM language specifies integer types as iN, where N is the bit-width of the integer, and ranges from 1 to 2^23-1 (According to: http://llvm.org/docs/LangRef.html#integer-type) I have 2 questions: When compiling a C program down to LLVM IR…
Ali J
  • 332
  • 1
  • 5
  • 8
26
votes
5 answers

How can I implement a string data type in LLVM?

I have been looking at LLVM lately, and I find it to be quite an interesting architecture. However, looking through the tutorial and the reference material, I can't see any examples of how I might implement a string data type. There is a lot of…
a_m0d
  • 12,034
  • 15
  • 57
  • 79
25
votes
2 answers

How to efficiently implement closures in LLVM IR?

I started adding closures (lambdas) to my language that uses LLVM as the backend. I have implemented them for simple cases where they can be always inlined i.e. code for the closure definition itself doesn't need to be generated, as it is inlined…
25
votes
6 answers

How to update LLVM and Clang on Mac OS X

On my version of Mac OS X (10.7.1 (Lion) and Xcode 4.1), there is LLVM 3.0svn and Clang 2.1. The current versions are LLVM 3.0 and Clang 3.0. From the Xcode web site, it seems that the latest version (4.2.1) still uses LLVM 2.0, and this seems to be…
Pietro
  • 12,086
  • 26
  • 100
  • 193
25
votes
5 answers

Which functionality/feature in Scala only exists as a concession to the underlying platform and should be removed if targeting something else?

A while ago I read about Scala for LLVM and I kept wondering which things in the Scala language/specification/library) only exist to make the JVM happy or improve interop with Java. Considering that running Scala on the LLVM provides much more…
soc
  • 27,983
  • 20
  • 111
  • 215
25
votes
3 answers

How is LLVM isa<> implemented?

From http://llvm.org/docs/CodingStandards.html#ci_rtti_exceptions LLVM does make extensive use of a hand-rolled form of RTTI that use templates like isa<>, cast<>, and dyn_cast<>. This form of RTTI is opt-in and can be added to any class. …
user34537
25
votes
1 answer

Providing a C API to your C++ library and strict aliasing

A common pattern when providing a C API is to forward declare some opaque types in your public header which are passed to your API methods and then reinterpret_cast them into your defined C++ types once inside the translation unit (and therefore…
Sam Kellett
  • 1,277
  • 12
  • 33
25
votes
3 answers

LTO with LLVM and CMake

I am trying to apply Link Time Optimization with LLVM on a CMake Project, that creates a shared library. My question is pretty much the same as this one: Switching between GCC and Clang/LLVM using CMake. However, the answers do not seem to be…
SPMP
  • 1,181
  • 1
  • 9
  • 24
25
votes
3 answers

Can I bind an existing method to a LLVM Function* and use it from JIT-compiled code?

I'm toying around with the LLVM C++ API. I'd like to JIT compile code and run it. However, I need to call a C++ method from said JIT-compiled code. Normally, LLVM treats method calls as function calls with the object pointer passed as the first…
zneak
  • 134,922
  • 42
  • 253
  • 328
25
votes
2 answers

Linking libc++ to CMake project on Linux

I want to use libc++ together with clang on Arch Linux in CMake project. I installed libc++ and added following lines to CMakeLists.txt as said on LLVM site in Linux section of "Using libc++ in your programs": set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}…
Ostrea
  • 262
  • 1
  • 4
  • 9
25
votes
3 answers

Bootstrapping a language on LLVM

I'm bootstrapping a programming language compiler on top of LLVM. Currently I'm mostly done writing a compiler for a subset of C which is self-compiling. When I'm finished with that, I'll bootstrap my language away from C, maintaining…
Imagist
  • 18,086
  • 12
  • 58
  • 77
25
votes
2 answers

Where is llvm-config in Windows?

I am open to either a Visual Studio answer or a MinGW answer. I just finished building LLVM 3.2 using CMake and Visual Studio 2010. Everything went smoothly, but I have no llvm-config. Do I need it? Every example I see on the intertubes makes use of…
TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58
24
votes
2 answers

Getting the operands in an LLVM Instruction

I am writing an optimization for my compiler and I use LLVM IR as my Intermediate Language. I have parsed the input file and converted it to LLVM IR. During optimization, I need to retrieve the operands of the instructions. I am able to find…
Chethan Ravindranath
  • 2,001
  • 2
  • 16
  • 28
24
votes
4 answers

Is there a debugger for LLVM IR?

I would like to step through some LLVM IR code I have generated. The code is syntactically and type valid as far as the llc and lli are concerned, but the results are not what I expected. The chunks are large enough that I have been unsuccessful in…
orm
  • 2,835
  • 2
  • 22
  • 35