Miscellaneous cleanups:
  * Convert post to pre-increment for for loops
  * Use generic programming more
  * Use new Value::cast* instructions
  * Use new Module, Method, & BasicBlock forwarding methods
  * Use new facilities in STLExtras.h
  * Use new Instruction::isPHINode() method


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/IntervalPartition.cpp b/lib/Analysis/IntervalPartition.cpp
index f820d7a..32936fd 100644
--- a/lib/Analysis/IntervalPartition.cpp
+++ b/lib/Analysis/IntervalPartition.cpp
@@ -6,6 +6,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/IntervalIterator.h"
+#include "llvm/Tools/STLExtras.h"
 
 using namespace cfg;
 
@@ -49,22 +50,24 @@
 // specified method...
 //
 IntervalPartition::IntervalPartition(Method *M) {
-  assert(M->getBasicBlocks().front() && "Cannot operate on prototypes!");
+  assert(M->front() && "Cannot operate on prototypes!");
 
   // Pass false to intervals_begin because we take ownership of it's memory
   method_interval_iterator I = intervals_begin(M, false);
-  method_interval_iterator End = intervals_end(M);
-  assert(I != End && "No intervals in method!?!?!");
+  assert(I != intervals_end(M) && "No intervals in method!?!?!");
 
   addIntervalToPartition(RootInterval = *I);
 
-  for (++I; I != End; ++I)
-    addIntervalToPartition(*I);
+  ++I;  // After the first one...
+
+  // Add the rest of the intervals to the partition...
+  for_each(I, intervals_end(M),
+	   bind_obj(this, &IntervalPartition::addIntervalToPartition));
 
   // Now that we know all of the successor information, propogate this to the
   // predecessors for each block...
-  for(iterator It = begin(), E = end(); It != E; ++It)
-    updatePredecessors(*It);
+  for_each(begin(), end(), 
+	   bind_obj(this, &IntervalPartition::updatePredecessors));
 }
 
 
@@ -78,16 +81,18 @@
 
   // Pass false to intervals_begin because we take ownership of it's memory
   interval_part_interval_iterator I = intervals_begin(IP, false);
-  interval_part_interval_iterator End = intervals_end(IP);
-  assert(I != End && "No intervals in interval partition!?!?!");
+  assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
 
   addIntervalToPartition(RootInterval = *I);
 
-  for (++I; I != End; ++I)
-    addIntervalToPartition(*I);
+  ++I;  // After the first one...
+
+  // Add the rest of the intervals to the partition...
+  for_each(I, intervals_end(IP),
+	   bind_obj(this, &IntervalPartition::addIntervalToPartition));
 
   // Now that we know all of the successor information, propogate this to the
   // predecessors for each block...
-  for(iterator I = begin(), E = end(); I != E; ++I)
-    updatePredecessors(*I);
+  for_each(begin(), end(), 
+	   bind_obj(this, &IntervalPartition::updatePredecessors));
 }
diff --git a/lib/Analysis/ModuleAnalyzer.cpp b/lib/Analysis/ModuleAnalyzer.cpp
index 1c3464e..0f028d1 100644
--- a/lib/Analysis/ModuleAnalyzer.cpp
+++ b/lib/Analysis/ModuleAnalyzer.cpp
@@ -13,6 +13,7 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/ConstPoolVals.h"
+#include "llvm/Tools/STLExtras.h"
 #include <map>
 
 // processModule - Driver function to call all of my subclasses virtual methods.
@@ -87,7 +88,7 @@
     if (processConstPoolPlane(CP, Plane, isMethod)) return true;
 
     for (ConstantPool::PlaneType::const_iterator CI = Plane.begin(); 
-	 CI != Plane.end(); CI++) {
+	 CI != Plane.end(); ++CI) {
       if ((*CI)->getType() == Type::TypeTy)
 	if (handleType(TypeSet, ((const ConstPoolType*)(*CI))->getValue())) 
 	  return true;
@@ -98,11 +99,9 @@
   }
   
   if (!isMethod) {
-    assert(CP.getParent()->getValueType() == Value::ModuleVal);
-    const Module *M = (const Module*)CP.getParent();
+    const Module *M = CP.getParent()->castModuleAsserting();
     // Process the method types after the constant pool...
-    for (Module::MethodListType::const_iterator I = M->getMethodList().begin();
-	 I != M->getMethodList().end(); I++) {
+    for (Module::const_iterator I = M->begin(); I != M->end(); ++I) {
       if (handleType(TypeSet, (*I)->getType())) return true;
       if (visitMethod(*I)) return true;
     }
@@ -111,34 +110,28 @@
 }
 
 bool ModuleAnalyzer::processMethods(const Module *M) {
-  for (Module::MethodListType::const_iterator I = M->getMethodList().begin();
-       I != M->getMethodList().end(); I++)
-    if (processMethod(*I)) return true;
-
-  return false;
+  return apply_until(M->begin(), M->end(),
+		     bind_obj(this, &ModuleAnalyzer::processMethod));
 }
 
 bool ModuleAnalyzer::processMethod(const Method *M) {
   // Loop over the arguments, processing them...
-  const Method::ArgumentListType &ArgList = M->getArgumentList();
-  for (Method::ArgumentListType::const_iterator AI = ArgList.begin(); 
-       AI != ArgList.end(); AI++)
-    if (processMethodArgument(*AI)) return true;
+  if (apply_until(M->getArgumentList().begin(), M->getArgumentList().end(),
+		  bind_obj(this, &ModuleAnalyzer::processMethodArgument)))
+    return true;
 
   // Loop over the constant pool, adding the constants to the table...
   processConstPool(M->getConstantPool(), true);
   
   // Loop over all the basic blocks, in order...
-  Method::BasicBlocksType::const_iterator BBI = M->getBasicBlocks().begin();
-  for (; BBI != M->getBasicBlocks().end(); BBI++) 
-    if (processBasicBlock(*BBI)) return true;
-  return false;
+  return apply_until(M->begin(), M->end(),
+		     bind_obj(this, &ModuleAnalyzer::processBasicBlock));
 }
 
 bool ModuleAnalyzer::processBasicBlock(const BasicBlock *BB) {
   // Process all of the instructions in the basic block
-  BasicBlock::InstListType::const_iterator Inst = BB->getInstList().begin();
-  for (; Inst != BB->getInstList().end(); Inst++) {
+  BasicBlock::const_iterator Inst = BB->begin();
+  for (; Inst != BB->end(); Inst++) {
     if (preProcessInstruction(*Inst) || processInstruction(*Inst)) return true;
   }
   return false;
diff --git a/lib/AsmParser/llvmAsmParser.cpp b/lib/AsmParser/llvmAsmParser.cpp
index 98417c4..9f18db0 100644
--- a/lib/AsmParser/llvmAsmParser.cpp
+++ b/lib/AsmParser/llvmAsmParser.cpp
@@ -1569,7 +1569,7 @@
 {
   MethodType::ParamTypes ParamTypeList;
   if (yyvsp[-1].MethodArgList)
-    for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++)
+    for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); ++I)
       ParamTypeList.push_back((*I)->getType());
 
   const MethodType *MT = MethodType::getMethodType(yyvsp[-4].TypeVal, ParamTypeList);
@@ -1585,7 +1585,7 @@
   if (yyvsp[-1].MethodArgList) {        // Is null if empty...
     Method::ArgumentListType &ArgList = M->getArgumentList();
 
-    for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++) {
+    for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); ++I) {
       InsertValue(*I);
       ArgList.push_back(*I);
     }
