Implement the TargetMachine::getJITStubForFunction method for X86, finegrainify
[oota-llvm.git] / lib / VMCore / SlotCalculator.cpp
index b182f6dbfaa3745efe748086da542fe243eaf505..f4414a5921d84e4f5a1f3ed5c091b08d5443b2db 100644 (file)
@@ -1,4 +1,11 @@
 //===-- SlotCalculator.cpp - Calculate what slots values land in ----------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file implements a useful analysis step to figure out what numbered 
 // slots values in a program will land in (keeping track of per plane
 #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>
+using namespace llvm;
 
 #if 0
 #define SC_DEBUG(X) std::cerr << X
@@ -33,6 +41,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);
@@ -49,6 +58,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);
@@ -167,8 +177,12 @@ void SlotCalculator::incorporateFunction(const Function *F) {
   SC_DEBUG("Inserting Instructions:\n");
 
   // Add all of the instructions to the type planes...
-  for_each(inst_begin(F), inst_end(F),
-          bind_obj(this, &SlotCalculator::getOrCreateSlot));
+  for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
+    for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
+      getOrCreateSlot(I);
+      if (const VANextInst *VAN = dyn_cast<VANextInst>(I))
+        getOrCreateSlot(VAN->getArgType());
+    }
 
   if (!IgnoreNamedNodes) {
     SC_DEBUG("Inserting SymbolTable values:\n");
@@ -274,20 +288,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;
   }