[LLVMdev] llvm get annotations

Alexandru Ionut Diaconescu alexandruionutdiaconescu at gmail.com
Wed Feb 27 06:15:41 PST 2013


Hello everyone !

I followed
http://stackoverflow.com/questions/4976298/modern-equivalent-of-llvm-annotationmanagerin
order to get annotations from my target bytecode. All the examples
that
I give in the following is related to the code from that link. I have
`__attribute__((annotate("DS"))) int f=0;` into the target C++ program and
the related IR code:

    @.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 have two problems following the examples from
http://stackoverflow.com/questions/4976298/modern-equivalent-of-llvm-annotationmanager:

1. Cannot use `annotatedValue->getUnderlyingObject()` since Value class has
not this method. Instead, I found in LLVM the following methods:
`llvm::GetUnderlyingObject()`,`getUnderlyingObjectFromInt(),
getUnderlyingObjects()`.

 I hacked the method `llvm::GetUnderlyingObject()`...that is with Capital G
(different from `getUnderlyingObject()`) and call
`myGetUnderlyingObject(annotatedValue,0,6)` as mentioned at
http://llvm.org/docs/doxygen/html/namespacellvm.html#ace6c957db39858291c6ce01c38e78480.

2. Since I write my code into runOnFunction(), I have problems with
`getGlobalVariableString(std::string name)` function from the stackoverflow
link. So I have to integrate the following part of code into
runOnFunction():

    std::string name = gv->getName().str();

// assumption: the zeroth operand of a Value::GlobalVariableVal is the
actual Value

    //Module* module = ; //can I use Module& llvm::CallGraph::getModule() ?
    Value *v = module->getNamedValue(name)->getOperand(0);
    if(v->getValueID() == Value::ConstantArrayVal)
    {
        ConstantArray *ca = (ConstantArray *)v;
        std::cout << "    argument " << a->getType()->getDescription() << "
"<<a->getName().str()
            << " has annotation \"" << ca->getAsString() << "\"\n";
    }


Is there an easier way to get the simple DS annotation of @f ?

Thank you for any suggestion!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130227/39dbfc2f/attachment.html>


More information about the llvm-dev mailing list