brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 3311131 Raw
70 lines · cpp
1//===- Support.cpp - Helpers for C interface to MLIR API ------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/CAPI/Support.h"10#include "llvm/ADT/StringRef.h"11#include "llvm/Support/ThreadPool.h"12 13#include <cstring>14 15MlirStringRef mlirStringRefCreateFromCString(const char *str) {16  return mlirStringRefCreate(str, strlen(str));17}18 19bool mlirStringRefEqual(MlirStringRef string, MlirStringRef other) {20  return llvm::StringRef(string.data, string.length) ==21         llvm::StringRef(other.data, other.length);22}23 24//===----------------------------------------------------------------------===//25// LLVM ThreadPool API.26//===----------------------------------------------------------------------===//27MlirLlvmThreadPool mlirLlvmThreadPoolCreate() {28  return wrap(new llvm::DefaultThreadPool());29}30 31void mlirLlvmThreadPoolDestroy(MlirLlvmThreadPool threadPool) {32  delete unwrap(threadPool);33}34 35//===----------------------------------------------------------------------===//36// TypeID API.37//===----------------------------------------------------------------------===//38MlirTypeID mlirTypeIDCreate(const void *ptr) {39  assert(reinterpret_cast<uintptr_t>(ptr) % 8 == 0 &&40         "ptr must be 8 byte aligned");41  // This is essentially a no-op that returns back `ptr`, but by going through42  // the `TypeID` functions we can get compiler errors in case the `TypeID`43  // api/representation changes44  return wrap(mlir::TypeID::getFromOpaquePointer(ptr));45}46 47bool mlirTypeIDEqual(MlirTypeID typeID1, MlirTypeID typeID2) {48  return unwrap(typeID1) == unwrap(typeID2);49}50 51size_t mlirTypeIDHashValue(MlirTypeID typeID) {52  return hash_value(unwrap(typeID));53}54 55//===----------------------------------------------------------------------===//56// TypeIDAllocator API.57//===----------------------------------------------------------------------===//58 59MlirTypeIDAllocator mlirTypeIDAllocatorCreate() {60  return wrap(new mlir::TypeIDAllocator());61}62 63void mlirTypeIDAllocatorDestroy(MlirTypeIDAllocator allocator) {64  delete unwrap(allocator);65}66 67MlirTypeID mlirTypeIDAllocatorAllocateTypeID(MlirTypeIDAllocator allocator) {68  return wrap(unwrap(allocator)->allocate());69}70