Basic doubt related to Module::iterator

Hi,

I believe that Module::iterator iterates through all the functions in a program. Am i wrong somewhere?

I run this for different files, each having one function each ie main(), but for one it loops twice, and for another it loops thrice.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)

Can someone explain this behavior.

regards,
Ambika

It might be iterating over the LLVM intrinsic functions as well as the user-defined functions. Try printing out the function names on each iteration and see what you get.

Trevor

Hi,

Yeah I found that it is running LLVM's functions. The functions that are running are:

main
llvm.dbg.func.start
llvm.dbg.stoppoint
scanf
llvm.dbg.region.end

But I dont want all the functions to be called as I am using Dominator Trees and whenever I the statement

  DominatorTree &DT = getAnalysis<DominatorTree>(F);

is encountered by functions other than main, it gives error.

What can I do?

regards,
Ambika

Trevor Harmon wrote:

ambika wrote:

Hi,

Yeah I found that it is running LLVM's functions. The functions that are running are:

main
llvm.dbg.func.start
llvm.dbg.stoppoint
scanf
llvm.dbg.region.end

But I dont want all the functions to be called as I am using Dominator Trees and whenever I the statement

  DominatorTree &DT = getAnalysis<DominatorTree>(F);

is encountered by functions other than main, it gives error.

What can I do?
  
You should first check to see if the function is an external function before calling getAnalysis<DominatorTree>() on it:

if (!(F->isDeclaration())) {
    DominatorTree & DT = getAnalysis<DominatorTree>(F);
    ...
}

-- John T.

Thanks a lot !!!!

John Criswell wrote: