89 lines · cpp
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-exception6//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// GenericSpaceAttr22//===----------------------------------------------------------------------===//23 24bool GenericSpaceAttr::isValidLoad(25 Type type, ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,26 const ::mlir::DataLayout *dataLayout,27 function_ref<InFlightDiagnostic()> emitError) const {28 return true;29}30 31bool GenericSpaceAttr::isValidStore(32 Type type, ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,33 const ::mlir::DataLayout *dataLayout,34 function_ref<InFlightDiagnostic()> emitError) const {35 return true;36}37 38bool GenericSpaceAttr::isValidAtomicOp(39 ptr::AtomicBinOp op, Type type, ptr::AtomicOrdering ordering,40 std::optional<int64_t> alignment, const ::mlir::DataLayout *dataLayout,41 function_ref<InFlightDiagnostic()> emitError) const {42 return true;43}44 45bool GenericSpaceAttr::isValidAtomicXchg(46 Type type, ptr::AtomicOrdering successOrdering,47 ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,48 const ::mlir::DataLayout *dataLayout,49 function_ref<InFlightDiagnostic()> emitError) const {50 return true;51}52 53bool 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 the56 // dialect.57 assert(false && "unimplemented, see TODO in the source.");58 return false;59}60 61bool GenericSpaceAttr::isValidPtrIntCast(62 Type intLikeTy, Type ptrLikeTy,63 function_ref<InFlightDiagnostic()> emitError) const {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// SpecAttr71//===----------------------------------------------------------------------===//72 73LogicalResult SpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,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}89