1//===- PtrAttrs.cpp - Pointer dialect attributes ----------------*- C++ -*-===//
2//
3// This file is licensed 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 Ptr dialect attributes.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Dialect/Ptr/IR/PtrAttrs.h"
14
15using namespace mlir;
16using namespace mlir::ptr;
17
18constexpr const static unsigned kBitsInByte = 8;
19
20//===----------------------------------------------------------------------===//
21// GenericSpaceAttr
22//===----------------------------------------------------------------------===//
23
24bool GenericSpaceAttr::isValidLoad(
25 Type type, ptr::AtomicOrdering ordering, IntegerAttr alignment,
26 function_ref<InFlightDiagnostic()> emitError) const {
27 return true;
28}
29
30bool GenericSpaceAttr::isValidStore(
31 Type type, ptr::AtomicOrdering ordering, IntegerAttr alignment,
32 function_ref<InFlightDiagnostic()> emitError) const {
33 return true;
34}
35
36bool GenericSpaceAttr::isValidAtomicOp(
37 ptr::AtomicBinOp op, Type type, ptr::AtomicOrdering ordering,
38 IntegerAttr alignment, function_ref<InFlightDiagnostic()> emitError) const {
39 return true;
40}
41
42bool GenericSpaceAttr::isValidAtomicXchg(
43 Type type, ptr::AtomicOrdering successOrdering,
44 ptr::AtomicOrdering failureOrdering, IntegerAttr alignment,
45 function_ref<InFlightDiagnostic()> emitError) const {
46 return true;
47}
48
49bool GenericSpaceAttr::isValidAddrSpaceCast(
50 Type tgt, Type src, function_ref<InFlightDiagnostic()> emitError) const {
51 // TODO: update this method once the `addrspace_cast` op is added to the
52 // dialect.
53 assert(false && "unimplemented, see TODO in the source.");
54 return false;
55}
56
57bool GenericSpaceAttr::isValidPtrIntCast(
58 Type intLikeTy, Type ptrLikeTy,
59 function_ref<InFlightDiagnostic()> emitError) const {
60 // TODO: update this method once the int-cast ops are added to the dialect.
61 assert(false && "unimplemented, see TODO in the source.");
62 return false;
63}
64
65//===----------------------------------------------------------------------===//
66// SpecAttr
67//===----------------------------------------------------------------------===//
68
69LogicalResult SpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
70 uint32_t size, uint32_t abi, uint32_t preferred,
71 uint32_t index) {
72 if (size % kBitsInByte != 0)
73 return emitError() << "size entry must be divisible by 8";
74 if (abi % kBitsInByte != 0)
75 return emitError() << "abi entry must be divisible by 8";
76 if (preferred % kBitsInByte != 0)
77 return emitError() << "preferred entry must be divisible by 8";
78 if (index != kOptionalSpecValue && index % kBitsInByte != 0)
79 return emitError() << "index entry must be divisible by 8";
80 if (abi > preferred)
81 return emitError() << "preferred alignment is expected to be at least "
82 "as large as ABI alignment";
83 return success();
84}
85

source code of mlir/lib/Dialect/Ptr/IR/PtrAttrs.cpp