[Mlir-commits] [mlir] e5a8f50 - [mlir] Use std::size instead of llvm::array_lengthof
Joe Loser
llvmlistbot at llvm.org
Wed Sep 7 08:55:46 PDT 2022
Author: Joe Loser
Date: 2022-09-07T09:54:51-06:00
New Revision: e5a8f50ab160c56a316e79f46e787afa15c1cbcc
URL: https://github.com/llvm/llvm-project/commit/e5a8f50ab160c56a316e79f46e787afa15c1cbcc
DIFF: https://github.com/llvm/llvm-project/commit/e5a8f50ab160c56a316e79f46e787afa15c1cbcc.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
mlir/lib/Dialect/SPIRV/IR/SPIRVEnums.cpp
mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
index d27ee36b533f9..5429bba0cd903 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<list<I32EnumAttrCase> 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<list<I32EnumAttrCase> 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 0562d42cfca43..0ad1477dc1681 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 <iterator>
+
using namespace mlir;
// Pull in all enum utility function definitions
@@ -59,16 +61,16 @@ ArrayRef<spirv::Extension> 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<spirv::Extension>(exts, llvm::array_lengthof(exts));
+ return ArrayRef<spirv::Extension>(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<spirv::Extension>(exts, llvm::array_lengthof(exts));
+ return ArrayRef<spirv::Extension>(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<spirv::Extension>(exts, llvm::array_lengthof(exts));
+ return ArrayRef<spirv::Extension>(exts, std::size(exts));
}
}
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
index a4c622b8d8199..6c1a8f00bb95b 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 <iterator>
+
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<Capability> ref(caps, llvm::array_lengthof(caps));
+ ArrayRef<Capability> ref(caps, std::size(caps));
capabilities.push_back(ref);
}
return type.getElementType().cast<ScalarType>().getCapabilities(
@@ -248,7 +250,7 @@ void CooperativeMatrixNVType::getExtensions(
Optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getExtensions(extensions, storage);
static const Extension exts[] = {Extension::SPV_NV_cooperative_matrix};
- ArrayRef<Extension> ref(exts, llvm::array_lengthof(exts));
+ ArrayRef<Extension> ref(exts, std::size(exts));
extensions.push_back(ref);
}
@@ -257,7 +259,7 @@ void CooperativeMatrixNVType::getCapabilities(
Optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getCapabilities(capabilities, storage);
static const Capability caps[] = {Capability::CooperativeMatrixNV};
- ArrayRef<Capability> ref(caps, llvm::array_lengthof(caps));
+ ArrayRef<Capability> ref(caps, std::size(caps));
capabilities.push_back(ref);
}
@@ -316,7 +318,7 @@ void JointMatrixINTELType::getExtensions(
Optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getExtensions(extensions, storage);
static const Extension exts[] = {Extension::SPV_INTEL_joint_matrix};
- ArrayRef<Extension> ref(exts, llvm::array_lengthof(exts));
+ ArrayRef<Extension> ref(exts, std::size(exts));
extensions.push_back(ref);
}
@@ -325,7 +327,7 @@ void JointMatrixINTELType::getCapabilities(
Optional<StorageClass> storage) {
getElementType().cast<SPIRVType>().getCapabilities(capabilities, storage);
static const Capability caps[] = {Capability::JointMatrixINTEL};
- ArrayRef<Capability> ref(caps, llvm::array_lengthof(caps));
+ ArrayRef<Capability> ref(caps, std::size(caps));
capabilities.push_back(ref);
}
@@ -551,7 +553,7 @@ void RuntimeArrayType::getCapabilities(
Optional<StorageClass> storage) {
{
static const Capability caps[] = {Capability::Shader};
- ArrayRef<Capability> ref(caps, llvm::array_lengthof(caps));
+ ArrayRef<Capability> ref(caps, std::size(caps));
capabilities.push_back(ref);
}
getElementType().cast<SPIRVType>().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<Extension> ref(exts, llvm::array_lengthof(exts));
+ ArrayRef<Extension> 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<Extension> ref(exts, llvm::array_lengthof(exts));
+ ArrayRef<Extension> 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<Capability> ref(caps, llvm::array_lengthof(caps)); \
+ ArrayRef<Capability> ref(caps, std::size(caps)); \
capabilities.push_back(ref); \
return; \
} \
if (bitwidth == 16) { \
static const Capability caps[] = {Capability::cap16}; \
- ArrayRef<Capability> ref(caps, llvm::array_lengthof(caps)); \
+ ArrayRef<Capability> 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<Capability> ref(caps, llvm::array_lengthof(caps));
+ ArrayRef<Capability> 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<Capability> ref(caps, llvm::array_lengthof(caps)); \
+ ArrayRef<Capability> ref(caps, std::size(caps)); \
capabilities.push_back(ref); \
} break
@@ -1234,7 +1236,7 @@ void MatrixType::getCapabilities(
Optional<StorageClass> storage) {
{
static const Capability caps[] = {Capability::Matrix};
- ArrayRef<Capability> ref(caps, llvm::array_lengthof(caps));
+ ArrayRef<Capability> ref(caps, std::size(caps));
capabilities.push_back(ref);
}
// Add any capabilities associated with the underlying vectors (i.e., columns)
More information about the Mlir-commits
mailing list