llvm/mlir/lib/ExecutionEngine/CRunnerUtils.cpp

//===- CRunnerUtils.cpp - Utils for MLIR execution ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements basic functions to manipulate structured MLIR types at
// runtime. Entities in this file are meant to be retargetable, including on
// targets without a C++ runtime, and must be kept C compatible.
//
//===----------------------------------------------------------------------===//

#include "mlir/ExecutionEngine/CRunnerUtils.h"
#include "mlir/ExecutionEngine/Msan.h"

#ifndef _WIN32
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
    defined(__DragonFly__)
#include <cstdlib>
#else
#include <alloca.h>
#endif
#include <sys/time.h>
#else
#include "malloc.h"
#endif // _WIN32

#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <random>
#include <string.h>

#ifdef MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS

namespace {
template <typename V>
void stdSort(uint64_t n, V *p) {}

} // namespace

// Small runtime support "lib" for vector.print lowering.
// By providing elementary printing methods only, this
// library can remain fully unaware of low-level implementation
// details of our vectors. Also useful for direct LLVM IR output.
extern "C" void printI64(int64_t i) {}
extern "C" void printU64(uint64_t u) {}
extern "C" void printF32(float f) {}
extern "C" void printF64(double d) {}
extern "C" void printString(char const *s) {}
extern "C" void printOpen() {}
extern "C" void printClose() {}
extern "C" void printComma() {}
extern "C" void printNewline() {}

extern "C" void memrefCopy(int64_t elemSize, UnrankedMemRefType<char> *srcArg,
                           UnrankedMemRefType<char> *dstArg) {}

/// Prints GFLOPS rating.
extern "C" void printFlops(double flops) {}

/// Returns the number of seconds since Epoch 1970-01-01 00:00:00 +0000 (UTC).
extern "C" double rtclock() {}

extern "C" void *mlirAlloc(uint64_t size) {}

extern "C" void *mlirAlignedAlloc(uint64_t alignment, uint64_t size) {}

extern "C" void mlirFree(void *ptr) {}

extern "C" void mlirAlignedFree(void *ptr) {}

extern "C" void *rtsrand(uint64_t s) {}

extern "C" uint64_t rtrand(void *g, uint64_t m) {}

extern "C" void rtdrand(void *g) {}

extern "C" void _mlir_ciface_shuffle(StridedMemRefType<uint64_t, 1> *mref,
                                     void *g) {}

#define IMPL_STDSORT
IMPL_STDSORT(I64, int64_t)
IMPL_STDSORT(F64, double)
IMPL_STDSORT(F32, float)
#undef IMPL_STDSORT

#endif // MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS