[LLVMdev] Most efficient way to count # of intrcutions in a module ?

Gabi bugspynet at gmail.com
Tue Apr 13 22:57:58 PDT 2010

I need to count the total number of instructions in a given module.
The only way I found is using the obvious  double iteration as seen
below. Is there any more efficient way to achieve this ? I don't like
the fact that simple calculation like that has performance of o(F*B)
(# of functions * # of blocks per function)

unsigned int calcSize(Module* mod)
    unsigned int size = 0;
    for (Module::iterator f = mod->begin(), fe = mod->end(); f != fe; ++f)
        for (Function::iterator b = f->begin(), be = f->end(); b != be; ++b)
            BasicBlock* bb = (BasicBlock*) b;
    return size;



More information about the llvm-dev mailing list