[LLVMdev] llvm get annotations
Sebastian Dreßler
dressler at zib.de
Wed Feb 27 07:07:06 PST 2013
Hi Alexandru,
On 02/27/2013 03:15 PM, Alexandru Ionut Diaconescu wrote:
> [...]
> Is there an easier way to get the simple DS annotation of @f ?
>
I used to annotate C / C++ functions with e.g.
__attribute__((annotate("kernel"))) and the retrieved the name of the
function with the following code:
/*****************************************************/
GlobalValue *gv;
Value *a = gv->getOperand(0);
ConstantStruct *annoStruct =
dynamic_cast<ConstantStruct>(
dynamic_cast<ConstantArray>(a)->getOperand(0);
);
GlobalVariable *gvar = dynamic_cast<GlobalVariable>(
dynamic_cast<ConstantExpr>(
annoStruct->getOperand(1)
)->getOperand(0)
);
std::string str = dynamic_cast<ConstantDataArray>(
gvar->getOperand(0)
)->getAsString();
if (str.find("kernel")) {
[...]
}
/*****************************************************/
Inside the last if one can find the function that belongs to the annotation.
IMO its a bit ugly, but it works for me ;)
Cheers,
Sebastian
--
Mit freundlichen Grüßen / Kind regards
Sebastian Dreßler
Zuse Institute Berlin (ZIB)
Takustraße 7
D-14195 Berlin-Dahlem
Germany
dressler at zib.de
Phone: +49 30 84185-261
http://www.zib.de/
More information about the llvm-dev
mailing list