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 "llvm/ADT/TypeSwitch.h" 15 16 using namespace mlir; 17 using namespace mlir::ptr; 18 19 constexpr const static unsigned kBitsInByte = 8; 20 21 //===----------------------------------------------------------------------===// 22 // SpecAttr 23 //===----------------------------------------------------------------------===// 24 verify(function_ref<InFlightDiagnostic ()> emitError,uint32_t size,uint32_t abi,uint32_t preferred,uint32_t index)25LogicalResult SpecAttr::verify(function_ref<InFlightDiagnostic()> emitError, 26 uint32_t size, uint32_t abi, uint32_t preferred, 27 uint32_t index) { 28 if (size % kBitsInByte != 0) 29 return emitError() << "size entry must be divisible by 8"; 30 if (abi % kBitsInByte != 0) 31 return emitError() << "abi entry must be divisible by 8"; 32 if (preferred % kBitsInByte != 0) 33 return emitError() << "preferred entry must be divisible by 8"; 34 if (index != kOptionalSpecValue && index % kBitsInByte != 0) 35 return emitError() << "index entry must be divisible by 8"; 36 if (abi > preferred) 37 return emitError() << "preferred alignment is expected to be at least " 38 "as large as ABI alignment"; 39 return success(); 40 } 41