aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bytecode/Reader/Reader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-09 20:30:04 +0000
committerChris Lattner <sabre@nondot.org>2003-10-09 20:30:04 +0000
commit9073613d0ca9a90bf09fe4f507e12dc849a48358 (patch)
tree14463f032c9e395b6367926e0ccd9b4c47c2eb18 /lib/Bytecode/Reader/Reader.cpp
parent927b185c175a8eb6d64ea97e1735fc6102114766 (diff)
downloadexternal_llvm-9073613d0ca9a90bf09fe4f507e12dc849a48358.zip
external_llvm-9073613d0ca9a90bf09fe4f507e12dc849a48358.tar.gz
external_llvm-9073613d0ca9a90bf09fe4f507e12dc849a48358.tar.bz2
Remove potentially N^2 algorithm from symbol table reader. No speedup
in practice though git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8985 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/Reader.cpp')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index e649cdc..c515c15 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -219,6 +219,9 @@ 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;
@@ -231,12 +234,17 @@ void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf,
if (Typ == Type::TypeTyID)
V = (Value*)getType(slot);
else if (Typ == Type::LabelTyID) {
- if (CurrentFunction) {
- // FIXME: THIS IS N^2!!!
- Function::iterator BlockIterator = CurrentFunction->begin();
- std::advance(BlockIterator, slot);
- V = BlockIterator;
+ 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
V = getValue(Typ, slot, false); // Find mapping...
if (V == 0) throw std::string("Failed value look-up.");