[sac-user] Fwd: Re: sac-visualization tool

Sven-Bodo Scholz S.Scholz at herts.ac.uk
Wed Jun 11 15:23:07 BST 2008


X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on
	berlix.feis.herts.ac.uk
X-Spam-Level: 
X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham
	version=3.2.3
From: Sven-Bodo Scholz <S.Scholz at herts.ac.uk>
To: sac user mailing list <sac-user at sac-home.org>,
	Sunita Chandrasekaran <sunisg123 at gmail.com>
Subject: Re: [sac-user] sac-visualization tool
X-UH-MailScanner-Information: 
X-H-UH-MailScanner: No Virus detected
X-UH-MailScanner-From: s.scholz at herts.ac.uk

On Wed, Jun 11, 2008 at 03:32:39PM +0800, Sunita Chandrasekaran wrote:
> Hi
> 
> Does this sac2c compiler come with any graphic analyzer tool?
> How do you view the graphs or the optimization effects? vcg?

Hi Sunita,

there are 2 things you might want to visualize: a) programs
b) data (i.e. arrays)

For the latter, we use off-the-shelve tools that exist as C libraries
such as SDL or DISLIN.

However, I assume that you are interested in the former since you
mentioned vcg. AFAIK, there exists no graphical tol to visualise SaC
programs. BUT, we have built-in support for printing optimised programs
as SaC code itself. if you use 'sac2c -h' you will get lots of possible
compiler flags include the BREAK-options -b<xyz>.
Be aware though that the further "down" in the compilation process that
you break the more difficult to relate to the original program the code
becomes.

Here a quick example to get started:

Let's look at the following program:

--------------------------------------------------------------------------------
use Array: all;

int main()
{
  a = 0;

  for( i=0; i<10; i++) {
    a += i;
  }
  return( a);
}
--------------------------------------------------------------------------------

sac2c -b3 sunita.sac gives 

--------------------------------------------------------------------------------
[.... lots of "gibberish"....]
/*
 *  function definitions (FUNDEFS)
 */

int _MAIN::main()
/*
 *  main ::  ---
 */
{ 
  a = 0; 
  i = 0; 
  while (i Array::< 10) 
  { 
    a = Array::+( a, i); 
    i = Array::+( i, 1); 
  }
  return( a); 
}
--------------------------------------------------------------------------------

sac2c -b6 sunita.sac gives

--------------------------------------------------------------------------------
[.... lots of "gibberish"....]
/*
 *  function definitions (FUNDEFS)
 */

/* Loop function */
int _MAIN::_dup_5_main__Loop_0( int a, int i)
/*
 *  _dup_5_main__Loop_0 ::  ---
 */
{ 
  int a__SSA0_3; 
  int a__SSA0_2; 
  int i__SSA0_1; 
  int a__SSA0_1; 
  int{1} _flat_2; 
  int{10} _flat_4; 
  bool _flat_3; 

  a__SSA0_1 = wrapper:Array::+( a, i); 
  _flat_2 = 1; 
  i__SSA0_1 = wrapper:Array::+( i, _flat_2); 
  _flat_4 = 10; 
  _flat_3 = wrapper:Array::<( i__SSA0_1, _flat_4); 
  if (_flat_3) 
  { 
    a__SSA0_2 = _MAIN::_dup_5_main__Loop_0( a__SSA0_1, i__SSA0_1); 
  }
  else
  { 
    /* empty */
  }
  a__SSA0_3 = ( _flat_3 ? a__SSA0_2 : a__SSA0_1 ); 
  return( a__SSA0_3); 
}

/* Cond function */
int _MAIN::main__Cond_1( int{0} a, int{0} i, bool _flat_0)
/*
 *  main__Cond_1 ::  ---
 */
{ 
  int a__SSA0_2; 
  int a__SSA0_1; 

  if (_flat_0) 
  { 
    a__SSA0_1 = _MAIN::_dup_5_main__Loop_0( a, i); 
  }
  else
  { 
    /* empty */
  }
  a__SSA0_2 = ( _flat_0 ? a__SSA0_1 : a ); 
  return( a__SSA0_2); 
}

int _MAIN::main()
/*
 *  main ::  ---
 */
{ 
  int a__SSA0_2; 
  int a__SSA0_1; 
  bool _flat_0; 
  int{10} _flat_1; 
  int{0} i; 
  int{0} a; 

  a = 0; 
  i = 0; 
  _flat_1 = 10; 
  _flat_0 = wrapper:Array::<( i, _flat_1); 
  a__SSA0_1 = _MAIN::main__Cond_1( a, i, _flat_0); 
  a__SSA0_2 = _type_conv_( int, a__SSA0_1); 
  return( a__SSA0_2); 
}
--------------------------------------------------------------------------------

Here you can see that our compiler has transformed the loop into a tail
recursive function called _MAIN::_dup_5_main__Loop_0. You can also see
what the type inference has found out.
Notice here as well that, on this level, we may have things that are
exceed the set of user-level SaC. An example are types of the form
int{0} a which indicates that a has the value 0!

If we preceed and let the optimiser do its job, i.e.
sac2c -b11 sunita.sac, we obtain:

--------------------------------------------------------------------------------
[ I am picking the relevant parts here :-) ]

int _MAIN::main()
/*
 *  main ::  ---
 */
{
  int a__SSA0_1;
  int{0} a;

  a = 0;
  a__SSA0_1 = _MAIN::_dup_279__main__Loop_0( a, a);
  return( a__SSA0_1);
}

int _MAIN::_dup_279__main__Loop_0( int a, int i)
/*
 *  _dup_279__main__Loop_0 ::  ---
 */
{
  int _pinl_19__flat_69;
  int _pinl_20__flat_69;
  bool _pinl_21__flat_42;
  int a__SSA0_3;
  int a__SSA0_2;

  _pinl_19__flat_69 = _add_SxS_( a, i);
  _pinl_20__flat_69 = _add_SxS_( i, 1);
  _pinl_21__flat_42 = _lt_SxS_( _pinl_20__flat_69, 10);
  if (_pinl_21__flat_42)
  {
    a__SSA0_2 = _MAIN::_dup_279__main__Loop_0( _pinl_19__flat_69,
_pinl_20__flat_69);
  }
  else
  {
    /* empty */
  }
  a__SSA0_3 = ( _pinl_21__flat_42 ? a__SSA0_2 : _pinl_19__flat_69 );
  return( a__SSA0_3);
}

--------------------------------------------------------------------------------
Usually, you do NOT want to see any code thereafter because our C-code
generator is rather generic and therefore the intermediate code becomes
ebven less readable to the "untrained eye" ;-)

If you want to tweak the optimisation you could, for example, increase
the loop unrolling threshold by using

sac2c -maxlur 10 -b11 sunita.sac

In which case you obtain:
--------------------------------------------------------------------------------
[...gibberish...]

int{45} _MAIN::main()
/*
 *  main ::  ---
 */
{
  int{45} a__SSA0_1;

  a__SSA0_1 = 45;
  return( a__SSA0_1);
}
--------------------------------------------------------------------------------

' hope that you were after some way to get this kind of information
about about the optimisation results....

Cheers,
   Bodo





More information about the sac-user mailing list