MLIR  18.0.0git
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 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 //===----------------------------------------------------------------------===//
18 #include "mlir-c/Support.h"
19 #include "mlir/CAPI/Wrap.h"
21 #include "mlir/Support/TypeID.h"
22 #include "llvm/ADT/StringRef.h"
24 namespace llvm {
25 class ThreadPool;
26 } // namespace llvm
28 /// Converts a StringRef into its MLIR C API equivalent.
29 inline MlirStringRef wrap(llvm::StringRef ref) {
30  return mlirStringRefCreate(, ref.size());
31 }
33 /// Creates a StringRef out of its MLIR C API equivalent.
34 inline llvm::StringRef unwrap(MlirStringRef ref) {
35  return llvm::StringRef(, ref.length);
36 }
39  if (mlir::succeeded(res))
40  return mlirLogicalResultSuccess();
41  return mlirLogicalResultFailure();
42 }
46 }
48 DEFINE_C_API_PTR_METHODS(MlirLlvmThreadPool, llvm::ThreadPool)
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
Include the generated interface declarations.
Definition: CallGraph.h:229
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:68
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
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
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26