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
10
votes
2 answers

How to save the variable name when use clang to generate llvm ir?

I generate ir by use 'clang -S -emit-llvm test.c'. int main(int argc, char **argv) { int* a=0; a=(int *)malloc(sizeof(int)); printf("hello world\n"); return 0; } and this is the ir: define i32 @main(i32, i8**) #0 { %3 = alloca…
huixing123
  • 101
  • 1
  • 3
10
votes
1 answer

LLVM run PassManager (non-legacy)

How do I run a non-legacy PassManager? I have tried doing the following but there is some exception thrown when trying to invalidate the analysis manager in the run function. Is there something else I should do for…
10
votes
1 answer

What's the proper way of calling a Win32/64 function from LLVM?

I'm attempting to call a method from LLVM IR back to C++ code. I'm working in 64-bit Visual C++, or as LLVM describes it: Machine CPU: skylake Machine info: x86_64-pc-windows-msvc For integer types and pointer types my code works fine…
atlaste
  • 30,418
  • 3
  • 57
  • 87
10
votes
2 answers

Generating Rust executable from LLVM bitcode

How can I generate an executable of an application written in Rust that was compiled into LLVM-IR bitcode? If I try to compile the .bc file with rustc it tells me stream did not contain valid UTF-8 and I can't seem to figure out if there is a…
Leonardo Marques
  • 3,721
  • 7
  • 36
  • 50
10
votes
1 answer

How to distinguish signed and unsigned integer in LLVM

The LLVM project does not distinguish between signed and unsigned integers as described here. There are situations where you need to know if a particular variable should be interpreted as signed or as unsigned though, for instance when it is size…
Rick
  • 680
  • 1
  • 7
  • 20
10
votes
1 answer

Make LLVM inline a function from a library

I am trying to make LLVM inline a function from a library. I have LLVM bitcode files (manually generated) that I linked together with llvm-link, and I also have a library (written in C) compiled into bitcode by clang and archived with llvm-ar. I…
capitrane
  • 487
  • 6
  • 20
10
votes
1 answer

LLVM IR opcode documentation

I have read LLVM IR language reference and bitcode file format, but I haven't found any documentation containing an opcode list or explaining the instruction encoding. Is there any place where it'd be possible to find this information, or searching…
user35443
  • 6,309
  • 12
  • 52
  • 75
9
votes
3 answers

the expression of label in llvm IR code

Sometimes I found the label identifier in llvm IR is started with comma ';', such as ;
bluesea
  • 429
  • 4
  • 9
9
votes
1 answer

Why does Julia not optimize this code when C++ (LLVM) can?

When using a C++ compiler with LLVM version 6.0.0, the following code bool isEven(int n) { bool ret = true; for (int i = 0; i < n; i ++) { ret = !ret; } return ret; } emits the LLVM IR define zeroext i1 @_Z6isEveni(i32)…
kdheepak
  • 1,274
  • 11
  • 22
9
votes
1 answer

LLVM Pass to insert an external function call to LLVM bitcode

I am writing an LLVM pass to instrument a C source program. I want to insert a function call before each branch instruction which calls an external function like this : void print(int x){ printf("x = %d\n", x); return; } I want to link…
Ali94
  • 205
  • 2
  • 12
9
votes
1 answer

LLVM IR : C++ API : Typecast from i1 to i32 and i32 to i1

I am writing a compiler for a self-made language which can handle only int values i.e. i32. Conditions and expressions are similar to C language. Thus, I am considering conditional statements as expressions i.e. they return an int value. They can…
Chaitanya Patel
  • 390
  • 1
  • 4
  • 15
9
votes
2 answers

lli: LLVM ERROR: Cannot select: X86ISD::WrapperRIP TargetGlobalTLSAddress:i64

Running the following code with clang++ -S -emit-llvm main.cpp && lli main.ll on Linux(Debian) #include int main () { return std::async([]{return 1;}).get(); } fails to run on lli due to the following error: LLVM ERROR: Cannot select:…
Gaetano
  • 1,090
  • 1
  • 9
  • 25
9
votes
1 answer

Which code in LLVM IR runs before "main()"?

Does anyone know the general rule for exactly which LLVM IR code will be executed before main? When using Clang++ 3.6, it seems that global class variables have their constructors called via a function in the ".text.startup" section of the object…
Christian Convey
  • 1,202
  • 11
  • 19
9
votes
1 answer

LLVM arbitrary precision integer

LLVM language reference states that The integer type is a very simple type that simply specifies an arbitrary bit width for the integer type desired. Any bit width from 1 bit to 223-1 (about 8 million) can be specified. Does that mean that I…
GdelP
  • 153
  • 9
9
votes
2 answers

LLVM tail call optimization

Here is my understanding of things: A function "f" is tail recursive when calling itself is its last action. Tail-recursion can be significantly optimized by forming a loop instead of calling the function again; the function's parameters are updated…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31
1 2
3
84 85