Remove usage of ConstantPointer
[oota-llvm.git] / lib / Bytecode / Writer / SlotCalculator.cpp
index 9969550d0b0fbcd41c7594a1310b80d04f169af3..c6e44e8266f35d07c3710a72a8412a43d1498ad8 100644 (file)
 #include "llvm/Constant.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
-#include "Support/DepthFirstIterator.h"
+#include "Support/PostOrderIterator.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 #if 0
 #define SC_DEBUG(X) std::cerr << X
 #else
@@ -40,6 +42,7 @@ SlotCalculator::SlotCalculator(const Module *M, bool IgnoreNamed) {
   // Preload table... Make sure that all of the primitive types are in the table
   // and that their Primitive ID is equal to their slot #
   //
+  SC_DEBUG("Inserting primitive types:\n");
   for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
     assert(Type::getPrimitiveType((Type::PrimitiveID)i));
     insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
@@ -56,6 +59,7 @@ SlotCalculator::SlotCalculator(const Function *M, bool IgnoreNamed) {
   // Preload table... Make sure that all of the primitive types are in the table
   // and that their Primitive ID is equal to their slot #
   //
+  SC_DEBUG("Inserting primitive types:\n");
   for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
     assert(Type::getPrimitiveType((Type::PrimitiveID)i));
     insertValue(Type::getPrimitiveType((Type::PrimitiveID)i), true);
@@ -285,20 +289,22 @@ int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
     SC_DEBUG("  Inserted type: " << TheTy->getDescription() << " slot=" <<
              ResultSlot << "\n");
 
-    // Loop over any contained types in the definition... in depth first order.
+    // Loop over any contained types in the definition... in post
+    // order.
     //
-    for (df_iterator<const Type*> I = df_begin(TheTy), E = df_end(TheTy);
-         I != E; ++I)
+    for (po_iterator<const Type*> I = po_begin(TheTy), E = po_end(TheTy);
+         I != E; ++I) {
       if (*I != TheTy) {
+        const Type *SubTy = *I;
        // If we haven't seen this sub type before, add it to our type table!
-       const Type *SubTy = *I;
-       if (getSlot(SubTy) == -1) {
-         SC_DEBUG("  Inserting subtype: " << SubTy->getDescription() << "\n");
-         int Slot = doInsertValue(SubTy);
-         SC_DEBUG("  Inserted subtype: " << SubTy->getDescription() << 
-                  " slot=" << Slot << "\n");
-       }
+        if (getSlot(SubTy) == -1) {
+          SC_DEBUG("  Inserting subtype: " << SubTy->getDescription() << "\n");
+          int Slot = doInsertValue(SubTy);
+          SC_DEBUG("  Inserted subtype: " << SubTy->getDescription() << 
+                   " slot=" << Slot << "\n");
+        }
       }
+    }
     return ResultSlot;
   }
 
@@ -357,3 +363,5 @@ int SlotCalculator::doInsertValue(const Value *D) {
   SC_DEBUG("]\n");
   return (int)DestSlot;
 }
+
+} // End llvm namespace