diff options
author | Jim Laskey <jlaskey@mac.com> | 2006-07-19 19:32:06 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2006-07-19 19:32:06 +0000 |
commit | 613f1f83fd183681cb7a2c68ea3b63aa6c44befb (patch) | |
tree | c0769289830da96c9e16278224c5f9c80996e4f3 | |
parent | af7fd20b54a88e60f5a6420de3f37588215434d9 (diff) |
Tidy up a few things.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29213 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.cpp | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 155a11f543..db78d9dc47 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -199,10 +199,15 @@ static MachineInstr *MakeRMIInst(unsigned Opcode, unsigned FrameIndex, //===----------------------------------------------------------------------===// namespace { + /// TableEntry - Maps the 'from' opcode to a fused form of the 'to' opcode. + /// struct TableEntry { - unsigned from; - unsigned to; - unsigned make; + unsigned from; // Original opcode. + unsigned to; // New opcode. + unsigned make; // Form of make required to produce the + // new instruction. + + // less operators used by STL search. bool operator<(const TableEntry &TE) const { return from < TE.from; } friend bool operator<(const TableEntry &TE, unsigned V) { return TE.from < V; @@ -213,20 +218,26 @@ namespace { }; } +/// TableIsSorted - Return true if the table is in 'from' opcode order. +/// static bool TableIsSorted(const TableEntry *Table, unsigned NumEntries) { - for (unsigned i = 0; i != NumEntries-1; ++i) - if (!(Table[i] < Table[i+1])) return false; + for (unsigned i = 1; i != NumEntries; ++i) + if (!(Table[i-1] < Table[i])) { + std::cerr << "Entries out of order" << Table[i-1].from + << " " << Table[i].from << "\n"; + return false; + } return true; } -static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode, - unsigned &make) { +/// TableLookup - Return the table entry matching the specified opcode. +/// Otherwise return NULL. +static const TableEntry *TableLookup(const TableEntry *Table, unsigned N, + unsigned Opcode) { const TableEntry *I = std::lower_bound(Table, Table+N, Opcode); - if (I != Table+N && I->from == Opcode) { - make = I->make; - return I->to; - } - return -1; + if (I != Table+N && I->from == Opcode) + return I; + return NULL; } #define ARRAY_SIZE(TABLE) \ @@ -237,9 +248,11 @@ static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode, #else #define ASSERT_SORTED(TABLE) \ { static bool TABLE##Checked = false; \ - if (!TABLE##Checked) \ + if (!TABLE##Checked) { \ assert(TableIsSorted(TABLE, ARRAY_SIZE(TABLE)) && \ "All lookup tables must be sorted for efficient access!"); \ + TABLE##Checked = true; \ + } \ } #endif @@ -474,9 +487,9 @@ MachineInstr* X86RegisterInfo::foldMemoryOperand(MachineInstr* MI, { X86::CMOVNS16rr, X86::CMOVNS16rm, makeRMInst }, { X86::CMOVNS32rr, X86::CMOVNS32rm, makeRMInst }, { X86::CMOVP16rr, X86::CMOVP16rm, makeRMInst }, + { X86::CMOVP32rr, X86::CMOVP32rm, makeRMInst }, { X86::CMOVS16rr, X86::CMOVS16rm, makeRMInst }, { X86::CMOVS32rr, X86::CMOVS32rm, makeRMInst }, - { X86::CMOVP32rr, X86::CMOVP32rm, makeRMInst }, { X86::CMP16ri, X86::CMP16mi, makeMIInst }, { X86::CMP16ri8, X86::CMP16mi8, makeMIInst }, { X86::CMP16rr, X86::CMP16rm, makeRMInst }, @@ -660,23 +673,26 @@ MachineInstr* X86RegisterInfo::foldMemoryOperand(MachineInstr* MI, { X86::XORPDrr, X86::XORPDrm, makeRMInst }, { X86::XORPSrr, X86::XORPSrm, makeRMInst } }; + ASSERT_SORTED(OpcodeTable); OpcodeTablePtr = OpcodeTable; OpcodeTableSize = ARRAY_SIZE(OpcodeTable); } // If table selected if (OpcodeTablePtr) { - // Opcode to translate + // Opcode to fuse unsigned fromOpcode = MI->getOpcode(); - // Type of make to use - unsigned make; // Lookup fromOpcode in table - int toOpcode = Lookup(OpcodeTablePtr, OpcodeTableSize, fromOpcode, make); + const TableEntry *entry = TableLookup(OpcodeTablePtr, OpcodeTableSize, + fromOpcode); // If opcode found in table - if (toOpcode != -1) { + if (entry) { + // Fused opcode + unsigned toOpcode = entry->to; + // Make new instruction - switch (make) { + switch (entry->make) { case makeM0Inst: return MakeM0Inst(toOpcode, FrameIndex, MI); case makeMIInst: return MakeMIInst(toOpcode, FrameIndex, MI); case makeMInst: return MakeMInst(toOpcode, FrameIndex, MI); |