Create a BlockAddress array from LLVM Pass

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Create a BlockAddress array from LLVM Pass

David Blaikie via cfe-dev
Hi

Good day. For the following function local static constant array:
static const __attribute__((used))
__attribute__((section("data"))) void *codetable[] = {
&&RETURN, &&INCREMENT, &&DECREMENT, &&DOUBLE, &&SWAPWORD};
I have the following in the LLVM IR.

@sampleCode.codetable = internal global [5 x i8*] [i8* blockaddress(@sampleCode, %19), i8* blockaddress(@sampleCode, %22), i8* blockaddress(@sampleCode, %25), i8* blockaddress(@sampleCode, %28), i8* blockaddress(@sampleCode, %31)], section "data", align 16

Here the array elements are labels in c code. I have done following to create the same array from LLVM pass.

std::vector<BlockAddress *> tmp;

Function *fn = ...
BasicBlock *bb = ...

BlockAddress *bba = BlockAddress::get(fn, bb);
tmp.push_back(bba);

GlobalVariable *gvar_ptr_abc = new GlobalVariable(
/*Module=*/*fn->getParent(),
/*Type=*/PointerTy,
/*isConstant=*/false,
/*Linkage=*/GlobalValue::InternalLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"labelTracker");
gvar_ptr_abc->setAlignment(16);
Constant *blockItems = ConstantDataArray::get(fn->getContext(), tmp);
gvar_ptr_abc->setInitializer(blockItems);
I get error with following: Unsupported type in Type::getScalarTy

Can anyone suggest what I suppose to do? It is definitely related to my type declaration and BlockAddress items, but I don't know what it is exactly.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Create a BlockAddress array from LLVM Pass

David Blaikie via cfe-dev

Please don’t send questions to both cfe-dev and llvm-dev; usually one or the other is more appropriate (in this case, it’s llvm-dev, since there’s no clang code involved).

 

I think you meant to call ConstantArray::get, not ConstantDataArray::get.  (We should probably fix ConstantDataArray::get() to use enable_if or something like that, so your example fails to compile instead of generating a weird runtime error.)

 

-Eli

 

From: cfe-dev <[hidden email]> On Behalf Of Mustakimur Rahman Khandaker (Mustakim) via cfe-dev
Sent: Monday, January 28, 2019 12:12 PM
To: [hidden email]; [hidden email]
Subject: [EXT] [cfe-dev] Create a BlockAddress array from LLVM Pass

 

Hi

 

Good day. For the following function local static constant array:

static const __attribute__((used))
__attribute__((section("data"))) void *codetable[] = {
&&RETURN, &&INCREMENT, &&DECREMENT, &&DOUBLE, &&SWAPWORD};

I have the following in the LLVM IR.

 

@sampleCode.codetable = internal global [5 x i8*] [i8* blockaddress(@sampleCode, %19), i8* blockaddress(@sampleCode, %22), i8* blockaddress(@sampleCode, %25), i8* blockaddress(@sampleCode, %28), i8* blockaddress(@sampleCode, %31)], section "data", align 16

 

Here the array elements are labels in c code. I have done following to create the same array from LLVM pass.



std::vector<BlockAddress *> tmp;
 
Function *fn = ...
BasicBlock *bb = ...
 
BlockAddress *bba = BlockAddress::get(fn, bb);
tmp.push_back(bba);
 
GlobalVariable *gvar_ptr_abc = new GlobalVariable(
/*Module=*/*fn->getParent(),
/*Type=*/PointerTy,
/*isConstant=*/false,
/*Linkage=*/GlobalValue::InternalLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"labelTracker");
gvar_ptr_abc->setAlignment(16);
Constant *blockItems = ConstantDataArray::get(fn->getContext(), tmp);
gvar_ptr_abc->setInitializer(blockItems);

I get error with following: Unsupported type in Type::getScalarTy

 

Can anyone suggest what I suppose to do? It is definitely related to my type declaration and BlockAddress items, but I don't know what it is exactly.


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev