Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save depau/14c974b78400bc95886756e208220efd to your computer and use it in GitHub Desktop.
Save depau/14c974b78400bc95886756e208220efd to your computer and use it in GitHub Desktop.
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