From 79c738599bb3683380f778bd4c101b3b13d05ff2 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Sun, 24 Mar 2002 03:17:16 +0000 Subject: [PATCH] Regression tests for DecomposeMultiDimRefs pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1958 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Transforms/DecomposeMultiDimRefs/Makefile | 10 +++ .../DecomposeMultiDimRefs/mixedindices.c | 72 +++++++++++++++++++ .../DecomposeMultiDimRefs/multidim.ll | 47 ++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 test/Transforms/DecomposeMultiDimRefs/Makefile create mode 100644 test/Transforms/DecomposeMultiDimRefs/mixedindices.c create mode 100644 test/Transforms/DecomposeMultiDimRefs/multidim.ll diff --git a/test/Transforms/DecomposeMultiDimRefs/Makefile b/test/Transforms/DecomposeMultiDimRefs/Makefile new file mode 100644 index 00000000000..dac45dac748 --- /dev/null +++ b/test/Transforms/DecomposeMultiDimRefs/Makefile @@ -0,0 +1,10 @@ +# test/Regression/Transforms/DecomposeArrayRefs/Makefile +# +# This directory contains regression tests for the DecomposeArrayRefs pass. +# Since the main tests are single C source files, we'll use the same +# Makefile as test/Programs/SingleSource. +# The *.ll tests are mainly useful to run manually. +# +LEVEL = ../../../.. +include $(LEVEL)/test/Programs/SingleSource/Makefile.singlesrc + diff --git a/test/Transforms/DecomposeMultiDimRefs/mixedindices.c b/test/Transforms/DecomposeMultiDimRefs/mixedindices.c new file mode 100644 index 00000000000..13fb6909fcc --- /dev/null +++ b/test/Transforms/DecomposeMultiDimRefs/mixedindices.c @@ -0,0 +1,72 @@ +/*===- test/Regression/Transforms/Scalar/DecomposeMultiDimRefs.cpp -----=* + * + * This is a regression test for the DecomposeArrayRefs pass. + * It tests several different combinations of structure and + * array indexes in individual references. It does *not* yet + * sufficiently test type-unsafe operations like treating a + * 1-D array as a 2-D or 3-D array. (multidim.ll in this directory + * tests a simple case of that though.) + *===---------------------------------------------------------------------===*/ + +#include +#include + +typedef struct Flat_struct { + char c; + float x; +} Flat_t; + +typedef struct Mixed_struct { + int N; + double A[10]; + double B[10][10]; + Flat_t F[10]; +} Mixed_t; + + +double +InitializeMixed(Mixed_t* M, int base) +{ + double sum; + int i, j; + + for (i=0; i < 10; ++i) { + int coord; + coord = i + base; + M->A[i] = coord; + sum += coord; + } + + for (i=0; i < 10; ++i) + for (j=0; j < 10; ++j) { + int coord; + coord = i*10 + j + base; + M->B[i][j] = coord; + sum += coord; + } + + for (i=0; i < 10; ++i) { + double ratio; + M->F[i].c = 'Q'; + ratio = i / 10 + base; + M->F[i].x = ratio; + sum += ratio; + } + + return sum; +} + +int +main(int argc, char** argv) +{ + Mixed_t M; + Mixed_t MA[4]; + int i; + + printf("Sum(M) = %.2f\n", InitializeMixed(&M, 100)); + + for (i=0; i < 4; i++) + printf("Sum(MA[%d]) = %.2f\n", i, InitializeMixed(&MA[i], 400)); + + return 0; +} diff --git a/test/Transforms/DecomposeMultiDimRefs/multidim.ll b/test/Transforms/DecomposeMultiDimRefs/multidim.ll new file mode 100644 index 00000000000..cacca9cd4cd --- /dev/null +++ b/test/Transforms/DecomposeMultiDimRefs/multidim.ll @@ -0,0 +1,47 @@ + %Flat_struct = type { sbyte, float } + %Flat_t = type { sbyte, float } + %Mixed_struct = type { int, [10 x double], [10 x [10 x double]], [10 x { sbyte, float }] } + %Mixed_t = type { int, [10 x double], [10 x [10 x double]], [10 x { sbyte, float }] } + +%trstr = internal constant [34 x sbyte] c"ENTERING METHOD: int () * %%ain\0A\00" + +declare int "printf"(sbyte *, ...) + +declare int "ArrayRef"([100 x int] * %Array, uint %I, uint %J) + +implementation + +void "InitializeMixed"(%Mixed_struct * %M, int %base) +begin +bb0: ;[#uses=2] + %reg112 = add int %base, 1 ; [#uses=1] + %reg164-idxcast = cast int %reg112 to uint ; [#uses=1] + store sbyte 81, %Mixed_struct * %M, uint 0, ubyte 3, uint %reg164-idxcast, ubyte 0 + + store double 2.17, %Mixed_struct * %M, uint 0, ubyte 1, uint %reg164-idxcast + ret void +end + + +int "main"() +begin +bb0: ;[#uses=1] + %Array = alloca [100 x [100 x int]] + %ArraySlice = getelementptr [100 x [100 x int]]* %Array, uint 0, uint 0 + %trstrP = getelementptr [34 x sbyte] * %trstr, uint 0, uint 0 + + %trace = call int (sbyte *, ...) * %printf( sbyte * %trstrP ) + + %eltVal = call int %ArrayRef([100 x int]* %ArraySlice, uint 8, uint 12) +;; ret int %eltVal + + ret int 0 +end + +int "ArrayRef"([100 x int] * %Array, uint %I, uint %J) +begin +bb0: ;[#uses=3] + %reg120 = getelementptr [100 x int] * %Array, uint %I ; <[100 x int] *> [#uses=1] + %reg121 = load [100 x int] * %reg120, uint 0, uint %J ; [#uses=1] + ret int %reg121; +end -- 2.34.1