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
74
votes
4 answers

What can make C++ RTTI undesirable to use?

Looking at the LLVM documentation, they mention that they use "a custom form of RTTI", and this is the reason they have isa<>, cast<> and dyn_cast<> templated functions. Usually, reading that a library reimplements some basic functionality of a…
zneak
  • 134,922
  • 42
  • 253
  • 328
71
votes
6 answers

LLVM Profile Error: Failed to write file "default.profraw": Permission denied

I'm getting the error LLVM Profile Error: Failed to write file "default.profraw": Permission denied after running unit tests in Xcode. I don't know where Xcode is trying to write this file to. What folder should I grant permissions for?
Cloud9999Strife
  • 3,102
  • 3
  • 30
  • 43
67
votes
3 answers

Understanding the simplest LLVM IR

I transform the simplest C code #include int main() { return 0; } to its LLVM IR, using clang -emit-llvm -S hello.c The generated IR is: define i32 @main() #0 { %1 = alloca i32, align 4 store i32 0, i32* %1 ret i32…
zell
  • 9,830
  • 10
  • 62
  • 115
67
votes
8 answers

How to detect LLVM and its version through #define directives?

The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version. This is part of the code I'm using: /* GNU C Compiler Detection…
Carla Álvarez
  • 1,077
  • 3
  • 10
  • 9
66
votes
4 answers

Is there a llvm java front end that converts java source to llvm's intermediate form?

From what I've read, there is a llvm program that converts java bytecode to llvm's intermediate form called class2llvm. My question is, how do I access this. What front end do I have to install in order to access this. VMkit is their implementation…
FeelTheBurns
  • 1,065
  • 2
  • 8
  • 14
64
votes
2 answers

What does the clang -cc1 option do?

I'm a newbie in clang. I have read a paper about source to source transformation from cuda to opencl using clang compiler front end. Can anyone tell me why the option -cc1 is sometimes used?
sp497
  • 2,363
  • 7
  • 25
  • 43
63
votes
3 answers

How do I specify a clang-format file?

I just built clang 5.0.0 on a Redhat 6 machine and tried to run clang-format. I'm unable to get the -style option to read in a style file. Here's an example of a set of commands that I think should work: ./clang-format -style=llvm -dump-config >…
dromodel
  • 9,581
  • 12
  • 47
  • 65
62
votes
1 answer

design suggestion: llvm multiple runtime contexts

My application needs to run many separate contexts in the same (single-threaded) process. They all share a single LLVMContext. The process will run many contexts (in the thread sense); that is, each one runs a function in a continuation object…
lurscher
  • 25,930
  • 29
  • 122
  • 185
61
votes
3 answers

lldb: Breakpoint on exceptions (equivalent of gdb's catch throw)

I am trying to use lldb for c++ debugging and I want to halt if an exception is thrown, like gdb's catch throw, and I cannot find an equivalent in the lldb documentation.
plaisthos
  • 6,255
  • 6
  • 35
  • 63
58
votes
1 answer

How does C-- compare to LLVM?

After learning a bit of how LLVM work I'm really excited about how portable low-level code can be generated and how modular this 'thing' is built. But I discovered today the existence of C-- that seems to share some concepts with LLVM. So I'm…
Alois Cochard
  • 9,812
  • 2
  • 29
  • 30
57
votes
6 answers

Why is llvm considered unsuitable for implementing a JIT?

Many dynamic languages implement (or want to implement) a JIT Compiler in order to speed up their execution times. Inevitably, someone from the peanut gallery asks why they don't use LLVM. The answer is often, "LLVM is unsuitable for building a…
Sean McMillan
  • 10,058
  • 6
  • 55
  • 65
56
votes
4 answers

How to view Clang AST?

I am trying to get hold on Clang. So, I would like to view the AST generated by Clang after parsing the given program. Is it possible to dump AST in .dot or .viz format? Is there any tool out there?
username_4567
  • 4,737
  • 12
  • 56
  • 92
54
votes
1 answer

Binding FFI and DSL

In Haskell LLVM bindings, I am trying to define a function with a variable number of arguments (actually I mean a constant number that is not known at compile time). I found this question and I am trying to follow the answer. I do not want to fall…
aelguindy
  • 3,703
  • 24
  • 31
54
votes
1 answer

Is it possible to debug a gcc-compiled program using lldb, or debug a clang-compiled program using gdb?

(Preface: I'm pretty new to C/C++ and I don't really know how debugging in native code actually works.) Some sources say that gdb and lldb can debug any program compiled to machine code. Others say that to debug with gdb you must compile in gcc with…
Neil Traft
  • 18,367
  • 15
  • 63
  • 70
53
votes
2 answers

Is there some literal dictionary or array syntax in Objective-C?

It's always been possible to create NSArrays (and NSDictionaries/NSNumber) with vararg method calls, like: [NSArray arrayWithObjects: @"a", @"b", @"c", nil]; Can these be created with in-line literals in a new improvement to LLVM and Clang?
AlBlue
  • 23,254
  • 14
  • 71
  • 91