Questions tagged [llvm-ir]

The LLVM Intermediate Representation

The idea behind the LLVM IR is to be "light-weight and low-level while being expressive, typed, and extensible at the same time." This is achieved by being as low-level as possible while it still being possible to map higher level concepts to the IR. The LLVM IR also provides type information, which can be useful for some optimizations.

Source: Aalto University Wiki (LLVM IR Advanced Course on Compilers)

1263 questions
120
votes
3 answers

What exactly PHI instruction does and how to use it in LLVM

LLVM has phi instruction with quite weird explanation: The 'phi' instruction is used to implement the φ node in the SSA graph representing the function. Typically it is used to implement branching. If I understood correctly, it is needed to make…
user730816
58
votes
1 answer

Pragmatics of typed intermediate languages

One trend in the compilation is to use typed intermediate languages. Haskell's ghc with its core intermediate language, a variant of System F-omega, is an example of this architecture [ 1 ]. Another is LLVM, which has a typed intermediate language…
37
votes
1 answer

How is GCC IR different from LLVM IR?

Why do people prefer LLVM IR, and how exactly is it different from the GCC IR? Is target dependency a factor here? I'm a complete newbie to compilers, and wasn't able to find anything relevant even after many hours of searching for an answer. Any…
lost_wanderer
  • 471
  • 5
  • 8
26
votes
1 answer

How to emulate thread_local in llvm-ir?

The following code is currently does not work in lli: //main.cpp extern thread_local int tls; int main() { tls = 42; return 0; } //clang++ -S -emit-llvm main.cpp && lli main.ll llvm-ir: ; ModuleID = 'main.cpp' target datalayout =…
Gaetano
  • 1,090
  • 1
  • 9
  • 25
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…
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
24
votes
1 answer

Clang - Compiling a C header to LLVM IR/bitcode

Say I have the following trivial C header file: // foo1.h typedef int foo; typedef struct { foo a; char const* b; } bar; bar baz(foo*, bar*, ...); My goal is to take this file, and produce an LLVM module that looks something like…
Kyle Lacy
  • 2,278
  • 1
  • 21
  • 29
24
votes
1 answer

Adding Metadata to Instructions in LLVM IR

First up, I am a newbie to LLVM passes. I am trying to add metadata to instructions in LLVM after a transformation pass (with the C++ API). I intend to store this information for use by another tool in a tool chain. I have two questions regarding…
ash
  • 1,170
  • 1
  • 15
  • 24
23
votes
2 answers

LLVM: difference between "uses" and "user" in Instruction or Value classes

I am new in LLVM and have checked Value and Instruction classes. I see that both of these classes have the methods uses and user. What are the differences between them? Also, regarding this post, can I use these methods to determine if an…
Carlos
  • 411
  • 1
  • 3
  • 11
23
votes
4 answers

Getting the original variable name for an LLVM Value

The operands for an llvm::User (e.g. instruction) are llvm::Values. After the mem2reg pass, variables are in SSA form, and their names as corresponding to the original source code are lost. Value::getName() is only set for some things; for most…
Will
  • 73,905
  • 40
  • 169
  • 246
22
votes
2 answers

How to emit LLVM-IR from Cargo

How can I get cargo to emit LLVM-IR instead of a binary for my project? I know that you can use the --emit=llvm-ir flag in rustc, but I've read some Github issues that show it's impossible to pass arbitrary compiler flags to cargo. Is there any…
Ameo
  • 2,307
  • 5
  • 21
  • 33
22
votes
3 answers

Call LLVM Jit from c program

I have generated a bc file with the online compiler on llvm.org, and I would like to know if it is possible to load this bc file from a c or c++ program, execute the IR in the bc file with the llvm jit (programmatically in the c program), and get…
Damien
  • 221
  • 1
  • 2
  • 4
20
votes
1 answer

LLVM and compiler nomenclature

I am looking into the LLVM system and I have read through the Getting Started documentation. However, some of the nomenclature (and the wording in the clang example) is still a little confusing. The following terms and commands are all part of the…
Ephemera
  • 8,672
  • 8
  • 44
  • 84
18
votes
1 answer

Attempting to write an LLVM backend. No good tutorial available

I am trying to write an LLVM backend for my custom processor that I have designed recently. I tried to follow the official tutorial at http://llvm.org/docs/WritingAnLLVMBackend.html But it is so vague, so incomplete and blurry that I failed to…
Dr. Ehsan Ali
  • 4,735
  • 4
  • 23
  • 37
17
votes
4 answers

Is it possible to use LLVM-assembly directly?

I have read some webpages and articles about llvm and I am quite interested in this project. (Maybe to learn something about compiler writing without the need to struggle with the complicated points of x86). There are pages that describe how to…
fuz
  • 88,405
  • 25
  • 200
  • 352
1
2 3
84 85