demo.cpp
/* Get a function id by name.
 */
Get a function id by name.
Get a function id by name .
int Support::GetFunctionID(Function *F) {
    if (F->begin() == F->end()) {
        return -1;
    }
    BasicBlock *EntryBB = &(F->getEntryBlock());
    if (EntryBB) {
        for (BasicBlock::iterator II = EntryBB->begin(); II != EntryBB->end(); II++) {
            Instruction *Inst = &*II;
            MDNode *Node = Inst->getMetadata("func_id");
            if (!Node) {
                continue;
            }
            assert(Node->getNumOperands() == 1);
            const Metadata *MD = Node->getOperand(0);
            if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
                Value *V = MDV->getValue();
                ConstantInt *CI = dyn_cast<ConstantInt>(V);
                assert(CI);
                return CI->getZExtValue();
            }
        }
    }
    return -1;
}
int Support :: GetFunctionID ( Function * F ) { if ( F -> begin ( ) == F -> end ( ) ) { return -1 ; } BasicBlock * EntryBB = & ( F -> getEntryBlock ( ) ) ; if ( EntryBB ) { for ( BasicBlock :: iterator II = EntryBB -> begin ( ) ; II != EntryBB -> end ( ) ; II ++ ) { Instruction * Inst = & * II ; MDNode * Node = Inst -> getMetadata ( " " ) ; if ( ! Node ) { continue ; } assert ( Node -> getNumOperands ( ) == 1 ) ; const Metadata * MD = Node -> getOperand ( 0 ) ; if ( auto * MDV = dyn_cast < ValueAsMetadata > ( MD ) ) { Value * V = MDV -> getValue ( ) ; ConstantInt * CI = dyn_cast < ConstantInt > ( V ) ; assert ( CI ) ; return CI -> getZExtValue ( ) ; } } } return -1 ; }
Get a function id by name.
Get a function id by name .