Project Stage 2: Testing

 To test my custom pass I first extracted the spo600-test-clone files into my gcc-test-001 directory and simply compiled and ran the program with -fdump-tree-ctyler.

I ran it on the vol1.c file, the contents of vol1.c are as following:

[dpark39@aarch64-002 test-clone]$ cat vol1.c

// vol1.c - fixed-point volume scaling algorithm

// Chris Tyler 2017.11.29-2021.11.16 - Licensed under GPLv3.

// For the Seneca College SPO600 Course


#include <stdlib.h>

#include <stdio.h>

#include <stdint.h>

#include <stdbool.h>

#include "vol.h"


int16_t scale_sample(int16_t sample, int volume) {


        return ((((int32_t) sample) * ((int32_t) (32767 * volume / 100) <<1) ) >> 16);

}


int main() {

        int             x;

        int             ttl=0;


// ---- Create in[] and out[] arrays

        int16_t*        in;

        int16_t*        out;

        in=(int16_t*) calloc(SAMPLES, sizeof(int16_t));

        out=(int16_t*) calloc(SAMPLES, sizeof(int16_t));


// ---- Create dummy samples in in[]

        vol_createsample(in, SAMPLES);


// ---- This is the part we're interested in!

// ---- Scale the samples from in[], placing results in out[]

        for (x = 0; x < SAMPLES; x++) {

                out[x]=scale_sample(in[x], VOLUME);

        }


// ---- This part sums the samples.

// ---- Q: Why is this needed?

        for (x = 0; x < SAMPLES; x++) {

                ttl=(ttl+out[x])%1000;

        }


// ---- Print the sum of the samples.

// ---- Q: Why is this needed?

        printf("Result: %d\n", ttl);


        return 0;


}

After running my pass on it I got a very long dump file below. 

[dpark39@aarch64-002 gcc-test-001]$ cat test-vol1.c.263t.ctyler


;; Function scale_sample (scale_sample, funcdef_no=22, decl_uid=5488, cgraph_uid=23, symbol_order=22)


_1 = (int) sample_7(D);

_2 = volume_8(D) * 32767;

_3 = _2 / 100;

_4 = _3 << 1;

_5 = _1 * _4;

_6 = _5 >> 16;

_9 = (int16_t) _6;

return _9;

PRUNE: scale_sample

int16_t scale_sample (int16_t sample, int volume)

{

  int _1;

  int _2;

  int _3;

  int _4;

  int _5;

  int _6;

  int16_t _9;


  <bb 2> [local count: 1073741824]:

  _1 = (int) sample_7(D);

  _2 = volume_8(D) * 32767;

  _3 = _2 / 100;

  _4 = _3 << 1;

  _5 = _1 * _4;

  _6 = _5 >> 16;

  _9 = (int16_t) _6;

  return _9;


}




;; Function main (main, funcdef_no=23, decl_uid=5490, cgraph_uid=24, symbol_order=23) (executed once)


in_18 = calloc (50000000, 2);

out_20 = calloc (50000000, 2);

vol_createsample (in_18, 50000000);

vect__4.11_53 = MEM <vector(8) short int> [(int16_t *)in_18 + ivtmp.29_30 * 1];

vect_patt_14.12_54 = WIDEN_MULT_LO_EXPR <vect__4.11_53, { 32766, 32766, 32766, 32766, 32766, 32766, 32766, 32766 }>;

vect_patt_14.12_55 = WIDEN_MULT_HI_EXPR <vect__4.11_53, { 32766, 32766, 32766, 32766, 32766, 32766, 32766, 32766 }>;

vect__29.13_56 = vect_patt_14.12_54 >> 16;

vect__29.13_57 = vect_patt_14.12_55 >> 16;

vect__30.14_58 = VEC_PACK_TRUNC_EXPR <vect__29.13_56, vect__29.13_57>;

MEM <vector(8) short int> [(int16_t *)out_20 + ivtmp.29_30 * 1] = vect__30.14_58;

ivtmp.29_29 = ivtmp.29_30 + 16;

if (ivtmp.29_29 != 100000000)

