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;