MLIR  21.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 #include "mlir/IR/BuiltinTypes.h"
15 #include "llvm/ADT/TypeSwitch.h"
16 
17 using namespace mlir;
18 using namespace mlir::ptr;
19 
20 constexpr const static unsigned kBitsInByte = 8;
21 
22 //===----------------------------------------------------------------------===//
23 // GenericSpaceAttr
24 //===----------------------------------------------------------------------===//
25 
26 bool GenericSpaceAttr::isValidLoad(
27  Type type, ptr::AtomicOrdering ordering, IntegerAttr alignment,
29  return true;
30 }
31 
32 bool GenericSpaceAttr::isValidStore(
33  Type type, ptr::AtomicOrdering ordering, IntegerAttr alignment,
35  return true;
36 }
37 
38 bool GenericSpaceAttr::isValidAtomicOp(
39  ptr::AtomicBinOp op, Type type, ptr::AtomicOrdering ordering,
40  IntegerAttr alignment, function_ref<InFlightDiagnostic()> emitError) const {
41  return true;
42 }
43 
44 bool GenericSpaceAttr::isValidAtomicXchg(
45  Type type, ptr::AtomicOrdering successOrdering,
46  ptr::AtomicOrdering failureOrdering, IntegerAttr alignment,
48  return true;
49 }
50 
51 bool 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 
59 bool GenericSpaceAttr::isValidPtrIntCast(
60  Type intLikeTy, Type ptrLikeTy,
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 
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 }
constexpr static const unsigned kBitsInByte
Definition: PtrAttrs.cpp:20
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:424