diff options
author | Owen Anderson <resistor@mac.com> | 2007-09-07 04:06:50 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2007-09-07 04:06:50 +0000 |
commit | 718cb665ca6ce2bc4d8e8479f46a45db91b49f86 (patch) | |
tree | 51ddca6b6eead9bf38aafd5507e6c3c06048f0ad /lib/Target/X86 | |
parent | af992f782fb2cac8d00b352c3dd73f6e782b5758 (diff) | |
download | external_llvm-718cb665ca6ce2bc4d8e8479f46a45db91b49f86.zip external_llvm-718cb665ca6ce2bc4d8e8479f46a45db91b49f86.tar.gz external_llvm-718cb665ca6ce2bc4d8e8479f46a45db91b49f86.tar.bz2 |
Add lengthof and endof templates that hide a lot of sizeof computations.
Patch by Sterling Stein!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41758 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86')
-rw-r--r-- | lib/Target/X86/X86FloatingPoint.cpp | 12 | ||||
-rw-r--r-- | lib/Target/X86/X86InstrInfo.cpp | 3 | ||||
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.cpp | 13 |
3 files changed, 12 insertions, 16 deletions
diff --git a/lib/Target/X86/X86FloatingPoint.cpp b/lib/Target/X86/X86FloatingPoint.cpp index d02de44..5d31b19 100644 --- a/lib/Target/X86/X86FloatingPoint.cpp +++ b/lib/Target/X86/X86FloatingPoint.cpp @@ -299,16 +299,13 @@ static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode) { 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, array_lengthof(TABLE)) && \ "All lookup tables must be sorted for efficient access!"); \ TABLE##Checked = true; \ } \ @@ -487,7 +484,7 @@ static const TableEntry OpcodeTable[] = { static unsigned getConcreteOpcode(unsigned Opcode) { ASSERT_SORTED(OpcodeTable); - int Opc = Lookup(OpcodeTable, ARRAY_SIZE(OpcodeTable), Opcode); + int Opc = Lookup(OpcodeTable, array_lengthof(OpcodeTable), Opcode); assert(Opc != -1 && "FP Stack instruction not in OpcodeTable!"); return Opc; } @@ -535,7 +532,7 @@ void FPS::popStackAfter(MachineBasicBlock::iterator &I) { 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, array_lengthof(PopTable), I->getOpcode()); if (Opcode != -1) { I->setInstrDescriptor(TII->get(Opcode)); if (Opcode == X86::UCOM_FPPr) @@ -830,7 +827,8 @@ void FPS::handleTwoArgFP(MachineBasicBlock::iterator &I) { InstTable = ReverseSTiTable; } - int Opcode = Lookup(InstTable, ARRAY_SIZE(ForwardST0Table), MI->getOpcode()); + int Opcode = Lookup(InstTable, array_lengthof(ForwardST0Table), + MI->getOpcode()); assert(Opcode != -1 && "Unknown TwoArgFP pseudo instruction!"); // NotTOS - The register which is not on the top of stack... diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index f34fcf0..017c799 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -17,13 +17,14 @@ #include "X86InstrBuilder.h" #include "X86Subtarget.h" #include "X86TargetMachine.h" +#include "llvm/ADT/STLExtras.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, array_lengthof(X86Insts)), TM(tm), RI(tm, *this) { } diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index b4006f3..442b113 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -392,16 +392,13 @@ static const TableEntry *TableLookup(const TableEntry *Table, unsigned N, 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, array_lengthof(TABLE)) && \ "All lookup tables must be sorted for efficient access!"); \ TABLE##Checked = true; \ } \ @@ -590,7 +587,7 @@ X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, unsigned i, }; ASSERT_SORTED(OpcodeTable); OpcodeTablePtr = OpcodeTable; - OpcodeTableSize = ARRAY_SIZE(OpcodeTable); + OpcodeTableSize = array_lengthof(OpcodeTable); isTwoAddrFold = true; } else if (i == 0) { // If operand 0 if (MI->getOpcode() == X86::MOV16r0) @@ -675,7 +672,7 @@ X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, unsigned i, ASSERT_SORTED(OpcodeTable); OpcodeTablePtr = OpcodeTable; - OpcodeTableSize = ARRAY_SIZE(OpcodeTable); + OpcodeTableSize = array_lengthof(OpcodeTable); } else if (i == 1) { static const TableEntry OpcodeTable[] = { { X86::CMP16rr, X86::CMP16rm }, @@ -784,7 +781,7 @@ X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, unsigned i, ASSERT_SORTED(OpcodeTable); OpcodeTablePtr = OpcodeTable; - OpcodeTableSize = ARRAY_SIZE(OpcodeTable); + OpcodeTableSize = array_lengthof(OpcodeTable); } else if (i == 2) { static const TableEntry OpcodeTable[] = { { X86::ADC32rr, X86::ADC32rm }, @@ -979,7 +976,7 @@ X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, unsigned i, ASSERT_SORTED(OpcodeTable); OpcodeTablePtr = OpcodeTable; - OpcodeTableSize = ARRAY_SIZE(OpcodeTable); + OpcodeTableSize = array_lengthof(OpcodeTable); } // If table selected... |