diff options
author | Chris Lattner <sabre@nondot.org> | 2003-10-08 21:18:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-10-08 21:18:57 +0000 |
commit | 36392bc5242accd1a5a1b3efe745ffa785616741 (patch) | |
tree | b3f096e469e812f33cb082001b033e1f429a1d01 /lib/Bytecode/Reader/Reader.cpp | |
parent | 7f58de2b991cb8dff4d1bd3e8c9ece9ea2ba639c (diff) |
Various cleanups and simplifications. This speeds up reading a bytecode file
Bill gave me from 8.69s to 6.90s.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8971 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/Reader.cpp')
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 727e2a9110..c3f7eb6434 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -55,8 +55,25 @@ const Type *BytecodeParser::getType(unsigned ID) { } //cerr << "Looking up Type ID: " << ID << "\n"; - const Value *V = getValue(Type::TypeTy, ID, false); - return cast_or_null<Type>(V); + + if (ID < Type::NumPrimitiveIDs) { + const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID); + if (T) return T; // Asked for a primitive type... + } + + // Otherwise, derived types need offset... + ID -= FirstDerivedTyID; + + // Is it a module-level type? + if (ID < ModuleTypeValues.size()) + return ModuleTypeValues[ID].get(); + + // Nope, is it a function-level type? + ID -= ModuleTypeValues.size(); + if (ID < FunctionTypeValues.size()) + return FunctionTypeValues[ID].get(); + + return 0; } int BytecodeParser::insertValue(Value *Val, ValueTable &ValueTab) { @@ -95,35 +112,18 @@ void BytecodeParser::setValueTo(ValueTable &ValueTab, unsigned Slot, ValueTab[type]->setOperand(Slot-HasImplicitZeroInitializer, Val); } -Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { - unsigned Num = oNum; - unsigned type = getTypeSlot(Ty); // The type plane it lives in... - - if (type == Type::TypeTyID) { // The 'type' plane has implicit values - assert(Create == false); - if (Num < Type::NumPrimitiveIDs) { - const Type *T = Type::getPrimitiveType((Type::PrimitiveID)Num); - if (T) return (Value*)T; // Asked for a primitive type... - } - - // Otherwise, derived types need offset... - Num -= FirstDerivedTyID; - - // Is it a module-level type? - if (Num < ModuleTypeValues.size()) - return (Value*)ModuleTypeValues[Num].get(); - // Nope, is it a function-level type? - Num -= ModuleTypeValues.size(); - if (Num < FunctionTypeValues.size()) - return (Value*)FunctionTypeValues[Num].get(); +Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { + return getValue(getTypeSlot(Ty), oNum, Create); +} - return 0; - } +Value *BytecodeParser::getValue(unsigned type, unsigned oNum, bool Create) { + assert(type != Type::TypeTyID && "getValue() cannot get types!"); + unsigned Num = oNum; if (HasImplicitZeroInitializer && type >= FirstDerivedTyID) { if (Num == 0) - return Constant::getNullValue(Ty); + return Constant::getNullValue(getType(type)); --Num; } @@ -138,19 +138,13 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { if (!Create) return 0; // Do not create a placeholder? - Value *d = 0; - switch (Ty->getPrimitiveID()) { - case Type::LabelTyID: - d = new BBPHolder(Ty, oNum); - break; - default: - d = new ValPHolder(Ty, oNum); - break; - } + const Type *Ty = getType(type); + Value *Val = type == Type::LabelTyID ? (Value*)new BBPHolder(Ty, oNum) : + (Value*)new ValPHolder(Ty, oNum); - assert(d != 0 && "How did we not make something?"); - if (insertValue(d, LateResolveValues) == -1) return 0; - return d; + assert(Val != 0 && "How did we not make something?"); + if (insertValue(Val, LateResolveValues) == -1) return 0; + return Val; } /// getConstantValue - Just like getValue, except that it returns a null pointer @@ -252,11 +246,12 @@ void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf, if (read(Buf, EndBuf, Name, false)) // Not aligned... throw std::string("Buffer not aligned."); - Value *V = getValue(Ty, slot, false); // Find mapping... - if (V == 0) { - BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << "\n"); - throw std::string("Failed value look-up."); - } + Value *V; + if (Typ == Type::TypeTyID) + V = (Value*)getType(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"); |