@@ -1658,9 +1658,9 @@
 {
     Value *D = getVal(Type::TypeTy, yyvsp[0].ValIDVal, true);
     if (D == 0) ThrowException("Invalid user defined type: " + yyvsp[0].ValIDVal.getName());
-    assert (D->getValueType() == Value::ConstantVal &&
-            "Internal error!  User defined type not in const pool!");
-    ConstPoolType *CPT = (ConstPoolType*)D;
+
+    // User defined type not in const pool!
+    ConstPoolType *CPT = (ConstPoolType*)D->castConstantAsserting();
     yyval.TypeVal = CPT->getValue();
   ;
     break;}
@@ -1805,7 +1805,7 @@
 
     list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(), 
                                                       end = yyvsp[-1].JumpTable->end();
-    for (; I != end; I++)
+    for (; I != end; ++I)
       S->dest_push_back(I->first, I->second);
   ;
     break;}
@@ -1916,7 +1916,7 @@
     const MethodType *Ty = (const MethodType*)yyvsp[-4].TypeVal;
 
     Value *V = getVal(Ty, yyvsp[-3].ValIDVal);
-    if (V->getValueType() != Value::MethodVal || V->getType() != Ty)
+    if (!V->isMethod() || V->getType() != Ty)
       ThrowException("Cannot call: " + yyvsp[-3].ValIDVal.getName() + "!");
 
     // Create or access a new type that corresponds to the function call...
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index 3f71274..6fa817f 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -643,7 +643,7 @@
 MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' {
   MethodType::ParamTypes ParamTypeList;
   if ($4)
-    for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++)
+    for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I)
       ParamTypeList.push_back((*I)->getType());
 
   const MethodType *MT = MethodType::getMethodType($1, ParamTypeList);
@@ -659,7 +659,7 @@
   if ($4) {        // Is null if empty...
     Method::ArgumentListType &ArgList = M->getArgumentList();
 
-    for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++) {
+    for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); ++I) {
       InsertValue(*I);
       ArgList.push_back(*I);
     }
@@ -713,9 +713,9 @@
 Types : ValueRef {
     Value *D = getVal(Type::TypeTy, $1, true);
     if (D == 0) ThrowException("Invalid user defined type: " + $1.getName());
-    assert (D->getValueType() == Value::ConstantVal &&
-            "Internal error!  User defined type not in const pool!");
-    ConstPoolType *CPT = (ConstPoolType*)D;
+
+    // User defined type not in const pool!
+    ConstPoolType *CPT = (ConstPoolType*)D->castConstantAsserting();
     $$ = CPT->getValue();
   }
   | TypesV '(' TypeList ')' {               // Method derived type?
@@ -811,7 +811,7 @@
 
     list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = $8->begin(), 
                                                       end = $8->end();
-    for (; I != end; I++)
+    for (; I != end; ++I)
       S->dest_push_back(I->first, I->second);
   }
 
@@ -894,7 +894,7 @@
     const MethodType *Ty = (const MethodType*)$2;
 
     Value *V = getVal(Ty, $3);
-    if (V->getValueType() != Value::MethodVal || V->getType() != Ty)
+    if (!V->isMethod() || V->getType() != Ty)
       ThrowException("Cannot call: " + $3.getName() + "!");
 
     // Create or access a new type that corresponds to the function call...
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index b85bd88..dd47d1c 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -156,7 +156,7 @@
       unsigned Slot;
       if (read_vbr(Buf, EndBuf, Slot)) return true;
       Value *V = getValue(AT->getElementType(), Slot, false);
-      if (!V || V->getValueType() != Value::ConstantVal)
+      if (!V || !V->isConstant())
 	return true;
       Elements.push_back((ConstPoolVal*)V);
     }
@@ -173,7 +173,7 @@
       unsigned Slot;
       if (read_vbr(Buf, EndBuf, Slot)) return true;
       Value *V = getValue(ET[i], Slot, false);
-      if (!V || V->getValueType() != Value::ConstantVal)
+      if (!V || !V->isConstant())
 	return true;
       Elements.push_back((ConstPoolVal*)V);      
     }
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index c3f4c90..e8bf17e 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -46,11 +46,8 @@
   const Value *D = getValue(Type::TypeTy, ID, false);
   if (D == 0) return 0;
 
