13fb6909fccaf0ffec3834fbe469f49d503dc613
[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 InitializeMixed(Mixed_t* M, int base)
29 {
30   double sum;
31   int i, j;
32   
33   for (i=0; i < 10; ++i) {
34     int coord;
35     coord = i + base;
36     M->A[i] = coord;
37     sum += coord;
38   }
39   
40   for (i=0; i < 10; ++i)
41     for (j=0; j < 10; ++j) {
42       int coord;
43       coord = i*10 + j + base;
44       M->B[i][j] = coord;
45       sum += coord;
46     }
47   
48   for (i=0; i < 10; ++i) {
49     double ratio;
50     M->F[i].c = 'Q';
51     ratio = i / 10 + base;
52     M->F[i].x = ratio;
53     sum += ratio;
54   }
55   
56   return sum;
57 }
58
59 int
60 main(int argc, char** argv)
61 {
62   Mixed_t M;
63   Mixed_t MA[4];
64   int i;
65   
66   printf("Sum(M)  = %.2f\n", InitializeMixed(&M, 100));
67   
68   for (i=0; i < 4; i++)
69     printf("Sum(MA[%d]) = %.2f\n", i, InitializeMixed(&MA[i], 400));
70
71   return 0;
72 }