[llvm-commits] sizeof

Evan Cheng evan.cheng at apple.com
Wed Sep 5 14:14:02 PDT 2007


Hi S3 (or whoever you are :-),

It's probably a good idea to post it to llvmdev first so more people  
can comment on it.

Thanks,

Evan

On Sep 4, 2007, at 10:44 PM, S3 wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Here is my first attempt at a patch.
> It introduces a new header file where
> people can put templates to be used wherever.
> I have put "endof" and "lengthof"
> which replace most uses of sizeof.
> This should make the code a little neater.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7-ecc0.1.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFG3kJQxzVgPqtIcfsRAjWIAJ0a1ROkY5i7pVfogeBshUiunw2eVwCeOpwC
> i+7a/sV92dlhlNBbnRTks28=
> =Qe8f
> -----END PGP SIGNATURE-----
> Index: include/llvm/Target/TargetLowering.h
> ===================================================================
> --- include/llvm/Target/TargetLowering.h	(revision 41716)
> +++ include/llvm/Target/TargetLowering.h	(working copy)
> @@ -22,6 +22,7 @@
> #ifndef LLVM_TARGET_TARGETLOWERING_H
> #define LLVM_TARGET_TARGETLOWERING_H
>
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/SelectionDAGNodes.h"
> #include "llvm/CodeGen/RuntimeLibcalls.h"
> #include "llvm/ADT/APFloat.h"
> @@ -155,7 +156,7 @@
>     void setTypeAction(MVT::ValueType VT, LegalizeAction Action) {
>       assert(!MVT::isExtendedVT(VT));
>       assert(unsigned(VT >> 4) <
> -             sizeof(ValueTypeActions)/sizeof(ValueTypeActions[0]));
> +             llvm::lengthof(ValueTypeActions));
>       ValueTypeActions[VT>>4] |= Action << ((VT*2) & 31);
>     }
>   };
> @@ -711,7 +712,7 @@
>   /// with the specified type and indicate what to do about it.
>   void setOperationAction(unsigned Op, MVT::ValueType VT,
>                           LegalizeAction Action) {
> -    assert(VT < 32 && Op < sizeof(OpActions)/sizeof(OpActions[0]) &&
> +    assert(VT < 32 && Op < llvm::lengthof(OpActions) &&
>            "Table isn't big enough!");
>     OpActions[Op] &= ~(uint64_t(3UL) << VT*2);
>     OpActions[Op] |= (uint64_t)Action << VT*2;
> @@ -721,7 +722,7 @@
>   /// work with the with specified type and indicate what to do  
> about it.
>   void setLoadXAction(unsigned ExtType, MVT::ValueType VT,
>                       LegalizeAction Action) {
> -    assert(VT < 32 && ExtType < sizeof(LoadXActions)/ 
> sizeof(LoadXActions[0]) &&
> +    assert(VT < 32 && ExtType < llvm::lengthof(LoadXActions) &&
>            "Table isn't big enough!");
>     LoadXActions[ExtType] &= ~(uint64_t(3UL) << VT*2);
>     LoadXActions[ExtType] |= (uint64_t)Action << VT*2;
> @@ -742,7 +743,7 @@
>   void setIndexedLoadAction(unsigned IdxMode, MVT::ValueType VT,
>                             LegalizeAction Action) {
>     assert(VT < 32 && IdxMode <
> -           sizeof(IndexedModeActions[0]) /  
> sizeof(IndexedModeActions[0][0]) &&
> +           llvm::lengthof(IndexedModeActions[0]) &&
>            "Table isn't big enough!");
>     IndexedModeActions[0][IdxMode] &= ~(uint64_t(3UL) << VT*2);
>     IndexedModeActions[0][IdxMode] |= (uint64_t)Action << VT*2;
> @@ -755,7 +756,7 @@
>   void setIndexedStoreAction(unsigned IdxMode, MVT::ValueType VT,
>                              LegalizeAction Action) {
>     assert(VT < 32 && IdxMode <
> -           sizeof(IndexedModeActions[1]) /  
> sizeof(IndexedModeActions[1][0]) &&
> +           llvm::lengthof(IndexedModeActions[1]) &&
>            "Table isn't big enough!");
>     IndexedModeActions[1][IdxMode] &= ~(uint64_t(3UL) << VT*2);
>     IndexedModeActions[1][IdxMode] |= (uint64_t)Action << VT*2;
> Index: include/llvm/Templates.h
> ===================================================================
> --- include/llvm/Templates.h	(revision 0)
> +++ include/llvm/Templates.h	(revision 0)
> @@ -0,0 +1,39 @@
> +//===- Templates.h - Miscellaneous Templates ------------------*- C+ 
> + -*-===//
> +//
> +//                      The LLVM Compiler Infrastructure
> +//
> +// This file was developed by Sterling Stein and is distributed  
> under the
> +// University of Illinois Open Source License. See LICENSE.TXT for  
> details.
> +//
> +// 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
> +//
> +// This file provides miscellaneous templates.
> +//
> +// 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
> +
> +#ifndef LLVM_TEMPLATES_H
> +#define LLVM_TEMPLATES_H
> +
> +#include <cstring> //For size_t
> +
> +namespace llvm {
> +
> +  /// Find where an array ends (for ending iterators)
> +  /// This returns a pointer to the byte immediately
> +  /// after the end of an array.
> +  template<class T, std::size_t N>
> +  inline T *endof(T (&x)[N])
> +  {
> +    return x+N;
> +  }
> +
> +  /// Find the length of an array.
> +  template<class T, std::size_t N>
> +  inline size_t lengthof(T (&x)[N])
> +  {
> +    return N;
> +  }
> +
> +}
> +
> +#endif
> Index: lib/Analysis/BasicAliasAnalysis.cpp
> ===================================================================
> --- lib/Analysis/BasicAliasAnalysis.cpp	(revision 41716)
> +++ lib/Analysis/BasicAliasAnalysis.cpp	(working copy)
> @@ -23,6 +23,7 @@
> #include "llvm/Instructions.h"
> #include "llvm/Intrinsics.h"
> #include "llvm/Pass.h"
> +#include "llvm/Templates.h"
> #include "llvm/Target/TargetData.h"
> #include "llvm/ADT/SmallVector.h"
> #include "llvm/ADT/StringMap.h"
> @@ -888,14 +889,10 @@
>   static bool Initialized = false;
>   if (!Initialized) {
>     NoMemoryTable->insert(NoMemoryTable->end(),
> -                          DoesntAccessMemoryFns,
> -                          DoesntAccessMemoryFns+
> -                sizeof(DoesntAccessMemoryFns)/ 
> sizeof(DoesntAccessMemoryFns[0]));
> +                          DoesntAccessMemoryFns,  
> endof(DoesntAccessMemoryFns));
>
>     OnlyReadsMemoryTable->insert(OnlyReadsMemoryTable->end(),
> -                                OnlyReadsMemoryFns,
> -                                OnlyReadsMemoryFns+
> -                      sizeof(OnlyReadsMemoryFns)/ 
> sizeof(OnlyReadsMemoryFns[0]));
> +                                OnlyReadsMemoryFns,  
> endof(OnlyReadsMemoryFns));
>
>     // Sort the table the first time through.
>     std::sort(NoMemoryTable->begin(), NoMemoryTable->end(),  
> StringCompare());
> Index: lib/CodeGen/IntrinsicLowering.cpp
> ===================================================================
> --- lib/CodeGen/IntrinsicLowering.cpp	(revision 41716)
> +++ lib/CodeGen/IntrinsicLowering.cpp	(working copy)
> @@ -15,6 +15,7 @@
> #include "llvm/DerivedTypes.h"
> #include "llvm/Module.h"
> #include "llvm/Instructions.h"
> +#include "llvm/Templates.h"
> #include "llvm/Type.h"
> #include "llvm/CodeGen/IntrinsicLowering.h"
> #include "llvm/Support/Streams.h"
> @@ -421,7 +422,7 @@
>     CI->getOperand(2),
>     CI->getOperand(3)
>   };
> -  return new CallInst(F, Args, Args+sizeof(Args)/sizeof(Args[0]),  
> CI->getName(), CI);
> +  return new CallInst(F, Args, endof(Args), CI->getName(), CI);
> }
>
> /// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes
> @@ -587,7 +588,7 @@
>     CI->getOperand(3),
>     CI->getOperand(4)
>   };
> -  return new CallInst(F, Args, Args+sizeof(Args)/sizeof(Args[0]),  
> CI->getName(), CI);
> +  return new CallInst(F, Args, endof(Args), CI->getName(), CI);
> }
>
>
> Index: lib/CodeGen/SelectionDAG/TargetLowering.cpp
> ===================================================================
> --- lib/CodeGen/SelectionDAG/TargetLowering.cpp	(revision 41716)
> +++ lib/CodeGen/SelectionDAG/TargetLowering.cpp	(working copy)
> @@ -145,8 +145,7 @@
>   ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD- 
> >getIntPtrType());
>   ShiftAmtHandling = Undefined;
>   memset(RegClassForVT,  
> 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
> -  memset(TargetDAGCombineArray, 0,
> -         sizeof(TargetDAGCombineArray)/ 
> sizeof(TargetDAGCombineArray[0]));
> +  memset(TargetDAGCombineArray, 0, lengthof(TargetDAGCombineArray));
>   maxStoresPerMemset = maxStoresPerMemcpy = maxStoresPerMemmove = 8;
>   allowUnalignedMemoryAccesses = false;
>   UseUnderscoreSetJmp = false;
> Index: lib/System/Unix/Signals.inc
> ===================================================================
> --- lib/System/Unix/Signals.inc	(revision 41716)
> +++ lib/System/Unix/Signals.inc	(working copy)
> @@ -13,6 +13,7 @@
> // 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
>
> #include "Unix.h"
> +#include "llvm/Templates.h"
> #include <vector>
> #include <algorithm>
> #if HAVE_EXECINFO_H
> @@ -40,7 +41,7 @@
> const int IntSigs[] = {
>   SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
> };
> -const int *IntSigsEnd = IntSigs + sizeof(IntSigs)/sizeof(IntSigs[0]);
> +const int *IntSigsEnd = endof(IntSigs);
>
> // KillSigs - Signals that are synchronous with the program that  
> will cause it
> // to die.
> @@ -50,7 +51,7 @@
>   , SIGEMT
> #endif
> };
> -const int *KillSigsEnd = KillSigs + sizeof(KillSigs)/ 
> sizeof(KillSigs[0]);
> +const int *KillSigsEnd = endof(KillSigs);
>
> #ifdef HAVE_BACKTRACE
> void* StackTrace[256];
> @@ -68,7 +69,7 @@
> void PrintStackTrace() {
> #ifdef HAVE_BACKTRACE
>   // Use backtrace() to output a backtrace on Linux systems with  
> glibc.
> -  int depth = backtrace(StackTrace, sizeof(StackTrace)/ 
> sizeof(StackTrace[0]));
> +  int depth = backtrace(StackTrace, lengthof(StackTrace));
>
>   // Create a one-way unix pipe.  The backtracing process writes to  
> PipeFDs[1],
>   // the c++filt process reads from PipeFDs[0].
> Index: lib/Target/PowerPC/PPCISelLowering.cpp
> ===================================================================
> --- lib/Target/PowerPC/PPCISelLowering.cpp	(revision 41716)
> +++ lib/Target/PowerPC/PPCISelLowering.cpp	(working copy)
> @@ -16,6 +16,7 @@
> #include "PPCPredicates.h"
> #include "PPCTargetMachine.h"
> #include "PPCPerfectShuffle.h"
> +#include "llvm/Templates.h"
> #include "llvm/ADT/VectorExtras.h"
> #include "llvm/Analysis/ScalarEvolutionExpressions.h"
> #include "llvm/CodeGen/CallingConvLower.h"
> @@ -1264,9 +1265,9 @@
>     PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13
>   };
>
> -  const unsigned Num_GPR_Regs = sizeof(GPR_32)/sizeof(GPR_32[0]);
> +  const unsigned Num_GPR_Regs = lengthof(GPR_32);
>   const unsigned Num_FPR_Regs = isMachoABI ? 13 : 8;
> -  const unsigned Num_VR_Regs  = sizeof( VR)/sizeof( VR[0]);
> +  const unsigned Num_VR_Regs  = lengthof( VR);
>
>   unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0;
>
> @@ -1583,9 +1584,9 @@
>     PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8,
>     PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13
>   };
> -  const unsigned NumGPRs = sizeof(GPR_32)/sizeof(GPR_32[0]);
> +  const unsigned NumGPRs = lengthof(GPR_32);
>   const unsigned NumFPRs = isMachoABI ? 13 : 8;
> -  const unsigned NumVRs  = sizeof( VR)/sizeof( VR[0]);
> +  const unsigned NumVRs  = lengthof( VR);
>
>   const unsigned *GPR = isPPC64 ? GPR_64 : GPR_32;
>
> @@ -2399,7 +2400,7 @@
>       -8, 8, -9, 9, -10, 10, -11, 11, -12, 12, -13, 13, 14, -14, 15,  
> -15, -16
>     };
>
> -    for (unsigned idx = 0; idx < sizeof(SplatCsts)/ 
> sizeof(SplatCsts[0]); ++idx){
> +    for (unsigned idx = 0; idx < lengthof(SplatCsts); ++idx){
>       // Indirect through the SplatCsts array so that we favor  
> 'vsplti -1' for
>       // cases which are ambiguous (e.g. formation of 0x8000_0000).   
> 'vsplti -1'
>       int i = SplatCsts[idx];
> Index: lib/Target/PowerPC/PPCInstrInfo.cpp
> ===================================================================
> --- lib/Target/PowerPC/PPCInstrInfo.cpp	(revision 41716)
> +++ lib/Target/PowerPC/PPCInstrInfo.cpp	(working copy)
> @@ -15,11 +15,12 @@
> #include "PPCPredicates.h"
> #include "PPCGenInstrInfo.inc"
> #include "PPCTargetMachine.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> using namespace llvm;
>
> PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm)
> -  : TargetInstrInfo(PPCInsts, sizeof(PPCInsts)/ 
> sizeof(PPCInsts[0])), TM(tm),
> +  : TargetInstrInfo(PPCInsts, lengthof(PPCInsts)), TM(tm),
>     RI(*TM.getSubtargetImpl(), *this) {}
>
> /// getPointerRegClass - Return the register class to use to hold  
> pointers.
> Index: lib/Target/ARM/ARMInstrInfo.cpp
> ===================================================================
> --- lib/Target/ARM/ARMInstrInfo.cpp	(revision 41716)
> +++ lib/Target/ARM/ARMInstrInfo.cpp	(working copy)
> @@ -17,6 +17,7 @@
> #include "ARMAddressingModes.h"
> #include "ARMGenInstrInfo.inc"
> #include "ARMMachineFunctionInfo.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/LiveVariables.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "llvm/CodeGen/MachineJumpTableInfo.h"
> @@ -28,7 +29,7 @@
>                                   cl::desc("Enable ARM 2-addr to 3- 
> addr conv"));
>
> ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
> -  : TargetInstrInfo(ARMInsts, sizeof(ARMInsts)/sizeof(ARMInsts[0])),
> +  : TargetInstrInfo(ARMInsts, lengthof(ARMInsts)),
>     RI(*this, STI) {
> }
>
> Index: lib/Target/Alpha/AlphaInstrInfo.cpp
> ===================================================================
> --- lib/Target/Alpha/AlphaInstrInfo.cpp	(revision 41716)
> +++ lib/Target/Alpha/AlphaInstrInfo.cpp	(working copy)
> @@ -14,11 +14,12 @@
> #include "Alpha.h"
> #include "AlphaInstrInfo.h"
> #include "AlphaGenInstrInfo.inc"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> using namespace llvm;
>
> AlphaInstrInfo::AlphaInstrInfo()
> -  : TargetInstrInfo(AlphaInsts, sizeof(AlphaInsts)/ 
> sizeof(AlphaInsts[0])),
> +  : TargetInstrInfo(AlphaInsts, lengthof(AlphaInsts)),
>     RI(*this) { }
>
>
> Index: lib/Target/X86/X86RegisterInfo.cpp
> ===================================================================
> --- lib/Target/X86/X86RegisterInfo.cpp	(revision 41716)
> +++ lib/Target/X86/X86RegisterInfo.cpp	(working copy)
> @@ -20,6 +20,7 @@
> #include "X86TargetMachine.h"
> #include "llvm/Constants.h"
> #include "llvm/Function.h"
> +#include "llvm/Templates.h"
> #include "llvm/Type.h"
> #include "llvm/CodeGen/ValueTypes.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> @@ -392,16 +393,13 @@
>   return NULL;
> }
>
> -#define ARRAY_SIZE(TABLE)  \
> -   (sizeof(TABLE)/sizeof(TABLE[0]))
> -
> #ifdef NDEBUG
> #define ASSERT_SORTED(TABLE)
> #else
> #define  
> ASSERT_SORTED(TABLE)                                              \
>   { static bool TABLE##Checked =  
> false;                                   \
>     if (!TABLE##Checked)  
> {                                                \
> -       assert(TableIsSorted(TABLE, ARRAY_SIZE(TABLE))  
> &&                  \
> +       assert(TableIsSorted(TABLE, lengthof(TABLE))  
> &&                    \
>               "All lookup tables must be sorted for efficient  
> access!");  \
>        TABLE##Checked =  
> true;                                             \
>     }                                                                     \
> @@ -590,7 +588,7 @@
>     };
>     ASSERT_SORTED(OpcodeTable);
>     OpcodeTablePtr = OpcodeTable;
> -    OpcodeTableSize = ARRAY_SIZE(OpcodeTable);
> +    OpcodeTableSize = lengthof(OpcodeTable);
>     isTwoAddrFold = true;
>   } else if (i == 0) { // If operand 0
>     if (MI->getOpcode() == X86::MOV16r0)
> @@ -675,7 +673,7 @@
>
>     ASSERT_SORTED(OpcodeTable);
>     OpcodeTablePtr = OpcodeTable;
> -    OpcodeTableSize = ARRAY_SIZE(OpcodeTable);
> +    OpcodeTableSize = lengthof(OpcodeTable);
>   } else if (i == 1) {
>     static const TableEntry OpcodeTable[] = {
>       { X86::CMP16rr,         X86::CMP16rm },
> @@ -784,7 +782,7 @@
>
>     ASSERT_SORTED(OpcodeTable);
>     OpcodeTablePtr = OpcodeTable;
> -    OpcodeTableSize = ARRAY_SIZE(OpcodeTable);
> +    OpcodeTableSize = lengthof(OpcodeTable);
>   } else if (i == 2) {
>     static const TableEntry OpcodeTable[] = {
>       { X86::ADC32rr,         X86::ADC32rm },
> @@ -979,7 +977,7 @@
>
>     ASSERT_SORTED(OpcodeTable);
>     OpcodeTablePtr = OpcodeTable;
> -    OpcodeTableSize = ARRAY_SIZE(OpcodeTable);
> +    OpcodeTableSize = lengthof(OpcodeTable);
>   }
>
>   // If table selected...
> Index: lib/Target/X86/X86InstrInfo.cpp
> ===================================================================
> --- lib/Target/X86/X86InstrInfo.cpp	(revision 41716)
> +++ lib/Target/X86/X86InstrInfo.cpp	(working copy)
> @@ -17,13 +17,14 @@
> #include "X86InstrBuilder.h"
> #include "X86Subtarget.h"
> #include "X86TargetMachine.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "llvm/CodeGen/LiveVariables.h"
> #include "llvm/CodeGen/SSARegMap.h"
> using namespace llvm;
>
> X86InstrInfo::X86InstrInfo(X86TargetMachine &tm)
> -  : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0])),
> +  : TargetInstrInfo(X86Insts, lengthof(X86Insts)),
>     TM(tm), RI(tm, *this) {
> }
>
> Index: lib/Target/X86/X86FloatingPoint.cpp
> ===================================================================
> --- lib/Target/X86/X86FloatingPoint.cpp	(revision 41716)
> +++ lib/Target/X86/X86FloatingPoint.cpp	(working copy)
> @@ -31,6 +31,7 @@
> #define DEBUG_TYPE "x86-codegen"
> #include "X86.h"
> #include "X86InstrInfo.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineFunctionPass.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "llvm/CodeGen/LiveVariables.h"
> @@ -299,16 +300,13 @@
>   return -1;
> }
>
> -#define ARRAY_SIZE(TABLE)  \
> -   (sizeof(TABLE)/sizeof(TABLE[0]))
> -
> #ifdef NDEBUG
> #define ASSERT_SORTED(TABLE)
> #else
> #define  
> ASSERT_SORTED(TABLE)                                              \
>   { static bool TABLE##Checked =  
> false;                                   \
>     if (!TABLE##Checked)  
> {                                                \
> -       assert(TableIsSorted(TABLE, ARRAY_SIZE(TABLE))  
> &&                  \
> +       assert(TableIsSorted(TABLE, lengthof(TABLE))  
> &&                    \
>               "All lookup tables must be sorted for efficient  
> access!");  \
>        TABLE##Checked =  
> true;                                             \
>     }                                                                     \
> @@ -487,7 +485,7 @@
>
> static unsigned getConcreteOpcode(unsigned Opcode) {
>   ASSERT_SORTED(OpcodeTable);
> -  int Opc = Lookup(OpcodeTable, ARRAY_SIZE(OpcodeTable), Opcode);
> +  int Opc = Lookup(OpcodeTable, lengthof(OpcodeTable), Opcode);
>   assert(Opc != -1 && "FP Stack instruction not in OpcodeTable!");
>   return Opc;
> }
> @@ -535,7 +533,7 @@
>   RegMap[Stack[--StackTop]] = ~0;     // Update state
>
>   // Check to see if there is a popping version of this instruction...
> -  int Opcode = Lookup(PopTable, ARRAY_SIZE(PopTable), I- 
> >getOpcode());
> +  int Opcode = Lookup(PopTable, lengthof(PopTable), I->getOpcode());
>   if (Opcode != -1) {
>     I->setInstrDescriptor(TII->get(Opcode));
>     if (Opcode == X86::UCOM_FPPr)
> @@ -830,7 +828,7 @@
>       InstTable = ReverseSTiTable;
>   }
>
> -  int Opcode = Lookup(InstTable, ARRAY_SIZE(ForwardST0Table), MI- 
> >getOpcode());
> +  int Opcode = Lookup(InstTable, lengthof(ForwardST0Table), MI- 
> >getOpcode());
>   assert(Opcode != -1 && "Unknown TwoArgFP pseudo instruction!");
>
>   // NotTOS - The register which is not on the top of stack...
> Index: lib/Target/IA64/IA64InstrInfo.cpp
> ===================================================================
> --- lib/Target/IA64/IA64InstrInfo.cpp	(revision 41716)
> +++ lib/Target/IA64/IA64InstrInfo.cpp	(working copy)
> @@ -14,12 +14,13 @@
> #include "IA64InstrInfo.h"
> #include "IA64.h"
> #include "IA64InstrBuilder.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "IA64GenInstrInfo.inc"
> using namespace llvm;
>
> IA64InstrInfo::IA64InstrInfo()
> -  : TargetInstrInfo(IA64Insts, sizeof(IA64Insts)/ 
> sizeof(IA64Insts[0])),
> +  : TargetInstrInfo(IA64Insts, lengthof(IA64Insts)),
>     RI(*this) {
> }
>
> Index: lib/Target/Mips/MipsInstrInfo.cpp
> ===================================================================
> --- lib/Target/Mips/MipsInstrInfo.cpp	(revision 41716)
> +++ lib/Target/Mips/MipsInstrInfo.cpp	(working copy)
> @@ -13,6 +13,7 @@
>
> #include "Mips.h"
> #include "MipsInstrInfo.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "MipsGenInstrInfo.inc"
>
> @@ -20,7 +21,7 @@
>
> // TODO: Add the subtarget support on this constructor
> MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
> -  : TargetInstrInfo(MipsInsts, sizeof(MipsInsts)/ 
> sizeof(MipsInsts[0])),
> +  : TargetInstrInfo(MipsInsts, lengthof(MipsInsts)),
>     TM(tm), RI(*this) {}
>
> static bool isZeroImm(const MachineOperand &op) {
> Index: lib/Target/Sparc/SparcInstrInfo.cpp
> ===================================================================
> --- lib/Target/Sparc/SparcInstrInfo.cpp	(revision 41716)
> +++ lib/Target/Sparc/SparcInstrInfo.cpp	(working copy)
> @@ -13,12 +13,13 @@
>
> #include "SparcInstrInfo.h"
> #include "Sparc.h"
> +#include "llvm/Templates.h"
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "SparcGenInstrInfo.inc"
> using namespace llvm;
>
> SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST)
> -  : TargetInstrInfo(SparcInsts, sizeof(SparcInsts)/ 
> sizeof(SparcInsts[0])),
> +  : TargetInstrInfo(SparcInsts, lengthof(SparcInsts)),
>     RI(ST, *this) {
> }
>
> Index: lib/VMCore/Mangler.cpp
> ===================================================================
> --- lib/VMCore/Mangler.cpp	(revision 41716)
> +++ lib/VMCore/Mangler.cpp	(working copy)
> @@ -14,6 +14,7 @@
> #include "llvm/Support/Mangler.h"
> #include "llvm/DerivedTypes.h"
> #include "llvm/Module.h"
> +#include "llvm/Templates.h"
> #include "llvm/ADT/StringExtras.h"
> using namespace llvm;
>
> @@ -185,9 +186,7 @@
> Mangler::Mangler(Module &M, const char *prefix)
>   : Prefix(prefix), UseQuotes(false), PreserveAsmNames(false),
>     Count(0), TypeCounter(0) {
> -  std::fill(AcceptableChars,
> -          AcceptableChars+sizeof(AcceptableChars)/ 
> sizeof(AcceptableChars[0]),
> -            0);
> +  std::fill(AcceptableChars, endof(AcceptableChars), 0);
>
>   // Letters and numbers are acceptable.
>   for (unsigned char X = 'a'; X <= 'z'; ++X)
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list