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

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