llvm-ir

LLVM IR alloca instruction

风格不统一 提交于 2021-02-18 20:50:09
问题 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? 回答1: The ‘alloca‘ instruction allocates memory on the stack frame of the currently executing function, to be automatically released when this function returns to its caller. The object is always allocated in the address space for allocas indicated in the datalayout. The ‘alloca‘ instruction is commonly

LLVM Insert function call defined from another file

丶灬走出姿态 提交于 2021-02-18 17:16:46
问题 I want to insert a function all before a certain instruction but the function call is defined in another file. I tried IRBuilder<> Builder(pi); CallInst *callOne = Builder.CreateCall(func_ins, "foo"); where func_ins is func*(or Value* to be more general) and foo is the variable name prefix of calling function got assigned. Since this function is defined in another file I've no idea where the pointer func_ins should point to so I just set it to NULL but it didn't work. Can anyone give me some

LLVM Insert function call defined from another file

家住魔仙堡 提交于 2021-02-18 17:15:10
问题 I want to insert a function all before a certain instruction but the function call is defined in another file. I tried IRBuilder<> Builder(pi); CallInst *callOne = Builder.CreateCall(func_ins, "foo"); where func_ins is func*(or Value* to be more general) and foo is the variable name prefix of calling function got assigned. Since this function is defined in another file I've no idea where the pointer func_ins should point to so I just set it to NULL but it didn't work. Can anyone give me some

How to save IR to a file and build it to an executable file?

白昼怎懂夜的黑 提交于 2020-08-22 12:52:50
问题 Now I use clang build my .c file to .s file. And I have used the llvm API modify the IR. However, now I can't save my modified IR to a file. I want to use "LLVMWriteBitcodeToFile", but I can't find the struct of "LLVMOpaqueModule"; I want to use "WriteBitcodeToFile", it always show me "type mismatch". And I also want to know how to build an IR file to a executable file. Next are two methods I use to save a module: 1、First use WriteBitcodeToFile bool unbuffered = false; llvm::raw_ostream ro

printf doesn't work for floats in LLVM IR

我是研究僧i 提交于 2020-08-10 03:37:12
问题 I want to print the value of a floating point variable to the screen. I am declaring printf() function in the LLVM IR code, and it is linking in successfully. Whenever I print an integer or a character data type, or a string, printf() prints them normally to the screen as it prints them in the C code. However, if I pass a float to printf() , instead of printing the floating point number, it prints 0.000000 . I checked the source code multiple times and it seems that the syntax is correct. It

How to link all LLVM libraries in cmake?

妖精的绣舞 提交于 2020-08-09 17:24:50
问题 I want to link all LLVM libraries in my cmake C++ project. I use llvm-config --components to get all the components of LLVM, it gives me: $ llvm-config --components aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter

SOLVED: relocation R_X86_64_32 against symbol `G8' can not be used when making a PIE object; recompile with -fPIE

↘锁芯ラ 提交于 2020-08-09 09:14:06
问题 I'm trying to compile lambda-expressions from scheme to llvm-ir and am having trouble with position independet code. source: (lambda (x) (display x)) target: bunch of declares... define %SObj* @G7() { entry: %calltmp = call %SObj* @closure_create(i64 ptrtoint (%SObj* (%SObj*)* @G8 to i64), %SObj* null) ret %SObj* %calltmp } define %SObj* @G8(%SObj* %G6) { entry: %calltmp = call %SObj* @display(%SObj* %G6) ret %SObj* %calltmp } define i32 @main(i32 %0, i8** %1) { entry: %calltmp = call %SObj*

LLVM OPT not giving optimised file as output.

有些话、适合烂在心里 提交于 2020-07-21 03:29:41
问题 The man page for opt says: "It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file or the analysis results". My Goal: To use the inbuilt optimisation pass -dce available in opt . This pass does Dead Code Elimination My Source file foo.c : int foo(void) { int a = 24; int b = 25; /* Assignment to dead variable -- dead code */ int c; c = a * 4; return c; } Here is what I did: 1. clang-7.0 -S -emit-llvm foo.c -o foo.ll 2. opt

LLVM OPT not giving optimised file as output.

孤街浪徒 提交于 2020-07-21 03:28:28
问题 The man page for opt says: "It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file or the analysis results". My Goal: To use the inbuilt optimisation pass -dce available in opt . This pass does Dead Code Elimination My Source file foo.c : int foo(void) { int a = 24; int b = 25; /* Assignment to dead variable -- dead code */ int c; c = a * 4; return c; } Here is what I did: 1. clang-7.0 -S -emit-llvm foo.c -o foo.ll 2. opt