diff options
author | Chris Lattner <sabre@nondot.org> | 2003-10-10 05:43:47 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-10-10 05:43:47 +0000 |
commit | 39cacceb551be6f0f675e2d887fa9ac9b908380d (patch) | |
tree | ca3a1a788606aba0b56dd4cdddbf090387e63acc /lib/Bytecode/Reader | |
parent | 25839f02c68e00f91fbc92c954c2fc5524472032 (diff) | |
download | external_llvm-39cacceb551be6f0f675e2d887fa9ac9b908380d.zip external_llvm-39cacceb551be6f0f675e2d887fa9ac9b908380d.tar.gz external_llvm-39cacceb551be6f0f675e2d887fa9ac9b908380d.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9002 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader')
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index bff0b12..e735564 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -214,6 +214,13 @@ void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf, 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 @@ void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf, 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 @@ void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf, 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"); |