Get a pointer to llvm :: The value previously allocated for the CreateLoad function

I am new to llvm and I am writing a small IR Builder llvm. I use IRBuilder and all these Create * functions to generate my IR. I am trying to create a load statement that will create a new local SSA variable with the value previously highlighted by llvm :: Value .

What I expected to have:

%2 = load i32* %1

Using % 2 the results of the load command and % 1 my previously highlighted value (CreateAlloca)

Here is what I tried:

// Get Ptr from Val
Value* ptr = ConstantExpr::getIntToPtr((Constant*)loc[n],PointerType::getUnqual(builder->getInt32Ty()));

// Générate load instruction with the new Ptr
builder->CreateLoad(ptr);

And here is what I have:

%2 = load i32* null

loc is an array containing all my llvm :: Value * values

Could you tell me what I am doing wrong? Or maybe if I'm bad? Thanks.

0
1

ConstantExpr::getIntToPtr() . , , , IR:

%2 = load i32* inttoptr (i32 %1 to i32*)

, , , constants, % 1 . ConstantExpr::getIntToPtr() Constant , , .

IRBuilder::createIntToPtr. , , (loc[n]) alloca, , - : builder->CreateLoad(loc[n]).

, LLVM c-style cast, cast<>, : cast<Constant>(loc[n]).

0

Source: https://habr.com/ru/post/1621500/


All Articles