MLIR  20.0.0git
Support.h
Go to the documentation of this file.
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/TypeID.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/LogicalResult.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(ref.data(), 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(llvm::LogicalResult res) {
39  if (mlir::succeeded(res))
40  return mlirLogicalResultSuccess();
41  return mlirLogicalResultFailure();
42 }
43 
44 inline llvm::LogicalResult unwrap(MlirLogicalResult res) {
45  return mlir::success(mlirLogicalResultIsSuccess(res));
46 }
47 
48 DEFINE_C_API_PTR_METHODS(MlirLlvmThreadPool, llvm::ThreadPoolInterface)
51 
52 #endif // MLIR_CAPI_SUPPORT_H
#define DEFINE_C_API_PTR_METHODS(name, cpptype)
Definition: Wrap.h:25
#define DEFINE_C_API_METHODS(name, cpptype)
Definition: Wrap.h:31
This class provides a way to define new TypeIDs at runtime.
Definition: TypeID.h:292
This class provides an efficient unique identifier for a specific C++ type.
Definition: TypeID.h:104
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
Definition: Support.h:82
static MlirLogicalResult mlirLogicalResultFailure(void)
Creates a logical result representing a failure.
Definition: Support.h:138
static MlirLogicalResult mlirLogicalResultSuccess(void)
Creates a logical result representing a success.
Definition: Support.h:132
static bool mlirLogicalResultIsSuccess(MlirLogicalResult res)
Checks if the given logical result represents a success.
Definition: Support.h:122
llvm::StringRef unwrap(MlirStringRef ref)
Creates a StringRef out of its MLIR C API equivalent.
Definition: Support.h:34
MlirStringRef wrap(llvm::StringRef ref)
Converts a StringRef into its MLIR C API equivalent.
Definition: Support.h:29
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
A logical result value, essentially a boolean with named states.
Definition: Support.h:116
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73
const char * data
Pointer to the first symbol.
Definition: Support.h:74
size_t length
Length of the fragment.
Definition: Support.h:75