aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Reader/Reader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-03 23:41:28 +0000
committerChris Lattner <sabre@nondot.org>2004-08-03 23:41:28 +0000
commit45b5dd29183cdcca8c75e6d3aac992bbc41528b3 (patch)
tree54f0e0d148fb42b3f5df171f2bdc822e09026904 /lib/Bytecode/Reader/Reader.cpp
parent301fe481c25f3dda2d90aea8ab9133990534914f (diff)
Do not do a linear std::find to reconstruct information we had, but later threw
away. This speeds up by .bc reader by 30% in a profile build on 252.eon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15450 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/Reader.cpp')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index 3ebd7c88f4..13fecc53df 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -26,7 +26,6 @@
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "Support/StringExtras.h"
#include <sstream>
-
using namespace llvm;
namespace {
@@ -294,7 +293,7 @@ const Type *BytecodeReader::getType(unsigned ID) {
if (!CompactionTypes.empty()) {
if (ID >= CompactionTypes.size())
error("Type ID out of range for compaction table!");
- return CompactionTypes[ID];
+ return CompactionTypes[ID].first;
}
// Is it a module-level type?
@@ -337,12 +336,11 @@ unsigned BytecodeReader::getTypeSlot(const Type *Ty) {
// Scan the compaction table for the type if needed.
if (!CompactionTypes.empty()) {
- std::vector<const Type*>::const_iterator I =
- find(CompactionTypes.begin(), CompactionTypes.end(), Ty);
+ for (unsigned i = 0, e = CompactionTypes.size(); i != e; ++i)
+ if (CompactionTypes[i].first == Ty)
+ return Type::FirstDerivedTyID + i;
- if (I == CompactionTypes.end())
- error("Couldn't find type specified in compaction table!");
- return Type::FirstDerivedTyID + (&*I - &CompactionTypes[0]);
+ error("Couldn't find type specified in compaction table!");
}
// Check the function level types first...
@@ -403,15 +401,10 @@ Value * BytecodeReader::getValue(unsigned type, unsigned oNum, bool Create) {
// By default, the global type id is the type id passed in
unsigned GlobalTyID = type;
- // If the type plane was compactified, figure out the global type ID
- // by adding the derived type ids and the distance.
- if (!CompactionTypes.empty() && type >= Type::FirstDerivedTyID) {
- const Type *Ty = CompactionTypes[type-Type::FirstDerivedTyID];
- TypeListTy::iterator I =
- find(ModuleTypes.begin(), ModuleTypes.end(), Ty);
- assert(I != ModuleTypes.end());
- GlobalTyID = Type::FirstDerivedTyID + (&*I - &ModuleTypes[0]);
- }
+ // If the type plane was compactified, figure out the global type ID by
+ // adding the derived type ids and the distance.
+ if (!CompactionTypes.empty() && type >= Type::FirstDerivedTyID)
+ GlobalTyID = CompactionTypes[type-Type::FirstDerivedTyID].second;
if (hasImplicitNull(GlobalTyID)) {
if (Num == 0)
@@ -1053,7 +1046,7 @@ void BytecodeReader::ParseCompactionTypes(unsigned NumEntries) {
if (read_typeid(TypeSlot))
error("Invalid type in compaction table: type type");
const Type *Typ = getGlobalTableType(TypeSlot);
- CompactionTypes.push_back(Typ);
+ CompactionTypes.push_back(std::make_pair(Typ, TypeSlot));
if (Handler) Handler->handleCompactionTableType(i, TypeSlot, Typ);
}
}