Check that we don't have external varaibles with internal linkage
[oota-llvm.git] / lib / VMCore / SlotCalculator.cpp
index 9c5d97a5881bcfaffd03b70580ed5329bb36128f..f0a549e81cc8d6e5a2e8bde0e908ec03ffe8ff79 100644 (file)
@@ -9,14 +9,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Analysis/SlotCalculator.h"
+#include "llvm/SlotCalculator.h"
 #include "llvm/Analysis/ConstantsScanner.h"
-#include "llvm/Method.h"
-#include "llvm/GlobalVariable.h"
 #include "llvm/Module.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/ConstantVals.h"
 #include "llvm/iOther.h"
+#include "llvm/Constant.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
 #include "Support/DepthFirstIterator.h"
@@ -45,7 +42,7 @@ SlotCalculator::SlotCalculator(const Module *M, bool IgnoreNamed) {
   processModule();
 }
 
-SlotCalculator::SlotCalculator(const Method *M, bool IgnoreNamed) {
+SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
   IgnoreNamedNodes = IgnoreNamed;
   TheModule = M ? M->getParent() : 0;
 
@@ -60,11 +57,11 @@ SlotCalculator::SlotCalculator(const Method *M, bool IgnoreNamed) {
   if (TheModule == 0) return;   // Empty table...
 
   processModule();              // Process module level stuff
-  incorporateMethod(M);         // Start out in incorporated state
+  incorporateFunction(M);         // Start out in incorporated state
 }
 
 
-// processModule - Process all of the module level method declarations and
+// processModule - Process all of the module level function declarations and
 // types that are available.
 //
 void SlotCalculator::processModule() {
@@ -74,20 +71,22 @@ void SlotCalculator::processModule() {
   //
   for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
        I != E; ++I) {
-    if ((*I)->hasInitializer())
-      insertValue((*I)->getInitializer());
+    if (I->hasInitializer())
+      insertValue(I->getInitializer());
   }
 
   // Add all of the global variables to the value table...
   //
-  for_each(TheModule->gbegin(), TheModule->gend(),
-          bind_obj(this, &SlotCalculator::insertValue));
+  for(Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
+      I != E; ++I)
+    insertValue(I);
 
-  // Scavenge the types out of the methods, then add the methods themselves to
-  // the value table...
+  // Scavenge the types out of the functions, then add the functions themselves
+  // to the value table...
   //
-  for_each(TheModule->begin(), TheModule->end(),  // Insert methods...
-          bind_obj(this, &SlotCalculator::insertValue));
+  for(Module::const_iterator I = TheModule->begin(), E = TheModule->end();
+      I != E; ++I)
+    insertValue(I);
 
   // Insert constants that are named at module level into the slot pool so that
   // the module symbol table can refer to them...
@@ -119,36 +118,36 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
 }
 
 
-void SlotCalculator::incorporateMethod(const Method *M) {
+void SlotCalculator::incorporateFunction(const Function *M) {
   assert(ModuleLevel.size() == 0 && "Module already incorporated!");
 
-  SC_DEBUG("begin processMethod!\n");
+  SC_DEBUG("begin processFunction!\n");
 
-  // Save the Table state before we process the method...
+  // Save the Table state before we process the function...
   for (unsigned i = 0; i < Table.size(); ++i)
     ModuleLevel.push_back(Table[i].size());
 
-  SC_DEBUG("Inserting method arguments\n");
+  SC_DEBUG("Inserting function arguments\n");
 
-  // Iterate over method arguments, adding them to the value table...
-  for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
-          bind_obj(this, &SlotCalculator::insertValue));
+  // Iterate over function arguments, adding them to the value table...
+  for(Function::const_aiterator I = M->abegin(), E = M->aend(); I != E; ++I)
+    insertValue(I);
 
-  // Iterate over all of the instructions in the method, looking for constant
+  // Iterate over all of the instructions in the function, looking for constant
   // values that are referenced.  Add these to the value pools before any
   // nonconstant values.  This will be turned into the constant pool for the
   // bytecode writer.
   //
   if (!IgnoreNamedNodes) {                // Assembly writer does not need this!
-    SC_DEBUG("Inserting method constants:\n";
+    SC_DEBUG("Inserting function constants:\n";
             for (constant_iterator I = constant_begin(M), E = constant_end(M);
                  I != E; ++I) {
-              cerr << "  " << I->getType()->getDescription() 
-                   << " " << I->getStrValue() << endl;
+              cerr << "  " << *I->getType()
+                   << " " << *I << "\n";
             });
 
     // Emit all of the constants that are being used by the instructions in the
-    // method...
+    // function...
     for_each(constant_begin(M), constant_end(M),
             bind_obj(this, &SlotCalculator::insertValue));
 
@@ -165,13 +164,15 @@ void SlotCalculator::incorporateMethod(const Method *M) {
   SC_DEBUG("Inserting Labels:\n");
 
   // Iterate over basic blocks, adding them to the value table...
-  for_each(M->begin(), M->end(),
-          bind_obj(this, &SlotCalculator::insertValue));
+  for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
+    insertValue(I);
+  /*  for_each(M->begin(), M->end(),
+      bind_obj(this, &SlotCalculator::insertValue));*/
 
   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) {
@@ -179,24 +180,25 @@ void SlotCalculator::incorporateMethod(const Method *M) {
     processSymbolTable(M->getSymbolTable());
   }
 
-  SC_DEBUG("end processMethod!\n");
+  SC_DEBUG("end processFunction!\n");
 }
 
-void SlotCalculator::purgeMethod() {
+void SlotCalculator::purgeFunction() {
   assert(ModuleLevel.size() != 0 && "Module not incorporated!");
   unsigned NumModuleTypes = ModuleLevel.size();
 
-  SC_DEBUG("begin purgeMethod!\n");
+  SC_DEBUG("begin purgeFunction!\n");
 
   // First, remove values from existing type planes
   for (unsigned i = 0; i < NumModuleTypes; ++i) {
-    unsigned ModuleSize = ModuleLevel[i];  // Size of plane before method came
+    unsigned ModuleSize = ModuleLevel[i];  // Size of plane before function came
     TypePlane &CurPlane = Table[i];
     //SC_DEBUG("Processing Plane " <<i<< " of size " << CurPlane.size() <<endl);
             
     while (CurPlane.size() != ModuleSize) {
       //SC_DEBUG("  Removing [" << i << "] Value=" << CurPlane.back() << "\n");
-      map<const Value *, unsigned>::iterator NI = NodeMap.find(CurPlane.back());
+      std::map<const Value *, unsigned>::iterator NI =
+        NodeMap.find(CurPlane.back());
       assert(NI != NodeMap.end() && "Node not in nodemap?");
       NodeMap.erase(NI);   // Erase from nodemap
       CurPlane.pop_back();                            // Shrink plane
@@ -206,7 +208,7 @@ void SlotCalculator::purgeMethod() {
   // We don't need this state anymore, free it up.
   ModuleLevel.clear();
 
-  // Next, remove any type planes defined by the method...
+  // Next, remove any type planes defined by the function...
   while (NumModuleTypes != Table.size()) {
     TypePlane &Plane = Table.back();
     SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
@@ -219,11 +221,11 @@ void SlotCalculator::purgeMethod() {
     Table.pop_back();                      // Nuke the plane, we don't like it.
   }
 
-  SC_DEBUG("end purgeMethod!\n");
+  SC_DEBUG("end purgeFunction!\n");
 }
 
 int SlotCalculator::getValSlot(const Value *D) const {
-  map<const Value*, unsigned>::const_iterator I = NodeMap.find(D);
+  std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(D);
   if (I == NodeMap.end()) return -1;
  
   return (int)I->second;
@@ -237,7 +239,7 @@ int SlotCalculator::insertValue(const Value *D) {
     // of const ints), that they are inserted also.  Same for global variable
     // initializers.
     //
-    for(User::op_const_iterator I = U->op_begin(), E = U->op_end(); I != E; ++I)
+    for(User::const_op_iterator I = U->op_begin(), E = U->op_end(); I != E; ++I)
       if (!isa<GlobalValue>(*I))  // Don't chain insert global values
        insertValue(*I);
   }
@@ -248,7 +250,7 @@ int SlotCalculator::insertValue(const Value *D) {
 }
 
 
-int SlotCalculator::insertVal(const Value *D, bool dontIgnore = false) {
+int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
   assert(D && "Can't insert a null value!");
   assert(getValSlot(D) == -1 && "Value is already in the table!");
 
@@ -336,9 +338,9 @@ int SlotCalculator::doInsertVal(const Value *D) {
 
   SC_DEBUG("  Inserting value [" << Ty << "] = " << D << " slot=" << 
           DestSlot << " [");
-  // G = Global, C = Constant, T = Type, M = Method, o = other
+  // G = Global, C = Constant, T = Type, F = Function, o = other
   SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" : 
-           (isa<Type>(D) ? "T" : (isa<Method>(D) ? "M" : "o")))));
+           (isa<Type>(D) ? "T" : (isa<Function>(D) ? "F" : "o")))));
   SC_DEBUG("]\n");
   return (int)DestSlot;
 }