Programming assignment 2

This assignment builds on your solution to the first assignment: finding basic blocks.
Write a simple basic block profiler: for a given run of a program, write a pass that allows you to obtain a count of the number of times each basic block is executed. For a run of the program, generate a profile file in the following format:

<count> <proc id><basic block start>

<proc id> is a unique number that identifies a procedure.  To generate proc ids, run the suif pass ipnumber as follows:
   ipnumber test.suif test.ipnumber
test.ipnumber, the output of the pass, contains the same code as test.suif, except that each proc_sym has an annotation on it (ip_procedure_num) that gives the number of the procedure

Mechanics

1. Modify your pass in assignment 1 so that it marks the beginnning of each basic block in the SUIF file using annotations.  Note that you should dismantle the SUIF file and run ipnumber before running any of your passes.
2. Write a pass that uses the annotations in Step 1 to insert adds a call to an "external" routine "EnterBasicBlock(unsigned, unsigned)" in each basic block.  This routine is external (i.e., you don't need to give the body of this routine in SUIF form).  The two arguments correspond to procedure id and basic block start instruction (which uniquely identifies a basic block in the program).  Also, this pass should add a call just before the "ret" in the main routine to an external routine "EndProgram".  (optional: you can also add a call to EndProgram before all calls to "exit" in the program)
3. Write a C routine called EnterBasicBlock in a separate C file that computes the basic block profiles from its calls.  Also write an EndProgram routine that outputs the profile information collected by EnterBasicBlock.
4. Convert the suif file generated by step 2 to C using s2c.
5. Link the C file generated in Step 4 with the C routines in step 3 and run the program to generate a profile.
 

Administrivia

This assignment is necessary to do only if you intend to do your programming project in SUIF.  This assignment is due February 22nd via email.