Method.h no longer includes BasicBlock.h
authorChris Lattner <sabre@nondot.org>
Tue, 12 Feb 2002 21:07:25 +0000 (21:07 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 12 Feb 2002 21:07:25 +0000 (21:07 +0000)
Method::inst_* is now in llvm/Support/InstIterator.h
GraphTraits specializations for BasicBlock and Methods are now in llvm/Support/CFG.h

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1746 91177308-0d34-0410-b5e6-96231b3b80d8

37 files changed:
lib/Analysis/IPA/CallGraph.cpp
lib/Analysis/IPA/FindUnsafePointerTypes.cpp
lib/Analysis/IPA/FindUsedTypes.cpp
lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
lib/Analysis/LoopInfo.cpp
lib/Analysis/PostDominators.cpp
lib/Bytecode/Reader/ReaderInternals.h
lib/Bytecode/Writer/SlotCalculator.cpp
lib/CodeGen/InstrSched/SchedPriorities.cpp
lib/CodeGen/InstrSelection/InstrForest.cpp
lib/CodeGen/MachineFunction.cpp
lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
lib/ExecutionEngine/Interpreter/Execution.cpp
lib/ExecutionEngine/Interpreter/Interpreter.h
lib/Linker/LinkModules.cpp
lib/Target/SparcV9/InstrSched/SchedPriorities.cpp
lib/Target/SparcV9/InstrSelection/InstrForest.cpp
lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp
lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
lib/Target/SparcV9/SparcV9TargetMachine.cpp
lib/Transforms/Scalar/ADCE.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InductionVars.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/Linker.cpp
lib/VMCore/Dominators.cpp
lib/VMCore/Instruction.cpp
lib/VMCore/Linker.cpp
lib/VMCore/Pass.cpp
lib/VMCore/SlotCalculator.cpp
tools/analyze/analyze.cpp
tools/dis/dis.cpp
tools/llvm-dis/dis.cpp
tools/llvm-dis/llvm-dis.cpp

index 244c35ea46ec037db0a29cdef5a55ec2af689edf..04b8c2d6bc8d4aa8d7bbeb0c3feb8660913b6921 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/Method.h"
 #include "llvm/iOther.h"
 #include "llvm/iTerminators.h"
+#include "llvm/Support/InstIterator.h"// FIXME: CallGraph should use method uses
 #include "Support/STLExtras.h"
 #include <algorithm>
 
@@ -46,8 +47,7 @@ void cfg::CallGraph::addToCallGraph(Method *M) {
   if (!M->hasInternalLinkage())
     Root->addCalledMethod(Node);
 
-  for (Method::inst_iterator I = M->inst_begin(), E = M->inst_end();
-       I != E; ++I) {
+  for (inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I) {
     // Dynamic calls will cause Null nodes to be created
     if (CallInst *CI = dyn_cast<CallInst>(*I))
       Node->addCalledMethod(getNodeFor(CI->getCalledMethod()));
@@ -138,8 +138,7 @@ bool IsLeafMethod(const Method* M, const cfg::CallGraph* CG) {
     return (cgn->begin() == cgn->end());
   }
 
-  for (Method::const_inst_iterator I = M->inst_begin(), E = M->inst_end();
-       I != E; ++I)
+  for (const_inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I)
     if ((*I)->getOpcode() == Instruction::Call)
       return false;
   return true;
index bc092920907e1ddfef89a2e907f936ff999e9e47..0179cbb74c884c317d24baf1e583602532de2f12 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/Instruction.h"
 #include "llvm/Method.h"
 #include "llvm/Module.h"
+#include "llvm/Support/InstIterator.h"
 #include "Support/CommandLine.h"
 
 AnalysisID FindUnsafePointerTypes::ID(AnalysisID::create<FindUnsafePointerTypes>());
@@ -58,8 +59,7 @@ bool FindUnsafePointerTypes::run(Module *Mod) {
   for (Module::iterator MI = Mod->begin(), ME = Mod->end();
        MI != ME; ++MI) {
     const Method *M = *MI;  // We don't need/want write access
-    for (Method::const_inst_iterator I = M->inst_begin(), E = M->inst_end();
-         I != E; ++I) {
+    for (const_inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I) {
       const Instruction *Inst = *I;
       const Type *ITy = Inst->getType();
       if (ITy->isPointerType() && !UnsafeTypes.count((PointerType*)ITy))
index b876e5e68d8d2db7dbd41cb342f1f67e939e50aa..e02429ab9771db479eb2c5718427f03cc246b3cc 100644 (file)
@@ -11,6 +11,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/Support/InstIterator.h"
 
 AnalysisID FindUsedTypes::ID(AnalysisID::create<FindUsedTypes>());
 AnalysisID FindUsedTypes::IncludeSymbolTableID(AnalysisID::create<FindUsedTypes>());
@@ -59,7 +60,7 @@ bool FindUsedTypes::run(Module *m) {
     // Loop over all of the instructions in the method, adding their return type
     // as well as the types of their operands.
     //
-    for (Method::const_inst_iterator II = M->inst_begin(), IE = M->inst_end();
+    for (const_inst_iterator II = inst_begin(M), IE = inst_end(M);
          II != IE; ++II) {
       const Instruction *I = *II;
       const Type *Ty = I->getType();
index a1a2dba9fb325aeb6e944aedcf3bcbd582a52cb7..b83359f94b89cdd6fc6fdb7bef79343f7ad34f08 100644 (file)
@@ -9,6 +9,7 @@
 #include "BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/SetOperations.h"
 #include <iostream>
index 9b34095e4f2477c07d07e0d68905d8f8175896c5..876161d34fc9199555a353ee2a4ef25ab59adf65 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/Dominators.h"
-#include "llvm/BasicBlock.h"
+#include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include <algorithm>
 
index aad6e1cb386ba3d96b9c4968c98d9fa7f998861f..33e14e9fc583e1058af861de42e4a689cad465b2 100644 (file)
@@ -7,6 +7,7 @@
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Transforms/UnifyMethodExitNodes.h"
 #include "llvm/Method.h"
+#include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/STLExtras.h"
 #include "Support/SetOperations.h"
index 8a7297a8b3deaf01d86d767eafa8b06f42183366..a5b3b7acfd66b1b2d444d602549d8f5d7bf30832 100644 (file)
@@ -10,6 +10,7 @@
 #include "llvm/Bytecode/Primitives.h"
 #include "llvm/SymTabValue.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/Instruction.h"
 #include "llvm/DerivedTypes.h"
 #include <map>
index 4738f712a162465cdca091b818cfe6edbfe4d24e..43a4591cb8ad567fd54ffb3716e88b1585266ad0 100644 (file)
@@ -171,7 +171,7 @@ void SlotCalculator::incorporateMethod(const Method *M) {
   SC_DEBUG("Inserting Instructions:\n");
 
   // Add all of the instructions to the type planes...
-  for_each(M->inst_begin(), M->inst_end(),
+  for_each(inst_begin(M), inst_end(M),
           bind_obj(this, &SlotCalculator::insertValue));
 
   if (M->hasSymbolTable() && !IgnoreNamedNodes) {
index 1d4983130e7b9a809c9891ee0f6550f9d4ac0388..ef9f9e459972bb2b01c3f2ce341926fd18a872fc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "SchedPriorities.h"
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
+#include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 #include <iostream>
 using std::cerr;
index 29090e06cc0ee9f65c286432e872a7cac69d48fe..b11d71e1f6b1cd78817475e10553b57b0856bf92 100644 (file)
@@ -189,15 +189,18 @@ LabelNode::dumpNode(int indent) const
 
 InstrForest::InstrForest(Method *M)
 {
-  for (Method::inst_iterator I = M->inst_begin(); I != M->inst_end(); ++I)
-    this->buildTreeForInstruction(*I);
+  for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+    BasicBlock *BB = *MI;
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+      buildTreeForInstruction(*I);
+  }
 }
 
 InstrForest::~InstrForest()
 {
   for (std::hash_map<const Instruction*,InstructionNode*>::iterator I = begin();
        I != end(); ++I)
-      delete (*I).second;
+      delete I->second;
 }
 
 void
index 3ff3e8ceea228cd4e58dcf593687e3133ef5e6e9..4bb17f15fec7228a517ebdb424e562983fcc4830 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/Target/MachineFrameInfo.h"
 #include "llvm/Target/MachineCacheInfo.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/iOther.h"
 #include <limits.h>
 
@@ -56,11 +57,11 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Method* method)
   
   unsigned int maxSize = 0;
   
-  for (Method::const_inst_iterator I=method->inst_begin(),E=method->inst_end();
-       I != E; ++I)
-    if ((*I)->getOpcode() == Instruction::Call)
-      {
-        CallInst* callInst = cast<CallInst>(*I);
+  for (Method::const_iterator MI=method->begin(), ME=method->end();
+       MI != ME; ++MI) {
+    const BasicBlock *BB = *MI;
+    for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+      if (CallInst *callInst = dyn_cast<CallInst>(*I)) {
         unsigned int numOperands = callInst->getNumOperands() - 1;
         int numExtra = (int) numOperands - frameInfo.getNumFixedOutgoingArgs();
         if (numExtra <= 0)
@@ -84,7 +85,7 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Method* method)
         if (maxSize < sizeForThisCall)
           maxSize = sizeForThisCall;
       }
-  
+  }
   return maxSize;
 }
 
index 7302baa2864e01c28421880608ae92f5adc81057..32951769e00a20cd14bafa1d18ed3b9b926743a0 100644 (file)
@@ -3,6 +3,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "Support/SetOperations.h"
 #include <iostream>
 using std::cerr;
index 18d019e8f4cda16e462c86fc4265340cc0b0a4f9..c78b971e796dd29b2d3ba4f77e5c49f25ebcdd73 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/MachineFrameInfo.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/Type.h"
 #include <iostream>
index 0fad82964d2fce3faad3a8a67f448d995b46d53d..9f6317fd3937b25aae661ddcbb9b4c523f041bb5 100644 (file)
@@ -1034,10 +1034,12 @@ MethodInfo::MethodInfo(Method *M) : Annotation(MethodInfoAID) {
 
   // Iterate over all of the instructions...
   unsigned InstNum = 0;
-  for (Method::inst_iterator MI = M->inst_begin(), ME = M->inst_end();
-       MI != ME; ++MI) {
-    Instruction *I = *MI;                          // For each instruction...
-    I->addAnnotation(new InstNumber(++InstNum, getValueSlot(I))); // Add Annote
+  for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+    BasicBlock *BB = *MI;
+    for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II){
+      Instruction *I = *II;          // For each instruction... Add Annote
+      I->addAnnotation(new InstNumber(++InstNum, getValueSlot(I)));
+    }
   }
 }
 
index ffe10015978f352f68fc8c016c19b70ec40b9ddd..050b7d332d2f9038a75299675bb94725f18f1f4a 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "Support/DataTypes.h"
 #include "llvm/Assembly/CachedWriter.h"
 
index e1622529c26041ffe7e5dc56fdffed3c3291eb8e..f265bb05d17b6d020bd8d9f3559e9544a214e60d 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/Transforms/Linker.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
@@ -337,13 +338,16 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
   // in the Source method as operands.  Loop through all of the operands of the
   // methods and patch them up to point to the local versions...
   //
-  for (Method::inst_iterator I = Dest->inst_begin(), E = Dest->inst_end();
-       I != E; ++I) {
-    Instruction *Inst = *I;
-
-    for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
-         OI != OE; ++OI)
-      *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+  for (Method::iterator BI = Dest->begin(), BE = Dest->end();
+       BI != BE; ++BI) {
+    BasicBlock *BB = *BI;
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
+      Instruction *Inst = *I;
+      
+      for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
+           OI != OE; ++OI)
+        *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+    }
   }
 
   return false;
index 1d4983130e7b9a809c9891ee0f6550f9d4ac0388..ef9f9e459972bb2b01c3f2ce341926fd18a872fc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "SchedPriorities.h"
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
+#include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 #include <iostream>
 using std::cerr;
index 29090e06cc0ee9f65c286432e872a7cac69d48fe..b11d71e1f6b1cd78817475e10553b57b0856bf92 100644 (file)
@@ -189,15 +189,18 @@ LabelNode::dumpNode(int indent) const
 
 InstrForest::InstrForest(Method *M)
 {
-  for (Method::inst_iterator I = M->inst_begin(); I != M->inst_end(); ++I)
-    this->buildTreeForInstruction(*I);
+  for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+    BasicBlock *BB = *MI;
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+      buildTreeForInstruction(*I);
+  }
 }
 
 InstrForest::~InstrForest()
 {
   for (std::hash_map<const Instruction*,InstructionNode*>::iterator I = begin();
        I != end(); ++I)
-      delete (*I).second;
+      delete I->second;
 }
 
 void
index a1a2dba9fb325aeb6e944aedcf3bcbd582a52cb7..b83359f94b89cdd6fc6fdb7bef79343f7ad34f08 100644 (file)
@@ -9,6 +9,7 @@
 #include "BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/SetOperations.h"
 #include <iostream>
index 7302baa2864e01c28421880608ae92f5adc81057..32951769e00a20cd14bafa1d18ed3b9b926743a0 100644 (file)
@@ -3,6 +3,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "Support/SetOperations.h"
 #include <iostream>
 using std::cerr;
index 18d019e8f4cda16e462c86fc4265340cc0b0a4f9..c78b971e796dd29b2d3ba4f77e5c49f25ebcdd73 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/MachineFrameInfo.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/Type.h"
 #include <iostream>
index 14be99231545608c30d603f359e24faa545bec2d..b026ccd67a0d58fd21558cdf2b7991b5e6865ecc 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/RegisterAllocation.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/PassManager.h"
 #include <iostream>
 using std::cerr;
@@ -229,7 +230,11 @@ struct FreeMachineCodeForMethod : public MethodPass {
   }
 
   bool runOnMethod(Method *M) {
-    for_each(M->inst_begin(), M->inst_end(), freeMachineCode);
+    for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
+      for (BasicBlock::iterator I = (*MI)->begin(), E = (*MI)->end();
+           I != E; ++I)
+        freeMachineCode(*I);
+
     // Don't destruct MachineCodeForMethod - The global printer needs it
     //MachineCodeForMethod::destruct(M);
     return false;
index 71c50674f4cccf4d4c6ee832f88101072ecb1503..7f71cf18504a0717bda3248ef5b842b28de84ac5 100644 (file)
@@ -13,6 +13,7 @@
 #include "llvm/Analysis/Writer.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iPHINode.h"
+#include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
 #include "Support/DepthFirstIterator.h"
 #include <algorithm>
@@ -156,10 +157,12 @@ bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
 
 #ifdef DEBUG_ADCE
   cerr << "Current Method: X = Live\n";
-  for (Method::inst_iterator IL = M->inst_begin(); IL != M->inst_end(); ++IL) {
-    if (LiveSet.count(*IL)) cerr << "X ";
-    cerr << *IL;
-  }
+  for (Method::iterator I = M->begin(), E = M->end(); I != E; ++I)
+    for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end();
+         BI != BE; ++BI) {
+      if (LiveSet.count(*BI)) cerr << "X ";
+      cerr << *BI;
+    }
 #endif
 
   // After the worklist is processed, recursively walk the CFG in depth first
index d06c19787fec5836c23e48044edba19841a0e5c7..59442ea2773488ade7b345c741758cf5d2ccb1ff 100644 (file)
@@ -11,6 +11,7 @@
 #include "llvm/iPHINode.h"
 #include "llvm/iOther.h"
 #include "llvm/Type.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/ConstantVals.h"
 #include "Support/STLExtras.h"
 
index 48982f4773d99280cd961784c7113c88965c033f..bc130f0faf5932e2c1f74cf8477a7990a934e41e 100644 (file)
@@ -26,6 +26,7 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 #include <iostream>
index 25590661b77f552b38dd29f7b63eea92c7d31926..962ca97dec59bcd88b4344adf9b0013c38800cee 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Transforms/Scalar/ConstantHandling.h"
 #include "llvm/Method.h"
 #include "llvm/iMemory.h"
+#include "llvm/Support/InstIterator.h"
 #include "../TransformInternals.h"
 
 static Instruction *CombineBinOp(BinaryOperator *I) {
@@ -126,7 +127,7 @@ bool InstructionCombining::CombineInstruction(Instruction *I) {
 
 bool InstructionCombining::doit(Method *M) {
   // Start the worklist out with all of the instructions in the method in it.
-  std::vector<Instruction*> WorkList(M->inst_begin(), M->inst_end());
+  std::vector<Instruction*> WorkList(inst_begin(M), inst_end(M));
 
   while (!WorkList.empty()) {
     Instruction *I = WorkList.back();  // Get an instruction from the worklist
index d6b7c40f34b885aa58fc0bbabab96b9a104a1e9f..ada670deb818f5516aa7657546c5f5419d997ae4 100644 (file)
@@ -244,39 +244,36 @@ bool SCCP::doSCCP() {
   // constants if we have found them to be of constant values.
   //
   bool MadeChanges = false;
-  for (Method::inst_iterator II = M->inst_begin(); II != M->inst_end(); ) {
-    Instruction *Inst = *II;
-    InstVal &IV = ValueState[Inst];
-    if (IV.isConstant()) {
-      Constant *Const = IV.getConstant();
-      // cerr << "Constant: " << Inst << "  is: " << Const;
-
-      // Replaces all of the uses of a variable with uses of the constant.
-      Inst->replaceAllUsesWith(Const);
-
-      // Remove the operator from the list of definitions...
-      Inst->getParent()->getInstList().remove(II.getInstructionIterator());
-
-      // The new constant inherits the old name of the operator...
-      if (Inst->hasName() && !Const->hasName())
-        Const->setName(Inst->getName(), M->getSymbolTableSure());
-
-      // Delete the operator now...
-      delete Inst;
-
-      // Incrementing the iterator in an unchecked manner could mess up the
-      // internals of 'II'.  To make sure everything is happy, tell it we might
-      // have broken it.
-      II.resyncInstructionIterator();
-
-      // Hey, we just changed something!
-      MadeChanges = true;
-      continue;   // Skip the ++II at the end of the loop here...
-    } else if (Inst->isTerminator()) {
-      MadeChanges |= ConstantFoldTerminator(cast<TerminatorInst>(Inst));
-    }
+  for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+    BasicBlock *BB = *MI;
+    for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
+      Instruction *Inst = *BI;
+      InstVal &IV = ValueState[Inst];
+      if (IV.isConstant()) {
+        Constant *Const = IV.getConstant();
+        // cerr << "Constant: " << Inst << "  is: " << Const;
+
+        // Replaces all of the uses of a variable with uses of the constant.
+        Inst->replaceAllUsesWith(Const);
+
+        // Remove the operator from the list of definitions...
+        BB->getInstList().remove(BI);
+
+        // The new constant inherits the old name of the operator...
+        if (Inst->hasName() && !Const->hasName())
+          Const->setName(Inst->getName(), M->getSymbolTableSure());
+
+        // Delete the operator now...
+        delete Inst;
+
+        // Hey, we just changed something!
+        MadeChanges = true;
+      } else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Inst)) {
+        MadeChanges |= ConstantFoldTerminator(TI);
+      }
 
-    ++II;
+      ++BI;
+    }
   }
 
   // Merge identical constants last: this is important because we may have just
index e1622529c26041ffe7e5dc56fdffed3c3291eb8e..f265bb05d17b6d020bd8d9f3559e9544a214e60d 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/Transforms/Linker.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
@@ -337,13 +338,16 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
   // in the Source method as operands.  Loop through all of the operands of the
   // methods and patch them up to point to the local versions...
   //
-  for (Method::inst_iterator I = Dest->inst_begin(), E = Dest->inst_end();
-       I != E; ++I) {
-    Instruction *Inst = *I;
-
-    for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
-         OI != OE; ++OI)
-      *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+  for (Method::iterator BI = Dest->begin(), BE = Dest->end();
+       BI != BE; ++BI) {
+    BasicBlock *BB = *BI;
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
+      Instruction *Inst = *I;
+      
+      for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
+           OI != OE; ++OI)
+        *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+    }
   }
 
   return false;
index aad6e1cb386ba3d96b9c4968c98d9fa7f998861f..33e14e9fc583e1058af861de42e4a689cad465b2 100644 (file)
@@ -7,6 +7,7 @@
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Transforms/UnifyMethodExitNodes.h"
 #include "llvm/Method.h"
+#include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/STLExtras.h"
 #include "Support/SetOperations.h"
index 50fdd44227871ce96ac783c7d664b3ef55a4571f..e729a65a3864ce9c9b3c1d7a057be8229834391a 100644 (file)
@@ -5,6 +5,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Instruction.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/SymbolTable.h"
 
index e1622529c26041ffe7e5dc56fdffed3c3291eb8e..f265bb05d17b6d020bd8d9f3559e9544a214e60d 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/Transforms/Linker.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
@@ -337,13 +338,16 @@ static bool LinkMethodBody(Method *Dest, const Method *Src,
   // in the Source method as operands.  Loop through all of the operands of the
   // methods and patch them up to point to the local versions...
   //
-  for (Method::inst_iterator I = Dest->inst_begin(), E = Dest->inst_end();
-       I != E; ++I) {
-    Instruction *Inst = *I;
-
-    for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
-         OI != OE; ++OI)
-      *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+  for (Method::iterator BI = Dest->begin(), BE = Dest->end();
+       BI != BE; ++BI) {
+    BasicBlock *BB = *BI;
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
+      Instruction *Inst = *I;
+      
+      for (Instruction::op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
+           OI != OE; ++OI)
+        *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+    }
   }
 
   return false;
index c18ff0adcc5a48fc760961fa175bd95e9cb663cc..b6e222d98aae1e3681011c800f858696e790d78f 100644 (file)
@@ -9,6 +9,7 @@
 #include "llvm/PassManager.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/BasicBlock.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 
index 4738f712a162465cdca091b818cfe6edbfe4d24e..43a4591cb8ad567fd54ffb3716e88b1585266ad0 100644 (file)
@@ -171,7 +171,7 @@ void SlotCalculator::incorporateMethod(const Method *M) {
   SC_DEBUG("Inserting Instructions:\n");
 
   // Add all of the instructions to the type planes...
-  for_each(M->inst_begin(), M->inst_end(),
+  for_each(inst_begin(M), inst_end(M),
           bind_obj(this, &SlotCalculator::insertValue));
 
   if (M->hasSymbolTable() && !IgnoreNamedNodes) {
index 112bfcc04b4285ea040ac6d44b8bd77eb8172fa8..5f3e52ef0067dafddfcceb041407bd7965957571 100644 (file)
@@ -28,6 +28,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/FindUnsafePointerTypes.h"
 #include "llvm/Analysis/FindUsedTypes.h"
+#include "llvm/Support/InstIterator.h"
 #include "Support/CommandLine.h"
 #include <algorithm>
 #include <iostream>
@@ -119,8 +120,7 @@ struct InstForest : public MethodPass {
 struct IndVars : public MethodPass {
   void doit(Method *M) {
     cfg::LoopInfo &LI = getAnalysis<cfg::LoopInfo>();
-    for (Method::inst_iterator I = M->inst_begin(), E = M->inst_end();
-         I != E; ++I)
+    for (inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I)
       if (PHINode *PN = dyn_cast<PHINode>(*I)) {
         InductionVariable IV(PN, &LI);
         if (IV.InductionType != InductionVariable::Unknown)
@@ -137,8 +137,7 @@ struct IndVars : public MethodPass {
 struct Exprs : public MethodPass {
   static void doit(Method *M) {
     cout << "Classified expressions for: " << M->getName() << "\n";
-    Method::inst_iterator I = M->inst_begin(), E = M->inst_end();
-    for (; I != E; ++I) {
+    for (inst_iterator I = inst_begin(M), E = inst_end(M); I != E; ++I) {
       cout << *I;
       
       if ((*I)->getType() == Type::VoidTy) continue;
index 11e67c4fe8b076005ad415392d11703bdbd06307..3495465d3f4add6cd55abc8a5a0b598da4e0d9ce 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Method.h"
+#include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/CommandLine.h"
index 11e67c4fe8b076005ad415392d11703bdbd06307..3495465d3f4add6cd55abc8a5a0b598da4e0d9ce 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Method.h"
+#include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/CommandLine.h"
index 11e67c4fe8b076005ad415392d11703bdbd06307..3495465d3f4add6cd55abc8a5a0b598da4e0d9ce 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Method.h"
+#include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/PostOrderIterator.h"
 #include "Support/CommandLine.h"