1 | //===- Support.h - C API Helpers Implementation -----------------*- 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 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file contains definitions for converting MLIR C++ objects into helper |
10 | // C structures for the purpose of C API. This file should not be included from |
11 | // C++ code other than C API implementation nor from C code. |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef MLIR_CAPI_SUPPORT_H |
16 | #define MLIR_CAPI_SUPPORT_H |
17 | |
18 | #include "mlir-c/Support.h" |
19 | #include "mlir/CAPI/Wrap.h" |
20 | #include "mlir/Support/LogicalResult.h" |
21 | #include "mlir/Support/TypeID.h" |
22 | #include "llvm/ADT/StringRef.h" |
23 | |
24 | namespace llvm { |
25 | class ThreadPoolInterface; |
26 | } // namespace llvm |
27 | |
28 | /// Converts a StringRef into its MLIR C API equivalent. |
29 | inline MlirStringRef wrap(llvm::StringRef ref) { |
30 | return mlirStringRefCreate(str: ref.data(), length: ref.size()); |
31 | } |
32 | |
33 | /// Creates a StringRef out of its MLIR C API equivalent. |
34 | inline llvm::StringRef unwrap(MlirStringRef ref) { |
35 | return llvm::StringRef(ref.data, ref.length); |
36 | } |
37 | |
38 | inline MlirLogicalResult wrap(mlir::LogicalResult res) { |
39 | if (mlir::succeeded(result: res)) |
40 | return mlirLogicalResultSuccess(); |
41 | return mlirLogicalResultFailure(); |
42 | } |
43 | |
44 | inline mlir::LogicalResult unwrap(MlirLogicalResult res) { |
45 | return mlir::success(isSuccess: mlirLogicalResultIsSuccess(res)); |
46 | } |
47 | |
48 | DEFINE_C_API_PTR_METHODS(MlirLlvmThreadPool, llvm::ThreadPoolInterface) |
49 | DEFINE_C_API_METHODS(MlirTypeID, mlir::TypeID) |
50 | DEFINE_C_API_PTR_METHODS(MlirTypeIDAllocator, mlir::TypeIDAllocator) |
51 | |
52 | #endif // MLIR_CAPI_SUPPORT_H |
53 |