Forked from serge-sans-paille/Accessing llvm.global.annotations
Created
April 21, 2023 13:53
-
-
Save depau/14c974b78400bc95886756e208220efd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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