Support for really global optimizations with ICD-C

ICD-C is capable of handling multiple compilation units within one IR, meaning that multiple source files that make up a program can all be considered together. This opens up the possibility of performing optimizations on a really global level, as opposed to optimizations confined to function boundaries.

Consider the two compilation units 'decode.c' and 'io.c' as an example from an embedded application:

decode.c: io.c:
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 );

}
int fread( void *p, size_t size, size_t num, FILE *F ) {

  int sum = 0;
  char *buf = (void*)p;

  for ( int i=0; i < size*num ; i++ ) {

    int c = fgetc( f );

    if ( c == EOF ) return( sum );

    *buf++ = c;

    sum++;

  }

  return ( sum );

}

Without support for multiple compilation units, a compiler would have to treat the above units separately and thus could not apply any optimization that requires information beyond the scope of the corresponding compilation unit scopes.

By loading both source files into the ICD-C at the same time, the compiler has the opportunity to perform analysis algorithms like function call graph analysis accross the compilation unit boundaries, resulting in connections among the functions:

Function callgraph after loading the modules decode.c and io.c

Optimizations can greatly benefit from the enlarged scope. Consider the optimization potential looking at function 'read_input_block':

This example shows that the full optimization potential can only be achieved when all the compilation units making up an application are loaded in ICD-C at the same time (whole-program analysis).


<< Back to ICD-C Example Applications