xref: /llvm-project/llvm/test/Transforms/HipStdPar/allocation-interposition.ll (revision 335f1a72b22560e61f6170efef740c9c26b24f1a)
1; RUN: opt -S -passes=hipstdpar-interpose-alloc %s | FileCheck %s
2
3%"struct.std::nothrow_t" = type { i8 }
4
5@_ZSt7nothrow = external global %"struct.std::nothrow_t", align 1
6
7declare ptr @__hipstdpar_aligned_alloc(i64, i64)
8
9declare ptr @__hipstdpar_malloc(i64)
10
11declare ptr @__hipstdpar_calloc(i64, i64)
12
13declare i32 @__hipstdpar_posix_aligned_alloc(ptr, i64, i64)
14
15declare void @__hipstdpar_hidden_free(ptr)
16
17declare ptr @__hipstdpar_hidden_malloc(i64)
18
19declare ptr @__hipstdpar_realloc(ptr, i64)
20
21declare ptr @__hipstdpar_realloc_array(ptr, i64, i64)
22
23declare void @__hipstdpar_free(ptr)
24
25declare ptr @__hipstdpar_operator_new_aligned(i64, i64)
26
27declare ptr @__hipstdpar_operator_new(i64)
28
29declare ptr @__hipstdpar_operator_new_nothrow(i64, %"struct.std::nothrow_t")
30
31declare ptr @__hipstdpar_operator_new_aligned_nothrow(i64, i64, %"struct.std::nothrow_t")
32
33declare void @__hipstdpar_operator_delete_aligned_sized(ptr, i64, i64)
34
35declare void @__hipstdpar_operator_delete(ptr)
36
37declare void @__hipstdpar_operator_delete_aligned(ptr, i64)
38
39declare void @__hipstdpar_operator_delete_sized(ptr, i64)
40
41define dso_local noundef i32 @allocs() {
42  ; CHECK: %1 = call noalias align 8 ptr @__hipstdpar_aligned_alloc(i64 noundef 8, i64 noundef 42)
43  %1 = call noalias align 8 ptr @aligned_alloc(i64 noundef 8, i64 noundef 42)
44  ; CHECK: call void @__hipstdpar_free(ptr noundef %1)
45  call void @free(ptr noundef %1)
46
47  ; CHECK: %2 = call noalias ptr @__hipstdpar_calloc(i64 noundef 1, i64 noundef 42)
48  %2 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 42)
49  ; CHECK: call void @__hipstdpar_free(ptr noundef %2)
50  call void @free(ptr noundef %2)
51
52  ; CHECK: %3 = call noalias ptr @__hipstdpar_malloc(i64 noundef 42)
53  %3 = call noalias ptr @malloc(i64 noundef 42)
54  ; CHECK: call void @__hipstdpar_free(ptr noundef %3)
55  call void @free(ptr noundef %3)
56
57  ; CHECK: %4 = call noalias align 8 ptr @__hipstdpar_aligned_alloc(i64 noundef 8, i64 noundef 42)
58  %4 = call noalias align 8 ptr @memalign(i64 noundef 8, i64 noundef 42)
59  ; CHECK: call void @__hipstdpar_free(ptr noundef %4)
60  call void @free(ptr noundef %4)
61
62  %tmp = alloca ptr, align 8
63  ; CHECK: %5 = call i32 @__hipstdpar_posix_aligned_alloc(ptr noundef %tmp, i64 noundef 8, i64 noundef 42)
64  %5 = call i32 @posix_memalign(ptr noundef %tmp, i64 noundef 8, i64 noundef 42)
65  ; CHECK: call void @__hipstdpar_free(ptr noundef %tmp)
66  call void @free(ptr noundef %tmp)
67
68  ; CHECK: %6 = call noalias ptr @__hipstdpar_malloc(i64 noundef 42)
69  %6 = call noalias ptr @malloc(i64 noundef 42)
70  ; CHECK: %7 = call ptr @__hipstdpar_realloc(ptr noundef %6, i64 noundef 42)
71  %7 = call ptr @realloc(ptr noundef %6, i64 noundef 42)
72  ; CHECK: call void @__hipstdpar_free(ptr noundef %7)
73  call void @free(ptr noundef %7)
74
75  ; CHECK: %8 = call noalias ptr @__hipstdpar_calloc(i64 noundef 1, i64 noundef 42)
76  %8 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 42)
77  ; CHECK: %9 = call ptr @__hipstdpar_realloc_array(ptr noundef %8, i64 noundef 1, i64 noundef 42)
78  %9 = call ptr @reallocarray(ptr noundef %8, i64 noundef 1, i64 noundef 42)
79  ; CHECK: call void @__hipstdpar_free(ptr noundef %9)
80  call void @free(ptr noundef %9)
81
82  ; CHECK: %10 = call noalias noundef nonnull ptr @__hipstdpar_operator_new(i64 noundef 1)
83  %10 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 1)
84  ; CHECK: call void @__hipstdpar_operator_delete(ptr noundef %10)
85  call void @_ZdlPv(ptr noundef %10)
86
87  ; CHECK: %11 = call noalias noundef nonnull align 8 ptr @__hipstdpar_operator_new_aligned(i64 noundef 1, i64 noundef 8)
88  %11 = call noalias noundef nonnull align 8 ptr @_ZnwmSt11align_val_t(i64 noundef 1, i64 noundef 8)
89  ; CHECK: call void @__hipstdpar_operator_delete_aligned(ptr noundef %11, i64 noundef 8)
90  call void @_ZdlPvSt11align_val_t(ptr noundef %11, i64 noundef 8)
91
92  ; CHECK: %12 = call noalias noundef ptr @__hipstdpar_operator_new_nothrow(i64 noundef 1, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
93  %12 = call noalias noundef ptr @_ZnwmRKSt9nothrow_t(i64 noundef 1, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
94  ; CHECK: call void @__hipstdpar_operator_delete(ptr noundef %12)
95  call void @_ZdlPv(ptr noundef %12)
96
97  ; CHECK: %13 = call noalias noundef align 8 ptr @__hipstdpar_operator_new_aligned_nothrow(i64 noundef 1, i64 noundef 8, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
98  %13 = call noalias noundef align 8 ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 noundef 1, i64 noundef 8, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
99  ; CHECK: call void @__hipstdpar_operator_delete_aligned(ptr noundef %13, i64 noundef 8)
100  call void @_ZdlPvSt11align_val_t(ptr noundef %13, i64 noundef 8)
101
102  ; CHECK: %14 = call noalias noundef nonnull ptr @__hipstdpar_operator_new(i64 noundef 42)
103  %14 = call noalias noundef nonnull ptr @_Znam(i64 noundef 42)
104  ; CHECK: call void @__hipstdpar_operator_delete(ptr noundef %14)
105  call void @_ZdaPv(ptr noundef %14)
106
107  ; CHECK: %15 = call noalias noundef nonnull align 8 ptr @__hipstdpar_operator_new_aligned(i64 noundef 42, i64 noundef 8)
108  %15 = call noalias noundef nonnull align 8 ptr @_ZnamSt11align_val_t(i64 noundef 42, i64 noundef 8)
109  ; CHECK: call void @__hipstdpar_operator_delete_aligned(ptr noundef %15, i64 noundef 8)
110  call void @_ZdaPvSt11align_val_t(ptr noundef %15, i64 noundef 8)
111
112  ; CHECK:  %16 = call noalias noundef ptr @__hipstdpar_operator_new_nothrow(i64 noundef 42, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
113  %16 = call noalias noundef ptr @_ZnamRKSt9nothrow_t(i64 noundef 42, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
114  ; CHECK: call void @__hipstdpar_operator_delete(ptr noundef %16)
115  call void @_ZdaPv(ptr noundef %16)
116
117  ; CHECK: %17 = call noalias noundef align 8 ptr @__hipstdpar_operator_new_aligned_nothrow(i64 noundef 42, i64 noundef 8, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
118  %17 = call noalias noundef align 8 ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64 noundef 42, i64 noundef 8, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
119  ; CHECK: call void @__hipstdpar_operator_delete_aligned(ptr noundef %17, i64 noundef 8)
120  call void @_ZdaPvSt11align_val_t(ptr noundef %17, i64 noundef 8)
121
122  ; CHECK:  %18 = call ptr @__hipstdpar_calloc(i64 noundef 1, i64 noundef 42)
123  %18 = call ptr @calloc(i64 noundef 1, i64 noundef 42)
124  ; CHECK: call void @__hipstdpar_free(ptr noundef %18)
125  call void @free(ptr noundef %18)
126
127  ; CHECK: %19 = call ptr @__hipstdpar_malloc(i64 noundef 42)
128  %19 = call ptr @malloc(i64 noundef 42)
129  ; CHECK: call void @__hipstdpar_free(ptr noundef %19)
130  call void @free(ptr noundef %19)
131
132  ; CHECK: %20 = call noalias noundef nonnull ptr @__hipstdpar_operator_new(i64 noundef 42)
133  %20 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 42)
134  ; CHECK: call void @__hipstdpar_operator_delete(ptr noundef %20)
135  call void @_ZdlPv(ptr noundef %20)
136
137  ; CHECK:  %21 = call noalias noundef nonnull align 8 ptr @__hipstdpar_operator_new_aligned(i64 noundef 42, i64 noundef 8)
138  %21 = call noalias noundef nonnull align 8 ptr @_ZnwmSt11align_val_t(i64 noundef 42, i64 noundef 8)
139  ; CHECK: call void @__hipstdpar_operator_delete_aligned(ptr noundef %21, i64 noundef 8)
140  call void @_ZdlPvSt11align_val_t(ptr noundef %21, i64 noundef 8)
141
142  ; CHECK: %22 = call noalias noundef ptr @__hipstdpar_operator_new_nothrow(i64 noundef 42, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
143  %22 = call noalias noundef ptr @_ZnwmRKSt9nothrow_t(i64 noundef 42, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
144  ; CHECK: call void @__hipstdpar_operator_delete(ptr noundef %22)
145  call void @_ZdlPv(ptr noundef %22)
146
147  ; CHECK:  %23 = call noalias noundef align 8 ptr @__hipstdpar_operator_new_aligned_nothrow(i64 noundef 42, i64 noundef 8, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
148  %23 = call noalias noundef align 8 ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 noundef 42, i64 noundef 8, ptr noundef nonnull align 1 dereferenceable(1) @_ZSt7nothrow)
149  ; CHECK: call void @__hipstdpar_operator_delete_aligned(ptr noundef %23, i64 noundef 8)
150  call void @_ZdlPvSt11align_val_t(ptr noundef %23, i64 noundef 8)
151
152  ; CHECK: %24 = call ptr @__hipstdpar_malloc(i64 noundef 42)
153  %24 = call ptr @malloc(i64 noundef 42)
154  ; CHECK: %25 = call ptr @__hipstdpar_realloc(ptr noundef %24, i64 noundef 41)
155  %25 = call ptr @realloc(ptr noundef %24, i64 noundef 41)
156  ; CHECK: call void @__hipstdpar_free(ptr noundef %25)
157  call void @free(ptr noundef %25)
158
159  ; CHECK: %26 = call ptr @__hipstdpar_calloc(i64 noundef 1, i64 noundef 42)
160  %26 = call ptr @__libc_calloc(i64 noundef 1, i64 noundef 42)
161  ; CHECK: call void @__hipstdpar_free(ptr noundef %26)
162  call void @__libc_free(ptr noundef %26)
163
164  ; CHECK: %27 = call ptr @__hipstdpar_malloc(i64 noundef 42)
165  %27 = call ptr @__libc_malloc(i64 noundef 42)
166  ; CHECK: call void @__hipstdpar_free(ptr noundef %27)
167  call void @__libc_free(ptr noundef %27)
168
169  ; CHECK: %28 = call ptr @__hipstdpar_aligned_alloc(i64 noundef 8, i64 noundef 42)
170  %28 = call ptr @__libc_memalign(i64 noundef 8, i64 noundef 42)
171  ; CHECK: call void @__hipstdpar_free(ptr noundef %28)
172  call void @__libc_free(ptr noundef %28)
173
174  ret i32 0
175}
176
177declare noalias ptr @aligned_alloc(i64 noundef, i64 noundef)
178
179declare void @free(ptr noundef)
180
181declare noalias ptr @calloc(i64 noundef, i64 noundef)
182
183declare noalias ptr @malloc(i64 noundef)
184
185declare noalias ptr @memalign(i64 noundef, i64 noundef)
186
187declare i32 @posix_memalign(ptr noundef, i64 noundef, i64 noundef)
188
189declare ptr @realloc(ptr noundef, i64 noundef)
190
191declare ptr @reallocarray(ptr noundef, i64 noundef, i64 noundef)
192
193declare noundef nonnull ptr @_Znwm(i64 noundef)
194
195declare void @_ZdlPv(ptr noundef)
196
197declare noalias noundef nonnull ptr @_ZnwmSt11align_val_t(i64 noundef, i64 noundef)
198
199declare void @_ZdlPvSt11align_val_t(ptr noundef, i64 noundef)
200
201declare noalias noundef ptr @_ZnwmRKSt9nothrow_t(i64 noundef, ptr noundef nonnull align 1 dereferenceable(1))
202
203declare noalias noundef ptr @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 noundef, i64 noundef, ptr noundef nonnull align 1 dereferenceable(1))
204
205declare noundef nonnull ptr @_Znam(i64 noundef)
206
207declare void @_ZdaPv(ptr noundef)
208
209declare noalias noundef nonnull ptr @_ZnamSt11align_val_t(i64 noundef, i64 noundef)
210
211declare void @_ZdaPvSt11align_val_t(ptr noundef, i64 noundef)
212
213declare noalias noundef ptr @_ZnamRKSt9nothrow_t(i64 noundef, ptr noundef nonnull align 1 dereferenceable(1))
214
215declare noalias noundef ptr @_ZnamSt11align_val_tRKSt9nothrow_t(i64 noundef, i64 noundef, ptr noundef nonnull align 1 dereferenceable(1))
216
217declare ptr @__libc_calloc(i64 noundef, i64 noundef)
218
219declare void @__libc_free(ptr noundef)
220
221declare ptr @__libc_malloc(i64 noundef)
222
223declare ptr @__libc_memalign(i64 noundef, i64 noundef)