Remove the InstrSched directory (moved to SparcV9)
[oota-llvm.git] / test / Transforms / DecomposeMultiDimRefs / mixedindices.c
1 /*===- test/Regression/Transforms/Scalar/DecomposeMultiDimRefs.cpp     -----=*
2  * 
3  * This is a regression test for the DecomposeArrayRefs pass.
4  * It tests several different combinations of structure and
5  * array indexes in individual references.  It does *not* yet
6  * sufficiently test type-unsafe operations like treating a
7  * 1-D array as a 2-D or 3-D array.  (multidim.ll in this directory
8  * tests a simple case of that though.)
9  *===---------------------------------------------------------------------===*/
10
11 #include <stdlib.h>
12 #include <stdio.h>
13
14 typedef struct Flat_struct {
15   char   c;
16   float  x;
17 } Flat_t;
18
19 typedef struct Mixed_struct {
20   int    N;
21   double A[10];
22   double B[10][10];
23   Flat_t F[10];
24 } Mixed_t;
25
26
27 double
28 AddMixed(Mixed_t* M)
29 {
30   double sum = 0;
31   int i, j;
32   
33   for (i=0; i < 10; ++i)
34     sum += M->A[i];
35   
36   for (i=0; i < 10; ++i)
37     for (j=0; j < 10; ++j)
38       sum += M->B[i][j];
39   
40   for (i=0; i < 10; ++i) {
41     sum += (double) M->F[i].c;
42     sum += M->F[i].x;
43   }
44   
45   return sum;
46 }
47
48 void
49 InitializeMixed(Mixed_t* M, int base)
50 {
51   int i, j;
52   
53   for (i=0; i < 10; ++i)
54     M->A[i] = i + base;
55     
56   for (i=0; i < 10; ++i)
57     for (j=0; j < 10; ++j)
58       M->B[i][j] = i*10 + j + base;
59   
60   for (i=0; i < 10; ++i) {
61     M->F[i].c = 'Q';
62     M->F[i].x = i / 10 + base;
63   }
64 }
65
66 int
67 main(int argc, char** argv)
68 {
69   Mixed_t M;
70   Mixed_t MA[4];
71   int i;
72   
73   InitializeMixed(&M, 100);
74   printf("Sum(M)  = %.2f\n", AddMixed(&M));
75   
76   for (i=0; i < 4; i++) {
77     InitializeMixed(&MA[i], 100 * (i+2));
78     printf("Sum(MA[%d]) = %.2f\n", i, AddMixed(&MA[i]));
79   }
80
81   return 0;
82 }