| 1 | //===- CIROpenCLAttrs.cpp - OpenCL specific attributes in CIR -------------===// |
| 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 defines the OpenCL-specific attrs in the CIR dialect. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "clang/CIR/Dialect/IR/CIRAttrs.h" |
| 14 | |
| 15 | #include "mlir/IR/Attributes.h" |
| 16 | #include "mlir/IR/Diagnostics.h" |
| 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | |
| 19 | using namespace mlir; |
| 20 | using namespace cir; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // OpenCLKernelArgMetadataAttr definitions |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | LogicalResult OpenCLKernelArgMetadataAttr::verify( |
| 27 | function_ref<InFlightDiagnostic()> emitError, ArrayAttr addrSpaces, |
| 28 | ArrayAttr accessQuals, ArrayAttr types, ArrayAttr baseTypes, |
| 29 | ArrayAttr typeQuals, ArrayAttr argNames) { |
| 30 | if (!llvm::all_of(Range: ArrayRef<ArrayAttr>{addrSpaces, accessQuals, types, |
| 31 | baseTypes, typeQuals, argNames}, |
| 32 | P: [&](ArrayAttr attr) { |
| 33 | return !attr || attr.size() == addrSpaces.size(); |
| 34 | })) |
| 35 | return emitError() << "all arrays must have the same number of elements" ; |
| 36 | |
| 37 | return success(); |
| 38 | } |
| 39 | |
| 40 | //===----------------------------------------------------------------------===// |
| 41 | // OpenCLVersionAttr definitions |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | |
| 44 | LogicalResult |
| 45 | OpenCLVersionAttr::verify(function_ref<InFlightDiagnostic()> emitError, |
| 46 | int32_t majorVersion, int32_t minorVersion) { |
| 47 | if (majorVersion <= 0) |
| 48 | return emitError() << "OpenCL major version must be positive" ; |
| 49 | if (minorVersion < 0) |
| 50 | return emitError() << "OpenCL minor version must be non-negative" ; |
| 51 | |
| 52 | return success(); |
| 53 | } |
| 54 | |