[test] Pre-commit llvm.experimental.memset.pattern tests prior to MemoryLocation...
[llvm-project.git] / llvm / test / tools / llvm-profdata / Inputs / update_memprof_inputs.sh
blob10c36a834c06a74ea4c4eb66d2950531c4276110
1 #!/bin/bash
3 if [ -z $1 ]; then
4 echo "Path to clang required!"
5 echo "Usage: update_memprof_inputs.sh /path/to/updated/clang"
6 exit 1
7 else
8 CLANG=$1
9 fi
11 # Allows the script to be invoked from other directories.
12 OUTDIR=$(dirname $(realpath -s $0))
14 read -r -d '' BASIC << EOF
15 #include <stdlib.h>
16 #include <string.h>
17 int main(int argc, char **argv) {
18 char *x = (char *)malloc(10);
19 memset(x, 0, 10);
20 free(x);
21 x = (char *)malloc(10);
22 memset(x, 0, 10);
23 free(x);
24 return 0;
26 EOF
28 read -r -d '' INLINE << EOF
29 #include <stdlib.h>
30 #include <string.h>
32 __attribute__((always_inline))
33 void qux(int x) {
34 char *ptr = (char*) malloc(x);
35 memset(ptr, 0, x);
36 free(ptr);
39 __attribute__((noinline))
40 void foo(int x){ qux(x); }
42 __attribute__((noinline))
43 void bar(int x) { foo(x); }
45 int main(int argc, char **argv) {
46 bar(argc);
47 return 0;
49 EOF
51 read -r -d '' MULTI << EOF
52 #include <sanitizer/memprof_interface.h>
53 #include <stdlib.h>
54 #include <string.h>
55 int main(int argc, char **argv) {
56 char *x = (char *)malloc(10);
57 memset(x, 0, 10);
58 free(x);
59 __memprof_profile_dump();
60 x = (char *)malloc(10);
61 memset(x, 0, 10);
62 free(x);
63 return 0;
65 EOF
67 read -r -d '' BASIC_HISTOGRAM << EOF
68 struct A {
69 long int a;
70 long int b;
71 long int c;
72 long int d;
73 long int e;
74 long int f;
75 long int g;
76 long int h;
77 A() {};
80 void foo() {
81 long int acc = 0;
82 A *a = new A();
83 acc += a->a;
84 acc += a->b;
85 acc += a->c;
86 acc += a->d;
87 acc += a->e;
88 acc += a->f;
89 acc += a->g;
90 acc += a->h;
91 delete a;
93 void bar() {
94 long int acc = 0;
95 A *a = new A();
96 acc += a->a;
97 acc += a->a;
98 acc += a->a;
99 acc += a->a;
100 acc += a->a;
101 acc += a->a;
102 acc += a->a;
103 acc += a->a;
104 acc += a->b;
105 acc += a->b;
106 acc += a->b;
107 acc += a->b;
108 acc += a->b;
109 acc += a->b;
110 acc += a->b;
111 acc += a->c;
112 acc += a->c;
113 acc += a->c;
114 acc += a->c;
115 acc += a->c;
116 acc += a->c;
117 acc += a->d;
118 acc += a->d;
119 acc += a->d;
120 acc += a->d;
121 acc += a->d;
122 acc += a->e;
123 acc += a->e;
124 acc += a->e;
125 acc += a->e;
126 acc += a->f;
127 acc += a->f;
128 acc += a->f;
129 acc += a->g;
130 acc += a->g;
131 acc += a->h;
133 delete a;
136 int main(int argc, char **argv) {
137 long int acc = 0;
138 A *a = new A();
139 acc += a->a;
140 acc += a->b;
141 acc += a->c;
142 acc += a->d;
143 acc += a->e;
144 acc += a->f;
145 acc += a->g;
146 acc += a->h;
148 delete a;
150 A *b = new A();
151 acc += b->a;
152 acc += b->a;
153 acc += b->a;
154 acc += b->a;
155 acc += b->a;
156 acc += b->a;
157 acc += b->a;
158 acc += b->a;
159 acc += b->b;
160 acc += b->b;
161 acc += b->b;
162 acc += b->b;
163 acc += b->b;
164 acc += b->b;
165 acc += b->b;
166 acc += b->c;
167 acc += b->c;
168 acc += b->c;
169 acc += b->c;
170 acc += b->c;
171 acc += b->c;
172 acc += b->d;
173 acc += b->d;
174 acc += b->d;
175 acc += b->d;
176 acc += b->d;
177 acc += b->e;
178 acc += b->e;
179 acc += b->e;
180 acc += b->e;
181 acc += b->f;
182 acc += b->f;
183 acc += b->f;
184 acc += b->g;
185 acc += b->g;
186 acc += b->h;
188 delete b;
190 A *c = new A();
191 acc += c->a;
193 for (int i = 0; i < 21; ++i) {
195 foo();
198 for (int i = 0; i < 21; ++i) {
200 bar();
203 return 0;
207 read -r -d '' PADDING_HISTOGRAM << EOF
208 struct A {
209 char a;
210 char b;
211 long int c;
212 char d;
213 int e;
214 A() {};
217 struct B {
218 double x;
219 double y;
220 B() {};
223 struct C {
224 A a;
225 char z;
226 B b;
227 C() {};
230 int main(int argc, char **argv) {
231 long int acc = 0;
233 A *a = new A();
234 acc += a->a;
235 acc += a->b;
236 acc += a->c;
237 acc += a->d;
238 acc += a->e;
240 C *c = new C();
241 acc += c->a.a;
242 acc += c->a.a;
243 acc += c->b.x;
244 acc += c->b.y;
246 return 0;
251 DEFAULT_MEMPROF_FLAGS="-fuse-ld=lld -Wl,--no-rosegment -gmlt -fdebug-info-for-profiling -fmemory-profile -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -m64 -Wl,-build-id -no-pie"
253 # Map each test to their source and any additional flags separated by ;
254 declare -A INPUTS
255 INPUTS["basic"]="BASIC"
256 INPUTS["inline"]="INLINE"
257 INPUTS["multi"]="MULTI"
258 INPUTS["pic"]="BASIC;-pie"
259 INPUTS["buildid"]="BASIC;-Wl,-build-id=sha1"
261 for name in "${!INPUTS[@]}"; do
262 IFS=";" read -r src flags <<< "${INPUTS[$name]}"
263 echo "${!src}" > ${OUTDIR}/${name}.c
264 ${CLANG} ${DEFAULT_MEMPROF_FLAGS} ${flags} ${OUTDIR}/${name}.c -o ${OUTDIR}/${name}.memprofexe
265 env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/${name}.memprofexe > ${OUTDIR}/${name}.memprofraw
266 rm ${OUTDIR}/${name}.c
267 done
270 DEFAULT_HIST_FLAGS="${DEFAULT_MEMPROF_FLAGS} -mllvm -memprof-use-callbacks=true -mllvm -memprof-histogram"
273 # Map each test to their source and any additional flags separated by ;
274 declare -A HISTOGRAM_INPUTS
275 HISTOGRAM_INPUTS["basic-histogram"]="BASIC_HISTOGRAM"
276 HISTOGRAM_INPUTS["padding-histogram"]="PADDING_HISTOGRAM"
278 for name in "${!HISTOGRAM_INPUTS[@]}"; do
279 IFS=";" read -r src flags <<< "${HISTOGRAM_INPUTS[$name]}"
280 echo "${!src}" > ${OUTDIR}/${name}.c
281 ${CLANG} ${DEFAULT_HIST_FLAGS} ${flags} ${OUTDIR}/${name}.c -o ${OUTDIR}/${name}.memprofexe
282 env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/${name}.memprofexe > ${OUTDIR}/${name}.memprofraw
283 rm ${OUTDIR}/${name}.c
284 done