Questions tagged [llvm-ir]

0

votes
0

answer
3

Views

Why implicit free's declaration is taken vararg parameter in llvm

Taken the following code int main() { int* a = (int*) malloc(sizeof(int) * 10); free(a); return 0; } If compile it to llvm IR by clang -S -emit-llvm -O0 -g, free's declaration is: declare i32 @free(...) #2 However, if I add #include , free's declaration is: declare void @free(i8*) #2 By adding inclu...
cgcgbcbc
1

votes
2

answer
551

Views

llvm - get label of br instruction

My question is simple. Given an instruction of type branch, how do I extract the label out of it? For example: br label %while.cond Should give me while.cond br label %while.end Should give me while.end br i1 %cmp1, label %if.then, label %if.end Should give me if, if.then, if.end respectively.
Eren555
1

votes
1

answer
46

Views

Cast from uint8_t* to StringRef

I'm using ExecutionEngine.cpp. I want to get StringRef from found addresses by the following code: const APInt &IntVal; uint8_t *y2 = reinterpret_cast(const_cast(IntVal.getRawData())); int v2 = *reinterpret_cast(y2); StringRef* Src1V=cast(y2); I got this error: home/rasha/llvm/llvm/include/llvm/Sup...
R.Omar
1

votes
1

answer
117

Views

How to get Instruction in MachineInstr?

I wanted to know variable dependence in a real register (like X86:EAX, EBX ...). So, I have created an IR-PASS that can identify dependencies on the IR. This pass uses the newly added variables unsigned HasDependency: 1; and unsigned HasMaybeDependency: 1; in the Value class. . . // Use the same typ...
RollRat
1

votes
1

answer
113

Views

LLVM physical register mapping

I have some function in LLVM IR, which has some input arguments. However, I want to keep an argument passed in a register, and I want to compile it only for x86. For instance, I am writing a function containing adding instruction: %sum = add i64 %val1, %val2 and no matter which args are in the list,...
ultrablox
1

votes
2

answer
261

Views

LLVM - How to Construct llvm::Value from a std::string

std::string myIR = '%3 = alloca i32, align 4'; How would I convert a C++ std::string (such as the one above) to a llvm::Value? I can put an llvm::Instruction into a std:string like this SO answer shows, but I am unsure on how to go from a std::string to an llvm::Instruction or a llvm::Value.
Chris Smyth
1

votes
1

answer
188

Views

Get rid of LLVM's Unconditional Branch

Consider this IR: label0: ret i32 0 br label %1 How do I get rid of the unconditional branch instruction? I have type casted it to BranchInst class and used removeFromParent() or eraseFromParent() but I'm getting this error. BranchInst *BI = dyn_cast(i); if(BI->isUnconditional()) BI->removeFromP...
Sourav Das
1

votes
0

answer
62

Views

How does llvm allocate and get element in union?

I have the following C code and the IR for function caller(). Can anyone explain why it allocates [2 x %struct.C] for karg1? Or more generally, how LLVM optimize a union? And I'm confused with the GEP instructions of %karg1.sub. int cmd = 1; struct T { int tuner; char name[32]; unsigned long rangel...
Crystal
1

votes
0

answer
178

Views

How can I call exported functions (dynamically in LLVM IR)?

I want to call the exported functions (functions from the shared libs - .dll, .so, end so on). From what I’ve seen so far, it’s seemed, as I can’t, because IR have no stack (is it true, about the stack?). With the C++, I can write something like this (for x86): // args - an array of a tagged u...
zk-t
1

votes
1

answer
163

Views

Instruction ID or number in LLVM IR

In Execution.cpp, I can get all instructions and the values of all variables. Is there any method to get the ID or the number of each instruction.
R.Omar
1

votes
1

answer
102

Views

Figure out function signatures of precompiled functions during JIT in LLVM

I am currently working on implementing a JIT compiler using LLVM. The problem I have is that a portion of the compiler runtime is implemented in C. From my intermediate representation, I can generate all native functions. However, certain operations in the language require calls to these external...
JKRT
1

votes
0

answer
87

Views

LLVM fails to optimize simple function

I'm using LLVM C++ API to generate a very simple function. Here's the IR output: target datalayout = 'e-m:e-i64:64-f80:128-n8:16:32:64-S128' define i64 @'foo'(i64) { %2 = alloca i64 store i64 %0, i64* %2 %3 = load i64, i64* %2 ret i64 %3 } I expect LLVM to get rid of the superfluous stores/loads whe...
llvm newbie
1

votes
1

answer
74

Views

Pros and cons of graphical and linear intermediate representation in compiler design?

There are two kinds of intermediate representation (IR) in compiler design, briefly introduced here: graphical (e.g. abstract syntax tree) and linear (e.g. LLVM IR). What are the pros and cons of the two? I noticed Clang implemented both, but it seems only the linear representation (LLVM IR) is used...
Leedehai
1

votes
1

