Thanks a lot Chris. Regarding basic block size I wish to calculate both: - The number of bytecode bytes - The number of machine code bytes for some target? TS Chris Lattner <sabre at nondot.org> wrote: On Thu, 7 Apr 2005, Tanu Sharma wrote:> Thanks for the reply, > > Actually I m aiming towards determining two values: > > - number of basic blocks in a program For this I have used Statistic > facility provided in llvm and increasing the counter for each basic > block for each function.but for some reason , I m getting different > number everytime !! Is Statistic is the right way to do it ?That should work fine. Remember that statistics accumulate across the whole execution of the tool though, they are not reset per function. Also, you might want to check out the -instcount pass. It prints BB counts among other things. For a small .ll file, it prints: $ llvm-as < t.ll | analyze -instcount -stats Printing analysis 'Counts the various types of Instructions' for function 'test': ===-------------------------------------------------------------------------==... Statistics Collected ... ===-------------------------------------------------------------------------== 1 instcount - Number of Cast insts 1 instcount - Number of Store insts 1 instcount - Number of SetLT insts 1 instcount - Number of Ret insts 1 instcount - Number of memory instructions 1 instcount - Number of non-external functions 1 instcount - Number of basic blocks 4 instcount - Number of instructions (of all types)> - Average basic block size in a program ( in bytes) > Any suggestions to make it simple and get an accurate result?What are you trying to measure? The in-memory footprint of hte LLVM IR? The number of bytecode bytes? The number of machine code bytes for some target? -Chris> > Regards, > Tanu > > > Chris Lattner wrote: > On Tue, 5 Apr 2005, Tanu Sharma wrote: > >> There is tool that calculates execution count and total number of blocks >> , is there anything available to detemine size of basic blocks in a >> program in bytes? > > Are you talking about native code? If you run the 'size' utility in unix, > the 'tex' value is the number of bytes of program code. If you're talking > about llvm code, I'm not sure what you mean "size of basic blocks in a > program in bytes". > > -Chris > >-Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/ _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev --------------------------------- Do you Yahoo!? Make Yahoo! your home page -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20050408/187e3afc/attachment.html>
On Fri, Apr 08, 2005 at 08:37:03AM -0700, Tanu Sharma wrote:> Regarding basic block size I wish to calculate both: > > - The number of bytecode bytesUse the llvm-bcanalyzer tool, it will tell you number of bytes per function and number of basic blocks. If you want number of bytes per basic block, check out what it does, and calculate basic blocks separately.> - The number of machine code bytes for some target?You have two options 1. Create a native executable, find and extract the code section using objdump or whatever is applicable to your platform, and analyze the basic blocks there by finding all branches. 2. Alternatively, the LLVM way: On a RISC-like machine, instructions are usually 4 bytes, so numInstrs * 4 = numBytes. On an architecture like X86 with variable-sized instructions, you will have to calculate the size on a per-emitted-instruction basis. We currently do this for the nightly tests, but it's outputted on a per-program basis, such as: $ lli -stats eks.bc | grep jit 4182 jit - Number of bytes of machine code compiled Note that this is only for the _executed_ part of the program, not the entire program. Your best bet would be to write a pass that runs after instruction selection, that loops over all the basic blocks of each function and calculates how many bytes each instruction would take up. For a RISC-like target, again, that's pretty trivial, but harder for a CISC. -- Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu
On Fri, 2005-04-08 at 12:14, Misha Brukman wrote:> On Fri, Apr 08, 2005 at 08:37:03AM -0700, Tanu Sharma wrote: > > - The number of machine code bytes for some target? > 1. Create a native executable, find and extract the code section using > objdump or whatever is applicable to your platform, and analyze the > basic blocks there by finding all branches.<shameless alpha plug> If you were compiling on alpha: objdump -t file |sort |grep -A 1 LBB then the size of each basic block would be the address of the symbol - the address of the next symbol (all basic blocks symbols are currently exported in alpha and start with LBB) </shameless alpha plug> Andrew