[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Oct 10 00:44:01 PDT 2003
Changes in directory llvm/lib/Bytecode/Reader:
Reader.cpp updated: 1.79 -> 1.80
---
Log message:
Ok, the "fix" for this is to do a real associative container. Symbol tables
are ordered by name, not by slot, so the previous solution wasn't any good.
On a large testcase, this reduces time to parse from 2.17s to 1.58s.
---
Diffs of the changes: (+11 -15)
Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.79 llvm/lib/Bytecode/Reader/Reader.cpp:1.80
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.79 Thu Oct 9 18:10:14 2003
+++ llvm/lib/Bytecode/Reader/Reader.cpp Fri Oct 10 00:43:47 2003
@@ -214,6 +214,13 @@
const unsigned char *EndBuf,
SymbolTable *ST,
Function *CurrentFunction) {
+ // Allow efficient basic block lookup by number.
+ std::vector<BasicBlock*> BBMap;
+ if (CurrentFunction)
+ for (Function::iterator I = CurrentFunction->begin(),
+ E = CurrentFunction->end(); I != E; ++I)
+ BBMap.push_back(I);
+
while (Buf < EndBuf) {
// Symtab block header: [num entries][type id number]
unsigned NumEntries, Typ;
@@ -223,9 +230,6 @@
BCR_TRACE(3, "Plane Type: '" << *Ty << "' with " << NumEntries <<
" entries\n");
- Function::iterator BlockIterator;
- unsigned CurBlockIteratorIdx = ~0;
-
for (unsigned i = 0; i < NumEntries; ++i) {
// Symtab entry: [def slot #][name]
unsigned slot;
@@ -238,19 +242,11 @@
if (Typ == Type::TypeTyID)
V = (Value*)getType(slot);
else if (Typ == Type::LabelTyID) {
- if (!CurrentFunction)
- throw std::string("Basic blocks don't exist at global scope!");
-
- if (slot < CurBlockIteratorIdx) {
- CurBlockIteratorIdx = 0;
- BlockIterator = CurrentFunction->begin();
- }
-
- std::advance(BlockIterator, slot-CurBlockIteratorIdx);
- CurBlockIteratorIdx = slot;
- V = BlockIterator;
- } else
+ if (slot < BBMap.size())
+ V = BBMap[slot];
+ } else {
V = getValue(Typ, slot, false); // Find mapping...
+ }
if (V == 0) throw std::string("Failed value look-up.");
BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << *V;
if (!isa<Instruction>(V)) std::cerr << "\n");
More information about the llvm-commits
mailing list