[LLVMdev] questions about llvm

xli3 at uiuc.edu xli3 at uiuc.edu
Mon Sep 16 16:22:01 PDT 2002


Hi, I have some basic questions. I'd appreciate if you can
help me with them.

1. In the LLVM programmer manual, section "Finding call sites:
a slightly more complex example", there is such piece of code:
-------------------------------------------------
class OurFunctionPass : public FunctionPass {
      public:
        OurFunctionPass(): callCounter(0) { }

        virtual runOnFunction(Function& F) {
            for(Function::iterator b = F.begin(), be =
F.end(); b != be; ++b) {
                for(BasicBlock::iterator i = b->begin(); ie =
b->end(); i != ie; ++i) {
                    if (CallInst* callInst =
dyn_cast<CallInst>(&*inst)) {
                        // we know we've encountered a call
instruction, so we
                        // need to determine if it's a call to
the
                        // function pointed to by m_func or
not.
      
                        if(callInst->getCalledFunction() ==
targetFunc)
                            ++callCounter;
                }
            }
        }
        
      private:
        unsigned  callCounter;
    };
------------------------------------------

I don't understand in this line:
if (CallInst* callInst = dyn_cast<CallInst>(&*inst)) {
Where does 'inst' come from? What is inst and how should we
get it? could you please clarify?

Thanks,
xiaodong



More information about the llvm-dev mailing list