blob: 01a1588461cd863f60e319ce6fb402a967d4ba89 [file] [log] [blame]
Vikram S. Adve79c73852002-03-24 03:17:16 +00001/*===- 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
14typedef struct Flat_struct {
15 char c;
16 float x;
17} Flat_t;
18
19typedef 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
27double
Vikram S. Adve12bcf842002-03-24 13:22:04 +000028AddMixed(Mixed_t* M)
Vikram S. Adve79c73852002-03-24 03:17:16 +000029{
Chris Lattnerdea73e52002-03-24 07:03:10 +000030 double sum = 0;
Vikram S. Adve79c73852002-03-24 03:17:16 +000031 int i, j;
32
Vikram S. Adve12bcf842002-03-24 13:22:04 +000033 for (i=0; i < 10; ++i)
34 sum += M->A[i];
Vikram S. Adve79c73852002-03-24 03:17:16 +000035
36 for (i=0; i < 10; ++i)
Vikram S. Adve12bcf842002-03-24 13:22:04 +000037 for (j=0; j < 10; ++j)
38 sum += M->B[i][j];
Vikram S. Adve79c73852002-03-24 03:17:16 +000039
40 for (i=0; i < 10; ++i) {
Vikram S. Adve12bcf842002-03-24 13:22:04 +000041 sum += (double) M->F[i].c;
42 sum += M->F[i].x;
Vikram S. Adve79c73852002-03-24 03:17:16 +000043 }
44
45 return sum;
46}
47
Vikram S. Adve12bcf842002-03-24 13:22:04 +000048void
49InitializeMixed(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
Vikram S. Adve79c73852002-03-24 03:17:16 +000066int
67main(int argc, char** argv)
68{
69 Mixed_t M;
70 Mixed_t MA[4];
71 int i;
72
Vikram S. Adve12bcf842002-03-24 13:22:04 +000073 InitializeMixed(&M, 100);
74 printf("Sum(M) = %.2f\n", AddMixed(&M));
Vikram S. Adve79c73852002-03-24 03:17:16 +000075
Vikram S. Adve12bcf842002-03-24 13:22:04 +000076 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 }
Vikram S. Adve79c73852002-03-24 03:17:16 +000080
81 return 0;
82}