Example Data- and Control-Flow analysis results

The following real-world code fragment, taken from a decoder implementation, is used to demonstrate ICD-C's capabilities with respect to analyses and visualization of analysis results.

extern int *input_buffer;
extern int input_bits;

/* Read input block from file to global input data
   buffer. */
int read_input_block( int buf_size, int n_bits, FILE *input ) {

  int byte = 0;

  while ( input_bits < buf_size ) {

    if ( fread(&byte, sizeof(char), 1, input) != 1 ) {
      *input_buffer = 0;
      return -1;
    }

    *input_buffer ++= byte & (1 << n_bits) - 1;
    input_bits +=8;
    byte++;
  }

  return( byte );

}

The control flow graph of the above function is visualized by ICD-C as follows:

Example control flow graph

The basic blocks contain the original C code statements. The green block represents the function entry block, the red blocks are function exit blocks. The remaining blocks belong to the 'while' loop and are thus highlighted in yellow.

During its data flow analysis, ICD-C determines the def/use chains for the involved symbols. For the local symbol 'byte', these chains are shown as visualized by ICD-C below.

Def/use chain for local symbol in presence of indirection

The yellow nodes represent occurrences of a symbol that is modified, whereas the white nodes represent passive uses of the symbol. Grey nodes indicate that there are further symbol occurrences that are unknown at this point, in this case caused by the address operator being used on the symbol 'byte'.

The following graph shows a part of the function call graph of the underlying decoder implementation starting from the function 'main()'. The subsequently called functions are connected with call edges. Functions that are unknown to ICD-C are displayed in grey.

Example function call graph

Information from function call analysis can be exploited when multiple compilation units are added to the IR so that really global observations of function calls and their parameters can be performed and taken as a basis for highly efficient optimizations.


<< Back to ICD-C Example Applications