Last active
May 17, 2023 18:03
-
-
Save serge-sans-paille/c57d0791c7a9dbfc76e5c2f794e650b4 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
/usr/lib/llvm-16/include/llvm/IR/User.h:170: Value *llvm::User::getOperand(unsigned int) const: Assertion `i < NumUserOperands && "getOperand() out of range!"' failed.