From: Joe Loser Date: Wed, 7 Sep 2022 00:01:39 +0000 (-0600) Subject: [mlir] Use std::size instead of llvm::array_lengthof X-Git-Tag: upstream/17.0.6~34175 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5a8f50ab160c56a316e79f46e787afa15c1cbcc;p=platform%2Fupstream%2Fllvm.git [mlir] Use std::size instead of llvm::array_lengthof LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133387 --- diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td index d27ee36..5429bba 100644 --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td @@ -189,7 +189,7 @@ class Extension extensions> : Availability { "}; " # // The following manual ArrayRef constructor call is to satisfy GCC 5. "ArrayRef<::mlir::spirv::Extension> " # - "ref(exts, ::llvm::array_lengthof(exts));"); + "ref(exts, std::size(exts));"); let instance = "ref"; } @@ -231,7 +231,7 @@ class Capability capabilities> : Availability { "}; " # // The following manual ArrayRef constructor call is to satisfy GCC 5. "ArrayRef<::mlir::spirv::Capability> " # - "ref(caps, ::llvm::array_lengthof(caps));"); + "ref(caps, std::size(caps));"); let instance = "ref"; } diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVEnums.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVEnums.cpp index 0562d42..0ad1477 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVEnums.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVEnums.cpp @@ -19,6 +19,8 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" +#include + using namespace mlir; // Pull in all enum utility function definitions @@ -59,16 +61,16 @@ ArrayRef spirv::getImpliedExtensions(spirv::Version version) { case Version::V_1_3: { // The following manual ArrayRef constructor call is to satisfy GCC 5. static const Extension exts[] = {V_1_3_IMPLIED_EXTS}; - return ArrayRef(exts, llvm::array_lengthof(exts)); + return ArrayRef(exts, std::size(exts)); } case Version::V_1_4: { static const Extension exts[] = {V_1_3_IMPLIED_EXTS, V_1_4_IMPLIED_EXTS}; - return ArrayRef(exts, llvm::array_lengthof(exts)); + return ArrayRef(exts, std::size(exts)); } case Version::V_1_5: { static const Extension exts[] = {V_1_3_IMPLIED_EXTS, V_1_4_IMPLIED_EXTS, V_1_5_IMPLIED_EXTS}; - return ArrayRef(exts, llvm::array_lengthof(exts)); + return ArrayRef(exts, std::size(exts)); } } diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp index a4c622b..6c1a8f0 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp @@ -17,6 +17,8 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/TypeSwitch.h" +#include + using namespace mlir; using namespace mlir::spirv; @@ -174,7 +176,7 @@ void CompositeType::getCapabilities( auto vecSize = getNumElements(); if (vecSize == 8 || vecSize == 16) { static const Capability caps[] = {Capability::Vector16}; - ArrayRef ref(caps, llvm::array_lengthof(caps)); + ArrayRef ref(caps, std::size(caps)); capabilities.push_back(ref); } return type.getElementType().cast().getCapabilities( @@ -248,7 +250,7 @@ void CooperativeMatrixNVType::getExtensions( Optional storage) { getElementType().cast().getExtensions(extensions, storage); static const Extension exts[] = {Extension::SPV_NV_cooperative_matrix}; - ArrayRef ref(exts, llvm::array_lengthof(exts)); + ArrayRef ref(exts, std::size(exts)); extensions.push_back(ref); } @@ -257,7 +259,7 @@ void CooperativeMatrixNVType::getCapabilities( Optional storage) { getElementType().cast().getCapabilities(capabilities, storage); static const Capability caps[] = {Capability::CooperativeMatrixNV}; - ArrayRef ref(caps, llvm::array_lengthof(caps)); + ArrayRef ref(caps, std::size(caps)); capabilities.push_back(ref); } @@ -316,7 +318,7 @@ void JointMatrixINTELType::getExtensions( Optional storage) { getElementType().cast().getExtensions(extensions, storage); static const Extension exts[] = {Extension::SPV_INTEL_joint_matrix}; - ArrayRef ref(exts, llvm::array_lengthof(exts)); + ArrayRef ref(exts, std::size(exts)); extensions.push_back(ref); } @@ -325,7 +327,7 @@ void JointMatrixINTELType::getCapabilities( Optional storage) { getElementType().cast().getCapabilities(capabilities, storage); static const Capability caps[] = {Capability::JointMatrixINTEL}; - ArrayRef ref(caps, llvm::array_lengthof(caps)); + ArrayRef ref(caps, std::size(caps)); capabilities.push_back(ref); } @@ -551,7 +553,7 @@ void RuntimeArrayType::getCapabilities( Optional storage) { { static const Capability caps[] = {Capability::Shader}; - ArrayRef ref(caps, llvm::array_lengthof(caps)); + ArrayRef ref(caps, std::size(caps)); capabilities.push_back(ref); } getElementType().cast().getCapabilities(capabilities, storage); @@ -600,7 +602,7 @@ void ScalarType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, case StorageClass::Uniform: if (getIntOrFloatBitWidth() == 8) { static const Extension exts[] = {Extension::SPV_KHR_8bit_storage}; - ArrayRef ref(exts, llvm::array_lengthof(exts)); + ArrayRef ref(exts, std::size(exts)); extensions.push_back(ref); } [[fallthrough]]; @@ -608,7 +610,7 @@ void ScalarType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, case StorageClass::Output: if (getIntOrFloatBitWidth() == 16) { static const Extension exts[] = {Extension::SPV_KHR_16bit_storage}; - ArrayRef ref(exts, llvm::array_lengthof(exts)); + ArrayRef ref(exts, std::size(exts)); extensions.push_back(ref); } break; @@ -630,13 +632,13 @@ void ScalarType::getCapabilities( case StorageClass::storage: { \ if (bitwidth == 8) { \ static const Capability caps[] = {Capability::cap8}; \ - ArrayRef ref(caps, llvm::array_lengthof(caps)); \ + ArrayRef ref(caps, std::size(caps)); \ capabilities.push_back(ref); \ return; \ } \ if (bitwidth == 16) { \ static const Capability caps[] = {Capability::cap16}; \ - ArrayRef ref(caps, llvm::array_lengthof(caps)); \ + ArrayRef ref(caps, std::size(caps)); \ capabilities.push_back(ref); \ return; \ } \ @@ -657,7 +659,7 @@ void ScalarType::getCapabilities( case StorageClass::Output: { if (bitwidth == 16) { static const Capability caps[] = {Capability::StorageInputOutput16}; - ArrayRef ref(caps, llvm::array_lengthof(caps)); + ArrayRef ref(caps, std::size(caps)); capabilities.push_back(ref); return; } @@ -675,7 +677,7 @@ void ScalarType::getCapabilities( #define WIDTH_CASE(type, width) \ case width: { \ static const Capability caps[] = {Capability::type##width}; \ - ArrayRef ref(caps, llvm::array_lengthof(caps)); \ + ArrayRef ref(caps, std::size(caps)); \ capabilities.push_back(ref); \ } break @@ -1234,7 +1236,7 @@ void MatrixType::getCapabilities( Optional storage) { { static const Capability caps[] = {Capability::Matrix}; - ArrayRef ref(caps, llvm::array_lengthof(caps)); + ArrayRef ref(caps, std::size(caps)); capabilities.push_back(ref); } // Add any capabilities associated with the underlying vectors (i.e., columns)