[llvm] r206115 - tools: remove unnecessary copy of array_lengthof

Saleem Abdulrasool compnerd at compnerd.org
Sat Apr 12 11:04:27 PDT 2014


Author: compnerd
Date: Sat Apr 12 13:04:27 2014
New Revision: 206115

URL: http://llvm.org/viewvc/llvm-project?rev=206115&view=rev
Log:
tools: remove unnecessary copy of array_lengthof

Modified:
    llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp
    llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h

Modified: llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp?rev=206115&r1=206114&r2=206115&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp Sat Apr 12 13:04:27 2014
@@ -9,6 +9,7 @@
 
 #include "ARMAttributeParser.h"
 #include "StreamWriter.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/LEB128.h"
 
@@ -22,11 +23,6 @@ static const EnumEntry<unsigned> TagName
   { "Tag_Symbol", ARMBuildAttrs::Symbol },
 };
 
-template <typename type_, size_t size_>
-size_t countof(const type_ (&)[size_]) {
-  return size_;
-}
-
 namespace llvm {
 #define ATTRIBUTE_HANDLER(Attr_)                                                \
   { ARMBuildAttrs::Attr_, &ARMAttributeParser::Attr_ }
@@ -129,7 +125,8 @@ void ARMAttributeParser::CPU_arch(AttrTy
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -155,7 +152,8 @@ void ARMAttributeParser::ARM_ISA_use(Att
   static const char *Strings[] = { "Not Permitted", "Permitted" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -164,7 +162,8 @@ void ARMAttributeParser::THUMB_ISA_use(A
   static const char *Strings[] = { "Not Permitted", "Thumb-1", "Thumb-2" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -176,7 +175,8 @@ void ARMAttributeParser::FP_arch(AttrTyp
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -185,7 +185,8 @@ void ARMAttributeParser::WMMX_arch(AttrT
   static const char *Strings[] = { "Not Permitted", "WMMXv1", "WMMXv2" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -196,7 +197,8 @@ void ARMAttributeParser::Advanced_SIMD_a
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -208,7 +210,8 @@ void ARMAttributeParser::PCS_config(Attr
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -217,7 +220,8 @@ void ARMAttributeParser::ABI_PCS_R9_use(
   static const char *Strings[] = { "v6", "Static Base", "TLS", "Unused" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -228,7 +232,8 @@ void ARMAttributeParser::ABI_PCS_RW_data
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -237,7 +242,8 @@ void ARMAttributeParser::ABI_PCS_RO_data
   static const char *Strings[] = { "Absolute", "PC-relative", "Not Permitted" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -246,7 +252,8 @@ void ARMAttributeParser::ABI_PCS_GOT_use
   static const char *Strings[] = { "Not Permitted", "Direct", "GOT-Indirect" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -257,7 +264,8 @@ void ARMAttributeParser::ABI_PCS_wchar_t
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -266,7 +274,8 @@ void ARMAttributeParser::ABI_FP_rounding
   static const char *Strings[] = { "IEEE-754", "Runtime" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -275,7 +284,8 @@ void ARMAttributeParser::ABI_FP_denormal
   static const char *Strings[] = { "Unsupported", "IEEE-754", "Sign Only" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -284,7 +294,8 @@ void ARMAttributeParser::ABI_FP_exceptio
   static const char *Strings[] = { "Not Permitted", "IEEE-754" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -294,7 +305,8 @@ void ARMAttributeParser::ABI_FP_user_exc
   static const char *Strings[] = { "Not Permitted", "IEEE-754" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -305,7 +317,8 @@ void ARMAttributeParser::ABI_FP_number_m
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -318,7 +331,7 @@ void ARMAttributeParser::ABI_align_neede
   uint64_t Value = ParseInteger(Data, Offset);
 
   std::string Description;
-  if (Value < countof(Strings))
+  if (Value < array_lengthof(Strings))
     Description = std::string(Strings[Value]);
   else if (Value <= 12)
     Description = std::string("8-byte alignment, ") + utostr(1 << Value)
@@ -339,7 +352,7 @@ void ARMAttributeParser::ABI_align_prese
   uint64_t Value = ParseInteger(Data, Offset);
 
   std::string Description;
-  if (Value < countof(Strings))
+  if (Value < array_lengthof(Strings))
     Description = std::string(Strings[Value]);
   else if (Value <= 12)
     Description = std::string("8-byte stack alignment, ") + utostr(1 << Value)
@@ -357,7 +370,8 @@ void ARMAttributeParser::ABI_enum_size(A
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -368,7 +382,8 @@ void ARMAttributeParser::ABI_HardFP_use(
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -379,7 +394,8 @@ void ARMAttributeParser::ABI_VFP_args(At
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -388,7 +404,8 @@ void ARMAttributeParser::ABI_WMMX_args(A
   static const char *Strings[] = { "AAPCS", "iWMMX", "Custom" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -401,7 +418,8 @@ void ARMAttributeParser::ABI_optimizatio
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -414,7 +432,8 @@ void ARMAttributeParser::ABI_FP_optimiza
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -445,7 +464,8 @@ void ARMAttributeParser::CPU_unaligned_a
   static const char *Strings[] = { "Not Permitted", "v6-style" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -454,7 +474,8 @@ void ARMAttributeParser::FP_HP_extension
   static const char *Strings[] = { "If Available", "Permitted" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -463,7 +484,8 @@ void ARMAttributeParser::ABI_FP_16bit_fo
   static const char *Strings[] = { "Not Permitted", "IEEE-754", "VFPv3" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -472,7 +494,8 @@ void ARMAttributeParser::MPextension_use
   static const char *Strings[] = { "Not Permitted", "Permitted" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -483,7 +506,8 @@ void ARMAttributeParser::DIV_use(AttrTyp
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -492,7 +516,8 @@ void ARMAttributeParser::T2EE_use(AttrTy
   static const char *Strings[] = { "Not Permitted", "Permitted" };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -504,7 +529,8 @@ void ARMAttributeParser::Virtualization_
   };
 
   uint64_t Value = ParseInteger(Data, Offset);
-  StringRef ValueDesc = (Value < countof(Strings)) ? Strings[Value] : NULL;
+  StringRef ValueDesc =
+    (Value < array_lengthof(Strings)) ? Strings[Value] : NULL;
   PrintAttribute(Tag, Value, ValueDesc);
 }
 
@@ -534,7 +560,7 @@ void ARMAttributeParser::ParseAttributeL
     Offset += Length;
 
     bool Handled = false;
-    for (unsigned AHI = 0, AHE = countof(DisplayRoutines);
+    for (unsigned AHI = 0, AHE = array_lengthof(DisplayRoutines);
          AHI != AHE && !Handled; ++AHI) {
       if (DisplayRoutines[AHI].Attribute == Tag) {
         (this->*DisplayRoutines[AHI].Routine)(ARMBuildAttrs::AttrType(Tag),

Modified: llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h?rev=206115&r1=206114&r2=206115&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h (original)
+++ llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h Sat Apr 12 13:04:27 2014
@@ -12,6 +12,7 @@
 
 #include "Error.h"
 #include "StreamWriter.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Object/ELF.h"
 #include "llvm/Object/ELFTypes.h"
 #include "llvm/Support/ARMEHABI.h"
@@ -20,13 +21,6 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/type_traits.h"
 
-namespace {
-template <typename type_, size_t N>
-size_t countof(const type_ (&)[N]) {
-  return N;
-}
-}
-
 namespace llvm {
 namespace ARM {
 namespace EHABI {
@@ -296,7 +290,8 @@ void OpcodeDecoder::PrintRegisters(uint3
 void OpcodeDecoder::Decode(const uint8_t *Opcodes, off_t Offset, size_t Length) {
   for (unsigned OCI = Offset; OCI < Length + Offset; ) {
     bool Decoded = false;
-    for (unsigned REI = 0, REE = countof(Ring); REI != REE && !Decoded; ++REI) {
+    for (unsigned REI = 0, REE = array_lengthof(Ring);
+         REI != REE && !Decoded; ++REI) {
       if ((Opcodes[OCI ^ 3] & Ring[REI].Mask) == Ring[REI].Value) {
         (this->*Ring[REI].Routine)(Opcodes, OCI);
         Decoded = true;





More information about the llvm-commits mailing list