MLIR  22.0.0git
PtrAttrs.cpp
Go to the documentation of this file.
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 
14 
15 using namespace mlir;
16 using namespace mlir::ptr;
17 
18 constexpr const static unsigned kBitsInByte = 8;
19 
20 //===----------------------------------------------------------------------===//
21 // GenericSpaceAttr
22 //===----------------------------------------------------------------------===//
23 
24 bool GenericSpaceAttr::isValidLoad(
25  Type type, ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
26  const ::mlir::DataLayout *dataLayout,
28  return true;
29 }
30 
31 bool GenericSpaceAttr::isValidStore(
32  Type type, ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
33  const ::mlir::DataLayout *dataLayout,
35  return true;
36 }
37 
38 bool GenericSpaceAttr::isValidAtomicOp(
39  ptr::AtomicBinOp op, Type type, ptr::AtomicOrdering ordering,
40  std::optional<int64_t> alignment, const ::mlir::DataLayout *dataLayout,
42  return true;
43 }
44 
45 bool GenericSpaceAttr::isValidAtomicXchg(
46  Type type, ptr::AtomicOrdering successOrdering,
47  ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,
48  const ::mlir::DataLayout *dataLayout,
50  return true;
51 }
52 
53 bool GenericSpaceAttr::isValidAddrSpaceCast(
54  Type tgt, Type src, function_ref<InFlightDiagnostic()> emitError) const {
55  // TODO: update this method once the `addrspace_cast` op is added to the
56  // dialect.
57  assert(false && "unimplemented, see TODO in the source.");
58  return false;
59 }
60 
61 bool GenericSpaceAttr::isValidPtrIntCast(
62  Type intLikeTy, Type ptrLikeTy,
64  // TODO: update this method once the int-cast ops are added to the dialect.
65  assert(false && "unimplemented, see TODO in the source.");
66  return false;
67 }
68 
69 //===----------------------------------------------------------------------===//
70 // SpecAttr
71 //===----------------------------------------------------------------------===//
72 
74  uint32_t size, uint32_t abi, uint32_t preferred,
75  uint32_t index) {
76  if (size % kBitsInByte != 0)
77  return emitError() << "size entry must be divisible by 8";
78  if (abi % kBitsInByte != 0)
79  return emitError() << "abi entry must be divisible by 8";
80  if (preferred % kBitsInByte != 0)
81  return emitError() << "preferred entry must be divisible by 8";
82  if (index != kOptionalSpecValue && index % kBitsInByte != 0)
83  return emitError() << "index entry must be divisible by 8";
84  if (abi > preferred)
85  return emitError() << "preferred alignment is expected to be at least "
86  "as large as ABI alignment";
87  return success();
88 }
constexpr static const unsigned kBitsInByte
Definition: PtrAttrs.cpp:18
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:314
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
Definition: Verifier.cpp:423