summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode
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
commita89c91020c4860adcec46458a1e8fb9b1297767d (patch)
tree7e61ba1bb911e1abae6b01b5e4e5bbd58c8862e7 /llvm/lib/Bytecode
parente7691a45200b60c1cfaec7f1d58ea64e034995b5 (diff)
downloadbcm5719-llvm-a89c91020c4860adcec46458a1e8fb9b1297767d.tar.gz
bcm5719-llvm-a89c91020c4860adcec46458a1e8fb9b1297767d.zip
Remove potentially N^2 algorithm from symbol table reader. No speedup
in practice though llvm-svn: 8985
Diffstat (limited to 'llvm/lib/Bytecode')
-rw-r--r--llvm/lib/Bytecode/Reader/Reader.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp
index e649cdc08f1..c515c1575c5 100644
--- a/llvm/lib/Bytecode/Reader/Reader.cpp
+++ b/llvm/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.");
OpenPOWER on IntegriCloud