ivtmp.24_15 = (unsigned long) out_20;

_27 = ivtmp.24_15 + 100000000;

_14 = (void *) ivtmp.24_26;

_9 = MEM[(int16_t *)_14];

_10 = (int) _9;

_11 = _10 + ttl_37;

ttl_23 = _11 % 1000;

ivtmp.24_31 = ivtmp.24_26 + 2;

if (_27 != ivtmp.24_31)

printf ("Result: %d\n", ttl_23);

return 0;

PRUNE: main

int main ()

{

  sizetype ivtmp.29;

  unsigned long ivtmp.24;

  vector(8) short int vect__30.14;

  vector(4) int vect__29.13;

  vector(4) int vect_patt_14.12;

  vector(8) short int vect__4.11;

  int16_t * out;

  int16_t * in;

  int ttl;

  short int _9;

  int _10;

  int _11;

  void * _14;

  unsigned long _27;


  <bb 2> [local count: 10737416]:

  in_18 = calloc (50000000, 2);

  out_20 = calloc (50000000, 2);

  vol_createsample (in_18, 50000000);


  <bb 3> [local count: 1063004408]:

  # ivtmp.29_30 = PHI <ivtmp.29_29(7), 0(2)>

  vect__4.11_53 = MEM <vector(8) short int> [(int16_t *)in_18 + ivtmp.29_30 * 1];

  vect_patt_14.12_54 = WIDEN_MULT_LO_EXPR <vect__4.11_53, { 32766, 32766, 32766, 32766, 32766, 32766, 32766, 32766 }>;

  vect_patt_14.12_55 = WIDEN_MULT_HI_EXPR <vect__4.11_53, { 32766, 32766, 32766, 32766, 32766, 32766, 32766, 32766 }>;

  vect__29.13_56 = vect_patt_14.12_54 >> 16;

  vect__29.13_57 = vect_patt_14.12_55 >> 16;

  vect__30.14_58 = VEC_PACK_TRUNC_EXPR <vect__29.13_56, vect__29.13_57>;

  MEM <vector(8) short int> [(int16_t *)out_20 + ivtmp.29_30 * 1] = vect__30.14_58;

  ivtmp.29_29 = ivtmp.29_30 + 16;

  if (ivtmp.29_29 != 100000000)

    goto <bb 7>; [98.99%]

  else

    goto <bb 4>; [1.01%]


  <bb 7> [local count: 1052266995]:

  goto <bb 3>; [100.00%]


  <bb 4> [local count: 10737413]:

  ivtmp.24_15 = (unsigned long) out_20;

  _27 = ivtmp.24_15 + 100000000;


  <bb 5> [local count: 1063004408]:

  # ttl_37 = PHI <ttl_23(8), 0(4)>

  # ivtmp.24_26 = PHI <ivtmp.24_31(8), ivtmp.24_15(4)>

  _14 = (void *) ivtmp.24_26;

  _9 = MEM[(int16_t *)_14];

  _10 = (int) _9;

  _11 = _10 + ttl_37;

  ttl_23 = _11 % 1000;

  ivtmp.24_31 = ivtmp.24_26 + 2;

  if (_27 != ivtmp.24_31)

    goto <bb 8>; [98.99%]

  else

    goto <bb 6>; [1.01%]


  <bb 8> [local count: 1052266995]:

  goto <bb 5>; [100.00%]


  <bb 6> [local count: 10737416]:

  printf ("Result: %d\n", ttl_23);

  return 0;


}

The two functions that were processed by my GCC pass was scale_sample and the main function. The result shows that my program has decided to prune both of them.



The functions scale_sample and main were found to be identical by my code and it was decided they should be pruned. Although the pruning process did not actually take place this is a good step towards creating a pass that can accurately prune functions in a program. 

The steps my pass took were: It analyzed the gimple representation and got the structure of both scale_sample and main, next it compared clones and found them to be basically the same, thus printing diagnostics and deciding those functions to be pruned.






Comments

Popular posts from this blog

Early stages of project

Building GCC again on aarch64-002