Changes in directory llvm/lib/Bytecode/Writer:
SlotCalculator.cpp updated: 1.99 -> 1.100 SlotCalculator.h updated: 1.40 -> 1.41 Writer.cpp updated: 1.160 -> 1.161 --- Log message: getSlot can never fail. Make it assert internally, eliminate checks in clients. Same for getTypeSlot. --- Diffs of the changes: (+32 -63) SlotCalculator.cpp | 20 +++++--------- SlotCalculator.h | 2 - Writer.cpp | 73 ++++++++++++++++------------------------------------- 3 files changed, 32 insertions(+), 63 deletions(-) Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.99 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.100 --- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.99 Fri Feb 9 23:02:50 2007 +++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp Fri Feb 9 23:13:03 2007 @@ -278,25 +278,21 @@ SC_DEBUG("end purgeFunction!\n"); } -int SlotCalculator::getSlot(const Value *V) const { +unsigned SlotCalculator::getSlot(const Value *V) const { std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(V); - if (I != NodeMap.end()) - return (int)I->second; - - return -1; + assert(I != NodeMap.end() && "Value not in slotcalculator!"); + return (int)I->second; } int SlotCalculator::getTypeSlot(const Type*T) const { std::map<const Type*, unsigned>::const_iterator I = TypeMap.find(T); - if (I != TypeMap.end()) - return (int)I->second; - - return -1; + assert(I != TypeMap.end() && "Type not in slotcalc!"); + return (int)I->second; } void SlotCalculator::CreateSlotIfNeeded(const Value *V) { // Check to see if it's already in! - if (getSlot(V) != -1) return; + if (NodeMap.count(V)) return; const Type *Ty = V->getType(); assert(Ty != Type::VoidTy && "Can't insert void values!"); @@ -351,8 +347,8 @@ unsigned SlotCalculator::getOrCreateTypeSlot(const Type *Ty) { - int SlotNo = getTypeSlot(Ty); // Check to see if it's already in! - if (SlotNo != -1) return (unsigned)SlotNo; + std::map<const Type*, unsigned>::iterator TyIt = TypeMap.find(Ty); + if (TyIt != TypeMap.end()) return TyIt->second; // Insert into TypeMap. unsigned ResultSlot = TypeMap[Ty] = Types.size(); Index: llvm/lib/Bytecode/Writer/SlotCalculator.h diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.40 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.41 --- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.40 Fri Feb 9 23:02:50 2007 +++ llvm/lib/Bytecode/Writer/SlotCalculator.h Fri Feb 9 23:13:03 2007 @@ -65,7 +65,7 @@ /// getSlot - Return the slot number of the specified value in it's type /// plane. This returns < 0 on error! /// - int getSlot(const Value *V) const; + unsigned getSlot(const Value *V) const; int getTypeSlot(const Type* T) const; inline unsigned getNumPlanes() const { return Table.size(); } Index: llvm/lib/Bytecode/Writer/Writer.cpp diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.160 llvm/lib/Bytecode/Writer/Writer.cpp:1.161 --- llvm/lib/Bytecode/Writer/Writer.cpp:1.160 Fri Feb 9 22:15:40 2007 +++ llvm/lib/Bytecode/Writer/Writer.cpp Fri Feb 9 23:13:03 2007 @@ -306,11 +306,10 @@ output_vbr(CE->getOpcode()); // Put out the CE op code for (User::const_op_iterator OI = CE->op_begin(); OI != CE->op_end(); ++OI){ - int Slot = Table.getSlot(*OI); - assert(Slot != -1 && "Unknown constant used in ConstantExpr!!"); - output_vbr((unsigned)Slot); + unsigned Slot = Table.getSlot(*OI); + output_vbr(Slot); Slot = Table.getTypeSlot((*OI)->getType()); - output_typeid((unsigned)Slot); + output_typeid(Slot); } if (CE->isCompare()) output_vbr((unsigned)CE->getPredicate()); @@ -338,33 +337,23 @@ const ConstantArray *CPA = cast<ConstantArray>(CPV); assert(!CPA->isString() && "Constant strings should be handled specially!"); - for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i) { - int Slot = Table.getSlot(CPA->getOperand(i)); - assert(Slot != -1 && "Constant used but not available!!"); - output_vbr((unsigned)Slot); - } + for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i) + output_vbr(Table.getSlot(CPA->getOperand(i))); break; } case Type::PackedTyID: { const ConstantPacked *CP = cast<ConstantPacked>(CPV); - - for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) { - int Slot = Table.getSlot(CP->getOperand(i)); - assert(Slot != -1 && "Constant used but not available!!"); - output_vbr((unsigned)Slot); - } + for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) + output_vbr(Table.getSlot(CP->getOperand(i))); break; } case Type::StructTyID: { const ConstantStruct *CPS = cast<ConstantStruct>(CPV); - for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i) { - int Slot = Table.getSlot(CPS->getOperand(i)); - assert(Slot != -1 && "Constant used but not available!!"); - output_vbr((unsigned)Slot); - } + for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i) + output_vbr(Table.getSlot(CPS->getOperand(i))); break; } @@ -452,11 +441,8 @@ isa<CmpInst>(I) || isa<VAArgInst>(I) || Opcode == 58)); if (!isa<GetElementPtrInst>(&I)) { - for (unsigned i = 0; i < NumArgs; ++i) { - int Slot = Table.getSlot(I->getOperand(i)); - assert(Slot >= 0 && "No slot number for value!?!?"); - output_vbr((unsigned)Slot); - } + for (unsigned i = 0; i < NumArgs; ++i) + output_vbr(Table.getSlot(I->getOperand(i))); if (isa<CastInst>(I) || isa<VAArgInst>(I)) { int Slot = Table.getTypeSlot(I->getType()); @@ -471,16 +457,13 @@ unsigned(cast<CallInst>(I)->isTailCall())); } } else { - int Slot = Table.getSlot(I->getOperand(0)); - assert(Slot >= 0 && "No slot number for value!?!?"); - output_vbr(unsigned(Slot)); + output_vbr(Table.getSlot(I->getOperand(0))); // We need to encode the type of sequential type indices into their slot # unsigned Idx = 1; for (gep_type_iterator TI = gep_type_begin(I), E = gep_type_end(I); Idx != NumArgs; ++TI, ++Idx) { - Slot = Table.getSlot(I->getOperand(Idx)); - assert(Slot >= 0 && "No slot number for value!?!?"); + unsigned Slot = Table.getSlot(I->getOperand(Idx)); if (isa<SequentialType>(*TI)) { // These should be either 32-bits or 64-bits, however, with bit @@ -493,7 +476,7 @@ unsigned IdxId = BitWidth == 32 ? 0 : 1; Slot = (Slot << 1) | IdxId; } - output_vbr(unsigned(Slot)); + output_vbr(Slot); } } } @@ -537,11 +520,8 @@ // The type for the function has already been emitted in the type field of the // instruction. Just emit the slot # now. - for (unsigned i = 0; i != NumFixedOperands; ++i) { - int Slot = Table.getSlot(I->getOperand(i)); - assert(Slot >= 0 && "No slot number for value!?!?"); - output_vbr((unsigned)Slot); - } + for (unsigned i = 0; i != NumFixedOperands; ++i) + output_vbr(Table.getSlot(I->getOperand(i))); for (unsigned i = NumFixedOperands, e = I->getNumOperands(); i != e; ++i) { // Output Arg Type ID @@ -550,9 +530,8 @@ output_typeid((unsigned)Slot); // Output arg ID itself - Slot = Table.getSlot(I->getOperand(i)); assert(Slot >= 0 && "No slot number for value!?!?"); - output_vbr((unsigned)Slot); + output_vbr(Table.getSlot(I->getOperand(i))); } if (isa<InvokeInst>(I)) { @@ -700,10 +679,9 @@ unsigned Slots[3]; Slots[0] = (1 << 12)-1; // Marker to signify 0 operands for (unsigned i = 0; i != NumOperands; ++i) { - int slot = Table.getSlot(I.getOperand(i)); - assert(slot != -1 && "Broken bytecode!"); - if (unsigned(slot) > MaxOpSlot) MaxOpSlot = unsigned(slot); - Slots[i] = unsigned(slot); + unsigned Slot = Table.getSlot(I.getOperand(i)); + if (Slot > MaxOpSlot) MaxOpSlot = Slot; + Slots[i] = Slot; } // Handle the special cases for various instructions... @@ -1005,11 +983,8 @@ } // If we have an initializer, output it now. - if (I->hasInitializer()) { - Slot = Table.getSlot((Value*)I->getInitializer()); - assert(Slot != -1 && "No slot for global var initializer!"); - output_vbr((unsigned)Slot); - } + if (I->hasInitializer()) + output_vbr(Table.getSlot((Value*)I->getInitializer())); } output_typeid((unsigned)Table.getTypeSlot(Type::VoidTy)); @@ -1172,9 +1147,7 @@ // Write each of the values in this plane for (; I != End; ++I) { // Symtab entry: [def slot #][name] - Slot = Table.getSlot(I->second); - assert(Slot != -1 && "Value in symtab but has no slot number!!"); - output_vbr((unsigned)Slot); + output_vbr(Table.getSlot(I->second)); output(I->first); } } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits