Download presentation
Presentation is loading. Please wait.
Published byArron McCarthy Modified over 9 years ago
1
CMPUT 680 - Compiler Design and Optimization1 CMPUT680 - Fall 2006 Topic 3: Intermediate Representation in the ORC José Nelson Amaral http://www.cs.ualberta.ca/~amaral/courses/680
2
CMPUT 680 - Compiler Design and Optimization2 WHIRL The Open Research Compiler (ORC) uses a tree-based intermediate representation called WHIRL, which stands for Winning Hierarchical Intermediate Representation Language.
3
CMPUT 680 - Compiler Design and Optimization3 Compilation Example #include #define COUNTINIT 1.0 void InitializeMatrix(double *A, int dimension); void InitializeVector(double *B, int dimension); void MatrixVectorMultiply(double *C, double *A, double *B, int dimension); void OutputVector(double *C, int dimension); int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; }
4
CMPUT 680 - Compiler Design and Optimization4 Compilation Example (cont.) void InitializeVector(double *B, int dimension) { int i; double count = 1.0; for(i=0 ; i<dimension ; i++) B[i] = count++; } void InitializeMatrix(double *A, int dimension) { int i,j; double count = 1.0; for(i=0 ; i<dimension ; i++) for(j=0 ; j<dimension ; j++) A[i][I] = count++; } void MatrixVectorMultiply(double *C, double *A, double *B, int dimension) { int i, j; for(i=0 ; i<dimension ; i++) { C[i] = 0.0; for(j=0 ; j<dimension ; j++) C[i] = C[i] + A[i*dimension+j]*B[j]; } void OutputVector(double *C, int dimension) { int i; printf("C = [ "); for(i=0 ; i<dimension ; i++) printf("%g ",C[i]); printf("]\n"); }
5
CMPUT 680 - Compiler Design and Optimization5 Highest WHIRL Representation FUNC_ENTRY [0x0x2b1c91d8],MID=0 IDNAME O_0 [0x0x2b1c9200],MID=0 IDNAME O_0 [0x0x2b1c921c],MID=1 BODY BLOCK [0x0x2b1c9248],MID=0 END_BLOCK [0x0x2b1c9248] BLOCK [0x0x2b1c9274],MID=1 END_BLOCK [0x0x2b1c9274] BLOCK [0x0x80ed668],MID=2 PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 I4I4LDID O_0: A direct load of a 4 byte integer into a 4 byte integer register with ofset of 0.
6
CMPUT 680 - Compiler Design and Optimization6 Highest WHIRL Representation FUNC_ENTRY [0x0x2b1c91d8],MID=0 IDNAME O_0 [0x0x2b1c9200],MID=0 IDNAME O_0 [0x0x2b1c921c],MID=1 BODY BLOCK [0x0x2b1c9248],MID=0 END_BLOCK [0x0x2b1c9248] BLOCK [0x0x2b1c9274],MID=1 END_BLOCK [0x0x2b1c9274] BLOCK [0x0x80ed668],MID=2 PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 I4INTCONST: Access a 4 byte integer constant. CV(2): The value of the constant is 2.
7
CMPUT 680 - Compiler Design and Optimization7 Highest WHIRL Representation FUNC_ENTRY [0x0x2b1c91d8],MID=0 IDNAME O_0 [0x0x2b1c9200],MID=0 IDNAME O_0 [0x0x2b1c921c],MID=1 BODY BLOCK [0x0x2b1c9248],MID=0 END_BLOCK [0x0x2b1c9248] BLOCK [0x0x2b1c9274],MID=1 END_BLOCK [0x0x2b1c9274] BLOCK [0x0x80ed668],MID=2 PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 I4I4NE: Tests if two four byte values are not equal.
8
CMPUT 680 - Compiler Design and Optimization8 Highest WHIRL Representation FUNC_ENTRY [0x0x2b1c91d8],MID=0 IDNAME O_0 [0x0x2b1c9200],MID=0 IDNAME O_0 [0x0x2b1c921c],MID=1 BODY BLOCK [0x0x2b1c9248],MID=0 END_BLOCK [0x0x2b1c9248] BLOCK [0x0x2b1c9274],MID=1 END_BLOCK [0x0x2b1c9274] BLOCK [0x0x80ed668],MID=2 PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 VCALL: A call to a function that returns an item of type void. U8PARM: An 8-byte unsigned parameter for the function. U8LDA: Accesses the address, in bytes, of the string. 0_0: Add offset of zero to the address.
9
CMPUT 680 - Compiler Design and Optimization9 Highest WHIRL Representation FUNC_ENTRY [0x0x2b1c91d8],MID=0 IDNAME O_0 [0x0x2b1c9200],MID=0 IDNAME O_0 [0x0x2b1c921c],MID=1 BODY BLOCK [0x0x2b1c9248],MID=0 END_BLOCK [0x0x2b1c9248] BLOCK [0x0x2b1c9274],MID=1 END_BLOCK [0x0x2b1c9274] BLOCK [0x0x80ed668],MID=2 PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } FUNC_ENTRY (main) IDNAME (argc) IDNAME (argv) BLOCK
10
CMPUT 680 - Compiler Design and Optimization10 Highest WHIRL Representation PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 LOC 1 21 exit(1); I4INTCONST CV(1) (0x1) [0x0x2b1c947c],MID=8 I4PARM Flg(2) T # by_value [0x0x2b1c9460],MID=7 VCALL Flg(126) # flags 0x7e [0x0x2b1c9444],MID=1 END_BLOCK [0x0x80ed698] ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } FUNC_ENTRY (main) IDNAME (argc) IDNAME (argv) BLOCK IF NE CV(2) LDID (argc) int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; }
11
CMPUT 680 - Compiler Design and Optimization11 Highest WHIRL Representation PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 LOC 1 21 exit(1); I4INTCONST CV(1) (0x1) [0x0x2b1c947c],MID=8 I4PARM Flg(2) T # by_value [0x0x2b1c9460],MID=7 VCALL Flg(126) # flags 0x7e [0x0x2b1c9444],MID=1 END_BLOCK [0x0x80ed698] ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } NC_ENTRY (main) BLOCK IF NE CV(2) LDID (argc) BLOCK (THEN) int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } VCALL (printf) VCALL (exit) PARM LDID (stderr) LDA PARM CV(1)
12
CMPUT 680 - Compiler Design and Optimization12 Highest WHIRL Representation PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1c92cc],MID=0 LOC 1 14 double *A; LOC 1 15 double *B; LOC 1 16 double *C; LOC 1 17 LOC 1 18 if(argc != 2) IF [0x0x2b1c92f8],MID=3 I4I4LDID O_0 T [0x0x2b1c9334],MID=0 I4INTCONST CV(2) (0x2) [0x0x2b1c9350],MID=3 I4I4NE [0x0x2b1c9318],MID=2 THEN BLOCK [0x0x80ed698],MID=4 LOC 1 19 { LOC 1 20 fprintf(stderr,"Syntax: linear \n"); U8U8LDID O_0 T [0x0x2b1c93e0],MID=1 U8PARM Flg(2) T # by_value [0x0x2b1c93c4],MID=4 U8LDA O_0 \n\000"> T [0x0x2b1c9418],MID=6 U8PARM Flg(2) T # by_value [0x0x2b1c93fc],MID=5 VCALL Flg(126) # flags 0x7e [0x0x2b1c93a8],MID=0 LOC 1 21 exit(1); I4INTCONST CV(1) (0x1) [0x0x2b1c947c],MID=8 I4PARM Flg(2) T # by_value [0x0x2b1c9460],MID=7 VCALL Flg(126) # flags 0x7e [0x0x2b1c9444],MID=1 END_BLOCK [0x0x80ed698] ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } NC_ENTRY (main) BLOCK IF NE CV(2) LDID (argc) BLOCK (THEN) int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } VCALL (printf) VCALL (exit) PARM LDID (stderr) LDA PARM CV(1) BLOCK (ELSE)
13
CMPUT 680 - Compiler Design and Optimization13 Highest WHIRL Representation ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } LOC 1 23 dimension = atoi(argv[1]); U8U8LDID O_0 T [0x0x2b1c959c],MID=3 U8U8ILOAD O_8 T T [0x0x2b1c9580],MID=2 U8PARM Flg(2) T # by_value [0x0x2b1c9564],MID=9 I4CALL Flg(126) # flags 0x7e [0x0x2b1c9548],MID=2 I4I4LDID O_-1 T [0x0x2b1c95b8],MID=5 I4STID O_264 T # __comma [0x0x80ed788],MID=4 I4I4LDID O_264 T # __comma [0x0x80ed7a8],MID=7 I4STID O_0 T [0x0x2b1c94d4],MID=6 LOC 1 24 LOC 1 25 A = (double *)malloc(dimension*dimension*sizeof(double)); I4I4LDID O_0 T [0x0x2b1c96e4],MID=8 I4I4LDID O_0 T [0x0x2b1c9700],MID=9 I4MPY [0x0x2b1c96c8],MID=13 U8I4CVT [0x0x2b1c96ac],MID=12 U8INTCONST CV(8) (0x8) [0x0x2b1c971c],MID=14 U8MPY [0x0x2b1c9690],MID=11 U8PARM Flg(2) T # by_value [0x0x2b1c9674],MID=10 U8CALL Flg(126) # flags 0x7e [0x0x2b1c9658],MID=3 U8U8LDID O_-1 T [0x0x2b1c9738],MID=11 U8STID O_265 T # __comma [0x0x80ed838],MID=10 U8U8LDID O_265 T # __comma [0x0x80ed858],MID=13 U8STID O_0 T [0x0x2b1c95e4],MID=12 int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } BLOCK IF BLOCK (THEN) VCALL (printf) VCALL (exit) PARM LDID (stderr) LDA PARM CV(1) BLOCK (ELSE) I4CALL (atoi) PARM ILOAD LDID (argv)
14
CMPUT 680 - Compiler Design and Optimization14 Highest WHIRL Representation ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } LOC 1 23 dimension = atoi(argv[1]); U8U8LDID O_0 T [0x0x2b1c959c],MID=3 U8U8ILOAD O_8 T T [0x0x2b1c9580],MID=2 U8PARM Flg(2) T # by_value [0x0x2b1c9564],MID=9 I4CALL Flg(126) # flags 0x7e [0x0x2b1c9548],MID=2 I4I4LDID O_-1 T [0x0x2b1c95b8],MID=5 I4STID O_264 T # __comma [0x0x80ed788],MID=4 I4I4LDID O_264 T # __comma [0x0x80ed7a8],MID=7 I4STID O_0 T [0x0x2b1c94d4],MID=6 LOC 1 24 LOC 1 25 A = (double *)malloc(dimension*dimension*sizeof(double)); I4I4LDID O_0 T [0x0x2b1c96e4],MID=8 I4I4LDID O_0 T [0x0x2b1c9700],MID=9 I4MPY [0x0x2b1c96c8],MID=13 U8I4CVT [0x0x2b1c96ac],MID=12 U8INTCONST CV(8) (0x8) [0x0x2b1c971c],MID=14 U8MPY [0x0x2b1c9690],MID=11 U8PARM Flg(2) T # by_value [0x0x2b1c9674],MID=10 U8CALL Flg(126) # flags 0x7e [0x0x2b1c9658],MID=3 U8U8LDID O_-1 T [0x0x2b1c9738],MID=11 U8STID O_265 T # __comma [0x0x80ed838],MID=10 U8U8LDID O_265 T # __comma [0x0x80ed858],MID=13 U8STID O_0 T [0x0x2b1c95e4],MID=12 int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } BLOCK IF BLOCK (THEN) VCALL (printf) VCALL (exit) PARM LDID (stderr) LDA PARM CV(1) BLOCK (ELSE) I4CALL (atoi) PARM ILOAD LDID (argv) STID (preg) LDID (ret_val.)
15
CMPUT 680 - Compiler Design and Optimization15 Highest WHIRL Representation ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } LOC 1 23 dimension = atoi(argv[1]); U8U8LDID O_0 T [0x0x2b1c959c],MID=3 U8U8ILOAD O_8 T T [0x0x2b1c9580],MID=2 U8PARM Flg(2) T # by_value [0x0x2b1c9564],MID=9 I4CALL Flg(126) # flags 0x7e [0x0x2b1c9548],MID=2 I4I4LDID O_-1 T [0x0x2b1c95b8],MID=5 I4STID O_264 T # __comma [0x0x80ed788],MID=4 I4I4LDID O_264 T # __comma [0x0x80ed7a8],MID=7 I4STID O_0 T [0x0x2b1c94d4],MID=6 LOC 1 24 LOC 1 25 A = (double *)malloc(dimension*dimension*sizeof(double)); I4I4LDID O_0 T [0x0x2b1c96e4],MID=8 I4I4LDID O_0 T [0x0x2b1c9700],MID=9 I4MPY [0x0x2b1c96c8],MID=13 U8I4CVT [0x0x2b1c96ac],MID=12 U8INTCONST CV(8) (0x8) [0x0x2b1c971c],MID=14 U8MPY [0x0x2b1c9690],MID=11 U8PARM Flg(2) T # by_value [0x0x2b1c9674],MID=10 U8CALL Flg(126) # flags 0x7e [0x0x2b1c9658],MID=3 U8U8LDID O_-1 T [0x0x2b1c9738],MID=11 U8STID O_265 T # __comma [0x0x80ed838],MID=10 U8U8LDID O_265 T # __comma [0x0x80ed858],MID=13 U8STID O_0 T [0x0x2b1c95e4],MID=12 int main(int argc, char *argv[]) { int dimension; double *A; double *B; double *C; if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } BLOCK (ELSE) I4CALL (atoi) PARM ILOAD LDID (argv) STID (preg) LDID (ret_val.) STID (dimension) LDID (preg)
16
CMPUT 680 - Compiler Design and Optimization16 Highest WHIRL Representation ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } LOC 1 23 dimension = atoi(argv[1]); U8U8LDID O_0 T [0x0x2b1c959c],MID=3 U8U8ILOAD O_8 T T [0x0x2b1c9580],MID=2 U8PARM Flg(2) T # by_value [0x0x2b1c9564],MID=9 I4CALL Flg(126) # flags 0x7e [0x0x2b1c9548],MID=2 I4I4LDID O_-1 T [0x0x2b1c95b8],MID=5 I4STID O_264 T # __comma [0x0x80ed788],MID=4 I4I4LDID O_264 T # __comma [0x0x80ed7a8],MID=7 I4STID O_0 T [0x0x2b1c94d4],MID=6 LOC 1 24 LOC 1 25 A = (double *)malloc(dimension*dimension*sizeof(double)); I4I4LDID O_0 T [0x0x2b1c96e4],MID=8 I4I4LDID O_0 T [0x0x2b1c9700],MID=9 I4MPY [0x0x2b1c96c8],MID=13 U8I4CVT [0x0x2b1c96ac],MID=12 U8INTCONST CV(8) (0x8) [0x0x2b1c971c],MID=14 U8MPY [0x0x2b1c9690],MID=11 U8PARM Flg(2) T # by_value [0x0x2b1c9674],MID=10 U8CALL Flg(126) # flags 0x7e [0x0x2b1c9658],MID=3 U8U8LDID O_-1 T [0x0x2b1c9738],MID=11 U8STID O_265 T # __comma [0x0x80ed838],MID=10 U8U8LDID O_265 T # __comma [0x0x80ed858],MID=13 U8STID O_0 T [0x0x2b1c95e4],MID=12 int main(int argc, char *argv[]) { ….. if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } STID (dimension) LDID (preg) U8CALL (malloc) PARM U8MPY CV(8)U8I4CVT I4MPY I4I4LDID (dimension) I4I4LDID (dimension)
17
CMPUT 680 - Compiler Design and Optimization17 Highest WHIRL Representation ELSE BLOCK [0x0x80ed6c8],MID=5 END_BLOCK [0x0x80ed6c8] END_IF LOC 1 22 } LOC 1 23 dimension = atoi(argv[1]); U8U8LDID O_0 T [0x0x2b1c959c],MID=3 U8U8ILOAD O_8 T T [0x0x2b1c9580],MID=2 U8PARM Flg(2) T # by_value [0x0x2b1c9564],MID=9 I4CALL Flg(126) # flags 0x7e [0x0x2b1c9548],MID=2 I4I4LDID O_-1 T [0x0x2b1c95b8],MID=5 I4STID O_264 T # __comma [0x0x80ed788],MID=4 I4I4LDID O_264 T # __comma [0x0x80ed7a8],MID=7 I4STID O_0 T [0x0x2b1c94d4],MID=6 LOC 1 24 LOC 1 25 A = (double *)malloc(dimension*dimension*sizeof(double)); I4I4LDID O_0 T [0x0x2b1c96e4],MID=8 I4I4LDID O_0 T [0x0x2b1c9700],MID=9 I4MPY [0x0x2b1c96c8],MID=13 U8I4CVT [0x0x2b1c96ac],MID=12 U8INTCONST CV(8) (0x8) [0x0x2b1c971c],MID=14 U8MPY [0x0x2b1c9690],MID=11 U8PARM Flg(2) T # by_value [0x0x2b1c9674],MID=10 U8CALL Flg(126) # flags 0x7e [0x0x2b1c9658],MID=3 U8U8LDID O_-1 T [0x0x2b1c9738],MID=11 U8STID O_265 T # __comma [0x0x80ed838],MID=10 U8U8LDID O_265 T # __comma [0x0x80ed858],MID=13 U8STID O_0 T [0x0x2b1c95e4],MID=12 int main(int argc, char *argv[]) { ….. if(argc != 2) { fprintf(stderr,"Syntax: linear \n"); exit(1); } dimension = atoi(argv[1]); A = (double *)malloc(dimension*dimension*sizeof(double)); B = (double *)malloc(dimension*sizeof(double)); C = (double *)malloc(dimension*sizeof(double)); InitializeMatrix(A, dimension); InitializeVector(B, dimension); MatrixVectorMultiply(C,A,B,dimension); OutputVector(C,dimension); return 0; } STID (dimension) LDID (preg) U8CALL (malloc) PARM U8MPY CV(8)U8I4CVT I4MPY I4I4LDID (dimension) I4I4LDID (dimension) STID (preg) LDID (ret_val.) STID (A) LDID (preg)
18
CMPUT 680 - Compiler Design and Optimization18 Highest WHIRL Representation LOC 1 52 void MatrixVectorMultiply(double *C, double *A, double *B, int dimension) LOC 1 53 { FUNC_ENTRY [0x0x2b1cad60],MID=0 IDNAME O_0 [0x0x2b1cad90],MID=0 IDNAME O_0 [0x0x2b1cadac],MID=1 IDNAME O_0 [0x0x2b1cadc8],MID=2 IDNAME O_0 [0x0x2b1cade4],MID=3 BODY BLOCK [0x0x2b1cae10],MID=0 END_BLOCK [0x0x2b1cae10] BLOCK [0x0x2b1cae3c],MID=1 END_BLOCK [0x0x2b1cae3c] BLOCK [0x0x2b1cae68],MID=2 PRAGMA ~0 !120 CV(0) (0x0) # PREAMBLE_END [0x0x2b1cae94],MID=0 LOC 1 54 int i, j; LOC 1 55 for(i=0 ; i<dimension ; i++) FUNC_ENTRY (MatrixVectorMultiply) IDNAME (C) IDNAME (A) IDNAME (B) IDNAME (dimension) BLOCK void MatrixVectorMultiply(double *C, double *A, double *B, int dimension) { int i, j; for(i=0 ; i<dimension ; i++) { C[i] = 0.0; for(j=0 ; j<dimension ; j++) C[i] = C[i] + A[i*dimension+j]*B[j]; } BLOCK
19
CMPUT 680 - Compiler Design and Optimization19 Highest WHIRL Representation FUNC_ENTRY (MatrixVectorMultiply) IDNAME (C) IDNAME (A) IDNAME (B) IDNAME (dimension) BLOCK WHILE GT LDID (i) LDID (dimension) STID (i) CV(0) BLOCK LOC 1 54 int i, j; LOC 1 55 for(i=0 ; i<dimension ; i++) I4INTCONST CV(0) (0x0) [0x0x2b1caedc],MID=4 I4STID O_0 T [0x0x2b1caec0],MID=0 WHILE_DO [0x0x2b1caf08],MID=3 I4I4LDID O_0 T [0x0x2b1caf40],MID=1 I4I4LDID O_0 T [0x0x2b1caf5c],MID=2 I4I4GT [0x0x2b1caf24],MID=5 BODY BLOCK [0x0x2b1caf88],MID=4 LOC 1 56 { LOC 1 57 C[i] = 0.0; F8CONST [0x0x2b1cafd0],MID=6 U8U8LDID O_0 T [0x0x2b1cb008],MID=4 I8I4LDID O_0 T [0x0x2b1cb05c],MID=5 U8I8CVT [0x0x2b1cb040],MID=9 U8INTCONST CV(8) (0x8) [0x0x2b1cb078],MID=10 U8MPY [0x0x2b1cb024],MID=8 U8ADD [0x0x2b1cafec],MID=7 F8ISTORE O_0 T [0x0x2b1cafb4],MID=3 void MatrixVectorMultiply(double *C, double *A, double *B, int dimension) { int i, j; for(i=0 ; i<dimension ; i++) { C[i] = 0.0; for(j=0 ; j<dimension ; j++) C[i] = C[i] + A[i*dimension+j]*B[j]; }
20
CMPUT 680 - Compiler Design and Optimization20 LOC 1 54 int i, j; LOC 1 55 for(i=0 ; i<dimension ; i++) I4INTCONST CV(0) (0x0) [0x0x2b1caedc],MID=4 I4STID O_0 T [0x0x2b1caec0],MID=0 WHILE_DO [0x0x2b1caf08],MID=3 I4I4LDID O_0 T [0x0x2b1caf40],MID=1 I4I4LDID O_0 T [0x0x2b1caf5c],MID=2 I4I4GT [0x0x2b1caf24],MID=5 BODY BLOCK [0x0x2b1caf88],MID=4 LOC 1 56 { LOC 1 57 C[i] = 0.0; F8CONST [0x0x2b1cafd0],MID=6 U8U8LDID O_0 T [0x0x2b1cb008],MID=4 I8I4LDID O_0 T [0x0x2b1cb05c],MID=5 U8I8CVT [0x0x2b1cb040],MID=9 U8INTCONST CV(8) (0x8) [0x0x2b1cb078],MID=10 U8MPY [0x0x2b1cb024],MID=8 U8ADD [0x0x2b1cafec],MID=7 F8ISTORE O_0 T [0x0x2b1cafb4],MID=3 void MatrixVectorMultiply(double *C, double *A, double *B, int dimension) { int i, j; for(i=0 ; i<dimension ; i++) { C[i] = 0.0; for(j=0 ; j<dimension ; j++) C[i] = C[i] + A[i*dimension+j]*B[j]; } Highest WHIRL Representation FUNC_ENTRY (MatrixVectorMultiply) IDNAME (C) IDNAME (A) IDNAME (B) IDNAME (dimension) BLOCK WHILE GT LDID (i) LDID (dimension) STID (i) CV(0) BLOCK F8ISTORE U8ADD U8MPY LDID (C) U8I8CVT LDID (i) CV(8) F8CONST(0.0) BLOCK
21
CMPUT 680 - Compiler Design and Optimization21 LOC 1 58 for(j=0 ; j<dimension ; j++) I4INTCONST CV(0) (0x0) [0x0x2b1cb0c0],MID=11 I4STID O_0 T [0x0x2b1cb0a4],MID=6 WHILE_DO [0x0x2b1cb0ec],MID=5 I4I4LDID O_0 T [0x0x2b1cb124],MID=7 I4I4LDID O_0 T [0x0x2b1cb140],MID=8 I4I4GT [0x0x2b1cb108],MID=12 BODY BLOCK [0x0x2b1cb16c],MID=6 void MatrixVectorMultiply(double *C, double *A, double *B, int dimension) { int i, j; for(i=0 ; i<dimension ; i++) { C[i] = 0.0; for(j=0 ; j<dimension ; j++) C[i] = C[i] + A[i*dimension+j]*B[j]; } Highest WHIRL Representation FUNC_ENTRY (MatrixVectorMultiply) IDNAME (C) IDNAME (A) IDNAME (B) IDNAME (dimension) BLOCK WHILE GT LDID (i) LDID (dimension) STID (i) CV(0) BLOCK F8ISTORE U8ADD U8MPY LDID (C) U8I8CVT LDID (i) CV(8) F8CONST(0.0) BLOCK STID (j) CV(0) WHILE GT LDID (j) LDID (dimension) BLOCK
22
CMPUT 680 - Compiler Design and Optimization22 LOC 1 59 C[i] = C[i] + A[i*dimension+j]*B[j]; U8U8LDID O_0 T [0x0x2b1cb208],MID=11 I8I4LDID O_0 T [0x0x2b1cb25c],MID=12 U8I8CVT [0x0x2b1cb240],MID=16 U8INTCONST CV(8) (0x8) [0x0x2b1cb278],MID=17 U8MPY [0x0x2b1cb224],MID=15 U8ADD [0x0x2b1cb1ec],MID=14 F8F8ILOAD O_0 T T [0x0x2b1cb1d0],MID=10 U8U8LDID O_0 T [0x0x2b1cb2e8],MID=14 I4I4LDID O_0 T [0x0x2b1cb358],MID=15 I4I4LDID O_0 T [0x0x2b1cb390],MID=16 I4I4LDID O_0 T [0x0x2b1cb3ac],MID=17 I4MPY [0x0x2b1cb374],MID=23 I4ADD [0x0x2b1cb33c],MID=22 U8I4CVT [0x0x2b1cb320],MID=21 U8INTCONST CV(8) (0x8) [0x0x2b1cb3c8],MID=24 U8MPY [0x0x2b1cb304],MID=20 U8ADD [0x0x2b1cb2cc],MID=19 F8F8ILOAD O_0 T T [0x0x2b1cb2b0],MID=13 U8U8LDID O_0 T [0x0x2b1cb41c],MID=19 I8I4LDID O_0 T [0x0x2b1cb470],MID=20 U8I8CVT [0x0x2b1cb454],MID=27 U8INTCONST CV(8) (0x8) [0x0x2b1cb48c],MID=28 U8MPY [0x0x2b1cb438],MID=26 U8ADD [0x0x2b1cb400],MID=25 F8F8ILOAD O_0 T T [0x0x2b1cb3e4],MID=18 F8MPY [0x0x2b1cb294],MID=18 F8ADD [0x0x2b1cb1b4],MID=13 U8U8LDID O_0 T [0x0x2b1cb4c4],MID=21 I8I4LDID O_0 T [0x0x2b1cb518],MID=22 U8I8CVT [0x0x2b1cb4fc],MID=31 U8INTCONST CV(8) (0x8) [0x0x2b1cb534],MID=32 U8MPY [0x0x2b1cb4e0],MID=30 U8ADD [0x0x2b1cb4a8],MID=29 F8ISTORE O_0 T [0x0x2b1cb198],MID=9 LABEL L2 Flg(0) [0x0x2b1cb560],MID=0 I4I4LDID O_0 T [0x0x2b1cb5c4],MID=24 LABEL L2 Flg(0) [0x0x2b1cb560],MID=0 I4I4LDID O_0 T [0x0x2b1cb5c4],MID=24 I4INTCONST CV(1) (0x1) [0x0x2b1cb5e0],MID=34 I4ADD [0x0x2b1cb5a8],MID=33 I4STID O_0 T [0x0x2b1cb58c],MID=23 END_BLOCK [0x0x2b1cb16c]
23
F8F8ILOAD U8ADD U8MPY LDID ( B ) U8I8CVT LDID ( j ) CV(8) F8F8ILOAD U8ADD U8MPY LDID ( A ) U8I4CVT I4ADD CV(8) I4MPY LDID ( i ) LDID (dimension) LDID ( j ) F8MPYF8F8ILOAD U8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ADDU8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ISTORE ADD LDID ( j ) CV(1) I4STID ( j ) BLOCK LOC 1 59 C[i] = C[i] + A[i*dimension+j]*B[j];
24
F8F8ILOAD U8ADD U8MPY LDID ( B ) U8I8CVT LDID ( j ) CV(8) F8F8ILOAD U8ADD U8MPY LDID ( A ) U8I4CVT I4ADD CV(8) I4MPY LDID ( i ) LDID (dimension) LDID ( j ) F8MPYF8F8ILOAD U8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ADDU8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ISTORE ADD LDID ( j ) CV(1) I4STID ( j ) BLOCK LOC 1 59 C[i] = C[i] + A[i*dimension+j]*B[j]; load B[j]
25
F8F8ILOAD U8ADD U8MPY LDID ( B ) U8I8CVT LDID ( j ) CV(8) F8F8ILOAD U8ADD U8MPY LDID ( A ) U8I4CVT I4ADD CV(8) I4MPY LDID ( i ) LDID (dimension) LDID ( j ) F8MPYF8F8ILOAD U8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ADDU8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ISTORE ADD LDID ( j ) CV(1) I4STID ( j ) BLOCK LOC 1 59 C[i] = C[i] + A[i*dimension+j]*B[j]; load A[i*dimesion+j]
26
F8F8ILOAD U8ADD U8MPY LDID ( B ) U8I8CVT LDID ( j ) CV(8) F8F8ILOAD U8ADD U8MPY LDID ( A ) U8I4CVT I4ADD CV(8) I4MPY LDID ( i ) LDID (dimension) LDID ( j ) F8MPYF8F8ILOAD U8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ADDU8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ISTORE ADD LDID ( j ) CV(1) I4STID ( j ) BLOCK LOC 1 59 C[i] = C[i] + A[i*dimension+j]*B[j]; load C[i]
27
F8F8ILOAD U8ADD U8MPY LDID ( B ) U8I8CVT LDID ( j ) CV(8) F8F8ILOAD U8ADD U8MPY LDID ( A ) U8I4CVT I4ADD CV(8) I4MPY LDID ( i ) LDID (dimension) LDID ( j ) F8MPYF8F8ILOAD U8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ADDU8ADD U8MPY LDID ( C ) U8I8CVT LDID ( i ) CV(8) F8ISTORE ADD LDID ( j ) CV(1) I4STID ( j ) BLOCK LOC 1 59 C[i] = C[i] + A[i*dimension+j]*B[j]; j++
28
F8ISTORE U8ADD U8MPY LDID (C) U8I8CVT LDID (i) CV(8) F8CONST(0.0) BLOCK WHILE GT LDID (I) LDID (dimension) BLOCK IDNAME (C) STID (j) CV(0) FUNC_ENTRY (MatrixVectorMultiply) IDNAME (A) IDNAME (B) IDNAME (dimension) BLOCK WHILE GT LDID (I) LDID (dimension) STID (i) CV(0) BLOCK Highest WHIRL Representation.
29
GT LDID (I) LDID (dimension) IDNAME (C) STID (j) CV(0) FUNC_ENTRY (MatrixVectorMultiply) IDNAME (A) IDNAME (B) IDNAME (dimension) BLOCK FALSEBR L4 GT LDID (I) LDID (dimension) STID (i) CV(0) BLOCK STID (C) LDID ($r32) STID (A) LDID ($r33) STID (B) LDID ($r34) STID (dimension) LDID ($r35) U8I8CVT U8ADD U8MPY LDID (C) LDID (i) CV(8) F8CONST(0.0) LABEL L3 F8ISTORE FALSEBR L5 After five lowering steps.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.