1,298 questions
Advice
0
votes
1
replies
43
views
Is there a char* type in the LLVM C++ API
I wanna make a function starting with a function prototype as usual in the LLVM C++ API and I want one of the accepted arguments of the function to be a char*. Can someone guide me on how I can do ...
0
votes
1
answer
93
views
How does `mlir::cast` transform objects to derived classes?
The LLVM Programmers Manual gives some brief idea of how llvm::cast works:
cast<>:
The cast<> operator is a “checked cast” operation. It converts a pointer or reference from a base class ...
3
votes
1
answer
137
views
Why does setjmp/longjmp cause 0xC0000028 in LLVM IR?
I write a compiler that generates LLVM IR code and then .obj file. Then I link it with some required .lib files. (msvcrt.lib, ucrt.lib, vcruntime.lib). I declared setjmp and longjmp there as follows:
...
0
votes
1
answer
43
views
Control flow semantics in llvm-IR: branches, labels, loops and control flow graph
Consider the example of llvm-IR code:
define void @f( i32* %pa, i32 %b) {
bb0:
call void @g()
%a0 = load i32, i32* %pa
%p0 = icmp slt i32 %a0, %b
br i1 %p1, label %bb1, label %bb2
bb1:
call ...
0
votes
0
answers
67
views
MLIR: map an operation to an external function call
I am not sure whether this is the correct category/group to ask this question.
I see that there is a way to map an op to external function:
https://mlir.llvm.org/docs/Dialects/Linalg/
Property 5: May ...
4
votes
2
answers
311
views
How do I find which Rust versions correspond to which specific LLVM version?
I'm writing a compiler in Rust using the llvm-ir crate but it only supports up to LLVM 19.
I need to compile Rust's LLVM IR output using my compiler. But running rustc --version --verbose outputs the ...
0
votes
0
answers
31
views
LLVM Pass: How to correctly use TargetIRAnalysis with getResult() in new PM (PassManager)?
I'm trying to develop a custom LLVM obfuscation pass using the new PassManager (NPM) infrastructure.
In my pass, I need to access TargetIRAnalysis (or TargetTransformInfo) by calling getResult(F).
...
0
votes
0
answers
115
views
How to handle MLIR assembly formats for two variadic inputs
I am currently trying to build an operation for matrix multiplication in my custom MLIR dialect. I've declared the operation in a .td file and I mean for it to handle two sets of variadic inputs but I ...
0
votes
0
answers
41
views
How to get LLVM function with correct function type?
I am new to LLVM, and I am using LLVM as the backend to my own compiler. Suppose I have the following struct type and a function:
// a POD struct type
struct type_fp32 {
float a;
float b;
...
0
votes
0
answers
46
views
`IN[BB] = ∅` for all BB instead of `IN[BB] = U , for all other BB != BB_EXIT` in Init of Anticipated Expression Dataflow analysis in SSA form
I am implementing an LLVM pass for anticipated expressions using dataflow analysis and code hoisting. The reference I am following is the Purple Dragon Book (Compilers: Principles, Techniques, and ...
0
votes
0
answers
71
views
Why the order of Assembly code changed after Machine Code Sinking?
I am new to compiler and llvm, and I am sorry if my question or approach is kinda odd...
Following is the example machine code:
bb.0.entry:
successors: %bb.1(0x50000000), %bb.5(0x30000000); %bb.1(62....
0
votes
1
answer
56
views
How to find address-taken variables and top-level variables in LLVM IR
By definition, top-level variables are those that cannot be referenced indirectly via a pointer, i.e., those whose address is never exposed via the address of operator or returned via a dynamic memory ...
0
votes
1
answer
29
views
Why this Fib() implementation on LLVM-IR can't output correctly from Fib(93)?
Here is my implementation of fib on LLVM-IR, everything work fine under i64 limit, but above that, it can't printf the correct result, even with attempt to truncate i128 into 2 halves of i64 :
define ...
2
votes
0
answers
118
views
Convert i32 to i8* using sprintf using Python llvmlite
I'm trying to convert an i32 (integer) to an i8 pointer (string) by creating a buffer and adding to it using sprintf like in C. However, this does not work because I get an error saying that sprintf ...
2
votes
0
answers
93
views
Advice on migrating from LLVM legacy FunctionPassManager to new PassManager
I currently have a compiler where I use the legacy FunctionPassManager. My code for this is essentially identical to the Kaleidoscope implementation here: https://llvm.org/docs/tutorial/BuildingAJIT2....
1
vote
1
answer
55
views
Segmentation fault encountered at `ret void` in llvm-ir instructions
I'm currently making a compiler that outputs bare LLVM-IR instructions and implementing variadic function calls. I have defined a println function that accepts a (format) string and variable amount of ...
0
votes
0
answers
154
views
Why does LLVM IR generate `alloca` and `store` instructions for unused variables?
I'm learning LLVM IR and noticed some seemingly redundant instructions in the generated code. For example, in the following LLVM IR:
define i32 @main() #0 {
%1 = alloca i32, align 4
store i32 0, ...
0
votes
1
answer
132
views
Problem with custom LLVM-IR for my compiler
I'm currently working on programming language compiler that generated LLVM-IR. I'm not using any library for the emitting, so I'm just writing instructions to a file. The problem is mutable variables, ...
0
votes
0
answers
166
views
How to run pass with clang
I have written a compiler pass, which needs to change IR, and I want to use it in Clang.
It works well when I use:
opt -load=/home/yyb/Desktop/test/libinsertca.so -passes=Insertca -S test.ll -o test2....
1
vote
0
answers
160
views
What's wrong in my generated debug info in LLVM IR
Generated by compiler
I'm adding debug info to a go compiller (github.com/goplus/llgo) that used LLVM as backend, it passed in most cases, excludes a few simple cases likes below:
func ...
2
votes
0
answers
130
views
How to tell the LLVM interpreter (`lli`) where the missing symbols are as I do when linking?
I have exported Rust code to a LLVM-IR (.ll) file and was able to compile and link it manually using both, clang and llc + link.exe. It required to link against a lot of system libraries, Rust ...
0
votes
1
answer
204
views
How to redefine symbol in the object file created in clang llvm LTO? It seems be "LLVM IR bitcode" file
There's an old project which needs to redefine symbol in build progress. I want to enable -flto, but it seems unable to redefine symbol now.
echo "int foo(){return 0;}" > foo.c
clang -c ...
0
votes
1
answer
84
views
how do compilers refer unboxed types?
I am currently in the middle of building my first compiler in python. I have completed the lexer, parser and analyzer. I was planning on using the llvmlite library to emit ir. I am having trouble ...
1
vote
0
answers
78
views
How to get the Constant FP value from a load from a constant pool in LLVM CodeGen?
Hi I have the following IR, I would like to get either ConstantFP or ConstantFPSDNode on the operand of this foo ( SDNode ) here's what I see in gdb, I see that this float value is not lowered to a ...
1
vote
0
answers
145
views
How to add a simple RISCV intrinsic in LLVM
I have a simple scalar instruction which I added to LLVM, which takes two inputs from GPR and writes the output also to GPR. I can compile C code using inline assembly for the new instruction. I would ...
0
votes
1
answer
210
views
LLVM DAG Pattern Instruction Selection Fails after introducing a new intrinsic
I am currently expanding a RISC-V core with a custom load instruction. For this question, the specifics are unimportant. It functionally behaves like a normal load instruction and should use the same ...
0
votes
0
answers
36
views
How to Quantize the Return Type of a Function in an LLVM Pass?
I'm developing an LLVM pass to quantize a function by changing its return type from float to int32. Specifically, I have a function called mulfix with the following definition:
define dso_local float ...
0
votes
0
answers
60
views
Allocating complex data (btVector3) on the stack in LLVM IR
I want to use LLVM to JIT compile some code in my game using the LLVM C/C++ API. The JIT compiled functions should be able to effect the physics of the world, which is handled by bullet3.
To do so I ...
1
vote
0
answers
46
views
Depth Search between CFGs in BFS algorithm using python with LLVM IR
Context: I am trying to find out the depth between two CFGs using BFS but the code is not properly working as it's only showing the results up to depth 0 and 1 but it's not showing the other depths ...
6
votes
3
answers
484
views
How to register np.float128 as a valid numba type so I can sum an array?
I want to write a numba function that takes the sum of an array of np.float128s. These have 80 bits of precision on my set up but if it is easier to cast them to real float128s I would be happy with ...
0
votes
1
answer
53
views
Local variable not destroyed at function end
So I have this LLVM-IR code:
; ModuleID = 'example.-.input.c'
source_filename = "example.-.input.c"
define ptr @test() {
entry:
%0 = alloca ptr, align 8
%1 = alloca i32, align 4
store ...
0
votes
0
answers
53
views
How does LLVM IR map to RISCV Assembly Code
I'm new to LLVM Backend development and I'm discovering some of its working by modifying an existing backend, compiling the llvm-project and observing the changes brought to the binaries and their ...
0
votes
1
answer
190
views
How to convert LLVM IR to other Intermediate Representations?
I want to know how LLVM IR can be converted t other intermediate representations. I know that using
llc -march=wasm32 -filetype=asm arithmetic.ll -o example.wat one can convert LLVM IR to the WASM IR ...
0
votes
1
answer
771
views
C runtime LLVM error: error while loading shared libraries
I am trying to write my first ever compiler in C using LLVM for its backend, but I get an error when I try to run it. I have not found anything about this exact error message on other places.
Here is ...
1
vote
1
answer
412
views
How to get pointer level in LLVM 17 with opaque pointer enabled?
According to llvm opaque pointer documentation, only opaque pointer will be supported since LLVM 17, which means it is no longer possible to get the pointer level (e.g., i8* is 1 and i8*** is 3) by ...
0
votes
2
answers
274
views
LLVM API produces invalid IR for ptr type
I am using LLVM 15 and I am trying to compile a language of my own (pretty much like Pascal in terms of syntax) to LLVM IR and I am using Ocaml.
When I try to create a struct and set its body to have ...
1
vote
0
answers
78
views
InstCountPass not working on new LLVM Pass Manager
I am trying to run the llvm InstCount pass in the new pass manager on a random generated c code.
I generated a .bc file from the c file , using command :
/usr/bin/clang -I/home/intern24001/csmith/...
1
vote
0
answers
65
views
llvm alias analysis cause a segmentation fault
I am new to llvm. I am trying to figure out all store instructions which may change the memory a given pointer points to, using the Basic-aa pass that llvm provides. However, when I run my code, it ...
0
votes
1
answer
278
views
Dynamic Arrays in LLVM - Declaring a constant/global
I want to model dynamic arrays. This is the plan i've come up with: there will be a base struct for all my arrays, including a vtable-pointer, and also the runtime-size of the array:
%anyarray_base = ...
0
votes
1
answer
55
views
How can I use LLVM call a function with variable parameters in my std library
Now I am trying to develop a compiler.I want a "print" function.It can be used like this:
print(90, "hello world")
Before,I use a list(or vector) to hold the arguments.But now I ...
0
votes
0
answers
180
views
LLVM Liveness Analysis for SSA registers
I am trying to implement a pass that will answer queries like isAlive(var,n) where n is a basic block and var is any SSA variable. isAlive returns true if var is alive in the basic block n.
From what ...
2
votes
0
answers
120
views
How to make Spoq generate high-level specifications in Coq (not just AST) for the functions in LLVM IR
I am trying to use Spoq framework (and on GitHub) to translate code from C to Coq.
I faced problem - I am getting only low-level specifications for my functions (just AST), but I want to get high-...
0
votes
1
answer
153
views
Link LLVM Library Problems & Using clion & llvm & cmake to build IR Problems
I am currently studying LLVM. And I am following《LLVM Essentials》。In “Creating an LLVM Moudle” There is something as:
static llvm::LLVMContext context;
Module *module = new Module("Module",...
0
votes
1
answer
710
views
inkwell/llvm-sys not able to compile on windows
I am working with LLVM to build a small compiler in Rust using inkwell (inkwell uses llvm-sys, so it is relevant to it too).
First of all, compiled windows binaries on llvm's github do not include ...
0
votes
0
answers
404
views
LLVM hello world pass
I just start learning LLVM and follow the start-up website quick-start-writing-hello-world to write my first HelloPass.
However, it doesn't work as expected.
The llvm version is 16.0.6
Here are my ...
0
votes
1
answer
237
views
Segmentation fault, when running compiled LLVM IR
EDIT:
I got it working by using ld -o output main.o -L /lib/gcc/x86_64-linux-gnu /lib/x86_64-linux-gnu/crti.o /lib/x86_64-linux-gnu/crtn.o /lib/x86_64-linux-gnu/crt1.o -dynamic-linker /lib64/ld-linux-...
0
votes
0
answers
74
views
LLVM: Does PrologEpilog Insertion pass acts only on entry block
I'm trying to insert splitblock at start of a function in function pass??
Trying this results in losing stack optimization done through PrologEpilog pass on entry block.
This seem to be because of ...
0
votes
0
answers
28
views
Why does getelementptr + store lead to segementation fault in some cases
While experimenting with LLVM I've run into a segmentation fault that I don't fully understand. For simplicity, I'm trying to allocate a chunk of memory as a large integer, and then using ...
0
votes
1
answer
66
views
Dumping LLVMModule with Value Names using the C-API
I am currently writing my own compiler using Rust and LLVM and therefore, the LLVM-C-API.
For Debugging purposes, the LLVM-C-API provides a Function called LLVMDumpModule().
Sadly, this seems to ...
1
vote
1
answer
227
views
How to create a new Instruction to replace the previous one in llvm pass?
Given such an example named TestCase1.ll:
; RUN: opt -load-pass-plugin=%dylibdir/libLocalOpts.so \
; RUN: -p=algebraic-identity,strength-reduction,multi-inst-opt \
; RUN: -S %s -o %basename_t
;...