[llvm-commits] [llvm] r52951 - in /llvm/trunk: include/llvm/Target/TargetRegisterInfo.h utils/TableGen/RegisterInfoEmitter.cpp
Chris Lattner
clattner at apple.com
Tue Jul 1 10:02:41 PDT 2008
On Jul 1, 2008, at 12:02 AM, Owen Anderson wrote:
> Author: resistor
> Date: Tue Jul 1 02:02:30 2008
> New Revision: 52951
>
> URL: http://llvm.org/viewvc/llvm-project?rev=52951&view=rev
> Log:
> Implement suggestions from Chris:
> - Use a more accurate heuristic for the size of the hashtable.
> - Use bitwise and instead of modulo since the size is a power of two.
> - Use new[] instead of malloc().
Thanks Owen! BTW, is there a reason you use malloc/free (now new/
delete) instead of a std::vector?
-Chris
>
>
> Modified:
> llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
> llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp
>
> Modified: llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegisterInfo.h?rev=52951&r1=52950&r2=52951&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/include/llvm/Target/TargetRegisterInfo.h (original)
> +++ llvm/trunk/include/llvm/Target/TargetRegisterInfo.h Tue Jul 1
> 02:02:30 2008
> @@ -413,14 +413,14 @@
> ///
> bool isSubRegister(unsigned regA, unsigned regB) const {
> // SubregHash is a simple quadratically probed hash table.
> - size_t index = (regA + regB * 37) % SubregHashSize;
> + size_t index = (regA + regB * 37) & (SubregHashSize-1);
> unsigned ProbeAmt = 2;
> while (SubregHash[index*2] != 0 &&
> SubregHash[index*2+1] != 0) {
> if (SubregHash[index*2] == regA && SubregHash[index*2+1] ==
> regB)
> return true;
>
> - index = (index + ProbeAmt) % SubregHashSize;
> + index = (index + ProbeAmt) & (SubregHashSize-1);
> ProbeAmt += 2;
> }
>
>
> Modified: llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp?rev=52951&r1=52950&r2=52951&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp (original)
> +++ llvm/trunk/utils/TableGen/RegisterInfoEmitter.cpp Tue Jul 1
> 02:02:30 2008
> @@ -466,15 +466,16 @@
> // Print the SubregHashTable, a simple quadratically probed
> // hash table for determining if a register is a subregister
> // of another register.
> - unsigned SubregHashTableSize = NextPowerOf2(2 * Regs.size());
> - unsigned* SubregHashTable =
> - (unsigned*)malloc(2 * SubregHashTableSize *
> sizeof(unsigned));
> - for (unsigned i = 0; i < SubregHashTableSize * 2; ++i)
> - SubregHashTable[i] = ~0U;
> -
> + unsigned NumSubRegs = 0;
> std::map<Record*, unsigned> RegNo;
> - for (unsigned i = 0, e = Regs.size(); i != e; ++i)
> + for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
> RegNo[Regs[i].TheDef] = i;
> + NumSubRegs += RegisterSubRegs[Regs[i].TheDef].size();
> + }
> +
> + unsigned SubregHashTableSize = NextPowerOf2(2 * NumSubRegs);
> + unsigned* SubregHashTable = new unsigned[2 * SubregHashTableSize];
> + std::fill(SubregHashTable, SubregHashTable + 2 *
> SubregHashTableSize, ~0U);
>
> for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
> Record* R = Regs[i].TheDef;
> @@ -484,11 +485,11 @@
> // We have to increase the indices of both registers by one when
> // computing the hash because, in the generated code, there
> // will be an extra empty slot at register 0.
> - size_t index = ((i+1) + (RegNo[RJ]+1) * 37) %
> SubregHashTableSize;
> + size_t index = ((i+1) + (RegNo[RJ]+1) * 37) &
> (SubregHashTableSize-1);
> unsigned ProbeAmt = 2;
> while (SubregHashTable[index*2] != ~0U &&
> SubregHashTable[index*2+1] != ~0U) {
> - index = (index + ProbeAmt) % SubregHashTableSize;
> + index = (index + ProbeAmt) & (SubregHashTableSize-1);
> ProbeAmt += 2;
> }
>
>
>
> _______________________________________________
> 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