[HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer (#117017)
[llvm-project.git] / llvm / unittests / Analysis / TargetLibraryInfoTest.cpp
blob97722483aefe0b2114e42ae815a20bcc61f10b5a
1 //===--- TargetLibraryInfoTest.cpp - TLI/LibFunc unit tests ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/TargetLibraryInfo.h"
10 #include "llvm/AsmParser/Parser.h"
11 #include "llvm/IR/DerivedTypes.h"
12 #include "llvm/IR/LLVMContext.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/SourceMgr.h"
15 #include "gtest/gtest.h"
17 using namespace llvm;
19 namespace {
21 class TargetLibraryInfoTest : public testing::Test {
22 protected:
23 LLVMContext Context;
24 TargetLibraryInfoImpl TLII;
25 TargetLibraryInfo TLI;
27 std::unique_ptr<Module> M;
29 TargetLibraryInfoTest() : TLI(TLII) {}
31 void parseAssembly(const char *Assembly) {
32 SMDiagnostic Error;
33 M = parseAssemblyString(Assembly, Error, Context);
35 std::string errMsg;
36 raw_string_ostream os(errMsg);
37 Error.print("", os);
39 if (!M)
40 report_fatal_error(Twine(errMsg));
43 ::testing::AssertionResult isLibFunc(const Function *FDecl,
44 LibFunc ExpectedLF) {
45 StringRef ExpectedLFName = TLI.getName(ExpectedLF);
47 if (!FDecl)
48 return ::testing::AssertionFailure() << ExpectedLFName << " not found";
50 LibFunc F;
51 if (!TLI.getLibFunc(*FDecl, F))
52 return ::testing::AssertionFailure() << ExpectedLFName << " invalid";
54 return ::testing::AssertionSuccess() << ExpectedLFName << " is LibFunc";
58 } // end anonymous namespace
60 // Check that we don't accept egregiously incorrect prototypes.
61 TEST_F(TargetLibraryInfoTest, InvalidProto) {
62 parseAssembly("%foo = type opaque\n");
64 auto *StructTy = StructType::getTypeByName(Context, "foo");
65 auto *InvalidFTy = FunctionType::get(StructTy, /*isVarArg=*/false);
67 for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
68 LibFunc LF = (LibFunc)FI;
69 auto *F = cast<Function>(
70 M->getOrInsertFunction(TLI.getName(LF), InvalidFTy).getCallee());
71 EXPECT_FALSE(isLibFunc(F, LF));
74 // i64 @labs(i32)
76 auto *InvalidLabsFTy = FunctionType::get(Type::getInt64Ty(Context),
77 {Type::getInt32Ty(Context)},
78 /*isVarArg=*/false);
79 auto *F = cast<Function>(
80 M->getOrInsertFunction("labs", InvalidLabsFTy).getCallee());
81 EXPECT_FALSE(isLibFunc(F, LibFunc_labs));
85 TEST_F(TargetLibraryInfoTest, SizeReturningNewInvalidProto) {
86 parseAssembly(
87 "target datalayout = \"p:64:64:64\"\n"
88 ";; Invalid additional params \n"
89 "declare {i8*, i64} @__size_returning_new(i64, i64)\n"
90 ";; Invalid params types \n"
91 "declare {i8*, i64} @__size_returning_new_hot_cold(i64, i32)\n"
92 ";; Invalid return struct types \n"
93 "declare {i8*, i8} @__size_returning_new_aligned(i64, i64)\n"
94 ";; Invalid return type \n"
95 "declare i8* @__size_returning_new_aligned_hot_cold(i64, i64, i8)\n");
97 for (const LibFunc LF :
98 {LibFunc_size_returning_new, LibFunc_size_returning_new_aligned,
99 LibFunc_size_returning_new_hot_cold,
100 LibFunc_size_returning_new_aligned_hot_cold}) {
101 TLII.setAvailable(LF);
102 Function *F = M->getFunction(TLI.getName(LF));
103 ASSERT_NE(F, nullptr);
104 EXPECT_FALSE(isLibFunc(F, LF));
108 // Check that we do accept know-correct prototypes.
109 TEST_F(TargetLibraryInfoTest, ValidProto) {
110 parseAssembly(
111 // These functions use a 64-bit size_t; use the appropriate datalayout.
112 "target datalayout = \"p:64:64:64\"\n"
114 // Struct pointers are replaced with an opaque pointer.
115 "%struct = type opaque\n"
117 // These functions were extracted as-is from the OS X headers.
118 "declare double @__cospi(double)\n"
119 "declare float @__cospif(float)\n"
120 "declare { double, double } @__sincospi_stret(double)\n"
121 "declare <2 x float> @__sincospif_stret(float)\n"
122 "declare double @__sinpi(double)\n"
123 "declare float @__sinpif(float)\n"
124 "declare i32 @abs(i32)\n"
125 "declare i32 @access(i8*, i32)\n"
126 "declare double @acos(double)\n"
127 "declare float @acosf(float)\n"
128 "declare double @acosh(double)\n"
129 "declare float @acoshf(float)\n"
130 "declare x86_fp80 @acoshl(x86_fp80)\n"
131 "declare x86_fp80 @acosl(x86_fp80)\n"
132 "declare i8* @aligned_alloc(i64, i64)\n"
133 "declare double @asin(double)\n"
134 "declare float @asinf(float)\n"
135 "declare double @asinh(double)\n"
136 "declare float @asinhf(float)\n"
137 "declare x86_fp80 @asinhl(x86_fp80)\n"
138 "declare x86_fp80 @asinl(x86_fp80)\n"
139 "declare double @atan(double)\n"
140 "declare double @atan2(double, double)\n"
141 "declare float @atan2f(float, float)\n"
142 "declare x86_fp80 @atan2l(x86_fp80, x86_fp80)\n"
143 "declare float @atanf(float)\n"
144 "declare double @atanh(double)\n"
145 "declare float @atanhf(float)\n"
146 "declare x86_fp80 @atanhl(x86_fp80)\n"
147 "declare x86_fp80 @atanl(x86_fp80)\n"
148 "declare double @atof(i8*)\n"
149 "declare i32 @atoi(i8*)\n"
150 "declare i64 @atol(i8*)\n"
151 "declare i64 @atoll(i8*)\n"
152 "declare i32 @bcmp(i8*, i8*, i64)\n"
153 "declare void @bcopy(i8*, i8*, i64)\n"
154 "declare void @bzero(i8*, i64)\n"
155 "declare i8* @calloc(i64, i64)\n"
156 "declare double @cbrt(double)\n"
157 "declare float @cbrtf(float)\n"
158 "declare x86_fp80 @cbrtl(x86_fp80)\n"
159 "declare double @ceil(double)\n"
160 "declare float @ceilf(float)\n"
161 "declare x86_fp80 @ceill(x86_fp80)\n"
162 "declare i32 @chown(i8*, i32, i32)\n"
163 "declare void @clearerr(%struct*)\n"
164 "declare double @copysign(double, double)\n"
165 "declare float @copysignf(float, float)\n"
166 "declare x86_fp80 @copysignl(x86_fp80, x86_fp80)\n"
167 "declare double @cabs([2 x double])\n"
168 "declare float @cabsf([2 x float])\n"
169 "declare x86_fp80 @cabsl([2 x x86_fp80])\n"
170 "declare double @cos(double)\n"
171 "declare float @cosf(float)\n"
172 "declare double @cosh(double)\n"
173 "declare float @coshf(float)\n"
174 "declare x86_fp80 @coshl(x86_fp80)\n"
175 "declare x86_fp80 @cosl(x86_fp80)\n"
176 "declare i8* @ctermid(i8*)\n"
177 "declare double @exp(double)\n"
178 "declare double @exp2(double)\n"
179 "declare float @exp2f(float)\n"
180 "declare x86_fp80 @exp2l(x86_fp80)\n"
181 "declare float @expf(float)\n"
182 "declare x86_fp80 @expl(x86_fp80)\n"
183 "declare double @expm1(double)\n"
184 "declare float @expm1f(float)\n"
185 "declare x86_fp80 @expm1l(x86_fp80)\n"
186 "declare double @fabs(double)\n"
187 "declare float @fabsf(float)\n"
188 "declare x86_fp80 @fabsl(x86_fp80)\n"
189 "declare i32 @fclose(%struct*)\n"
190 "declare i32 @feof(%struct*)\n"
191 "declare i32 @ferror(%struct*)\n"
192 "declare i32 @fflush(%struct*)\n"
193 "declare i32 @ffs(i32)\n"
194 "declare i32 @ffsl(i64)\n"
195 "declare i32 @ffsll(i64)\n"
196 "declare i32 @fgetc(%struct*)\n"
197 "declare i32 @fgetc_unlocked(%struct*)\n"
198 "declare i32 @fgetpos(%struct*, i64*)\n"
199 "declare i8* @fgets(i8*, i32, %struct*)\n"
200 "declare i8* @fgets_unlocked(i8*, i32, %struct*)\n"
201 "declare i32 @fileno(%struct*)\n"
202 "declare void @flockfile(%struct*)\n"
203 "declare double @floor(double)\n"
204 "declare float @floorf(float)\n"
205 "declare x86_fp80 @floorl(x86_fp80)\n"
206 "declare i32 @fls(i32)\n"
207 "declare i32 @flsl(i64)\n"
208 "declare i32 @flsll(i64)\n"
209 "declare double @fmax(double, double)\n"
210 "declare float @fmaxf(float, float)\n"
211 "declare x86_fp80 @fmaxl(x86_fp80, x86_fp80)\n"
212 "declare double @fmin(double, double)\n"
213 "declare float @fminf(float, float)\n"
214 "declare x86_fp80 @fminl(x86_fp80, x86_fp80)\n"
215 "declare double @fmaximum_num(double, double)\n"
216 "declare float @fmaximum_numf(float, float)\n"
217 "declare x86_fp80 @fmaximum_numl(x86_fp80, x86_fp80)\n"
218 "declare double @fminimum_num(double, double)\n"
219 "declare float @fminimum_numf(float, float)\n"
220 "declare x86_fp80 @fminimum_numl(x86_fp80, x86_fp80)\n"
221 "declare double @fmod(double, double)\n"
222 "declare float @fmodf(float, float)\n"
223 "declare x86_fp80 @fmodl(x86_fp80, x86_fp80)\n"
224 "declare i32 @fprintf(%struct*, i8*, ...)\n"
225 "declare i32 @fputc(i32, %struct*)\n"
226 "declare i32 @fputc_unlocked(i32, %struct*)\n"
227 "declare i64 @fread(i8*, i64, i64, %struct*)\n"
228 "declare i64 @fread_unlocked(i8*, i64, i64, %struct*)\n"
229 "declare void @free(i8*)\n"
230 "declare double @frexp(double, i32*)\n"
231 "declare float @frexpf(float, i32*)\n"
232 "declare x86_fp80 @frexpl(x86_fp80, i32*)\n"
233 "declare i32 @fscanf(%struct*, i8*, ...)\n"
234 "declare i32 @fseek(%struct*, i64, i32)\n"
235 "declare i32 @fseeko(%struct*, i64, i32)\n"
236 "declare i32 @fsetpos(%struct*, i64*)\n"
237 "declare i32 @fstatvfs(i32, %struct*)\n"
238 "declare i64 @ftell(%struct*)\n"
239 "declare i64 @ftello(%struct*)\n"
240 "declare i32 @ftrylockfile(%struct*)\n"
241 "declare void @funlockfile(%struct*)\n"
242 "declare i32 @getc(%struct*)\n"
243 "declare i32 @getc_unlocked(%struct*)\n"
244 "declare i32 @getchar()\n"
245 "declare i32 @getchar_unlocked()\n"
246 "declare i8* @getenv(i8*)\n"
247 "declare i32 @getitimer(i32, %struct*)\n"
248 "declare i32 @getlogin_r(i8*, i64)\n"
249 "declare %struct* @getpwnam(i8*)\n"
250 "declare i8* @gets(i8*)\n"
251 "declare i32 @gettimeofday(%struct*, i8*)\n"
252 "declare double @hypot(double, double)\n"
253 "declare float @hypotf(float, float)\n"
254 "declare x86_fp80 @hypotl(x86_fp80, x86_fp80)\n"
255 "declare i32 @_Z7isasciii(i32)\n"
256 "declare i32 @_Z7isdigiti(i32)\n"
257 "declare i64 @labs(i64)\n"
258 "declare double @ldexp(double, i32)\n"
259 "declare float @ldexpf(float, i32)\n"
260 "declare x86_fp80 @ldexpl(x86_fp80, i32)\n"
261 "declare i64 @llabs(i64)\n"
262 "declare double @log(double)\n"
263 "declare double @log10(double)\n"
264 "declare float @log10f(float)\n"
265 "declare x86_fp80 @log10l(x86_fp80)\n"
266 "declare double @log1p(double)\n"
267 "declare float @log1pf(float)\n"
268 "declare x86_fp80 @log1pl(x86_fp80)\n"
269 "declare double @log2(double)\n"
270 "declare float @log2f(float)\n"
271 "declare x86_fp80 @log2l(x86_fp80)\n"
272 "declare i32 @ilogb(double)\n"
273 "declare i32 @ilogbf(float)\n"
274 "declare i32 @ilogbl(x86_fp80)\n"
275 "declare double @logb(double)\n"
276 "declare float @logbf(float)\n"
277 "declare x86_fp80 @logbl(x86_fp80)\n"
278 "declare float @logf(float)\n"
279 "declare x86_fp80 @logl(x86_fp80)\n"
280 "declare i8* @malloc(i64)\n"
281 "declare i8* @memccpy(i8*, i8*, i32, i64)\n"
282 "declare i8* @memchr(i8*, i32, i64)\n"
283 "declare i32 @memcmp(i8*, i8*, i64)\n"
284 "declare i8* @memcpy(i8*, i8*, i64)\n"
285 "declare i8* @memmove(i8*, i8*, i64)\n"
286 "declare i8* @memset(i8*, i32, i64)\n"
287 "declare void @memset_pattern16(i8*, i8*, i64)\n"
288 "declare void @memset_pattern4(i8*, i8*, i64)\n"
289 "declare void @memset_pattern8(i8*, i8*, i64)\n"
290 "declare i32 @mkdir(i8*, i16)\n"
291 "declare double @modf(double, double*)\n"
292 "declare float @modff(float, float*)\n"
293 "declare x86_fp80 @modfl(x86_fp80, x86_fp80*)\n"
294 "declare double @nan(ptr)\n"
295 "declare float @nanf(ptr)\n"
296 "declare x86_fp80 @nanl(ptr)\n"
297 "declare double @nearbyint(double)\n"
298 "declare float @nearbyintf(float)\n"
299 "declare x86_fp80 @nearbyintl(x86_fp80)\n"
300 "declare i32 @pclose(%struct*)\n"
301 "declare void @perror(i8*)\n"
302 "declare i32 @posix_memalign(i8**, i64, i64)\n"
303 "declare double @pow(double, double)\n"
304 "declare float @powf(float, float)\n"
305 "declare x86_fp80 @powl(x86_fp80, x86_fp80)\n"
306 "declare double @erf(double)\n"
307 "declare float @erff(float)\n"
308 "declare x86_fp80 @erfl(x86_fp80)\n"
309 "declare double @tgamma(double)\n"
310 "declare float @tgammaf(float)\n"
311 "declare x86_fp80 @tgammal(x86_fp80)\n"
312 "declare i32 @printf(i8*, ...)\n"
313 "declare i32 @putc(i32, %struct*)\n"
314 "declare i32 @putc_unlocked(i32, %struct*)\n"
315 "declare i32 @putchar(i32)\n"
316 "declare i32 @putchar_unlocked(i32)\n"
317 "declare i32 @puts(i8*)\n"
318 "declare void @qsort(i8*, i64, i64, i32 (i8*, i8*)*)\n"
319 "declare i64 @readlink(i8*, i8*, i64)\n"
320 "declare i8* @realloc(i8*, i64)\n"
321 "declare i8* @reallocarray(i8*, i64, i64)\n"
322 "declare i8* @reallocf(i8*, i64)\n"
323 "declare double @remainder(double, double)\n"
324 "declare float @remainderf(float, float)\n"
325 "declare x86_fp80 @remainderl(x86_fp80, x86_fp80)\n"
326 "declare i32 @remove(i8*)\n"
327 "declare double @remquo(double, double, ptr)\n"
328 "declare float @remquof(float, float, ptr)\n"
329 "declare x86_fp80 @remquol(x86_fp80, x86_fp80, ptr)\n"
330 "declare double @fdim(double, double)\n"
331 "declare float @fdimf(float, float)\n"
332 "declare x86_fp80 @fdiml(x86_fp80, x86_fp80)\n"
333 "declare i32 @rename(i8*, i8*)\n"
334 "declare void @rewind(%struct*)\n"
335 "declare double @rint(double)\n"
336 "declare float @rintf(float)\n"
337 "declare x86_fp80 @rintl(x86_fp80)\n"
338 "declare i32 @rmdir(i8*)\n"
339 "declare double @round(double)\n"
340 "declare float @roundf(float)\n"
341 "declare x86_fp80 @roundl(x86_fp80)\n"
342 "declare double @roundeven(double)\n"
343 "declare float @roundevenf(float)\n"
344 "declare x86_fp80 @roundevenl(x86_fp80)\n"
345 "declare double @scalbln(double, i64)\n"
346 "declare float @scalblnf(float, i64)\n"
347 "declare x86_fp80 @scalblnl(x86_fp80, i64)\n"
348 "declare double @scalbn(double, i32)\n"
349 "declare float @scalbnf(float, i32)\n"
350 "declare x86_fp80 @scalbnl(x86_fp80, i32)\n"
351 "declare i32 @scanf(i8*, ...)\n"
352 "declare void @setbuf(%struct*, i8*)\n"
353 "declare i32 @setitimer(i32, %struct*, %struct*)\n"
354 "declare i32 @setvbuf(%struct*, i8*, i32, i64)\n"
355 "declare double @sin(double)\n"
356 "declare float @sinf(float)\n"
357 "declare double @sinh(double)\n"
358 "declare float @sinhf(float)\n"
359 "declare x86_fp80 @sinhl(x86_fp80)\n"
360 "declare x86_fp80 @sinl(x86_fp80)\n"
361 "declare void @sincos(double, ptr, ptr)\n"
362 "declare void @sincosf(float, ptr, ptr)\n"
363 "declare void @sincosl(x86_fp80, ptr, ptr)\n"
364 "declare i32 @snprintf(i8*, i64, i8*, ...)\n"
365 "declare i32 @sprintf(i8*, i8*, ...)\n"
366 "declare double @sqrt(double)\n"
367 "declare float @sqrtf(float)\n"
368 "declare x86_fp80 @sqrtl(x86_fp80)\n"
369 "declare i32 @sscanf(i8*, i8*, ...)\n"
370 "declare i32 @statvfs(i8*, %struct*)\n"
371 "declare i8* @stpcpy(i8*, i8*)\n"
372 "declare i8* @stpncpy(i8*, i8*, i64)\n"
373 "declare i32 @strcasecmp(i8*, i8*)\n"
374 "declare i8* @strcat(i8*, i8*)\n"
375 "declare i8* @strchr(i8*, i32)\n"
376 "declare i32 @strcmp(i8*, i8*)\n"
377 "declare i32 @strcoll(i8*, i8*)\n"
378 "declare i8* @strcpy(i8*, i8*)\n"
379 "declare i64 @strcspn(i8*, i8*)\n"
380 "declare i8* @strdup(i8*)\n"
381 "declare i64 @strlen(i8*)\n"
382 "declare i32 @strncasecmp(i8*, i8*, i64)\n"
383 "declare i8* @strncat(i8*, i8*, i64)\n"
384 "declare i32 @strncmp(i8*, i8*, i64)\n"
385 "declare i8* @strncpy(i8*, i8*, i64)\n"
386 "declare i8* @strndup(i8*, i64)\n"
387 "declare i64 @strnlen(i8*, i64)\n"
388 "declare i8* @strpbrk(i8*, i8*)\n"
389 "declare i8* @strrchr(i8*, i32)\n"
390 "declare i64 @strspn(i8*, i8*)\n"
391 "declare i8* @strstr(i8*, i8*)\n"
392 "declare i8* @strtok(i8*, i8*)\n"
393 "declare i8* @strtok_r(i8*, i8*, i8**)\n"
394 "declare i64 @strtol(i8*, i8**, i32)\n"
395 "declare i64 @strlcat(i8*, i8*, i64)\n"
396 "declare i64 @strlcpy(i8*, i8*, i64)\n"
397 "declare x86_fp80 @strtold(i8*, i8**)\n"
398 "declare i64 @strtoll(i8*, i8**, i32)\n"
399 "declare i64 @strtoul(i8*, i8**, i32)\n"
400 "declare i64 @strtoull(i8*, i8**, i32)\n"
401 "declare i64 @strxfrm(i8*, i8*, i64)\n"
402 "declare double @tan(double)\n"
403 "declare float @tanf(float)\n"
404 "declare double @tanh(double)\n"
405 "declare float @tanhf(float)\n"
406 "declare x86_fp80 @tanhl(x86_fp80)\n"
407 "declare x86_fp80 @tanl(x86_fp80)\n"
408 "declare i64 @times(%struct*)\n"
409 "declare %struct* @tmpfile()\n"
410 "declare i32 @_Z7toasciii(i32)\n"
411 "declare double @trunc(double)\n"
412 "declare float @truncf(float)\n"
413 "declare x86_fp80 @truncl(x86_fp80)\n"
414 "declare i32 @uname(%struct*)\n"
415 "declare i32 @ungetc(i32, %struct*)\n"
416 "declare i32 @unlink(i8*)\n"
417 "declare i32 @utime(i8*, %struct*)\n"
418 "declare i32 @utimes(i8*, %struct*)\n"
419 "declare i8* @valloc(i64)\n"
420 "declare i32 @vfprintf(%struct*, i8*, %struct*)\n"
421 "declare i32 @vfscanf(%struct*, i8*, %struct*)\n"
422 "declare i32 @vprintf(i8*, %struct*)\n"
423 "declare i32 @vscanf(i8*, %struct*)\n"
424 "declare i32 @vsnprintf(i8*, i64, i8*, %struct*)\n"
425 "declare i32 @vsprintf(i8*, i8*, %struct*)\n"
426 "declare i32 @vsscanf(i8*, i8*, %struct*)\n"
427 "declare i64 @wcslen(i32*)\n"
428 "declare i32 @fork()\n"
429 "declare i32 @execl(i8*, i8*, ...)\n"
430 "declare i32 @execle(i8*, i8*, ...)\n"
431 "declare i32 @execlp(i8*, i8*, ...)\n"
432 "declare i32 @execv(i8*, i8**)\n"
433 "declare i32 @execvP(i8*, i8*, i8**)\n"
434 "declare i32 @execve(i8*, i8**, i8**)\n"
435 "declare i32 @execvp(i8*, i8**)\n"
436 "declare i32 @execvpe(i8*, i8**, i8**)\n"
438 // These functions were also extracted from the OS X headers, but they are
439 // available with a special name on darwin.
440 // This test uses the default TLI name instead.
441 "declare i32 @chmod(i8*, i16)\n"
442 "declare i32 @closedir(%struct*)\n"
443 "declare %struct* @fdopen(i32, i8*)\n"
444 "declare %struct* @fopen(i8*, i8*)\n"
445 "declare i32 @fputs(i8*, %struct*)\n"
446 "declare i32 @fputs_unlocked(i8*, %struct*)\n"
447 "declare i32 @fstat(i32, %struct*)\n"
448 "declare i64 @fwrite(i8*, i64, i64, %struct*)\n"
449 "declare i64 @fwrite_unlocked(i8*, i64, i64, %struct*)\n"
450 "declare i32 @lchown(i8*, i32, i32)\n"
451 "declare i32 @lstat(i8*, %struct*)\n"
452 "declare i64 @mktime(%struct*)\n"
453 "declare i32 @open(i8*, i32, ...)\n"
454 "declare %struct* @opendir(i8*)\n"
455 "declare %struct* @popen(i8*, i8*)\n"
456 "declare i64 @pread(i32, i8*, i64, i64)\n"
457 "declare i64 @pwrite(i32, i8*, i64, i64)\n"
458 "declare i64 @read(i32, i8*, i64)\n"
459 "declare i8* @realpath(i8*, i8*)\n"
460 "declare i32 @stat(i8*, %struct*)\n"
461 "declare double @strtod(i8*, i8**)\n"
462 "declare float @strtof(i8*, i8**)\n"
463 "declare i32 @system(i8*)\n"
464 "declare i32 @unsetenv(i8*)\n"
465 "declare i64 @write(i32, i8*, i64)\n"
467 // These functions are available on Linux but not Darwin; they only differ
468 // from their non-64 counterparts in the struct type.
469 // Use the same prototype as the non-64 variant.
470 "declare %struct* @fopen64(i8*, i8*)\n"
471 "declare i32 @fstat64(i32, %struct*)\n"
472 "declare i32 @fstatvfs64(i32, %struct*)\n"
473 "declare i32 @lstat64(i8*, %struct*)\n"
474 "declare i32 @open64(i8*, i32, ...)\n"
475 "declare i32 @stat64(i8*, %struct*)\n"
476 "declare i32 @statvfs64(i8*, %struct*)\n"
477 "declare %struct* @tmpfile64()\n"
479 // These functions are also -64 variants, but do differ in the type of the
480 // off_t (vs off64_t) parameter. The non-64 variants declared above used
481 // a 64-bit off_t, so, in practice, they are also equivalent.
482 "declare i32 @fseeko64(%struct*, i64, i32)\n"
483 "declare i64 @ftello64(%struct*)\n"
485 "declare void @_ZdaPv(i8*)\n"
486 "declare void @_ZdaPvRKSt9nothrow_t(i8*, %struct*)\n"
487 "declare void @_ZdaPvSt11align_val_t(i8*, i64)\n"
488 "declare void @_ZdaPvSt11align_val_tRKSt9nothrow_t(i8*, i64, %struct*)\n"
489 "declare void @_ZdaPvj(i8*, i32)\n"
490 "declare void @_ZdaPvjSt11align_val_t(i8*, i32, i32)\n"
491 "declare void @_ZdaPvm(i8*, i64)\n"
492 "declare void @_ZdaPvmSt11align_val_t(i8*, i64, i64)\n"
493 "declare void @_ZdlPv(i8*)\n"
494 "declare void @_ZdlPvRKSt9nothrow_t(i8*, %struct*)\n"
495 "declare void @_ZdlPvSt11align_val_t(i8*, i64)\n"
496 "declare void @_ZdlPvSt11align_val_tRKSt9nothrow_t(i8*, i64, %struct*)\n"
497 "declare void @_ZdlPvj(i8*, i32)\n"
498 "declare void @_ZdlPvjSt11align_val_t(i8*, i32, i32)\n"
499 "declare void @_ZdlPvm(i8*, i64)\n"
500 "declare void @_ZdlPvmSt11align_val_t(i8*, i64, i64)\n"
501 "declare i8* @_Znaj(i32)\n"
502 "declare i8* @_ZnajRKSt9nothrow_t(i32, %struct*)\n"
503 "declare i8* @_ZnajSt11align_val_t(i32, i32)\n"
504 "declare i8* @_ZnajSt11align_val_tRKSt9nothrow_t(i32, i32, %struct*)\n"
505 "declare i8* @_Znam(i64)\n"
506 "declare i8* @_Znam12__hot_cold_t(i64, i8)\n"
507 "declare i8* @_ZnamRKSt9nothrow_t(i64, %struct*)\n"
508 "declare i8* @_ZnamRKSt9nothrow_t12__hot_cold_t(i64, %struct*, i8)\n"
509 "declare i8* @_ZnamSt11align_val_t(i64, i64)\n"
510 "declare i8* @_ZnamSt11align_val_t12__hot_cold_t(i64, i64, i8)\n"
511 "declare i8* @_ZnamSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n"
512 "declare i8* @_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, "
513 "%struct*, i8)\n"
514 "declare i8* @_Znwj(i32)\n"
515 "declare i8* @_ZnwjRKSt9nothrow_t(i32, %struct*)\n"
516 "declare i8* @_ZnwjSt11align_val_t(i32, i32)\n"
517 "declare i8* @_ZnwjSt11align_val_tRKSt9nothrow_t(i32, i32, %struct*)\n"
518 "declare i8* @_Znwm(i64)\n"
519 "declare i8* @_Znwm12__hot_cold_t(i64, i8)\n"
520 "declare i8* @_ZnwmRKSt9nothrow_t(i64, %struct*)\n"
521 "declare i8* @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64, %struct*, i8)\n"
522 "declare i8* @_ZnwmSt11align_val_t(i64, i64)\n"
523 "declare i8* @_ZnwmSt11align_val_t12__hot_cold_t(i64, i64, i8)\n"
524 "declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n"
525 "declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, "
526 "%struct*, i8)\n"
527 "declare {i8*, i64} @__size_returning_new(i64)\n"
528 "declare {i8*, i64} @__size_returning_new_hot_cold(i64, i8)\n"
529 "declare {i8*, i64} @__size_returning_new_aligned(i64, i64)\n"
530 "declare {i8*, i64} @__size_returning_new_aligned_hot_cold(i64, i64, "
531 "i8)\n"
533 "declare void @\"??3@YAXPEAX@Z\"(i8*)\n"
534 "declare void @\"??3@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n"
535 "declare void @\"??3@YAXPEAX_K@Z\"(i8*, i64)\n"
536 "declare void @\"??_V@YAXPEAX@Z\"(i8*)\n"
537 "declare void @\"??_V@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n"
538 "declare void @\"??_V@YAXPEAX_K@Z\"(i8*, i64)\n"
539 "declare i8* @\"??2@YAPAXI@Z\"(i32)\n"
540 "declare i8* @\"??2@YAPAXIABUnothrow_t@std@@@Z\"(i32, %struct*)\n"
541 "declare i8* @\"??2@YAPEAX_K@Z\"(i64)\n"
542 "declare i8* @\"??2@YAPEAX_KAEBUnothrow_t@std@@@Z\"(i64, %struct*)\n"
543 "declare i8* @\"??_U@YAPAXI@Z\"(i32)\n"
544 "declare i8* @\"??_U@YAPAXIABUnothrow_t@std@@@Z\"(i32, %struct*)\n"
545 "declare i8* @\"??_U@YAPEAX_K@Z\"(i64)\n"
546 "declare i8* @\"??_U@YAPEAX_KAEBUnothrow_t@std@@@Z\"(i64, %struct*)\n"
548 "declare void @\"??3@YAXPAX@Z\"(i8*)\n"
549 "declare void @\"??3@YAXPAXABUnothrow_t@std@@@Z\"(i8*, %struct*)\n"
550 "declare void @\"??3@YAXPAXI@Z\"(i8*, i32)\n"
551 "declare void @\"??_V@YAXPAX@Z\"(i8*)\n"
552 "declare void @\"??_V@YAXPAXABUnothrow_t@std@@@Z\"(i8*, %struct*)\n"
553 "declare void @\"??_V@YAXPAXI@Z\"(i8*, i32)\n"
555 // These other functions were derived from the .def C declaration.
556 "declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)\n"
557 "declare void @__cxa_guard_abort(%struct*)\n"
558 "declare i32 @__cxa_guard_acquire(%struct*)\n"
559 "declare void @__cxa_guard_release(%struct*)\n"
560 "declare void @__cxa_throw(ptr, ptr, ptr)\n"
562 "declare i32 @atexit(void ()*)\n"
564 "declare void @abort()\n"
565 "declare void @exit(i32)\n"
566 "declare void @_Exit(i32)\n"
567 "declare void @_ZSt9terminatev()\n"
569 "declare i32 @__nvvm_reflect(i8*)\n"
571 "declare i8* @__memcpy_chk(i8*, i8*, i64, i64)\n"
572 "declare i8* @__memmove_chk(i8*, i8*, i64, i64)\n"
573 "declare i8* @__memset_chk(i8*, i32, i64, i64)\n"
574 "declare i8* @__stpcpy_chk(i8*, i8*, i64)\n"
575 "declare i8* @__stpncpy_chk(i8*, i8*, i64, i64)\n"
576 "declare i8* @__strcpy_chk(i8*, i8*, i64)\n"
577 "declare i8* @__strncpy_chk(i8*, i8*, i64, i64)\n"
578 "declare i8* @__memccpy_chk(i8*, i8*, i32, i64, i64)\n"
579 "declare i8* @__mempcpy_chk(i8*, i8*, i64, i64)\n"
580 "declare i32 @__snprintf_chk(i8*, i64, i32, i64, i8*, ...)\n"
581 "declare i32 @__sprintf_chk(i8*, i32, i64, i8*, ...)\n"
582 "declare i8* @__strcat_chk(i8*, i8*, i64)\n"
583 "declare i64 @__strlcat_chk(i8*, i8*, i64, i64)\n"
584 "declare i64 @__strlen_chk(i8*, i64)\n"
585 "declare i8* @__strncat_chk(i8*, i8*, i64, i64)\n"
586 "declare i64 @__strlcpy_chk(i8*, i8*, i64, i64)\n"
587 "declare i32 @__vsnprintf_chk(i8*, i64, i32, i64, i8*, %struct*)\n"
588 "declare i32 @__vsprintf_chk(i8*, i32, i64, i8*, %struct*)\n"
590 "declare i8* @memalign(i64, i64)\n"
591 "declare i8* @mempcpy(i8*, i8*, i64)\n"
592 "declare i8* @memrchr(i8*, i32, i64)\n"
594 "declare void @__atomic_load(i64, i8*, i8*, i32)\n"
595 "declare void @__atomic_store(i64, i8*, i8*, i32)\n"
597 // These are similar to the FILE* fgetc/fputc.
598 "declare i32 @_IO_getc(%struct*)\n"
599 "declare i32 @_IO_putc(i32, %struct*)\n"
601 "declare i32 @__isoc99_scanf(i8*, ...)\n"
602 "declare i32 @__isoc99_sscanf(i8*, i8*, ...)\n"
603 "declare i8* @__strdup(i8*)\n"
604 "declare i8* @__strndup(i8*, i64)\n"
605 "declare i8* @__strtok_r(i8*, i8*, i8**)\n"
607 "declare double @__sqrt_finite(double)\n"
608 "declare float @__sqrtf_finite(float)\n"
609 "declare x86_fp80 @__sqrtl_finite(x86_fp80)\n"
610 "declare double @exp10(double)\n"
611 "declare float @exp10f(float)\n"
612 "declare x86_fp80 @exp10l(x86_fp80)\n"
614 // These printf variants have the same prototype as the non-'i' versions.
615 "declare i32 @fiprintf(%struct*, i8*, ...)\n"
616 "declare i32 @iprintf(i8*, ...)\n"
617 "declare i32 @siprintf(i8*, i8*, ...)\n"
619 // __small_printf variants have the same prototype as the non-'i'
620 // versions.
621 "declare i32 @__small_fprintf(%struct*, i8*, ...)\n"
622 "declare i32 @__small_printf(i8*, ...)\n"
623 "declare i32 @__small_sprintf(i8*, i8*, ...)\n"
625 "declare i32 @htonl(i32)\n"
626 "declare i16 @htons(i16)\n"
627 "declare i32 @ntohl(i32)\n"
628 "declare i16 @ntohs(i16)\n"
630 "declare i32 @isascii(i32)\n"
631 "declare i32 @isdigit(i32)\n"
632 "declare i32 @toascii(i32)\n"
634 // These functions were extracted from math-finite.h which provides
635 // functions similar to those in math.h, but optimized for handling
636 // finite values only.
637 "declare double @__acos_finite(double)\n"
638 "declare float @__acosf_finite(float)\n"
639 "declare x86_fp80 @__acosl_finite(x86_fp80)\n"
640 "declare double @__acosh_finite(double)\n"
641 "declare float @__acoshf_finite(float)\n"
642 "declare x86_fp80 @__acoshl_finite(x86_fp80)\n"
643 "declare double @__asin_finite(double)\n"
644 "declare float @__asinf_finite(float)\n"
645 "declare x86_fp80 @__asinl_finite(x86_fp80)\n"
646 "declare double @__atan2_finite(double, double)\n"
647 "declare float @__atan2f_finite(float, float)\n"
648 "declare x86_fp80 @__atan2l_finite(x86_fp80, x86_fp80)\n"
649 "declare double @__atanh_finite(double)\n"
650 "declare float @__atanhf_finite(float)\n"
651 "declare x86_fp80 @__atanhl_finite(x86_fp80)\n"
652 "declare double @__cosh_finite(double)\n"
653 "declare float @__coshf_finite(float)\n"
654 "declare x86_fp80 @__coshl_finite(x86_fp80)\n"
655 "declare double @__exp10_finite(double)\n"
656 "declare float @__exp10f_finite(float)\n"
657 "declare x86_fp80 @__exp10l_finite(x86_fp80)\n"
658 "declare double @__exp2_finite(double)\n"
659 "declare float @__exp2f_finite(float)\n"
660 "declare x86_fp80 @__exp2l_finite(x86_fp80)\n"
661 "declare double @__exp_finite(double)\n"
662 "declare float @__expf_finite(float)\n"
663 "declare x86_fp80 @__expl_finite(x86_fp80)\n"
664 "declare double @__log10_finite(double)\n"
665 "declare float @__log10f_finite(float)\n"
666 "declare x86_fp80 @__log10l_finite(x86_fp80)\n"
667 "declare double @__log2_finite(double)\n"
668 "declare float @__log2f_finite(float)\n"
669 "declare x86_fp80 @__log2l_finite(x86_fp80)\n"
670 "declare double @__log_finite(double)\n"
671 "declare float @__logf_finite(float)\n"
672 "declare x86_fp80 @__logl_finite(x86_fp80)\n"
673 "declare double @__pow_finite(double, double)\n"
674 "declare float @__powf_finite(float, float)\n"
675 "declare x86_fp80 @__powl_finite(x86_fp80, x86_fp80)\n"
676 "declare double @__sinh_finite(double)\n"
677 "declare float @__sinhf_finite(float)\n"
678 "declare x86_fp80 @__sinhl_finite(x86_fp80)\n"
680 // These functions are aix vec allocation/free routines
681 "declare i8* @vec_calloc(i64, i64)\n"
682 "declare i8* @vec_malloc(i64)\n"
683 "declare i8* @vec_realloc(i8*, i64)\n"
684 "declare void @vec_free(i8*)\n"
686 // These functions are OpenMP Offloading allocation / free routines
687 "declare i8* @__kmpc_alloc_shared(i64)\n"
688 "declare void @__kmpc_free_shared(i8*, i64)\n");
690 for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {
691 LibFunc LF = (LibFunc)FI;
692 // Make sure everything is available; we're not testing target defaults.
693 TLII.setAvailable(LF);
694 Function *F = M->getFunction(TLI.getName(LF));
695 EXPECT_TRUE(isLibFunc(F, LF));
699 namespace {
701 /// Creates TLI for AArch64 and uses it to get the LibFunc names for the given
702 /// Instruction opcode and Type.
703 class TLITestAarch64 : public ::testing::Test {
704 private:
705 const Triple TargetTriple;
707 protected:
708 LLVMContext Ctx;
709 std::unique_ptr<TargetLibraryInfoImpl> TLII;
710 std::unique_ptr<TargetLibraryInfo> TLI;
712 /// Create TLI for AArch64
713 TLITestAarch64() : TargetTriple(Triple("aarch64-unknown-linux-gnu")) {
714 TLII = std::make_unique<TargetLibraryInfoImpl>(
715 TargetLibraryInfoImpl(TargetTriple));
716 TLI = std::make_unique<TargetLibraryInfo>(TargetLibraryInfo(*TLII));
719 /// Returns the TLI function name for the given \p Opcode and type \p Ty.
720 StringRef getScalarName(unsigned int Opcode, Type *Ty) {
721 LibFunc Func;
722 if (!TLI->getLibFunc(Opcode, Ty, Func))
723 return "";
724 return TLI->getName(Func);
727 } // end anonymous namespace
729 TEST_F(TLITestAarch64, TestFrem) {
730 EXPECT_EQ(getScalarName(Instruction::FRem, Type::getDoubleTy(Ctx)), "fmod");
731 EXPECT_EQ(getScalarName(Instruction::FRem, Type::getFloatTy(Ctx)), "fmodf");