-  assert(D->getType() == Type::TypeTy &&
-	 D->getValueType() == Value::ConstantVal);
-
-
-  return ((const ConstPoolType*)D)->getValue();;
+  assert(D->getType() == Type::TypeTy);
+  return ((const ConstPoolType*)D->castConstantAsserting())->getValue();
 }
 
 bool BytecodeParser::insertValue(Value *Def, vector<ValueList> &ValueTab) {
@@ -63,7 +60,7 @@
   //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() 
   //     << "] = " << Def << endl;
 
-  if (type == Type::TypeTyID && Def->getValueType() == Value::ConstantVal) {
+  if (type == Type::TypeTyID && Def->isConstant()) {
     const Type *Ty = ((const ConstPoolType*)Def)->getValue();
     unsigned ValueOffset = FirstDerivedTyID;
 
@@ -123,7 +120,7 @@
 
 bool BytecodeParser::postResolveValues(ValueTable &ValTab) {
   bool Error = false;
-  for (unsigned ty = 0; ty < ValTab.size(); ty++) {
+  for (unsigned ty = 0; ty < ValTab.size(); ++ty) {
     ValueList &DL = ValTab[ty];
     unsigned Size;
     while ((Size = DL.size())) {
@@ -180,7 +177,7 @@
     const Type *Ty = getType(Typ);
     if (Ty == 0) return true;
 
-    for (unsigned i = 0; i < NumEntries; i++) {
+    for (unsigned i = 0; i < NumEntries; ++i) {
       // Symtab entry: [def slot #][name]
       unsigned slot;
       if (read_vbr(Buf, EndBuf, slot)) return true;
@@ -211,7 +208,7 @@
 
   const MethodType::ParamTypes &Params = MTy->getParamTypes();
   for (MethodType::ParamTypes::const_iterator It = Params.begin();
-       It != Params.end(); It++) {
+       It != Params.end(); ++It) {
     MethodArgument *MA = new MethodArgument(*It);
     if (insertValue(MA, Values)) { delete M; return true; }
     M->getArgumentList().push_back(MA);
@@ -267,7 +264,7 @@
 
   Value *MethPHolder = getValue(MTy, MethSlot, false);
   assert(MethPHolder && "Something is broken no placeholder found!");
-  assert(MethPHolder->getValueType() == Value::MethodVal && "Not a method?");
+  assert(MethPHolder->isMethod() && "Not a method?");
 
   unsigned type;  // Type slot
   assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp
index 01fae37..f7eada1 100644
--- a/lib/Bytecode/Writer/SlotCalculator.cpp
+++ b/lib/Bytecode/Writer/SlotCalculator.cpp
@@ -176,12 +176,11 @@
   // Insert node into table and NodeMap...
   NodeMap[D] = Table[Ty].size();
 
-  if (Typ == Type::TypeTy &&      // If it's a type constant, add the Type also
-      D->getValueType() != Value::TypeVal) {
-    assert(D->getValueType() == Value::ConstantVal && 
-           "All Type instances should be constant types!");
-
-    const ConstPoolType *CPT = (const ConstPoolType*)D;
+  if (Typ == Type::TypeTy && !D->isType()) {
+    // If it's a type constant, add the Type also
+      
+    // All Type instances should be constant types!
+    const ConstPoolType *CPT = (const ConstPoolType*)D->castConstantAsserting();
     int Slot = getValSlot(CPT->getValue());
     if (Slot == -1) {
       // Only add if it's not already here!
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index d03c945..2be490d 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -67,7 +67,7 @@
     
     unsigned NumConstants = 0;
     for (unsigned vn = ValNo; vn < Plane.size(); vn++)
-      if (Plane[vn]->getValueType() == Value::ConstantVal)
+      if (Plane[vn]->isConstant())
 	NumConstants++;
 
     if (NumConstants == 0) continue;  // Skip empty type planes...
@@ -85,21 +85,19 @@
 
     for (; ValNo < Plane.size(); ValNo++) {
       const Value *V = Plane[ValNo];
-      if (V->getValueType() == Value::ConstantVal) {
+      if (const ConstPoolVal *CPV = V->castConstant()) {
 	//cerr << "Serializing value: <" << V->getType() << ">: " 
 	//     << ((const ConstPoolVal*)V)->getStrValue() << ":" 
 	//     << Out.size() << "\n";
-	outputConstant((const ConstPoolVal*)V);
+	outputConstant(CPV);
       }
     }
   }
 
   delete CPool;  // End bytecode block section!
 
-  if (!isMethod) { // The ModuleInfoBlock follows directly after the c-pool
-    assert(CP.getParent()->getValueType() == Value::ModuleVal);
-    outputModuleInfoBlock((const Module*)CP.getParent());
-  }
+  if (!isMethod) // The ModuleInfoBlock follows directly after the c-pool
+    outputModuleInfoBlock(CP.getParent()->castModuleAsserting());
 
   return false;
 }
@@ -108,13 +106,11 @@
   BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out);
   
   // Output the types of the methods in this class
-  Module::MethodListType::const_iterator I = M->getMethodList().begin();
-  while (I != M->getMethodList().end()) {
+  for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) {
     int Slot = Table.getValSlot((*I)->getType());
     assert(Slot != -1 && "Module const pool is broken!");
     assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!");
     output_vbr((unsigned)Slot, Out);
-    I++;
   }
   output_vbr((unsigned)Table.getValSlot(Type::VoidTy), Out);
   align32(Out);
@@ -144,7 +140,7 @@
 void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
   BytecodeBlock MethodBlock(BytecodeFormat::SymbolTable, Out);
 
-  for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); TI++) {
+  for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) {
     SymbolTable::type_const_iterator I = MST.type_begin(TI->first);
     SymbolTable::type_const_iterator End = MST.type_end(TI->first);
     int Slot;
@@ -158,7 +154,7 @@
     assert(Slot != -1 && "Type in symtab, but not in table!");
     output_vbr((unsigned)Slot, Out);
 
-    for (; I != End; I++) {
+    for (; I != End; ++I) {
       // Symtab entry: [def slot #][name]
       Slot = Table.getValSlot(I->second);
       assert (Slot != -1 && "Value in symtab but not in method!!");
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index 0a191a5..e5bc171 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -36,9 +36,9 @@
 static inline void RemapInstruction(Instruction *I, 
 				    map<const Value *, Value*> &ValueMap) {
 
-  for (unsigned op = 0; const Value *Op = I->getOperand(op); op++) {
+  for (unsigned op = 0; const Value *Op = I->getOperand(op); ++op) {
     Value *V = ValueMap[Op];
-    if (!V && Op->getValueType() == Value::MethodVal) 
+    if (!V && Op->isMethod()) 
       continue;  // Methods don't get relocated
 
     if (!V) {
@@ -60,7 +60,7 @@
 // exists in the instruction stream.  Similiarly this will inline a recursive
 // method by one level.
 //
-bool InlineMethod(BasicBlock::InstListType::iterator CIIt) {
+bool InlineMethod(BasicBlock::iterator CIIt) {
   assert((*CIIt)->getInstType() == Instruction::Call && 
 	 "InlineMethod only works on CallInst nodes!");
   assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
@@ -124,9 +124,8 @@
   // Loop over all of the basic blocks in the method, inlining them as 
   // appropriate.  Keep track of the first basic block of the method...
   //
-  for (Method::BasicBlocksType::const_iterator BI = 
-	 CalledMeth->getBasicBlocks().begin(); 
-       BI != CalledMeth->getBasicBlocks().end(); BI++) {
+  for (Method::const_iterator BI = CalledMeth->begin(); 
+       BI != CalledMeth->end(); ++BI) {
     const BasicBlock *BB = *BI;
     assert(BB->getTerminator() && "BasicBlock doesn't have terminator!?!?");
     
@@ -143,8 +142,8 @@
    
     // Loop over all instructions copying them over...
     Instruction *NewInst;
-    for (BasicBlock::InstListType::const_iterator II = BB->getInstList().begin();
-	 II != (BB->getInstList().end()-1); II++) {
+    for (BasicBlock::const_iterator II = BB->begin();
+	 II != (BB->end()-1); ++II) {
       IBB->getInstList().push_back((NewInst = (*II)->clone()));
       ValueMap[*II] = NewInst;                  // Add instruction map to value.
     }
@@ -193,16 +192,14 @@
   // Loop over all of the instructions in the method, fixing up operand 
   // references as we go.  This uses ValueMap to do all the hard work.
   //
-  for (Method::BasicBlocksType::const_iterator BI = 
-	 CalledMeth->getBasicBlocks().begin(); 
-       BI != CalledMeth->getBasicBlocks().end(); BI++) {
+  for (Method::const_iterator BI = CalledMeth->begin(); 
+       BI != CalledMeth->end(); ++BI) {
     const BasicBlock *BB = *BI;
     BasicBlock *NBB = (BasicBlock*)ValueMap[BB];
 
     // Loop over all instructions, fixing each one as we find it...
     //
-    for (BasicBlock::InstListType::iterator II = NBB->getInstList().begin();
-	 II != NBB->getInstList().end(); II++)
+    for (BasicBlock::iterator II = NBB->begin(); II != NBB->end(); II++)
       RemapInstruction(*II, ValueMap);
   }
 
@@ -214,7 +211,7 @@
   TerminatorInst *Br = OrigBB->getTerminator();
   assert(Br && Br->getInstType() == Instruction::Br && 
 	 "splitBasicBlock broken!");
-  Br->setOperand(0, ValueMap[CalledMeth->getBasicBlocks().front()]);
+  Br->setOperand(0, ValueMap[CalledMeth->front()]);
 
   // Since we are now done with the CallInst, we can finally delete it.
   delete CI;
@@ -225,10 +222,9 @@
   assert(CI->getParent() && "CallInst not embeded in BasicBlock!");
   BasicBlock *PBB = CI->getParent();
 
-  BasicBlock::InstListType::iterator CallIt = find(PBB->getInstList().begin(),
-						   PBB->getInstList().end(),
-						   CI);
-  assert(CallIt != PBB->getInstList().end() && 
+  BasicBlock::iterator CallIt = find(PBB->begin(), PBB->end(), CI);
+
+  assert(CallIt != PBB->end() && 
 	 "CallInst has parent that doesn't contain CallInst?!?");
   return InlineMethod(CallIt);
 }
@@ -241,10 +237,10 @@
   if (CI->getParent()->getParent() == M) return false;
 
   // Don't inline something too big.  This is a really crappy heuristic
-  if (M->getBasicBlocks().size() > 3) return false;
+  if (M->size() > 3) return false;
 
   // Don't inline into something too big. This is a **really** crappy heuristic
-  if (CI->getParent()->getParent()->getBasicBlocks().size() > 10) return false;
+  if (CI->getParent()->getParent()->size() > 10) return false;
 
   // Go ahead and try just about anything else.
   return true;
@@ -252,8 +248,7 @@
 
 
 static inline bool DoMethodInlining(BasicBlock *BB) {
-  for (BasicBlock::InstListType::iterator I = BB->getInstList().begin();
-       I != BB->getInstList().end(); I++) {
+  for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
     if ((*I)->getInstType() == Instruction::Call) {
       // Check to see if we should inline this method
       CallInst *CI = (CallInst*)*I;
@@ -266,15 +261,14 @@
 }
 
 bool DoMethodInlining(Method *M) {
-  Method::BasicBlocksType &BBs = M->getBasicBlocks();
   bool Changed = false;
 
   // Loop through now and inline instructions a basic block at a time...
-  for (Method::BasicBlocksType::iterator I = BBs.begin(); I != BBs.end(); )
+  for (Method::iterator I = M->begin(); I != M->end(); )
     if (DoMethodInlining(*I)) {
       Changed = true;
       // Iterator is now invalidated by new basic blocks inserted
-      I = BBs.begin();
+      I = M->begin();
     } else {
       ++I;
     }
diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp
index 14ee8d5..5bc3c5b 100644
--- a/lib/Transforms/Scalar/DCE.cpp
+++ b/lib/Transforms/Scalar/DCE.cpp
@@ -61,7 +61,7 @@
       delete Vals.remove(DI);
       Changed = true;
     } else {
-      DI++;
+      ++DI;
     }
   }
   return Changed;
@@ -79,8 +79,8 @@
   if (PI == pred_end(BB) || ++PI != pred_end(BB)) 
     return false;   // More than one predecessor...
 
-  Instruction *I = BB->getInstList().front();
-  if (I->getInstType() != Instruction::PHINode) return false;  // No PHI nodes
+  Instruction *I = BB->front();
+  if (!I->isPHINode()) return false;  // No PHI nodes
 
   //cerr << "Killing PHIs from " << BB;
   //cerr << "Pred #0 = " << *pred_begin(BB);
@@ -93,10 +93,10 @@
     Value *V = PN->getOperand(0);
 
     PN->replaceAllUsesWith(V);      // Replace PHI node with its single value.
-    delete BB->getInstList().remove(BB->getInstList().begin());
+    delete BB->getInstList().remove(BB->begin());
 
-    I = BB->getInstList().front();
-  } while (I->getInstType() == Instruction::PHINode);
+    I = BB->front();
+  } while (I->isPHINode());
 	
   return true;  // Yes, we nuked at least one phi node
 }
@@ -154,8 +154,8 @@
   
   // Okay, now we know that we need to remove predecessor #pred_idx from all
   // PHI nodes.  Iterate over each PHI node fixing them up
-  BasicBlock::InstListType::iterator II(BB->getInstList().begin());
-  for (; (*II)->getInstType() == Instruction::PHINode; ++II) {
+  BasicBlock::iterator II(BB->begin());
+  for (; (*II)->isPHINode(); ++II) {
     PHINode *PN = (PHINode*)*II;
     PN->removeIncomingValue(BB);
 
@@ -177,25 +177,36 @@
 // Assumption: BB is the single predecessor of Succ.
 //
 static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
-  assert(BB && Succ && *pred_begin(Succ) == BB && "BB is only pred of Succ" &&
-	 ++pred_begin(Succ) == pred_end(Succ));
+  assert(Succ->front()->isPHINode() && "Only works on PHId BBs!");
 
   // If there is more than one predecessor, and there are PHI nodes in
   // the successor, then we need to add incoming edges for the PHI nodes
-  pred_iterator PI(pred_begin(BB));
-  for (; PI != pred_end(BB); ++PI) {
-    // TODO:
-  }
+  //
+  const vector<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB));
+
+  BasicBlock::iterator I = Succ->begin();
+  do {                     // Loop over all of the PHI nodes in the successor BB
+    PHINode *PN = (PHINode*)*I;
+    Value *OldVal = PN->removeIncomingValue(BB);
+    assert(OldVal && "No entry in PHI for Pred BB!");
+
+    for (vector<BasicBlock*>::const_iterator PredI = BBPreds.begin(), 
+	   End = BBPreds.end(); PredI != End; ++PredI) {
+      // Add an incoming value for each of the new incoming values...
+      PN->addIncoming(OldVal, *PredI);
+    }
+
+    ++I;
+  } while ((*I)->isPHINode());
 }
 
 static bool DoDCEPass(Method *M) {
-  Method::BasicBlocksType &BBs = M->getBasicBlocks();
-  Method::BasicBlocksType::iterator BBIt, BBEnd = BBs.end();
-  if (BBs.begin() == BBEnd) return false;  // Nothing to do
+  Method::iterator BBIt, BBEnd = M->end();
+  if (M->begin() == BBEnd) return false;  // Nothing to do
   bool Changed = false;
 
   // Loop through now and remove instructions that have no uses...
-  for (BBIt = BBs.begin(); BBIt != BBEnd; BBIt++) {
+  for (BBIt = M->begin(); BBIt != BBEnd; ++BBIt) {
     Changed |= RemoveUnusedDefs((*BBIt)->getInstList(), BasicBlockDCE());
     Changed |= RemoveSingularPHIs(*BBIt);
   }
@@ -203,11 +214,11 @@
   // Loop over all of the basic blocks (except the first one) and remove them
   // if they are unneeded...
   //
-  for (BBIt = BBs.begin(), ++BBIt; BBIt != BBs.end(); ++BBIt) {
+  for (BBIt = M->begin(), ++BBIt; BBIt != M->end(); ++BBIt) {
     BasicBlock *BB = *BBIt;
     assert(BB->getTerminator() && "Degenerate basic block encountered!");
 
-#if 0
+#if 0  // This is know to basically work?
     // Remove basic blocks that have no predecessors... which are unreachable.
     if (pred_begin(BB) == pred_end(BB) &&
 	!BB->hasConstantPoolReferences() && 0) {
@@ -215,43 +226,46 @@
 
       // Loop through all of our successors and make sure they know that one
       // of their predecessors is going away.
-      for (succ_iterator SI = succ_begin(BB), EI = succ_end(BB); SI != EI; ++SI)
-	RemovePredecessorFromBlock(*SI, BB);
+      for_each(succ_begin(BB), succ_end(BB),
+	       bind_2nd(RemovePredecessorFromBlock, BB));
 
-      while (!BB->getInstList().empty()) {
-	Instruction *I = BB->getInstList().front();
+      while (!BB->empty()) {
+	Instruction *I = BB->front();
 	// If this instruction is used, replace uses with an arbitrary
 	// constant value.  Because control flow can't get here, we don't care
 	// what we replace the value with.
 	if (!I->use_empty()) ReplaceUsesWithConstant(I);
 
 	// Remove the instruction from the basic block
-	delete BB->getInstList().remove(BB->getInstList().begin());
+	delete BB->getInstList().remove(BB->begin());
       }
-      delete BBs.remove(BBIt);
+      delete M->getBasicBlocks().remove(BBIt);
       --BBIt;  // remove puts use on the next block, we want the previous one
       Changed = true;
       continue;
     } 
+#endif
 
+#if 0  // This has problems
     // Check to see if this block has no instructions and only a single 
     // successor.  If so, replace block references with successor.
     succ_iterator SI(succ_begin(BB));
     if (SI != succ_end(BB) && ++SI == succ_end(BB)) {  // One succ?
-      Instruction *I = BB->getInstList().front();
+      Instruction *I = BB->front();
       if (I->isTerminator()) {   // Terminator is the only instruction!
+	BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
+	cerr << "Killing Trivial BB: \n" << BB;
 
-	if (Succ->getInstList().front()->getInstType() == Instruction::PHINode){
-	  // Add entries to the PHI nodes so that the PHI nodes have the right
-	  // number of entries...
+	if (Succ->front()->isPHINode()) {
+	  // If our successor has PHI nodes, then we need to update them to
+	  // include entries for BB's predecessors, not for BB itself.
+	  //
 	  PropogatePredecessorsForPHIs(BB, Succ);
 	}
 
-	BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
 	BB->replaceAllUsesWith(Succ);
-	cerr << "Killing Trivial BB: \n" << BB;
 
-	BB = BBs.remove(BBIt);
+	BB = M->getBasicBlocks().remove(BBIt);
 	--BBIt; // remove puts use on the next block, we want the previous one
 	
 	if (BB->hasName() && !Succ->hasName())  // Transfer name if we can
@@ -280,21 +294,21 @@
 	//cerr << "Merging: " << BB << "into: " << Pred;
 
 	// Delete the unconditianal branch from the predecessor...
-	BasicBlock::InstListType::iterator DI = Pred->getInstList().end();
+	BasicBlock::iterator DI = Pred->end();
 	assert(Pred->getTerminator() && 
 	       "Degenerate basic block encountered!");  // Empty bb???      
 	delete Pred->getInstList().remove(--DI);        // Destroy uncond branch
 	
 	// Move all definitions in the succecessor to the predecessor...
-	while (!BB->getInstList().empty()) {
-	  DI = BB->getInstList().begin();
+	while (!BB->empty()) {
+	  DI = BB->begin();
 	  Instruction *Def = BB->getInstList().remove(DI); // Remove from front
 	  Pred->getInstList().push_back(Def);              // Add to end...
 	}
 
 	// Remove basic block from the method... and advance iterator to the
 	// next valid block...
-	BB = BBs.remove(BBIt);
+	BB = M->getBasicBlocks().remove(BBIt);
 	--BBIt;  // remove puts us on the NEXT bb.  We want the prev BB
 	Changed = true;
 
diff --git a/lib/Transforms/Scalar/SymbolStripping.cpp b/lib/Transforms/Scalar/SymbolStripping.cpp
index af5f18f..33b6005 100644
--- a/lib/Transforms/Scalar/SymbolStripping.cpp
+++ b/lib/Transforms/Scalar/SymbolStripping.cpp
@@ -23,7 +23,7 @@
   if (SymTab == 0) return false;    // No symbol table?  No problem.
   bool RemovedSymbol = false;
 
-  for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); I++) {
+  for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) {
     map<const string, Value *> &Plane = I->second;
     
     map<const string, Value *>::iterator B;
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 97affcc..c68cd79 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -178,7 +178,7 @@
       writeOperand(I->getOperand(op+1), true);
     }
     Out << "\n\t]";
-  } else if (I->getInstType() == Instruction::PHINode) {
+  } else if (I->isPHINode()) {
     Out << " " << Operand->getType();
 
     Out << " [";  writeOperand(Operand, false); Out << ",";
@@ -262,7 +262,7 @@
   } else {
     int Slot = Table.getValSlot(Operand);
     
-    if (Operand->getValueType() == Value::ConstantVal) {
+    if (Operand->isConstant()) {
       Out << " " << ((ConstPoolVal*)Operand)->getStrValue();
     } else {
       if (Slot >= 0)  Out << " %" << Slot;
@@ -313,12 +313,11 @@
   // A Constant pool value may have a parent that is either a method or a 
   // module.  Untangle this now...
   //
-  if (CPV->getParent() == 0 || 
-      CPV->getParent()->getValueType() == Value::MethodVal) {
+  if (CPV->getParent() == 0 || CPV->getParent()->isMethod()) {
     SlotTable = new SlotCalculator((Method*)CPV->getParent(), true);
   } else {
-    assert(CPV->getParent()->getValueType() == Value::ModuleVal);
-    SlotTable = new SlotCalculator((Module*)CPV->getParent(), true);
+    SlotTable =
+      new SlotCalculator(CPV->getParent()->castModuleAsserting(), true);
   }
 
   AssemblyWriter W(o, *SlotTable);
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index f60bd46..36ad93d 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -73,7 +73,7 @@
 //
 bool BasicBlock::hasConstantPoolReferences() const {
   for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
-    if ((*I)->getValueType() == ConstantVal)
+    if ((*I)->isConstant())
       return true;
 
   return false;
@@ -91,7 +91,7 @@
 // cause a degenerate basic block to be formed, having a terminator inside of
 // the basic block). 
 //
-BasicBlock *BasicBlock::splitBasicBlock(InstListType::iterator I) {
+BasicBlock *BasicBlock::splitBasicBlock(iterator I) {
   assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
   assert(I != InstList.end() && 
 	 "Trying to get me to create degenerate basic block!");
@@ -102,7 +102,7 @@
   // to the new basic block...
   Instruction *Inst = 0;
   do {
-    InstListType::iterator EndIt = InstList.end();
+    iterator EndIt = end();
     Inst = InstList.remove(--EndIt);                  // Remove from end
     New->InstList.push_front(Inst);                   // Add to front
   } while (Inst != *I);   // Loop until we move the specified instruction.
diff --git a/lib/VMCore/ConstantPool.cpp b/lib/VMCore/ConstantPool.cpp
index d624c8d..77ed50a 100644
--- a/lib/VMCore/ConstantPool.cpp
+++ b/lib/VMCore/ConstantPool.cpp
@@ -85,9 +85,8 @@
 
 void ConstantPool::dropAllReferences() {
   for (unsigned i = 0; i < Planes.size(); i++)
-    for (PlaneType::iterator I = Planes[i]->begin();
-	 I != Planes[i]->end(); I++)
-      (*I)->dropAllReferences();
+    for_each(Planes[i]->begin(), Planes[i]->end(),
+	     mem_fun(&ConstPoolVal::dropAllReferences));
 }
 
 struct EqualsConstant {
@@ -280,10 +279,7 @@
 //                          getStrValue implementations
 
 string ConstPoolBool::getStrValue() const {
-  if (Val)
-    return "true";
-  else
-    return "false";
+  return Val ? "true" : "false";
 }
 
 string ConstPoolSInt::getStrValue() const {
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 550c4f0..aa0d08b 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -29,8 +29,8 @@
   dropAllReferences();    // After this it is safe to delete instructions.
 
   // TODO: Should remove from the end, not the beginning of vector!
-  BasicBlocksType::iterator BI = BasicBlocks.begin();
-  while ((BI = BasicBlocks.begin()) != BasicBlocks.end())
+  iterator BI = begin();
+  while ((BI = begin()) != end())
     delete BasicBlocks.remove(BI);
 
   // Delete all of the method arguments and unlink from symbol table...
@@ -70,6 +70,5 @@
 // delete.
 //
 void Method::dropAllReferences() {
-  for_each(BasicBlocks.begin(), BasicBlocks.end(), 
-	   std::mem_fun(&BasicBlock::dropAllReferences));
+  for_each(begin(), end(), std::mem_fun(&BasicBlock::dropAllReferences));
 }
diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp
index 142019b..baafe0b 100644
--- a/lib/VMCore/InstrTypes.cpp
+++ b/lib/VMCore/InstrTypes.cpp
@@ -68,8 +68,7 @@
   if (i >= IncomingValues.size()*2) return false;
 
   if (i & 1) {
-    assert(Val->getValueType() == BasicBlockVal && "Not a BB!");
-    IncomingValues[i/2].second = (BasicBlock*)Val;
+    IncomingValues[i/2].second = Val->castBasicBlockAsserting();
   } else {
     IncomingValues[i/2].first  = Val;
   }
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index 4f2eee4..7fa2802 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -37,6 +37,6 @@
 //
 void Module::dropAllReferences() {
   MethodListType::iterator MI = MethodList.begin();
-  for (; MI != MethodList.end(); MI++)
+  for (; MI != MethodList.end(); ++MI)
     (*MI)->dropAllReferences();
 }
diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp
index 01fae37..f7eada1 100644
--- a/lib/VMCore/SlotCalculator.cpp
+++ b/lib/VMCore/SlotCalculator.cpp
@@ -176,12 +176,11 @@
   // Insert node into table and NodeMap...
   NodeMap[D] = Table[Ty].size();
 
-  if (Typ == Type::TypeTy &&      // If it's a type constant, add the Type also
-      D->getValueType() != Value::TypeVal) {
-    assert(D->getValueType() == Value::ConstantVal && 
-           "All Type instances should be constant types!");
-
-    const ConstPoolType *CPT = (const ConstPoolType*)D;
+  if (Typ == Type::TypeTy && !D->isType()) {
+    // If it's a type constant, add the Type also
+      
+    // All Type instances should be constant types!
+    const ConstPoolType *CPT = (const ConstPoolType*)D->castConstantAsserting();
     int Slot = getValSlot(CPT->getValue());
     if (Slot == -1) {
       // Only add if it's not already here!
diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp
index 214f41f..07e4b87 100644
--- a/lib/VMCore/SymbolTable.cpp
+++ b/lib/VMCore/SymbolTable.cpp
@@ -15,9 +15,9 @@
 SymbolTable::~SymbolTable() {
 #ifndef NDEBUG   // Only do this in -g mode...
   bool Good = true;
-  for (iterator i = begin(); i != end(); i++) {
+  for (iterator i = begin(); i != end(); ++i) {
     if (i->second.begin() != i->second.end()) {
-      for (type_iterator I = i->second.begin(); I != i->second.end(); I++)
+      for (type_iterator I = i->second.begin(); I != i->second.end(); ++I)
         cerr << "Value still in symbol table! Type = " << i->first->getName() 
              << "  Name = " << I->first << endl;
       Good = false;
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index cf16309..5ae2cf9 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -157,13 +157,13 @@
 const MethodType *MethodType::getMethodType(const Type *ReturnType, 
                                             const vector<const Type*> &Params) {
   static vector<const MethodType*> ExistingMethodTypesCache;
-  for (unsigned i = 0; i < ExistingMethodTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingMethodTypesCache.size(); ++i) {
     const MethodType *T = ExistingMethodTypesCache[i];
     if (T->getReturnType() == ReturnType) {
       const ParamTypes &EParams = T->getParamTypes();
       ParamTypes::const_iterator I = Params.begin(); 
       ParamTypes::const_iterator J = EParams.begin(); 
-      for (; I != Params.end() && J != EParams.end(); I++, J++)
+      for (; I != Params.end() && J != EParams.end(); ++I, ++J)
         if (*I != *J) break;  // These types aren't equal!
 
       if (I == Params.end() && J == EParams.end()) {
@@ -189,7 +189,7 @@
   // Calculate the string name for the new type...
   string Name = ReturnType->getName() + " (";
   for (ParamTypes::const_iterator I = Params.begin();  
-       I != Params.end(); I++) {
+       I != Params.end(); ++I) {
     if (I != Params.begin())
       Name += ", ";
     Name += (*I)->getName();
@@ -211,7 +211,7 @@
   static vector<const ArrayType*> ExistingTypesCache;
 
   // Search cache for value...
-  for (unsigned i = 0; i < ExistingTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) {
     const ArrayType *T = ExistingTypesCache[i];
 
     if (T->getElementType() == ElementType && 
@@ -237,13 +237,13 @@
 const StructType *StructType::getStructType(const ElementTypes &ETypes) {
   static vector<const StructType*> ExistingStructTypesCache;
 
-  for (unsigned i = 0; i < ExistingStructTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingStructTypesCache.size(); ++i) {
     const StructType *T = ExistingStructTypesCache[i];
 
     const ElementTypes &Elements = T->getElementTypes();
     ElementTypes::const_iterator I = ETypes.begin(); 
     ElementTypes::const_iterator J = Elements.begin(); 
-    for (; I != ETypes.end() && J != Elements.end(); I++, J++)
+    for (; I != ETypes.end() && J != Elements.end(); ++I, ++J)
       if (*I != *J) break;  // These types aren't equal!
     
     if (I == ETypes.end() && J == Elements.end()) {
@@ -269,7 +269,7 @@
   // Calculate the string name for the new type...
   string Name = "{ ";
   for (ElementTypes::const_iterator I = ETypes.begin();  
-       I != ETypes.end(); I++) {
+       I != ETypes.end(); ++I) {
     if (I != ETypes.begin())
       Name += ", ";
     Name += (*I)->getName();
@@ -290,7 +290,7 @@
   static vector<const PointerType*> ExistingTypesCache;
 
   // Search cache for value...
-  for (unsigned i = 0; i < ExistingTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) {
     const PointerType *T = ExistingTypesCache[i];
 
     if (T->getValueType() == ValueType)
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index ee642f6..79d8e0a 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -34,7 +34,7 @@
   // a <badref>
   //
   if (Uses.begin() != Uses.end()) {
-    for (use_const_iterator I = Uses.begin(); I != Uses.end(); I++)
+    for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I)
       cerr << "Use still stuck around after Def is destroyed:" << *I << endl;
   }
 #endif
@@ -88,7 +88,7 @@
 void User::replaceUsesOfWith(Value *From, Value *To) {
   if (From == To) return;   // Duh what?
 
-  for (unsigned OpNum = 0; Value *D = getOperand(OpNum); OpNum++) {   
+  for (unsigned OpNum = 0; Value *D = getOperand(OpNum); ++OpNum) {   
     if (D == From) {  // Okay, this operand is pointing to our fake def.
       // The side effects of this setOperand call include linking to
       // "To", adding "this" to the uses list of To, and
@@ -140,7 +140,7 @@
   if (!SymTab) return false;
 
   for (SymbolTable::const_iterator I = SymTab->begin(); 
-       I != SymTab->end(); I++) {
+       I != SymTab->end(); ++I) {
     if (I->second.begin() != I->second.end())
       return true;                                // Found nonempty type plane!
   }
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 820fa5c..5b6654d 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -71,10 +71,9 @@
 bool verify(const Method *M, vector<string> &ErrorMsgs) {
   bool Bad = false;
   
-  for (Method::BasicBlocksType::const_iterator BBIt = M->getBasicBlocks().begin();
-       BBIt != M->getBasicBlocks().end(); BBIt++) {
+  for (Method::const_iterator BBIt = M->begin();
+       BBIt != M->end(); ++BBIt)
     Bad |= verify(*BBIt, ErrorMsgs);
-  }
 
   return Bad;
 }
@@ -84,11 +83,8 @@
   assert(Type::FirstDerivedTyID-1 < sizeof(long)*8 && 
 	 "Resize ValidTypes table to handle more than 32 primitive types!");
 
-  for (Module::MethodListType::const_iterator MI = C->getMethodList().begin();
-       MI != C->getMethodList().end(); MI++) {
-    const Method *M = *MI;
-    Bad |= verify(M, ErrorMsgs);
-  }
+  for (Module::const_iterator MI = C->begin(); MI != C->end(); ++MI)
+    Bad |= verify(*MI, ErrorMsgs);
   
   return Bad;
 }
diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp
index 9ff6bb6..7632798 100644
--- a/lib/VMCore/iCall.cpp
+++ b/lib/VMCore/iCall.cpp
@@ -14,7 +14,7 @@
 
   const MethodType* MT = M->getMethodType();
   const MethodType::ParamTypes &PL = MT->getParamTypes();
-  assert(params.size() == PL.size());
+  assert(params.size() == PL.size() && "Calling a function with bad signature");
 #ifndef NDEBUG
   MethodType::ParamTypes::const_iterator It = PL.begin();
 #endif
@@ -38,8 +38,7 @@
 bool CallInst::setOperand(unsigned i, Value *Val) {
   if (i > Params.size()) return false;
   if (i == 0) {
-    assert(Val->getValueType() == Value::MethodVal);
-    M = (Method*)Val;
+    M = Val->castMethodAsserting();
   } else {
     // TODO: assert = method arg type
     Params[i-1] = Val;