Questions tagged [llvm-ir]

The LLVM Intermediate Representation

llvm-ir
Filter by
Sorted by
Tagged with
1 vote
1 answer
126 views

Why does LLVM 10.0's GEP fail to compute address of a non-primitive field?

See this tiny piece of code: %ManuallyDrop = type { i32 } define void @ManuallyDrop.drop(%ManuallyDrop* %0) { entry: %1 = getelementptr inbounds %ManuallyDrop, %ManuallyDrop* %0, i32 0, i32 0 ...
Doubtful's user avatar
1 vote
1 answer
452 views

Find pointer to the Instruction that assigns to value in LLVM

Suppose I have a pointer to some Value* val in LLVM. I want to get a pointer to Instruction that assigned value to the variable that val points to. How can I do it? This is an example of code %add = ...
alienobserver's user avatar
0 votes
1 answer
106 views

LLVM IR: struct alignment is wrong

I'm new to llvm framework and using llvm to generate jit code. But the code generated about struct is a bit problematic: ` source_filename = "test1" target datalayout = "e-m:o-i64:64-...
jitao09423024's user avatar
0 votes
1 answer
311 views

MLIR for multiplying 2 matrices

I am trying to multiply 2 matrices using MLIR. However, IR does not compile and gives this error: ./matmult.mlir:24:16: error: custom op 'linalg.fill' [parseNamedStructuredOpRegion] ods-gen generated ...
Roy's user avatar
  • 117
0 votes
1 answer
192 views

ML-IR to LLVM IR generates wrong IR

I am following this toy example to lower mlir to llvm ir and compile the result. Following the instructions, I can compile the project. However, the generated llvm ir (print.ll file) is different from ...
Roy's user avatar
  • 117
0 votes
0 answers
130 views

Can Cranelift or LLVM IRs be used to develop a simple OS from scratch?

I am curious if I can develop my own programming language to output Cranelift or LLVM IRs, then use it to make a simple OS from scratch? Specifically, do the instruction sets of Cranelift/LLVM IRs ...
geeko's user avatar
  • 2,790
3 votes
1 answer
181 views

Any options that enable loop inversion in LLVM?

Are there any options that enable loop inversion? More specifically,can LLVM transform the while form loop into do-while form loop as the following. Before the transformation, the code is: void foo(...
shu's user avatar
  • 31
0 votes
1 answer
100 views

Can all LLVM frontends produce the same bytecode

LLVM is the backend for many languages such as C#, Ruby, Zig and so on. My question is: can all LLVM frontend languages “in principle” produce the same LLVM bytecode? Are there any minimum ...
apocalypsis's user avatar
0 votes
0 answers
28 views

questions about llvm plugin:expression expand,

expression expand does llvm have some interface to solve the expression expand problem? for example: b = a + 1 c = b + 1 d = b * c after expression expand, we can know that: c = a + 1 + 1 d = (a + 1 + ...
pressFforLove's user avatar
1 vote
0 answers
96 views

Is it possible to disable Vector Type in Clang?

I want to compile a program using Clang (version 10.0.1) with the following command: clang -O3 test.c -o test Checked the result of the IR, I found that there are many variables with the type llvm::...
Qingyu Zhang's user avatar
0 votes
0 answers
179 views

Having trouble building a simple if/else if/else functionality with ANTLR/LLVM/C++

I've got a barely functional compiled language working with ANTLR4, LLVM and the C++ LLVM API. I was able to get a simple if statement to work properly, but I'm struggling to add the else if and else ...
Nick S.'s user avatar
  • 353
0 votes
1 answer
60 views

[3.0]Question about how to use the store IR instruction to obtain the blockaddress

I am writing to enquire about a question. When I read the IR language generated by a piece of C programs, I found that in C programs, the behavior of getting tag addresses is handled by a store ...
zevorn's user avatar
  • 1
1 vote
1 answer
145 views

Adding a new LLVM target to llvmlite

Is it possible to add a new target to llvmlite (python library)? For a new hardware (e.g. ASIC), I need to have a new and custom LLVM target. This is not very clear from the documentation. If it is ...
Roy's user avatar
  • 117
6 votes
1 answer
789 views

How to add custom llvm pass into rustc

I am trying to add my llvm pass into Rustc. Rustc has one compiling option -C passes=val where we could add extra LLVM passes to run. However, as my try, this option can only accept the pass when the ...
Jerry's user avatar
  • 61
0 votes
1 answer
103 views

Why is my LLVM IR program crashing when i print a variable only 1 time but not 2?

If I print the value of %".2" 1 time, the program crashes but when I print it 2 times it works, I don't understand why. I think the problem is the _aligned_free function, is there any other ...
Aus.'s user avatar
  • 3
0 votes
0 answers
57 views

Detecting array indexing in llvm IR

My task is to detect things like: array[i][j][k]; And insert the next function before them: instrument_array_indexing(array, i, j, k); My first thought was to write a clang-pass which would find all ...
DKay's user avatar
  • 111
0 votes
1 answer
62 views

Error in LLVM IR or runtime library produces SEGV

I'm writing a programming language called PPL. In PPL integer literals are arbitrary width by default. This is archived with using pointer to GMP's mpz_class for integers. However, when compiling -1, ...
gavrilikhin.d's user avatar
-1 votes
1 answer
211 views

static analysis of linux kernel on source code or LLVM IR? [closed]

in https://www.usenix.org/system/files/sec21-tan.pdf the authors do static analysis on LLVM IR of linux kernel (a pass for call graph construction, a pass for data flow analysis and alias analysis and ...
saha's user avatar
  • 47
0 votes
1 answer
204 views

LLVM opt removes all my code (but runs correctly when unoptimized)

I'm trying out building a compiler with LLVM (inkwell crate in rust) by implementing a Brainf*** compiler/jit, dumping a main and a program function into a module and compiling. Both the JIT engine ...
Fl0wless's user avatar
  • 338
0 votes
1 answer
128 views

Checking the top bits of an i64 Value in LLVM IR

I am going to keep this short and to the point, but if further clarifications are needed please let me know. I have an i64 Value that I want to check the top bits of if they are zeros or not. If they ...
Mohannad Ismail's user avatar
0 votes
0 answers
266 views

LLVM, Get first usage of a global variable

I'm new to LLVM and I'm stuck on something that might seem basic. I'm writing a LLVM pass to apply some transformations to global variables before they are use. I would like to detect somehow when is ...
d00rt's user avatar
  • 17
0 votes
2 answers
445 views

How to update and get the analysis result from a analysis pass after transform the function in the function transform pass

want to konw how can we update and get the analysis result in the transform pass, after the function have been modified. i don't want go back to the pipeline and go through around all the analysis ...
Bryan968's user avatar
0 votes
1 answer
246 views

How do I do jumps to a label in an enclosing function in LLVM IR?

I want to do an LLVM compiler for a very old language, PL/M. This has some peculiar features, not least of which is having nested functions with the ability to jump out of an enclosing function. In ...
David Given's user avatar
  • 13.5k
0 votes
1 answer
796 views

In LLVM, how to get all the struct types in a program?

In LLVM, we can use StructType() to get all structs in a Module, but when we use multiple source files, the Modules are different, so the same struct type may display multiple times in different ...
Yerson.Dong's user avatar
0 votes
1 answer
603 views

LLVM IR for addition and subtraction

I use "builder->CreateSub" and "builder->CreateAdd" to generate LLVM-IR for subtraction and addition. left = this->builder->CreateAlloca(llvm::Type::getInt32Ty(*...
Roy's user avatar
  • 117
0 votes
0 answers
103 views

Store command in LLVM-IR

The following LLVM-IR cannot be compiled by clang to an executable file ("clang test2.ll") and give this error in store commands (Even IR generated by clang using "-S -emit-llvm -O0 -g0&...
Roy's user avatar
  • 117
2 votes
0 answers
111 views

LLVM: If/Then branching in tiny-go LLVM

I'm using tinygo's LLVM bindings for Go (don't know if this is relevant) and I'm trying to implement If/Then branching without the else block. I've found this answer on stackoverflow: LLVM IRBuilder ...
kamkow1's user avatar
  • 475
2 votes
0 answers
52 views

LLVM (golang): Unescaped global strings?

I'm writing my own compiler using LLVM and I'm trying to implement string literals. By the way, I'm also using LLVM bindings for Golang from tinygo: https://github.com/tinygo-org/go-llvm this is how I ...
kamkow1's user avatar
  • 475
1 vote
1 answer
391 views

eraseFromParent() vs removeFromParent() in llvm

I Understand the difference between eraseFromParent() and removeFromParent() is that former unlinks and deletes instruction from the BasicBlock, while later just unlinks but not delete it. When ...
harry's user avatar
  • 1,045
3 votes
1 answer
2k views

How LLVM mem2reg pass works

mem2reg is an important optimization pass in llvm. I want to understand how this optimization works but didn't find good articles, books, tutorials and similar. I found these two links: https://blog....
Hadley Siqueira's user avatar
0 votes
0 answers
48 views

How to read two IR File within one LLVMContext?

For example, I have two IR files named a.ll and b.ll. Both IR file contain the same struct type named Foo. b.ll contains a function named hello. I want to add the declaration of function hello into a....
liblaf's user avatar
  • 13
1 vote
1 answer
223 views

How to linking a external function from a .h file (header file) for LLVM getOrInsertFunction in a LLVM pass

let consider a header file named foo.h #ifndef __FOO_H__ #define __FOO_H__ #include<stdio.h> void display(){ printf("Hello"); } #endif and a simple program named simple.c #include&...
Satanu Maity's user avatar
0 votes
0 answers
60 views

Example on how to do error handling for llvm

I am using llvm 14 and I had looked at the llvm docs for error handling but I am still not able to understand how to implement it by using the CPP API. Is there an example on how to do this?
Maubg's user avatar
  • 23
1 vote
1 answer
517 views

LLVM opt unable to print instructions from a specific function, But it does for the rest of the functions in the IR

I am new to llvm framework and was able to run a basic pass to iterate over instructions in a simple IR function with only entry basic block, but to expand upon that I got an .ll file from clang for a ...
Pawan Nirpal's user avatar
1 vote
1 answer
260 views

LLVM linker: weird error message when importing a function

I'm trying to implement a module system in my programming language. I've read the docs (https://llvm.org/doxygen/classllvm_1_1Linker.html) and the linkModules() function is exactly what I need. When ...
kamkow1's user avatar
  • 475
0 votes
1 answer
408 views

LLVM: simple way to cast types?

I'm looking for a simple way to cast types using the LLVM C++ api. What I'm trying to avoid is endless nested if-else checks what will pick the right IR cast instruction. Here's an example code that I'...
kamkow1's user avatar
  • 475
1 vote
0 answers
131 views

LLVM how to link dynamic symbols to executable

I am currently using the llvm::sys::DynamicLibrary::AddSymbol to create and store symbols into the current process. I need to compile the module to an object file. When I use ld, it gives me errors ...
Maubg's user avatar
  • 23
1 vote
1 answer
85 views

Out of curiosity, I found that in v8 implementation JS Bytecode is executed by Interpreter-Assembler then to CodeAssembly?

Out of curiosity, I found that in v8 implementation JS Bytecode is executed by Interpreter-Assembler and then to CodeAssembly. Why there is an interpreter assembler between bytecode and machine code? ...
Zhe Li's user avatar
  • 23
0 votes
1 answer
248 views

how to resolve "LLVM ERROR: Tried to execute an unknown external function"

I am writing a pass that puts instructions into LLVM IR that are defined in an archive and should then be called from the IR during execution. I need to use the lli interpreter for this. the command I ...
Peter's user avatar
  • 37
0 votes
2 answers
596 views

LLVM IR C++ API create anonymous global variable

How can I create an anonymous global variable in LLVM IR C++ API? I can create a named global variable as follows: GlobalVariable *createGlobalVariable( Module *module, Type *type, std::...
CWKSC's user avatar
  • 306
1 vote
1 answer
140 views

importing a specific symbol from module in LLVM

I would like to know if there's any way to import only specific symbol in LLVM. Take a look at this javascript example in node: import mySymbol from 'some/path.mylang' I've already seen this post on ...
kamkow1's user avatar
  • 475
1 vote
0 answers
51 views

Why does the reference to local variable return successfully? [duplicate]

call1 and call2 fails to compile as expected. But call3 compiles rather than throws an error like "cannot return reference to temporary value". Why? struct Demo(i32); impl Demo { fn new(...
Hsu Jason's user avatar
0 votes
1 answer
51 views

How to pass an array to a C function via LLVM?

I'm trying to create an array with two elements of size 64 bits. Once the array is created, it is stored in a local variable. The local variable is then loaded to send the values to a C function. The ...
Samuel Rowe's user avatar
0 votes
1 answer
118 views

Instruction does not dominate all uses despite being the first one in a function

I am generating the following LLVM IR Code: define linkonce fastcc i32 @main() { %1 = call i35 @calc() %2 = call i35 @calc.1() %3 = trunc i35 %2 to i32 ret i32 %3 } define private fastcc i35 @...
Luke's user avatar
  • 405
0 votes
1 answer
899 views

How to run LLVM's Pass with new Pass Builder on IR by calling the LLVM API in program?

By using opt, we can run a custom pass, or run a -O1 -O2 -O3 pass pipeline on a foo.ll file, but it all happens on the command line, and the IR is a file form.This is not conducive to some ...
StudyingCui's user avatar
2 votes
1 answer
364 views

How to convert a cpp file's source code to IR by using libtooling (clang C++ API)?

We know that the IR file can be obtained from foo.cpp through the clang driver: clang++ -emit-llvm -S foo.cpp -o foo.ll Now I want to do this by using the libTooling's API without clang driver. But I ...
StudyingCui's user avatar
0 votes
1 answer
1k views

Unable to compile C++ program with Clang-14

I am currently trying to compile a small program I have been working on with Clang and am getting the following error on compilation using scons as the build system: /usr/bin/clang++ -o src/PluGen/...
Joseph Quinn's user avatar
0 votes
1 answer
616 views

LLVM IR: Get AllocaInst from CreateLoad

I'm using the LLVM IR C++ API to generate IR for my compiler. My question boils down to: From a CreateLoad instruction, can I get the AllocaInst* it was loaded from so I can store the result of ...
gmdev's user avatar
  • 2,925
0 votes
1 answer
239 views

Why Clang copies the constant arrays in LLVM IR?

I have this piece of code to demonstrate: int main(int argc, char** argv) { char a[8] = {65, 66, 67, 68, 69, 70, 71, 72}; printf("a %s", a); } What i expect would be that this array ...
Musa Kalaycı's user avatar
1 vote
0 answers
98 views

Need help installing go/golang bindings for llvm

I'm trying to use the Go llvm bindings from https://github.com/go-llvm/llvm I've done everything the README tells me to do, but for some reason the installation fails. it seems like I don't have ...
kamkow1's user avatar
  • 475

1 2
3
4 5
26