1 | //===- GPU.cpp - C Interface for GPU dialect ------------------------------===// |
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 | #include "mlir-c/Dialect/GPU.h" |
10 | #include "mlir/CAPI/Registration.h" |
11 | #include "mlir/Dialect/GPU/IR/GPUDialect.h" |
12 | #include "llvm/Support/Casting.h" |
13 | |
14 | using namespace mlir; |
15 | |
16 | MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(GPU, gpu, gpu::GPUDialect) |
17 | |
18 | //===---------------------------------------------------------------------===// |
19 | // ObjectAttr |
20 | //===---------------------------------------------------------------------===// |
21 | |
22 | bool mlirAttributeIsAGPUObjectAttr(MlirAttribute attr) { |
23 | return llvm::isa<gpu::ObjectAttr>(unwrap(attr)); |
24 | } |
25 | |
26 | MlirAttribute mlirGPUObjectAttrGet(MlirContext mlirCtx, MlirAttribute target, |
27 | uint32_t format, MlirStringRef objectStrRef, |
28 | MlirAttribute mlirObjectProps) { |
29 | MLIRContext *ctx = unwrap(c: mlirCtx); |
30 | llvm::StringRef object = unwrap(ref: objectStrRef); |
31 | DictionaryAttr objectProps; |
32 | if (mlirObjectProps.ptr != nullptr) |
33 | objectProps = llvm::cast<DictionaryAttr>(unwrap(c: mlirObjectProps)); |
34 | return wrap(gpu::ObjectAttr::get(ctx, unwrap(target), |
35 | static_cast<gpu::CompilationTarget>(format), |
36 | StringAttr::get(ctx, object), objectProps)); |
37 | } |
38 | |
39 | MlirAttribute mlirGPUObjectAttrGetTarget(MlirAttribute mlirObjectAttr) { |
40 | gpu::ObjectAttr objectAttr = |
41 | llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr)); |
42 | return wrap(objectAttr.getTarget()); |
43 | } |
44 | |
45 | uint32_t mlirGPUObjectAttrGetFormat(MlirAttribute mlirObjectAttr) { |
46 | gpu::ObjectAttr objectAttr = |
47 | llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr)); |
48 | return static_cast<uint32_t>(objectAttr.getFormat()); |
49 | } |
50 | |
51 | MlirStringRef mlirGPUObjectAttrGetObject(MlirAttribute mlirObjectAttr) { |
52 | gpu::ObjectAttr objectAttr = |
53 | llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr)); |
54 | llvm::StringRef object = objectAttr.getObject(); |
55 | return mlirStringRefCreate(str: object.data(), length: object.size()); |
56 | } |
57 | |
58 | bool mlirGPUObjectAttrHasProperties(MlirAttribute mlirObjectAttr) { |
59 | gpu::ObjectAttr objectAttr = |
60 | llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr)); |
61 | return objectAttr.getProperties() != nullptr; |
62 | } |
63 | |
64 | MlirAttribute mlirGPUObjectAttrGetProperties(MlirAttribute mlirObjectAttr) { |
65 | gpu::ObjectAttr objectAttr = |
66 | llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr)); |
67 | return wrap(objectAttr.getProperties()); |
68 | } |
69 | |