[LLVMdev] how can I parse a Value* ?

Alexandru Ionut Diaconescu alexandruionutdiaconescu at gmail.com
Thu Feb 28 02:23:13 PST 2013


Hello everyone,

I have the following LLVM IR :

@.str = private unnamed_addr constant [3 x i8] c"DS\00", section
"llvm.metadata"

@llvm.global.annotations = appending global [1 x { i8*, i8*, i8*, i32 }] [{
i8*, i8*, i8*, i32 } { i8* bitcast (i32* @f to i8*), i8* getelementptr
inbounds ([3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x
i8]* @.str1, i32 0, i32 0), i32 18 }], section "llvm.metadata"

I need to get @f (or maybe I can get somehow the definition of @f = global
i32 0, align 4 ) and also I need to get "DS" from @.str. In my target code
I have :

__attribute__((annotate("DS"))) int f=0;

I have problems to parse @llvm.global.annotations and I assume I will have
with @.str.  What I tried:

1.

for (Module::global_iterator I = F.global_begin(), E = F.global_end(); I !=
E; ++I) {
    if (I->getName() == "llvm.global.annotations") {
       Value *V = cast<Value>(I->getOperand(0));
        errs()<<"\n "<<*(V)<<"\n";
        errs()<<"\n "<<*(V->getType())<<"\n";

RESULT :

[1 x { i8*, i8*, i8*, i32 }] [{ i8*, i8*, i8*, i32 } { i8* bitcast (i32* @f
to i8*), i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i8*
getelementptr inbounds ([9 x i8]* @.str1, i32 0, i32 0), i32 18 }]

 [1 x { i8*, i8*, i8*, i32 }]

2.

errs()<<"\n "<<(V->getValueID())<<"\n";
if(V->getValueID() == Value::ConstantArrayVal) {
            ConstantArray *ca = (ConstantArray *)V;
            errs()<<"\n "<<(ca[0])<<"\n";  }

RESULT :

[1 x { i8*, i8*, i8*, i32 }] [{ i8*, i8*, i8*, i32 } { i8* bitcast (i32* @f
to i8*), i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i8*
getelementptr inbounds ([9 x i8]* @.str1, i32 0, i32 0), i32 18 }]

Any help is welcomed ! Thank you !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130228/87873cb3/attachment.html>


More information about the llvm-dev mailing list