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

LLVM IR alloca instruction

I want to design a IR (like LLVM IR) for my toy compiler and I don't know what is the purpose of the alloca instruction in further analysis. In which optimizations alloca informations are used?
temp01m7
  • 183
  • 1
  • 1
  • 5
17
votes
5 answers

Compiler output language - LLVM IR vs C

For writing a compiler, what are the advantages and disadvantages of using LLVM IR vs C for a target language? I know both are used, and I imagine that the final machine code would be similar if I were to use clang to compile the C. So what are…
Dan
  • 12,409
  • 3
  • 50
  • 87
16
votes
1 answer

Name mangling confusion in LLVM

I have been trying to build and execute LLVM modules. My code for generating the modules is quite long, so I won't post it here. Instead my question is about how Clang and LLVM work together to achieve name mangling. I will explain my specific issue…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
16
votes
1 answer

Is it possible to add arguments for user defined passes in llvm

Now we are implementing a analysis pass for llvm, following this tutorial. and need to pass an additional argument to the plugin such as below: opt -load /path/to/myplugin.so -mypass -mypass_option input.bc However I did not find any manual telling…
Hongxu Chen
  • 5,240
  • 2
  • 45
  • 85
15
votes
2 answers

Understanding how memory allocation works (LLVM)

I'm making progress on a toy compiler (first time), and trying to understand how to allocate/construct an LLVM struct type. The Kaleidoscope tutorial doesn't include or even mention this and I don't know what I'm looking for in the LLVM source/tests…
zcourts
  • 4,863
  • 6
  • 49
  • 74
15
votes
1 answer

Generate binary code (shared library) from embedded LLVM in C++

I am working on a high performance system written in C++. The process needs to be able to understand some complex logic (rules) at runtime written in a simple language developed for this application. We have two options: Interpret the logic - run a…
Sanjit
  • 321
  • 2
  • 8
14
votes
3 answers

Call vs Invoke in IR codes of LLVM

I have three questions: 1) What are the differences between Invoke and Call operations in IR codes of LLVM? 2) Why Call instruction is not considered as Terminator operation in BasicBlocks here? 3) Is it possible for both of the Invoke and Call…
Farzane
  • 173
  • 1
  • 8
14
votes
1 answer

Make an LLVM ModulePass available on clang command line

I have a ModulePass that's working with the opt tool, but I'm having trouble figuring out how to make it available to clang at the command line. My current workflow for using my pass is: clang -c -emit-llvm [c-source code files] llvm-link [llvm…
Erik
  • 301
  • 2
  • 10
13
votes
1 answer

Representing void pointer type in llvm ir

Currently I use i8* to represent void pointers in my generated IR, but this makes it quite difficult to differentiate void* from char*, for example. Are there any common approaches to solving this? I have searched around quite a bit with no…
Lane
  • 153
  • 1
  • 9
13
votes
3 answers

How to Insert a LLVM Instruction?

I've been searching for hours and I can't find anything that could help me. I'm working on a project that involves a FunctionPass. I've implemented a runOnFunction(Function &f) method and that's working fine. Basically it needs to: 1) Detect a store…
KritSandvich
  • 177
  • 1
  • 2
  • 8
12
votes
3 answers

How to write a custom intermodular pass in LLVM?

I've written a standard Analysis pass in LLVM, by extending the FunctionPass class. Everything seems to make sense. Now what I'd like to do is write a couple of intermodular passes, that is, passes that allows me to analyze more than one module at a…
stepthom
  • 1,432
  • 2
  • 16
  • 27
11
votes
1 answer

Why empty functions aren't removed as dead code in LLVM IR?

Starting with this simple C program: void nothing(void) {} int main() { int i; for (i = 0; i < 10; ++i) { nothing(); } return 0; } My passes output as follows: Note: IR statements are in Green. ; Function Attrs: nounwind readnone ssp…
Ahmed Ghoneim
  • 6,834
  • 9
  • 49
  • 79
11
votes
1 answer

How to convert javascript to LLVM IR?

Is there any LLVM backend for javascript? If not, other tools that convert dynamic language(similar to javascript) to LLVM IR will also be okay. Because I am writing a dynamic language compiler and such tools can help me find out how some features…
AllenLin
  • 170
  • 1
  • 10
11
votes
0 answers

Implement Dynamic Typing Lanugage Using LLVM IR

I'm trying to implement a toy language with dynamic typing, i.e., variables do not have types, only values do, and every variable needs to be declared before being used. For example, the code might look like var x; x = 3; x = 'a';. Furthermore, I…
11
votes
2 answers

How To Call @printf in LLVM through the module builder system

I am learning LLVM. I understand that thre are a number of useful C functions that are provided in LLVM already as intrinsic. So I'm trying to call the @printf function from my code. I found the respective parts in the LLVM reference manual that…
Rick
  • 680
  • 1
  • 7
  • 20
1
2
3
84 85