Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
if(GlobalVariable* GA = M.getGlobalVariable("llvm.global.annotations")) {
// the first operand holds the metadata
for (Value *AOp : GA->operands()) {
// all metadata are stored in an array of struct of metadata
if (ConstantArray *CA = dyn_cast<ConstantArray>(AOp)) {
// so iterate over the operands
for (Value *CAOp : CA->operands()) {
// get the struct, which holds a pointer to the annotated function
// as first field, and the annotation as second field
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(CAOp)) {
if (CS->getNumOperands() >= 2) {
Function* AnnotatedFunction = cast<Function>(CS->getOperand(0)->getOperand(0));
// the second field is a pointer to a global constant Array that holds the string
if (GlobalVariable *GAnn =
dyn_cast<GlobalVariable>(CS->getOperand(1)->getOperand(0))) {
if (ConstantDataArray *A =
dyn_cast<ConstantDataArray>(GAnn->getOperand(0))) {
// we have the annotation! Check it's an epona annotation and process
StringRef AS = A->getAsString();
if (AS.startswith(Marker)) {
FuncAnnotations[AnnotatedFunction].emplace_back(AS);
}
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment