These methods are inlined
[oota-llvm.git] / lib / VMCore / AsmWriter.cpp
index 60589ba7f1062bb1f11b9a1be325b073d321137a..0b10218ca40e2bfda5dd3e5a597b801d04032dfd 100644 (file)
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instruction.h"
-#include "llvm/iMemory.h"
-#include "llvm/iTerminators.h"
-#include "llvm/iPHINode.h"
-#include "llvm/iOther.h"
+#include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/CFG.h"
-#include "Support/StringExtras.h"
-#include "Support/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/STLExtras.h"
 #include <algorithm>
 using namespace llvm;
 
-namespace {
+namespace llvm {
 
 /// This class provides computation of slot numbers for LLVM Assembly writing.
 /// @brief LLVM Assembly Writing Slot Computation.
@@ -46,16 +43,24 @@ public:
 
   /// @brief A mapping of Values to slot numbers
   typedef std::map<const Value*, unsigned> ValueMap;
+  typedef std::map<const Type*, unsigned> TypeMap;
 
   /// @brief A plane with next slot number and ValueMap
-  struct Plane { 
+  struct ValuePlane { 
     unsigned next_slot;        ///< The next slot number to use
     ValueMap map;              ///< The map of Value* -> unsigned
-    Plane() { next_slot = 0; } ///< Make sure we start at 0
+    ValuePlane() { next_slot = 0; } ///< Make sure we start at 0
+  };
+
+  struct TypePlane {
+    unsigned next_slot;
+    TypeMap map;
+    TypePlane() { next_slot = 0; }
+    void clear() { map.clear(); next_slot = 0; }
   };
 
   /// @brief The map of planes by Type
-  typedef std::map<const Type*, Plane> TypedPlanes;
+  typedef std::map<const Type*, ValuePlane> TypedPlanes;
 
 /// @}
 /// @name Constructors
@@ -75,9 +80,11 @@ public:
   /// plane.  Its an error to ask for something not in the SlotMachine.
   /// Its an error to ask for a Type*
   int getSlot(const Value *V);
+  int getSlot(const Type*Ty);
 
   /// Determine if a Value has a slot or not
   bool hasSlot(const Value* V);
+  bool hasSlot(const Type* Ty);
 
 /// @}
 /// @name Mutators
@@ -85,7 +92,10 @@ public:
 public:
   /// If you'd like to deal with a function instead of just a module, use 
   /// this method to get its data into the SlotMachine.
-  void incorporateFunction(const Function *F) { TheFunction = F; }
+  void incorporateFunction(const Function *F) { 
+    TheFunction = F;  
+    FunctionProcessed = false;
+  }
 
   /// After calling incorporateFunction, use this method to remove the 
   /// most recently incorporated function from the SlotMachine. This 
@@ -103,11 +113,13 @@ private:
   /// been inserted already, they get inserted, otherwise they are ignored.
   /// Either way, the slot number for the Value* is returned.
   unsigned createSlot(const Value *V);
+  unsigned createSlot(const Type* Ty);
 
   /// Insert a value into the value table. Return the slot number
   /// that it now occupies.  BadThings(TM) will happen if you insert a
   /// Value that's already been inserted. 
   unsigned insertValue( const Value *V );
+  unsigned insertValue( const Type* Ty);
 
   /// Add all of the module level global variables (and their initializers)
   /// and function declarations, but not the contents of those functions.
@@ -129,18 +141,21 @@ public:
 
   /// @brief The function for which we are holding slot numbers
   const Function* TheFunction;
+  bool FunctionProcessed;
 
   /// @brief The TypePlanes map for the module level data
   TypedPlanes mMap;
+  TypePlane mTypes;
 
   /// @brief The TypePlanes map for the function level data
   TypedPlanes fMap;
+  TypePlane fTypes;
 
 /// @}
 
 };
 
-}
+}  // end namespace llvm
 
 static RegisterPass<PrintModulePass>
 X("printm", "Print module to stderr",PassInfo::Analysis|PassInfo::Optimization);
@@ -152,6 +167,11 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
                                  std::map<const Type *, std::string> &TypeTable,
                                    SlotMachine *Machine);
 
+static void WriteAsOperandInternal(std::ostream &Out, const Type *T, 
+                                   bool PrintName,
+                                 std::map<const Type *, std::string> &TypeTable,
+                                   SlotMachine *Machine);
+
 static const Module *getModuleFromVal(const Value *V) {
   if (const Argument *MA = dyn_cast<Argument>(V))
     return MA->getParent() ? MA->getParent()->getParent() : 0;
@@ -166,7 +186,6 @@ static const Module *getModuleFromVal(const Value *V) {
 }
 
 static SlotMachine *createSlotMachine(const Value *V) {
-  assert(!isa<Type>(V) && "Can't create an SC for a type!");
   if (const Argument *FA = dyn_cast<Argument>(V)) {
     return new SlotMachine(FA->getParent());
   } else if (const Instruction *I = dyn_cast<Instruction>(V)) {
@@ -304,6 +323,13 @@ static void calcTypeName(const Type *Ty,
     Result += "]";
     break;
   }
+  case Type::PackedTyID: {
+    const PackedType *PTy = cast<PackedType>(Ty);
+    Result += "<" + utostr(PTy->getNumElements()) + " x ";
+    calcTypeName(PTy->getElementType(), TypeStack, TypeNames, Result);
+    Result += ">";
+    break;
+  }
   case Type::OpaqueTyID:
     Result += "opaque";
     break;
@@ -363,6 +389,7 @@ std::ostream &llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty,
   }
 }
 
+/// @brief Internal constant writer. 
 static void WriteConstantInt(std::ostream &Out, const Constant *CV, 
                              bool PrintName,
                              std::map<const Type *, std::string> &TypeTable,
@@ -472,11 +499,27 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
     }
 
     Out << " }";
+  } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
+      const Type *ETy = CP->getType()->getElementType();
+      assert(CP->getNumOperands() > 0 && 
+             "Number of operands for a PackedConst must be > 0");
+      Out << '<';
+      Out << ' ';
+      printTypeInt(Out, ETy, TypeTable);
+      WriteAsOperandInternal(Out, CP->getOperand(0),
+                             PrintName, TypeTable, Machine);
+      for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
+          Out << ", ";
+          printTypeInt(Out, ETy, TypeTable);
+          WriteAsOperandInternal(Out, CP->getOperand(i), PrintName,
+                                 TypeTable, Machine);
+      }
+      Out << " >";
   } else if (isa<ConstantPointerNull>(CV)) {
     Out << "null";
 
-  } else if (const ConstantPointerRef *PR = dyn_cast<ConstantPointerRef>(CV)) {
-    WriteAsOperandInternal(Out, PR->getValue(), true, TypeTable, Machine);
+  } else if (isa<UndefValue>(CV)) {
+    Out << "undef";
 
   } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
     Out << CE->getOpcodeName() << " (";
@@ -509,21 +552,17 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
                                   std::map<const Type*, std::string> &TypeTable,
                                    SlotMachine *Machine) {
   Out << ' ';
-  if (PrintName && V->hasName()) {
+  if ((PrintName || isa<GlobalValue>(V)) && V->hasName())
     Out << getLLVMName(V->getName());
-  } else {
-    if (const Constant *CV = dyn_cast<Constant>(V)) {
+  else {
+    const Constant *CV = dyn_cast<Constant>(V);
+    if (CV && !isa<GlobalValue>(CV))
       WriteConstantInt(Out, CV, PrintName, TypeTable, Machine);
-    else {
+    else {
       int Slot;
       if (Machine) {
         Slot = Machine->getSlot(V);
       } else {
-        if (const Type *Ty = dyn_cast<Type>(V)) {
-          Out << Ty->getDescription();
-          return;
-        }
-
         Machine = createSlotMachine(V);
         if (Machine == 0) 
           Slot = Machine->getSlot(V);
@@ -539,7 +578,6 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
   }
 }
 
-
 /// WriteAsOperand - Write the name of the specified value out to the specified
 /// ostream.  This can be useful when you just want to print int %reg126, not
 /// the whole instruction that generated it.
@@ -556,13 +594,52 @@ std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Value *V,
   if (PrintType)
     printTypeInt(Out, V->getType(), TypeNames);
   
-  if (const Type *Ty = dyn_cast<Type> (V))
-    printTypeInt(Out, Ty, TypeNames);
-
   WriteAsOperandInternal(Out, V, PrintName, TypeNames, 0);
   return Out;
 }
 
+/// WriteAsOperandInternal - Write the name of the specified value out to 
+/// the specified ostream.  This can be useful when you just want to print 
+/// int %reg126, not the whole instruction that generated it.
+///
+static void WriteAsOperandInternal(std::ostream &Out, const Type *T, 
+                                   bool PrintName,
+                                  std::map<const Type*, std::string> &TypeTable,
+                                   SlotMachine *Machine) {
+  Out << ' ';
+  int Slot;
+  if (Machine) {
+    Slot = Machine->getSlot(T);
+    if (Slot != -1)
+      Out << '%' << Slot;
+    else
+      Out << "<badref>";
+  } else {
+    Out << T->getDescription();
+  }
+}
+
+/// WriteAsOperand - Write the name of the specified value out to the specified
+/// ostream.  This can be useful when you just want to print int %reg126, not
+/// the whole instruction that generated it.
+///
+std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Type *Ty,
+                                   bool PrintType, bool PrintName, 
+                                   const Module *Context) {
+  std::map<const Type *, std::string> TypeNames;
+  assert(Context != 0 && "Can't write types as operand without module context");
+
+  fillTypeNameTable(Context, TypeNames);
+
+  // if (PrintType)
+    // printTypeInt(Out, V->getType(), TypeNames);
+  
+  printTypeInt(Out, Ty, TypeNames);
+
+  WriteAsOperandInternal(Out, Ty, PrintName, TypeNames, 0);
+  return Out;
+}
+
 namespace llvm {
 
 class AssemblyWriter {
@@ -594,7 +671,7 @@ public:
 
   const Module* getModule() { return TheModule; }
 
-private :
+private:
   void printModule(const Module *M);
   void printSymbolTable(const SymbolTable &ST);
   void printConstant(const Constant *CPV);
@@ -653,7 +730,11 @@ std::ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) {
   } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
     Out << '[' << ATy->getNumElements() << " x ";
     printType(ATy->getElementType()) << ']';
-  } else if (const OpaqueType *OTy = dyn_cast<OpaqueType>(Ty)) {
+  } else if (const PackedType *PTy = dyn_cast<PackedType>(Ty)) {
+    Out << '<' << PTy->getNumElements() << " x ";
+    printType(PTy->getElementType()) << '>';
+  }
+  else if (const OpaqueType *OTy = dyn_cast<OpaqueType>(Ty)) {
     Out << "opaque";
   } else {
     if (!Ty->isPrimitiveType())
@@ -666,6 +747,7 @@ std::ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) {
 
 void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, 
                                   bool PrintName) {
+  assert(Operand != 0 && "Illegal Operand");
   if (PrintType) { Out << ' '; printType(Operand->getType()); }
   WriteAsOperandInternal(Out, Operand, PrintName, TypeNames, &Machine);
 }
@@ -682,8 +764,24 @@ void AssemblyWriter::printModule(const Module *M) {
   case Module::Pointer64:    Out << "target pointersize = 64\n"; break;
   case Module::AnyPointerSize: break;
   }
+  if (!M->getTargetTriple().empty())
+    Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
   
-  // Loop over the symbol table, emitting all named constants...
+  // Loop over the dependent libraries and emit them.
+  Module::lib_iterator LI = M->lib_begin();
+  Module::lib_iterator LE = M->lib_end();
+  if (LI != LE) {
+    Out << "deplibs = [ ";
+    while (LI != LE) {
+      Out << '"' << *LI << '"';
+      ++LI;
+      if (LI != LE)
+        Out << ", ";
+    }
+    Out << " ]\n";
+  }
+
+  // Loop over the symbol table, emitting all named constants.
   printSymbolTable(M->getSymbolTable());
   
   for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
@@ -691,7 +789,7 @@ void AssemblyWriter::printModule(const Module *M) {
 
   Out << "\nimplementation   ; Functions:\n";
   
-  // Output all of the functions...
+  // Output all of the functions.
   for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
     printFunction(I);
 }
@@ -708,13 +806,19 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
     case GlobalValue::WeakLinkage:      Out << "weak "; break;
     case GlobalValue::AppendingLinkage: Out << "appending "; break;
     case GlobalValue::ExternalLinkage: break;
+    case GlobalValue::GhostLinkage:
+      std::cerr << "GhostLinkage not allowed in AsmWriter!\n";
+      abort();
     }
 
   Out << (GV->isConstant() ? "constant " : "global ");
   printType(GV->getType()->getElementType());
 
-  if (GV->hasInitializer())
-    writeOperand(GV->getInitializer(), false, false);
+  if (GV->hasInitializer()) {
+    Constant* C = cast<Constant>(GV->getInitializer());
+    assert(C &&  "GlobalVar initializer isn't constant?");
+    writeOperand(GV->getInitializer(), false, isa<GlobalValue>(C));
+  }
 
   printInfoComment(*GV);
   Out << "\n";
@@ -743,8 +847,9 @@ void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
     SymbolTable::value_const_iterator VE = ST.value_end(PI->first);
 
     for (; VI != VE; ++VI) {
-      const Value *V = VI->second;
-      if (const Constant *CPV = dyn_cast<Constant>(V)) {
+      const Value* V = VI->second;
+      const Constant *CPV = dyn_cast<Constant>(V) ;
+      if (CPV && !isa<GlobalValue>(V)) {
         printConstant(CPV);
       }
     }
@@ -785,6 +890,9 @@ void AssemblyWriter::printFunction(const Function *F) {
     case GlobalValue::WeakLinkage:      Out << "weak "; break;
     case GlobalValue::AppendingLinkage: Out << "appending "; break;
     case GlobalValue::ExternalLinkage: break;
+    case GlobalValue::GhostLinkage:
+      std::cerr << "GhostLinkage not allowed in AsmWriter!\n";
+      abort();
     }
 
   printType(F->getReturnType()) << ' ';
@@ -1111,12 +1219,6 @@ void Instruction::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
 void Constant::print(std::ostream &o) const {
   if (this == 0) { o << "<null> constant value\n"; return; }
 
-  // Handle CPR's special, because they have context information...
-  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(this)) {
-    CPR->getValue()->print(o);  // Print as a global value, with context info.
-    return;
-  }
-
   o << ' ' << getType()->getDescription() << ' ';
 
   std::map<const Type *, std::string> TypeTable;
@@ -1131,7 +1233,8 @@ void Type::print(std::ostream &o) const {
 }
 
 void Argument::print(std::ostream &o) const {
-  WriteAsOperand(o, this, true, true, getParent()->getParent());
+  WriteAsOperand(o, this, true, true,
+                 getParent() ? getParent()->getParent() : 0);
 }
 
 // Value::dump - allow easy printing of  Values from the debugger.
@@ -1161,30 +1264,29 @@ CachedWriter::~CachedWriter() {
   delete SC;
 }
 
-CachedWriter &CachedWriter::operator<<(const Value *V) {
+CachedWriter &CachedWriter::operator<<(const Value &V) {
   assert(AW && SC && "CachedWriter does not have a current module!");
-  if (const Instruction *I = dyn_cast<Instruction>(V))
+  if (const Instruction *I = dyn_cast<Instruction>(&V))
     AW->write(I);
-  else if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
+  else if (const BasicBlock *BB = dyn_cast<BasicBlock>(&V))
     AW->write(BB);
-  else if (const Function *F = dyn_cast<Function>(V))
+  else if (const Function *F = dyn_cast<Function>(&V))
     AW->write(F);
-  else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+  else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(&V))
     AW->write(GV);
-  else if (const Type *Ty = dyn_cast<Type>(V))
-    AW->write(Ty);
   else 
-    AW->writeOperand(V, true, true);
+    AW->writeOperand(&V, true, true);
   return *this;
 }
 
-CachedWriter& CachedWriter::operator<<(const Type *X) {
+CachedWriter& CachedWriter::operator<<(const Type &Ty) {
   if (SymbolicTypes) {
     const Module *M = AW->getModule();
-    if (M) WriteTypeSymbolic(Out, X, M);
-    return *this;
-  } else
-    return *this << (const Value*)X;
+    if (M) WriteTypeSymbolic(Out, &Ty, M);
+  } else {
+    AW->write(&Ty);
+  }
+  return *this;
 }
 
 //===----------------------------------------------------------------------===//
@@ -1202,8 +1304,11 @@ CachedWriter& CachedWriter::operator<<(const Type *X) {
 SlotMachine::SlotMachine(const Module *M) 
   : TheModule(M)    ///< Saved for lazy initialization.
   , TheFunction(0)
+  , FunctionProcessed(false)
   , mMap()
+  , mTypes()
   , fMap()
+  , fTypes()
 {
 }
 
@@ -1212,8 +1317,11 @@ SlotMachine::SlotMachine(const Module *M)
 SlotMachine::SlotMachine(const Function *F ) 
   : TheModule( F ? F->getParent() : 0 ) ///< Saved for lazy initialization
   , TheFunction(F) ///< Saved for lazy initialization
+  , FunctionProcessed(false)
   , mMap()
+  , mTypes()
   , fMap()
+  , fTypes()
 {
 }
 
@@ -1222,7 +1330,7 @@ inline void SlotMachine::initialize(void) {
     processModule(); 
     TheModule = 0; ///< Prevent re-processing next time we're called.
   }
-  if ( TheFunction ) { 
+  if ( TheFunction && ! FunctionProcessed) { 
     processFunction(); 
   }
 }
@@ -1266,6 +1374,8 @@ void SlotMachine::processFunction() {
     }
   }
 
+  FunctionProcessed = true;
+
   SC_DEBUG("end processFunction!\n");
 }
 
@@ -1276,7 +1386,9 @@ void SlotMachine::processFunction() {
 void SlotMachine::purgeFunction() {
   SC_DEBUG("begin purgeFunction!\n");
   fMap.clear(); // Simply discard the function level map
+  fTypes.clear();
   TheFunction = 0;
+  FunctionProcessed = false;
   SC_DEBUG("end purgeFunction!\n");
 }
 
@@ -1285,17 +1397,12 @@ void SlotMachine::purgeFunction() {
 /// Types are forbidden because Type does not inherit from Value (any more).
 int SlotMachine::getSlot(const Value *V) {
   assert( V && "Can't get slot for null Value" );
-  assert( !isa<Type>(V) && "Can't get slot for a type" );
   assert(!isa<Constant>(V) || isa<GlobalValue>(V) && 
     "Can't insert a non-GlobalValue Constant into SlotMachine"); 
 
   // Check for uninitialized state and do lazy initialization
   this->initialize();
 
-  // Do not number CPR's at all. They are an abomination
-  if ( const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(V) )
-    V = CPR->getValue() ;
-
   // Get the type of the value
   const Type* VTy = V->getType();
 
@@ -1346,12 +1453,51 @@ int SlotMachine::getSlot(const Value *V) {
   return MVI->second;
 }
 
+/// Get the slot number for a value. This function will assert if you
+/// ask for a Value that hasn't previously been inserted with createSlot.
+/// Types are forbidden because Type does not inherit from Value (any more).
+int SlotMachine::getSlot(const Type *Ty) {
+  assert( Ty && "Can't get slot for null Type" );
+
+  // Check for uninitialized state and do lazy initialization
+  this->initialize();
+
+  if ( TheFunction ) {
+    // Lookup the Type in the function map
+    TypeMap::const_iterator FTI = fTypes.map.find(Ty);
+    // If the Type doesn't exist in the function map
+    if ( FTI == fTypes.map.end() ) {
+      TypeMap::const_iterator MTI = mTypes.map.find(Ty);
+      // If we didn't find it, it wasn't inserted
+      if (MTI == mTypes.map.end()) 
+        return -1;
+      // We found it only at the module level
+      return MTI->second; 
+
+    // else the value exists in the function map
+    } else {
+      // Return the slot number as the module's contribution to
+      // the type plane plus the index in the function's contribution
+      // to the type plane.
+      return mTypes.next_slot + FTI->second;
+    }
+  }
+
+  // N.B. Can get here only if either !TheFunction
+
+  // Lookup the value in the module's map
+  TypeMap::const_iterator MTI = mTypes.map.find(Ty);
+  // Make sure we found it.
+  if (MTI == mTypes.map.end()) return -1;
+  // Return it.
+  return MTI->second;
+}
+
 // Create a new slot, or return the existing slot if it is already
 // inserted. Note that the logic here parallels getSlot but instead
 // of asserting when the Value* isn't found, it inserts the value.
 unsigned SlotMachine::createSlot(const Value *V) {
   assert( V && "Can't insert a null Value to SlotMachine");
-  assert( !isa<Type>(V) && "Can't insert a Type into SlotMachine"); 
   assert(!isa<Constant>(V) || isa<GlobalValue>(V) && 
     "Can't insert a non-GlobalValue Constant into SlotMachine"); 
 
@@ -1428,12 +1574,49 @@ unsigned SlotMachine::createSlot(const Value *V) {
   return insertValue(V);
 }
 
+// Create a new slot, or return the existing slot if it is already
+// inserted. Note that the logic here parallels getSlot but instead
+// of asserting when the Value* isn't found, it inserts the value.
+unsigned SlotMachine::createSlot(const Type *Ty) {
+  assert( Ty && "Can't insert a null Type to SlotMachine");
+
+  if ( TheFunction ) {
+    // Lookup the Type in the function map
+    TypeMap::const_iterator FTI = fTypes.map.find(Ty);
+    // If the type doesn't exist in the function map
+    if ( FTI == fTypes.map.end() ) {
+      // Look up the type in the module map
+      TypeMap::const_iterator MTI = mTypes.map.find(Ty);
+      // If we didn't find it, it wasn't inserted
+      if ( MTI == mTypes.map.end() )
+        return insertValue(Ty);
+      else
+        // We found it only at the module level
+        return MTI->second;
+
+    // else the value exists in the function map
+    } else {
+      // Return the slot number as the module's contribution to
+      // the type plane plus the index in the function's contribution
+      // to the type plane.
+      return mTypes.next_slot + FTI->second;
+    }
+  }
+
+  // N.B. Can only get here if !TheFunction
+
+  // Lookup the type in the module's map
+  TypeMap::const_iterator MTI = mTypes.map.find(Ty);
+  if ( MTI != mTypes.map.end() ) 
+    return MTI->second;
+
+  return insertValue(Ty);
+}
 
 // Low level insert function. Minimal checking is done. This
 // function is just for the convenience of createSlot (above).
 unsigned SlotMachine::insertValue(const Value *V ) {
   assert(V && "Can't insert a null Value into SlotMachine!");
-  assert(!isa<Type>(V) && "Can't insert a Type into SlotMachine!");
   assert(!isa<Constant>(V) || isa<GlobalValue>(V) && 
     "Can't insert a non-GlobalValue Constant into SlotMachine"); 
 
@@ -1450,22 +1633,38 @@ unsigned SlotMachine::insertValue(const Value *V ) {
   if ( TheFunction ) {
     TypedPlanes::iterator I = fMap.find( VTy );
     if ( I == fMap.end() ) 
-      I = fMap.insert(std::make_pair(VTy,Plane())).first;
+      I = fMap.insert(std::make_pair(VTy,ValuePlane())).first;
     DestSlot = I->second.map[V] = I->second.next_slot++;
   } else {
     TypedPlanes::iterator I = mMap.find( VTy );
     if ( I == mMap.end() )
-      I = mMap.insert(std::make_pair(VTy,Plane())).first;
+      I = mMap.insert(std::make_pair(VTy,ValuePlane())).first;
     DestSlot = I->second.map[V] = I->second.next_slot++;
   }
 
   SC_DEBUG("  Inserting value [" << VTy << "] = " << V << " slot=" << 
            DestSlot << " [");
   // G = Global, C = Constant, T = Type, F = Function, o = other
-  SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : (isa<Constant>(V) ? 'C' : 
-           (isa<Function>(V) ? 'F' : 'o'))));
+  SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : (isa<Function>(V) ? 'F' : 
+           (isa<Constant>(V) ? 'C' : 'o'))));
   SC_DEBUG("]\n");
   return DestSlot;
 }
 
+// Low level insert function. Minimal checking is done. This
+// function is just for the convenience of createSlot (above).
+unsigned SlotMachine::insertValue(const Type *Ty ) {
+  assert(Ty && "Can't insert a null Type into SlotMachine!");
+
+  unsigned DestSlot = 0;
+
+  if ( TheFunction ) {
+    DestSlot = fTypes.map[Ty] = fTypes.next_slot++;
+  } else {
+    DestSlot = fTypes.map[Ty] = fTypes.next_slot++;
+  }
+  SC_DEBUG("  Inserting type [" << DestSlot << "] = " << Ty << "\n");
+  return DestSlot;
+}
+
 // vim: sw=2