1855ec517SAlex Zinenko //===- Support.cpp - Helpers for C interface to MLIR API ------------------===// 2855ec517SAlex Zinenko // 3855ec517SAlex Zinenko // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4855ec517SAlex Zinenko // See https://llvm.org/LICENSE.txt for license information. 5855ec517SAlex Zinenko // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6855ec517SAlex Zinenko // 7855ec517SAlex Zinenko //===----------------------------------------------------------------------===// 8855ec517SAlex Zinenko 92387fadeSDaniel Resnick #include "mlir/CAPI/Support.h" 1030d61893SAlex Zinenko #include "llvm/ADT/StringRef.h" 11d9e04b06SKrzysztof Drewniak #include "llvm/Support/ThreadPool.h" 12855ec517SAlex Zinenko 13855ec517SAlex Zinenko #include <cstring> 14855ec517SAlex Zinenko mlirStringRefCreateFromCString(const char * str)15855ec517SAlex ZinenkoMlirStringRef mlirStringRefCreateFromCString(const char *str) { 16855ec517SAlex Zinenko return mlirStringRefCreate(str, strlen(str)); 17855ec517SAlex Zinenko } 1830d61893SAlex Zinenko mlirStringRefEqual(MlirStringRef string,MlirStringRef other)1930d61893SAlex Zinenkobool mlirStringRefEqual(MlirStringRef string, MlirStringRef other) { 2030d61893SAlex Zinenko return llvm::StringRef(string.data, string.length) == 2130d61893SAlex Zinenko llvm::StringRef(other.data, other.length); 2230d61893SAlex Zinenko } 232387fadeSDaniel Resnick 242387fadeSDaniel Resnick //===----------------------------------------------------------------------===// 25d9e04b06SKrzysztof Drewniak // LLVM ThreadPool API. 26d9e04b06SKrzysztof Drewniak //===----------------------------------------------------------------------===// mlirLlvmThreadPoolCreate()27d9e04b06SKrzysztof DrewniakMlirLlvmThreadPool mlirLlvmThreadPoolCreate() { 28*716042a6SMehdi Amini return wrap(new llvm::DefaultThreadPool()); 29d9e04b06SKrzysztof Drewniak } 30d9e04b06SKrzysztof Drewniak mlirLlvmThreadPoolDestroy(MlirLlvmThreadPool threadPool)31d9e04b06SKrzysztof Drewniakvoid mlirLlvmThreadPoolDestroy(MlirLlvmThreadPool threadPool) { 32d9e04b06SKrzysztof Drewniak delete unwrap(threadPool); 33d9e04b06SKrzysztof Drewniak } 34d9e04b06SKrzysztof Drewniak 35d9e04b06SKrzysztof Drewniak //===----------------------------------------------------------------------===// 362387fadeSDaniel Resnick // TypeID API. 372387fadeSDaniel Resnick //===----------------------------------------------------------------------===// mlirTypeIDCreate(const void * ptr)382387fadeSDaniel ResnickMlirTypeID mlirTypeIDCreate(const void *ptr) { 392387fadeSDaniel Resnick assert(reinterpret_cast<uintptr_t>(ptr) % 8 == 0 && 402387fadeSDaniel Resnick "ptr must be 8 byte aligned"); 412387fadeSDaniel Resnick // This is essentially a no-op that returns back `ptr`, but by going through 422387fadeSDaniel Resnick // the `TypeID` functions we can get compiler errors in case the `TypeID` 432387fadeSDaniel Resnick // api/representation changes 442387fadeSDaniel Resnick return wrap(mlir::TypeID::getFromOpaquePointer(ptr)); 452387fadeSDaniel Resnick } 462387fadeSDaniel Resnick mlirTypeIDEqual(MlirTypeID typeID1,MlirTypeID typeID2)472387fadeSDaniel Resnickbool mlirTypeIDEqual(MlirTypeID typeID1, MlirTypeID typeID2) { 482387fadeSDaniel Resnick return unwrap(typeID1) == unwrap(typeID2); 492387fadeSDaniel Resnick } 502387fadeSDaniel Resnick mlirTypeIDHashValue(MlirTypeID typeID)512387fadeSDaniel Resnicksize_t mlirTypeIDHashValue(MlirTypeID typeID) { 522387fadeSDaniel Resnick return hash_value(unwrap(typeID)); 532387fadeSDaniel Resnick } 542387fadeSDaniel Resnick 552387fadeSDaniel Resnick //===----------------------------------------------------------------------===// 562387fadeSDaniel Resnick // TypeIDAllocator API. 572387fadeSDaniel Resnick //===----------------------------------------------------------------------===// 582387fadeSDaniel Resnick mlirTypeIDAllocatorCreate()592387fadeSDaniel ResnickMlirTypeIDAllocator mlirTypeIDAllocatorCreate() { 602387fadeSDaniel Resnick return wrap(new mlir::TypeIDAllocator()); 612387fadeSDaniel Resnick } 622387fadeSDaniel Resnick mlirTypeIDAllocatorDestroy(MlirTypeIDAllocator allocator)632387fadeSDaniel Resnickvoid mlirTypeIDAllocatorDestroy(MlirTypeIDAllocator allocator) { 642387fadeSDaniel Resnick delete unwrap(allocator); 652387fadeSDaniel Resnick } 662387fadeSDaniel Resnick mlirTypeIDAllocatorAllocateTypeID(MlirTypeIDAllocator allocator)672387fadeSDaniel ResnickMlirTypeID mlirTypeIDAllocatorAllocateTypeID(MlirTypeIDAllocator allocator) { 682387fadeSDaniel Resnick return wrap(unwrap(allocator)->allocate()); 692387fadeSDaniel Resnick } 70