MEGAPATCH checkin.
[oota-llvm.git] / lib / Analysis / IPA / FindUsedTypes.cpp
index 1d98983115cf4813b38acc7915a3749702afea24..8cfe1085a3acd2f97607702723e44d310d1d68b9 100644 (file)
@@ -1,4 +1,4 @@
-//===- FindUsedTypes.h - Find all Types used by a module --------------------=//
+//===- FindUsedTypes.cpp - Find all Types used by a module ------------------=//
 //
 // This pass is used to seek out all of the types in use by the program.
 //
@@ -7,8 +7,12 @@
 #include "llvm/Analysis/FindUsedTypes.h"
 #include "llvm/Assembly/CachedWriter.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/GlobalVariable.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
+#include "llvm/Support/InstIterator.h"
+
+AnalysisID FindUsedTypes::ID(AnalysisID::create<FindUsedTypes>());
+AnalysisID FindUsedTypes::IncludeSymbolTableID(AnalysisID::create<FindUsedTypes>());
 
 // IncorporateType - Incorporate one type and all of its subtypes into the
 // collection of used types.
@@ -34,43 +38,39 @@ void FindUsedTypes::IncorporateSymbolTable(const SymbolTable *ST) {
   assert(0 && "Unimp");
 }
 
-
-// doPassInitialization - This loops over global constants defined in the
-// module, converting them to their new type.
+// run - This incorporates all types used by the specified module
 //
-bool FindUsedTypes::doPassInitialization(Module *m) {
-  const Module *M = m;
-  if (IncludeSymbolTables && M->hasSymbolTable())
-    IncorporateSymbolTable(M->getSymbolTable()); // Add symtab first...
+bool FindUsedTypes::run(Module &m) {
+  UsedTypes.clear();  // reset if run multiple times...
+
+  if (IncludeSymbolTables && m.hasSymbolTable())
+    IncorporateSymbolTable(m.getSymbolTable()); // Add symtab first...
 
   // Loop over global variables, incorporating their types
-  for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
-    IncorporateType((*I)->getType());
-  return false;
-}
+  for (Module::const_giterator I = m.gbegin(), E = m.gend(); I != E; ++I)
+    IncorporateType(I->getType());
 
-// doPerMethodWork - This incorporates all types used by the specified method
-//
-bool FindUsedTypes::doPerMethodWork(Method *m) {
-  const Method *M = m;
-  if (IncludeSymbolTables && M->hasSymbolTable())
-  IncorporateSymbolTable(M->getSymbolTable()); // Add symtab first...
+  for (Module::iterator MI = m.begin(), ME = m.end(); MI != ME; ++MI) {
+    const Function &F = *MI;
+    if (IncludeSymbolTables && F.hasSymbolTable())
+      IncorporateSymbolTable(F.getSymbolTable()); // Add symtab first...
   
-  // 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();
-       II != IE; ++II) {
-    const Instruction *I = *II;
-    const Type *Ty = I->getType();
+    // Loop over all of the instructions in the function, adding their return
+    // type as well as the types of their operands.
+    //
+    for (const_inst_iterator II = inst_begin(F), IE = inst_end(F);
+         II != IE; ++II) {
+      const Instruction *I = *II;
+      const Type *Ty = I->getType();
     
-    IncorporateType(Ty);  // Incorporate the type of the instruction
-    for (User::const_op_iterator OI = I->op_begin(), OE = I->op_end();
-         OI != OE; ++OI)
-      if ((*OI)->getType() != Ty)          // Avoid set lookup in common case
-        IncorporateType((*OI)->getType()); // Insert inst operand types as well
+      IncorporateType(Ty);  // Incorporate the type of the instruction
+      for (User::const_op_iterator OI = I->op_begin(), OE = I->op_end();
+           OI != OE; ++OI)
+        if ((*OI)->getType() != Ty)         // Avoid set lookup in common case
+          IncorporateType((*OI)->getType());// Insert inst operand types as well
+    }
   }
-  
   return false;
 }