[llvm-commits] CVS: llvm/lib/Bytecode/Reader/InstructionReader.cpp Reader.cpp ReaderInternals.h
Chris Lattner
lattner at cs.uiuc.edu
Wed Oct 8 16:20:02 PDT 2003
Changes in directory llvm/lib/Bytecode/Reader:
InstructionReader.cpp updated: 1.52 -> 1.53
Reader.cpp updated: 1.66 -> 1.67
ReaderInternals.h updated: 1.47 -> 1.48
---
Log message:
Various cleanups and simplifications. This speeds up reading a bytecode file
Bill gave me from 8.69s to 6.90s.
---
Diffs of the changes: (+58 -62)
Index: llvm/lib/Bytecode/Reader/InstructionReader.cpp
diff -u llvm/lib/Bytecode/Reader/InstructionReader.cpp:1.52 llvm/lib/Bytecode/Reader/InstructionReader.cpp:1.53
--- llvm/lib/Bytecode/Reader/InstructionReader.cpp:1.52 Tue Sep 23 11:17:50 2003
+++ llvm/lib/Bytecode/Reader/InstructionReader.cpp Wed Oct 8 16:18:57 2003
@@ -161,12 +161,12 @@
delete PN;
return true;
case 2: PN->addIncoming(getValue(Raw->Ty, Raw->Arg1),
- cast<BasicBlock>(getValue(Type::LabelTy,
+ cast<BasicBlock>(getValue(Type::LabelTyID,
Raw->Arg2)));
break;
default:
PN->addIncoming(getValue(Raw->Ty, Raw->Arg1),
- cast<BasicBlock>(getValue(Type::LabelTy, Raw->Arg2)));
+ cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg2)));
if (Raw->VarArgs->size() & 1) {
std::cerr << "PHI Node with ODD number of arguments!\n";
delete PN;
@@ -175,7 +175,7 @@
std::vector<unsigned> &args = *Raw->VarArgs;
for (unsigned i = 0; i < args.size(); i+=2)
PN->addIncoming(getValue(Raw->Ty, args[i]),
- cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
+ cast<BasicBlock>(getValue(Type::LabelTyID, args[i+1])));
}
delete Raw->VarArgs;
break;
@@ -188,7 +188,7 @@
case Instruction::Shr:
Res = new ShiftInst((Instruction::OtherOps)Raw->Opcode,
getValue(Raw->Ty, Raw->Arg1),
- getValue(Type::UByteTy, Raw->Arg2));
+ getValue(Type::UByteTyID, Raw->Arg2));
return false;
case Instruction::Ret:
if (Raw->NumOperands == 0) {
@@ -200,12 +200,12 @@
case Instruction::Br:
if (Raw->NumOperands == 1) {
- Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy,Raw->Arg1)));
+ Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTyID,Raw->Arg1)));
return false;
} else if (Raw->NumOperands == 3) {
- Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw->Arg1)),
- cast<BasicBlock>(getValue(Type::LabelTy, Raw->Arg2)),
- getValue(Type::BoolTy , Raw->Arg3));
+ Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg1)),
+ cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg2)),
+ getValue(Type::BoolTyID , Raw->Arg3));
return false;
}
break;
@@ -213,7 +213,7 @@
case Instruction::Switch: {
SwitchInst *I =
new SwitchInst(getValue(Raw->Ty, Raw->Arg1),
- cast<BasicBlock>(getValue(Type::LabelTy, Raw->Arg2)));
+ cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg2)));
Res = I;
if (Raw->NumOperands < 3) return false; // No destinations? Weird.
@@ -226,7 +226,7 @@
std::vector<unsigned> &args = *Raw->VarArgs;
for (unsigned i = 0; i < args.size(); i += 2)
I->addCase(cast<Constant>(getValue(Raw->Ty, args[i])),
- cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
+ cast<BasicBlock>(getValue(Type::LabelTyID, args[i+1])));
delete Raw->VarArgs;
return false;
@@ -311,11 +311,11 @@
if (!FTy->isVarArg()) {
if (Raw->NumOperands < 3) return true;
- Normal = cast<BasicBlock>(getValue(Type::LabelTy, Raw->Arg2));
+ Normal = cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg2));
if (Raw->NumOperands == 3)
- Except = cast<BasicBlock>(getValue(Type::LabelTy, Raw->Arg3));
+ Except = cast<BasicBlock>(getValue(Type::LabelTyID, Raw->Arg3));
else {
- Except = cast<BasicBlock>(getValue(Type::LabelTy, args[0]));
+ Except = cast<BasicBlock>(getValue(Type::LabelTyID, args[0]));
FunctionType::ParamTypes::const_iterator It = PL.begin();
for (unsigned i = 1; i < args.size(); i++) {
@@ -329,13 +329,13 @@
if (args.size() < 4) return true;
if (getType(args[0]) != Type::LabelTy ||
getType(args[2]) != Type::LabelTy) return true;
- Normal = cast<BasicBlock>(getValue(Type::LabelTy, args[1]));
- Except = cast<BasicBlock>(getValue(Type::LabelTy, args[3]));
+ Normal = cast<BasicBlock>(getValue(Type::LabelTyID, args[1]));
+ Except = cast<BasicBlock>(getValue(Type::LabelTyID, args[3]));
if ((args.size() & 1) != 0)
return true; // Must be pairs of type/value
for (unsigned i = 4; i < args.size(); i+=2) {
- Params.push_back(getValue(getType(args[i]), args[i+1]));
+ Params.push_back(getValue(args[i], args[i+1]));
if (Params.back() == 0) return true;
}
}
@@ -347,7 +347,7 @@
}
case Instruction::Malloc:
if (Raw->NumOperands > 2) return true;
- V = Raw->NumOperands ? getValue(Type::UIntTy, Raw->Arg1) : 0;
+ V = Raw->NumOperands ? getValue(Type::UIntTyID, Raw->Arg1) : 0;
if (const PointerType *PTy = dyn_cast<PointerType>(Raw->Ty))
Res = new MallocInst(PTy->getElementType(), V);
else
@@ -356,7 +356,7 @@
case Instruction::Alloca:
if (Raw->NumOperands > 2) return true;
- V = Raw->NumOperands ? getValue(Type::UIntTy, Raw->Arg1) : 0;
+ V = Raw->NumOperands ? getValue(Type::UIntTyID, Raw->Arg1) : 0;
if (const PointerType *PTy = dyn_cast<PointerType>(Raw->Ty))
Res = new AllocaInst(PTy->getElementType(), V);
else
Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.66 llvm/lib/Bytecode/Reader/Reader.cpp:1.67
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.66 Sat Oct 4 15:00:03 2003
+++ llvm/lib/Bytecode/Reader/Reader.cpp Wed Oct 8 16:18:57 2003
@@ -55,8 +55,25 @@
}
//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 @@
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 @@
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;
- }
-
- assert(d != 0 && "How did we not make something?");
- if (insertValue(d, LateResolveValues) == -1) return 0;
- return d;
+ const Type *Ty = getType(type);
+ Value *Val = type == Type::LabelTyID ? (Value*)new BBPHolder(Ty, oNum) :
+ (Value*)new ValPHolder(Ty, oNum);
+
+ 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 @@
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");
Index: llvm/lib/Bytecode/Reader/ReaderInternals.h
diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.47 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.48
--- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.47 Sat Oct 4 15:14:40 2003
+++ llvm/lib/Bytecode/Reader/ReaderInternals.h Wed Oct 8 16:18:57 2003
@@ -179,6 +179,7 @@
const unsigned char *EndBuf);
Value *getValue(const Type *Ty, unsigned num, bool Create = true);
+ Value *getValue(unsigned TypeID, unsigned num, bool Create = true);
const Type *getType(unsigned ID);
Constant *getConstantValue(const Type *Ty, unsigned num);
More information about the llvm-commits
mailing list