answer
98

Views

Issue Creating Vector LLVM

I am trying to create a vector and return it as a value using llvm. Here is what my code looks like: Value *ArrayAST::codeGen() { Type *dType = Type::getDoubleTy(mContext); Type *vectorType = VectorType::get(dType, 4); Value *emptyVector = UndefValue::get(vectorType); Constant *index0 = Constant::ge...
zoecarver
1

votes
0

answer
61

Views

LLVM - Type substitution creates duplicate types

What I am trying to achieve: Replace every occurrence of i64 with i32 in LLVM IR. Initially I tried this with a block pass. A block pass works for function bodies but not function declarations and global variables. I then switched to using a module pass, executing the following on every LLVM instruc...
Henricus V.
1

votes
0

answer
110

Views

LLVM IR less or equal compare with negation

I want to make compare less or equal operation with two integers: op1
ultrablox
1

votes
1

answer
46

Views

Error in adding TargetData in PassManager in llvm

I am beginner to llvm. I am implementing a program main.cpp of https://github.com/davidar/lljvm/blob/master/backend/main.cpp . When I am declaring a PassManager PM PM.add(new DataLayout td), it throws a error : error: missing template arguments before ‘PM’ PassManager PM; As keeping above erro...
Arya
1

votes
1

answer
229

Views

Understanding bitcast in LLVM IR

I am trying to understand the LLVM IR generated from a C++ program int add(int *x); int func() { int T; T=25; return add(&T); } The generated IR is: define i32 @_Z4funcv() local_unnamed_addr #0 { entry: %T = alloca i32, align 4 %0 = bitcast i32* %T to i8* call void @llvm.lifetime.start.p0i8(i64...
Ratnesh
1

votes
0

answer
55

Views

Why “-fno-inline” brings so bad performance in clang?

We use clang to compile IR code, then execute the IR in some place. For some reasons, we add '-fno-inline' in compile options, which brings very bad performance. Before the IR code takes less than 1ms, after open '-fno-inline', the IR code takes more than 20ms. From my understanding, inline only eli...
Tongxuan Liu
1

votes
1

answer
50

Views

Detecting Integer Comparison conditional in LLVM

#include #include int main (){ unsigned short int a = 10; if (a == 10){ //something } } In an LLVM pass, how would I detect 2 operand integer comparison conditional statements like the one shown above: (a == 10)? Please let me know what I should look for in the LLVM api.
Nemo_Sol
1

votes
0

answer
34

Views

llvm Costmodel Analysis Pass is showing different result via opt compared to my own project

I have a llvm IR file that includes instructions like fadd and fmul. These instructions when calculating the cost with the cost-model pass opt -analyze -targetlibinfo -cost-model myIRFile.ll I have also created my own pass and run this pass in my code. But when I do this I am getting different resu...
Mark
1

votes
0

answer
98

Views

LLVM IR: expose variables to GDB?

I am writing a custom programming language. I am generating LLVM IR as an intermediate (via LLVMlite), and I want to expose variables to GDB. This is an example of the generated IR: ; ModuleID = 'tests/debuginfo.xan' source_filename = 'debuginfo.xan' target triple = 'x86_64-unknown-linux-gnu' target...
NoOneIsHere
1

votes
0

answer
64

Views

Call parameter to function LLVM

I am working on a toy language. I want to create a function which takes a function as a parameter which it can call later. In LLVM IR it would look like this: define i8 @foo(i8 ()* %f) { entry: %0 = call i8 %f() ret i8 %0 } When I tried to re-create this using the c++ API, I ran into some issues. I...
zoecarver
1

votes
1

answer
29

Views

phi instruction semantics in llvm-IR

Trying to understand phi instruction semantics in llvm-IR (https://llvm.org/docs/LangRef.html#phi-instruction) Let's consider the following example: ; Function Attrs: norecurse nounwind define i32 @main( i32 %argc, i8** %argv) { entry: switch i32 %argc, label %L1 [ i32 0, label %L0 i32 1, label %L1...
Павел
1

votes
1

answer
46

Views

How to use UserOp1/UserOp2 instruction?

how to use LLVM UserOp1? I can't find any examples of this instruction.
Duan Bing
1

votes
1

answer
468

Views

meaning of inline assembly in the linux kernel

I would like to know the meaning of %P3 in the following code: #define get_user(x, ptr) \ ({ \ int __ret_gu; \ register __inttype(*(ptr)) __val_gu asm('%edx'); \ __chk_user_ptr(ptr); \ mig...
user2521982
1

votes
1

answer
162

Views

Is there any symbolic execution tools in llvm?

I want to do points-to anlysis in llvm IR. I want it to be path sensitive, which means that when I print out the result, I need append the condition for the 'May' Points-to. I plan to using symbolic execution to achieve this goal. Are there any tools in llvm, or stand-alone tools to solve the symbol...
blankboy2011
1

votes
2

answer
140

Views

LLVM return from calling external function is wrong

I'm trying LLVM and hitting some walls, like this one. When I compile and run the piece of code below, instead of getting the current year, I'm getting the day of the week: target datalayout = 'e' declare dllimport x86_stdcallcc void @GetLocalTime(%SYSTEMTIME*) %SYSTEMTIME = type { i16, ; wYear i16,...
user1577561
1

votes
1

answer
264

Views

replacing use of one def with other def in llvm IR

I have following IR: %2 = load i32* %b, align 4 store i32 %2, i32* %a, align 4 %3 = load i32* %a, align 4 store i32 %3, i32* %b, align 4 which is essentially a=b; b=a; Now, after copy propagation, i want something like: a=b; b=b; So, I do this: i->setOperand(0,op1) //op1 points to %b, i points to...
rahuL
1

votes
1

answer
606

Views

How to read local arrays in llvm

I have generated the following bitcode. fuelTank is an array that I pass to a function called getEngineValue(int x[]). %fuelTank = alloca [5 x i32], align 4 call void @llvm.dbg.declare(metadata !{[5 x i32]* %fuelTank}, metadata !39), !dbg !40 %0 = bitcast [5 x i32]* %fuelTank to i8*, !dbg !40 call...
1

votes
1

answer
534

Views

Error when converting Value* to PointerType in llvm pass

I try to instrument load/store instructions in LLVM IR and trace their memory address, therefore I need to insert instrumentation function to record the address of load/store instructions. I have a type conversion problem when I try to create recordLoad/Store function: First, I create pointer type,...
henry
1

votes
1

answer
306

Views

LLVM indvars pass

I am using -indvars pass in LLVM. It says that is makes the loop counter start from 0 where it is possible. I used it for a simple loop, but its not making the loop count start from 0. Any idea why is it so? The loop is for(i=30;i
coder hacker
1

votes
1

answer
1.1k

Views

Method to create LLVM IR

I am creating clang tool and I want to generate LLVM IR from clang AST. I am aware of -emit-llvm option that I can use to get *.ll file, but is there way to generate IR inside code? Some method that I can call that takes clang AST or AST context and returns llvm::Module? I cannot find any example th...
benderto
1

votes
1

answer
213

Views

clang: support for bitwidth attribute when generating LLVM IR

I wanted to use __attribute__((bitwidth(N))) to define custom-sized integer types when generating LLVM IR code with clang. I found some information that there is no plan to support this attribute. However, supporting such an attribute for IR generation (i.e. assembly representation) would be very he...
TheFish
1

votes
1

answer
140

Views

Finding DILocation for GlobalValue in LLVM IR?

I have a GlobalValue I would like to find the DILocation for. I can see the metadata exists, but can't find an obvious lookup path to get at it. Doing the same for llvm::Instruction is easy, but this isn't obvious.
oconnor0
1

votes
1

answer
207

Views

Generate LLVM IR for httpd

I am trying to compile apache2 with LLVM, to generate final binaries in LLVM IR. I used flto option in compiling and linking and passed 'also-emit-llvm' to the linker through clang. It seems to work for most steps, however I had two concerns 1) Earlier I used LLVM 3.6, whose gold plugin doesn't acc...
user1489092
1

votes
1

answer
476

Views

In LLVM IR, how can I print the name of a unnamed value which is represented as an unsigned numeric value with their prefix such as %2?

I want to print out the instructions written in LLVM IR( for practice ) and I have a BitCastInst like this: %0 = bitcast [32xi32]* %reg to i8* How can I print its name of left value which is a unnamed value %0 in this case?
Shindou
1

votes
1

answer
184

Views

How is the `llvm::ilist_iterator<NodeTy>::operator pointer() const` method utilized?

I've found that the implementation of this method was to simply return the pointer stored within the ilist_iterator class (http://llvm.org/docs/doxygen/html/ilist_8h_source.html#l00195). However, it is unclear to me how this operator is used. I'm assuming that with that operator, we can do the follo...
rzcs
1

votes
1

answer
274

Views

What does this inline assembly within an LLVM-IR CodeGen testcase mean?

I'm trying to understand an LLVM CodeGen/Generic testcase so I can get it passing for a backend for a new processor. This is the testcase (llvm/test/CodeGen/Generic/2007-04-08-MultipleFrameIndices.ll): ; RUN: llc -no-integrated-as < %s ; XFAIL: sparc-sun-solaris2 ; PR1308 ; PR1557 define i32 @stuff...
aneccodeal
1

votes
1

answer
197

Views

Extracting LLVM IR Identifiers

I have an instruction visitor implemented that inspects FCmpInst. In my IR, I have a couple lines generated from clang on a c++ file: %2 = load float, float* %x, align 4 %3 = fcmp ogt float %2, 1.0000e+00 Calling getOperand(0) during the FCmpInst visit returns the load instruction above. Then, if I...
Patrick Martin

View additional questions