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
7
votes
1 answer

Creating raw_ostream object in LLVM

What is the correct way to create a raw_ostream object and use it for printing? I read various articles and the only example I can find is (How to redirect llvm::outs() to file?) raw_ostream *output = &outs(); which made use of llvm::outs. Sorry…
localacct
  • 611
  • 5
  • 13
7
votes
1 answer

How to tell LLVM that it can optimize away stores?

Background (there may be a better way to do this): I am developing a Julia library in which I manually manage memory; I mmap a large block, and then mostly treat it like a stack: functions receive the pointer as an argument, and if they allocate an…
Chris Elrod
  • 357
  • 2
  • 8
7
votes
0 answers

How do I generate a fully linked, executable LLVM bitcode file from Rust?

I would like to generate a fully linked LLVM bitcode file from Rust source code which could be executed by LLVM IR interpreters such as lli. I found solutions such as one from Reddit and another one from Stack Overflow, but they didn't provide…
zsf222
  • 345
  • 1
  • 10
7
votes
1 answer

Understanding the different linkage types of global values in LLVM IR with examples

The LLVM IR doc discusses the IR in detail, much of which is clear. However, I get particularly confused with the Linkage Types. The linkage types apart from private, internal, external become quite confusing without an example. Can someone throw…
codeman48
  • 1,330
  • 11
  • 17
7
votes
1 answer

Traversal of LLVM Operands

Using a ModulePass, my goal is to traverse a SSA graph upwards: going from one Statement with 0..2 operands (most opcodes fall under that), I want to find out two things: Is an operand a metadata / constant (easy: just try casting to Constant-Type)…
5-to-9
  • 649
  • 8
  • 16
7
votes
1 answer

How to get the arguments of a function call in LLVM?

I want to write an LLVM pass that'll extract the arguments of function calls. If the argument is a constant one, my objective is to recover what that constant is. The IR looks like %2 = call noalias i8* @malloc(i64 512) #3 The LLVM pass looks…
sherlock
  • 2,397
  • 3
  • 27
  • 44
7
votes
2 answers

Determine all global variables of a module

How to determine all global variables of a LLVM module? I want to modify them using a module pass.
Peter W.
  • 73
  • 3
7
votes
1 answer

How do I find the function pointers for tests from the LLVM IR code of a Rust program?

We are developing a mutation testing system based on LLVM. The system supports C++ projects that use GoogleTest and I am trying to support Rust. To do so, we need to accomplish the following steps: Compile the language into LLVM IR. Rust supports…
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
7
votes
1 answer

clang-3.8 and compiler-rt vs libgcc

I have been using clang-3.5 to happily build bitcode versions of musl libc and use the result to produce nice stand alone executables. Recent attempts with clang-3.8 have not been so happy. It seems that the bitcode clang-3.8 generates uses…
Ian A. Mason
  • 207
  • 3
  • 8
7
votes
1 answer

What is PIC level in program compilation?

I'm taking a look at LLVM libraries and I figured out that Clang emits the LLVM IR modules adding this metadata: !llvm.module.flags = !{!0} !llvm.ident = !{!1} !0 = !{i32 1, !"PIC Level", i32 2} !1 = !{!"Apple LLVM version 7.3.0…
NoImaginationGuy
  • 1,795
  • 14
  • 24
7
votes
3 answers

How to track down LLVM verifyFunction error "Expected no forward declarations!"?

I'm developing a compiler for a new language of mine in LLVM and have run into an issue while generating debug information. I have not yet found much documentation on how to actually generate the debug information using the DIBuilder so it is very…
Matthew Sanders
  • 4,875
  • 26
  • 45
7
votes
0 answers

Generate LLVM IR from Haskell code

My goal is take source codes in different languages (mostly C, C++, Obj-C and Haskell) and tell every kind of statistics about them. (eg. number of variables, functions, memory allocations, complexity etc.) LLVM seemed to be a perfect tool for…
Adam
  • 418
  • 3
  • 12
7
votes
0 answers

Modifying the debug information of llvm IR

I want to modify debug information of an llvm instruction so that the modified debug info is subsequently passed to executable binary. So if I use "addr2line" utility on the binary, it will return my modified debug information. I've tried to…
user
  • 5,335
  • 7
  • 47
  • 63
7
votes
1 answer

Can Clang accept LLVM IR or bitcode via pipe?

Clang can accept source files through a pipe if a language is specified with the -x flag. cat hello_world.c | clang -x c -o hello_world Clang can also compile LLVM IR and bitcode to object files clang hello_world.c -S -emit-llvm && clang -o…
7
votes
1 answer

Assigning literal value to local variable in LLVM IR

I've been messing around with code generation to LLVM IR, and there's something I don't quite understand, which is the distinction of when local variables have to be allocated, and how to load a literal value into a local variable. If I compile the…
Jumhyn
  • 6,687
  • 9
  • 48
  • 76