Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / DeviceRTL / src / LibC.cpp
blobaf675b97256f6c94898cfd1e1b0f4c10c333c4e0
1 //===------- LibC.cpp - Simple implementation of libc functions --- C++ ---===//
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 "LibC.h"
11 #pragma omp begin declare target device_type(nohost)
13 namespace impl {
14 int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t);
17 #pragma omp begin declare variant match( \
18 device = {arch(nvptx, nvptx64)}, \
19 implementation = {extension(match_any)})
20 extern "C" int32_t vprintf(const char *, void *);
21 namespace impl {
22 int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t) {
23 return vprintf(Format, Arguments);
25 } // namespace impl
26 #pragma omp end declare variant
28 // We do not have a vprintf implementation for AMD GPU yet so we use a stub.
29 #pragma omp begin declare variant match(device = {arch(amdgcn)})
30 namespace impl {
31 int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t) {
32 return -1;
34 } // namespace impl
35 #pragma omp end declare variant
37 extern "C" {
39 int memcmp(const void *lhs, const void *rhs, size_t count) {
40 auto *L = reinterpret_cast<const unsigned char *>(lhs);
41 auto *R = reinterpret_cast<const unsigned char *>(rhs);
43 for (size_t I = 0; I < count; ++I)
44 if (L[I] != R[I])
45 return (int)L[I] - (int)R[I];
47 return 0;
50 void memset(void *dst, int C, size_t count) {
51 auto *dstc = reinterpret_cast<char *>(dst);
52 for (size_t I = 0; I < count; ++I)
53 dstc[I] = C;
56 /// printf() calls are rewritten by CGGPUBuiltin to __llvm_omp_vprintf
57 int32_t __llvm_omp_vprintf(const char *Format, void *Arguments, uint32_t Size) {
58 return impl::omp_vprintf(Format, Arguments, Size);
62 #pragma omp end declare target