12 changes: 6 additions & 6 deletions llvm/unittests/ADT/StringRefTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ TEST(StringRefTest, getAsInteger) {
uint32_t U32;
uint64_t U64;

for (size_t i = 0; i < array_lengthof(Unsigned); ++i) {
for (size_t i = 0; i < size(Unsigned); ++i) {
bool U8Success = StringRef(Unsigned[i].Str).getAsInteger(0, U8);
if (static_cast<uint8_t>(Unsigned[i].Expected) == Unsigned[i].Expected) {
ASSERT_FALSE(U8Success);
Expand Down Expand Up @@ -691,7 +691,7 @@ TEST(StringRefTest, getAsInteger) {
int32_t S32;
int64_t S64;

for (size_t i = 0; i < array_lengthof(Signed); ++i) {
for (size_t i = 0; i < size(Signed); ++i) {
bool S8Success = StringRef(Signed[i].Str).getAsInteger(0, S8);
if (static_cast<int8_t>(Signed[i].Expected) == Signed[i].Expected) {
ASSERT_FALSE(S8Success);
Expand Down Expand Up @@ -737,7 +737,7 @@ static const char* BadStrings[] = {

TEST(StringRefTest, getAsUnsignedIntegerBadStrings) {
unsigned long long U64;
for (size_t i = 0; i < array_lengthof(BadStrings); ++i) {
for (size_t i = 0; i < size(BadStrings); ++i) {
bool IsBadNumber = StringRef(BadStrings[i]).getAsInteger(0, U64);
ASSERT_TRUE(IsBadNumber);
}
Expand Down Expand Up @@ -820,7 +820,7 @@ TEST(StringRefTest, consumeIntegerUnsigned) {
uint32_t U32;
uint64_t U64;

for (size_t i = 0; i < array_lengthof(ConsumeUnsigned); ++i) {
for (size_t i = 0; i < size(ConsumeUnsigned); ++i) {
StringRef Str = ConsumeUnsigned[i].Str;
bool U8Success = Str.consumeInteger(0, U8);
if (static_cast<uint8_t>(ConsumeUnsigned[i].Expected) ==
Expand Down Expand Up @@ -868,7 +868,7 @@ TEST(StringRefTest, consumeIntegerSigned) {
int32_t S32;
int64_t S64;

for (size_t i = 0; i < array_lengthof(ConsumeSigned); ++i) {
for (size_t i = 0; i < size(ConsumeSigned); ++i) {
StringRef Str = ConsumeSigned[i].Str;
bool S8Success = Str.consumeInteger(0, S8);
if (static_cast<int8_t>(ConsumeSigned[i].Expected) ==
Expand Down Expand Up @@ -945,7 +945,7 @@ static const char join_result3[] = "a::b::c";
TEST(StringRefTest, joinStrings) {
std::vector<StringRef> v1;
std::vector<std::string> v2;
for (size_t i = 0; i < array_lengthof(join_input); ++i) {
for (size_t i = 0; i < size(join_input); ++i) {
v1.push_back(join_input[i]);
v2.push_back(join_input[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/ADT/TinyPtrVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TinyPtrVectorTest : public testing::Test {
std::vector<PtrT> TestPtrs;

TinyPtrVectorTest() {
for (size_t i = 0, e = array_lengthof(TestValues); i != e; ++i)
for (size_t i = 0, e = size(TestValues); i != e; ++i)
TestPtrs.push_back(PtrT(&TestValues[i]));

std::shuffle(TestPtrs.begin(), TestPtrs.end(), std::mt19937{});
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/ProfileData/CoverageMappingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ TEST_P(CoverageMappingTest, basic_write_read) {

TEST_P(CoverageMappingTest, correct_deserialize_for_more_than_two_files) {
const char *FileNames[] = {"bar", "baz", "foo"};
static const unsigned N = array_lengthof(FileNames);
static const unsigned N = size(FileNames);

startFunction("func", 0x1234);
for (unsigned I = 0; I < N; ++I)
Expand Down Expand Up @@ -321,7 +321,7 @@ TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) {
ProfileWriter.addRecord({"func", 0x1234, {0}}, Err);

const char *FileNames[] = {"bar", "baz", "foo"};
static const unsigned N = array_lengthof(FileNames);
static const unsigned N = size(FileNames);

startFunction("func", 0x1234);
for (unsigned I = 0; I < N; ++I)
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Support/BinaryStreamTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BrokenStream : public WritableBinaryStream {
};

constexpr endianness Endians[] = {big, little, native};
constexpr uint32_t NumEndians = llvm::array_lengthof(Endians);
constexpr uint32_t NumEndians = llvm::size(Endians);
constexpr uint32_t NumStreams = 2 * NumEndians;

class BinaryStreamTest : public testing::Test {
Expand Down
10 changes: 5 additions & 5 deletions llvm/unittests/Support/CommandLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ TEST(CommandLineTest, AliasesWithArguments) {
{ "-tool", "-alias", "x" }
};

for (size_t i = 0, e = array_lengthof(Inputs); i < e; ++i) {
for (size_t i = 0, e = size(Inputs); i < e; ++i) {
StackOption<std::string> Actual("actual");
StackOption<bool> Extra("extra");
StackOption<std::string> Input(cl::Positional);
Expand Down Expand Up @@ -374,8 +374,8 @@ void testAliasRequired(int argc, const char *const *argv) {
TEST(CommandLineTest, AliasRequired) {
const char *opts1[] = { "-tool", "-option=x" };
const char *opts2[] = { "-tool", "-o", "x" };
testAliasRequired(array_lengthof(opts1), opts1);
testAliasRequired(array_lengthof(opts2), opts2);
testAliasRequired(size(opts1), opts1);
testAliasRequired(size(opts2), opts2);
}

TEST(CommandLineTest, HideUnrelatedOptions) {
Expand Down Expand Up @@ -987,8 +987,8 @@ TEST(CommandLineTest, ResponseFileEOLs) {
/*CurrentDir=*/StringRef(TestRoot), FS));
const char *Expected[] = {"clang", "-Xclang", "-Wno-whatever", nullptr,
"input.cpp"};
ASSERT_EQ(array_lengthof(Expected), Argv.size());
for (size_t I = 0, E = array_lengthof(Expected); I < E; ++I) {
ASSERT_EQ(size(Expected), Argv.size());
for (size_t I = 0, E = size(Expected); I < E; ++I) {
if (Expected[I] == nullptr) {
ASSERT_EQ(Argv[I], nullptr);
} else {
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Support/FormatVariadicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ TEST(FormatVariadicTest, BigTest) {
std::string S;
llvm::raw_string_ostream Stream(S);
Stream << formatv(Intro, std::tuple_size<Tuple>::value,
llvm::array_lengthof(Ts))
llvm::size(Ts))
<< "\n";
Stream << formatv(Header, "Char", "HexInt", "Str", "Ref", "std::str",
"double", "float", "pointer", "comma", "exp", "bigint",
Expand Down
12 changes: 6 additions & 6 deletions llvm/unittests/Support/TargetParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ TEST(TargetParserTest, ARMArchExtFeature) {
{"mve", "nomve", "+mve", "-mve"},
{"mve.fp", "nomve.fp", "+mve.fp", "-mve.fp"}};

for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
for (unsigned i = 0; i < size(ArchExt); i++) {
EXPECT_EQ(StringRef(ArchExt[i][2]), ARM::getArchExtFeature(ArchExt[i][0]));
EXPECT_EQ(StringRef(ArchExt[i][3]), ARM::getArchExtFeature(ArchExt[i][1]));
}
Expand Down Expand Up @@ -764,7 +764,7 @@ TEST(TargetParserTest, ARMArchExtDependencies) {
TEST(TargetParserTest, ARMparseHWDiv) {
const char *hwdiv[] = {"thumb", "arm", "arm,thumb", "thumb,arm"};

for (unsigned i = 0; i < array_lengthof(hwdiv); i++)
for (unsigned i = 0; i < size(hwdiv); i++)
EXPECT_NE(ARM::AEK_INVALID, ARM::parseHWDiv((StringRef)hwdiv[i]));
}

Expand All @@ -782,7 +782,7 @@ TEST(TargetParserTest, ARMparseArchEndianAndISA) {
"v8.7a", "v8.8-a", "v8.8a", "v8-r", "v8m.base", "v8m.main",
"v8.1m.main"};

for (unsigned i = 0; i < array_lengthof(Arch); i++) {
for (unsigned i = 0; i < size(Arch); i++) {
std::string arm_1 = "armeb" + (std::string)(Arch[i]);
std::string arm_2 = "arm" + (std::string)(Arch[i]) + "eb";
std::string arm_3 = "arm" + (std::string)(Arch[i]);
Expand Down Expand Up @@ -821,7 +821,7 @@ TEST(TargetParserTest, ARMparseArchEndianAndISA) {
}

TEST(TargetParserTest, ARMparseArchProfile) {
for (unsigned i = 0; i < array_lengthof(ARMArch); i++) {
for (unsigned i = 0; i < size(ARMArch); i++) {
switch (ARM::parseArch(ARMArch[i])) {
case ARM::ArchKind::ARMV6M:
case ARM::ArchKind::ARMV7M:
Expand Down Expand Up @@ -861,7 +861,7 @@ TEST(TargetParserTest, ARMparseArchProfile) {
}

TEST(TargetParserTest, ARMparseArchVersion) {
for (unsigned i = 0; i < array_lengthof(ARMArch); i++)
for (unsigned i = 0; i < size(ARMArch); i++)
if (((std::string)ARMArch[i]).substr(0, 4) == "armv")
EXPECT_EQ((ARMArch[i][4] - 48u), ARM::parseArchVersion(ARMArch[i]));
else
Expand Down Expand Up @@ -1526,7 +1526,7 @@ TEST(TargetParserTest, AArch64ArchExtFeature) {
{"pmuv3", "nopmuv3", "+perfmon", "-perfmon"},
};

for (unsigned i = 0; i < array_lengthof(ArchExt); i++) {
for (unsigned i = 0; i < size(ArchExt); i++) {
EXPECT_EQ(StringRef(ArchExt[i][2]),
AArch64::getArchExtFeature(ArchExt[i][0]));
EXPECT_EQ(StringRef(ArchExt[i][3]),
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/KillTheDoctor/KillTheDoctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static std::error_code GetFileNameFromHandle(HANDLE FileHandle,
Success = ::GetMappedFileNameA(::GetCurrentProcess(),
MappedFile,
Filename,
array_lengthof(Filename) - 1);
size(Filename) - 1);

if (!Success)
return windows_error(::GetLastError());
Expand Down Expand Up @@ -242,12 +242,12 @@ static std::string FindProgram(const std::string &Program,
DWORD length = ::SearchPathA(NULL,
Program.c_str(),
Extension,
array_lengthof(PathName),
size(PathName),
PathName,
NULL);
if (length == 0)
ec = windows_error(::GetLastError());
else if (length > array_lengthof(PathName)) {
else if (length > size(PathName)) {
// This may have been the file, return with error.
ec = windows_error(ERROR_BUFFER_OVERFLOW);
break;
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/AsmWriterEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
O.indent(2) << " makeArrayRef(OpToPatterns),\n";
O.indent(2) << " makeArrayRef(Patterns),\n";
O.indent(2) << " makeArrayRef(Conds),\n";
O.indent(2) << " StringRef(AsmStrings, array_lengthof(AsmStrings)),\n";
O.indent(2) << " StringRef(AsmStrings, size(AsmStrings)),\n";
if (MCOpPredicates.empty())
O.indent(2) << " nullptr,\n";
else
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/CodeGenTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static const char *const FixedInstrs[] = {
nullptr};

unsigned CodeGenTarget::getNumFixedInstructions() {
return array_lengthof(FixedInstrs) - 1;
return size(FixedInstrs) - 1;
}

/// Return all of the instructions defined by the target, ordered by
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/RegisterInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void RegisterInfoEmitter::EmitRegMappingTables(
OS << "extern const unsigned " << Namespace
<< (j == 0 ? "DwarfFlavour" : "EHFlavour") << I << "Dwarf2LSize";
if (!isCtor)
OS << " = array_lengthof(" << Namespace
OS << " = size(" << Namespace
<< (j == 0 ? "DwarfFlavour" : "EHFlavour") << I << "Dwarf2L);\n\n";
else
OS << ";\n\n";
Expand Down Expand Up @@ -498,7 +498,7 @@ void RegisterInfoEmitter::EmitRegMappingTables(
OS << "extern const unsigned " << Namespace
<< (j == 0 ? "DwarfFlavour" : "EHFlavour") << i << "L2DwarfSize";
if (!isCtor)
OS << " = array_lengthof(" << Namespace
OS << " = size(" << Namespace
<< (j == 0 ? "DwarfFlavour" : "EHFlavour") << i << "L2Dwarf);\n\n";
else
OS << ";\n\n";
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/X86DisassemblerTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ static const char* stringForDecisionType(ModRMDecisionType dt) {
}

DisassemblerTables::DisassemblerTables() {
for (unsigned i = 0; i < array_lengthof(Tables); i++)
for (unsigned i = 0; i < size(Tables); i++)
Tables[i] = std::make_unique<ContextDecision>();

HasConflicts = false;
Expand Down
4 changes: 2 additions & 2 deletions mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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, ::llvm::size(exts));");
let instance = "ref";
}

Expand Down Expand Up @@ -228,7 +228,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, ::llvm::size(caps));");
let instance = "ref";
}

Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,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, llvm::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, llvm::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, llvm::size(exts));
}
}

Expand Down
22 changes: 11 additions & 11 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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, llvm::size(caps));
capabilities.push_back(ref);
}
return type.getElementType().cast<ScalarType>().getCapabilities(
Expand Down Expand Up @@ -242,7 +242,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, llvm::size(exts));
extensions.push_back(ref);
}

Expand All @@ -251,7 +251,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, llvm::size(caps));
capabilities.push_back(ref);
}

Expand Down Expand Up @@ -468,7 +468,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, llvm::size(caps));
capabilities.push_back(ref);
}
getElementType().cast<SPIRVType>().getCapabilities(capabilities, storage);
Expand Down Expand Up @@ -517,15 +517,15 @@ 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, llvm::size(exts));
extensions.push_back(ref);
}
LLVM_FALLTHROUGH;
case StorageClass::Input:
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, llvm::size(exts));
extensions.push_back(ref);
}
break;
Expand All @@ -547,11 +547,11 @@ 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, llvm::size(caps)); \
capabilities.push_back(ref); \
} else if (bitwidth == 16) { \
static const Capability caps[] = {Capability::cap16}; \
ArrayRef<Capability> ref(caps, llvm::array_lengthof(caps)); \
ArrayRef<Capability> ref(caps, llvm::size(caps)); \
capabilities.push_back(ref); \
} \
/* No requirements for other bitwidths */ \
Expand All @@ -571,7 +571,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, llvm::size(caps));
capabilities.push_back(ref);
}
return;
Expand All @@ -588,7 +588,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, llvm::size(caps)); \
capabilities.push_back(ref); \
} break

Expand Down Expand Up @@ -1147,7 +1147,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, llvm::size(caps));
capabilities.push_back(ref);
}
// Add any capabilities associated with the underlying vectors (i.e., columns)
Expand Down