Index: include/llvm/TableGen/Record.h
===================================================================
--- include/llvm/TableGen/Record.h	(revision 173941)
+++ include/llvm/TableGen/Record.h	(working copy)
@@ -61,6 +61,7 @@
 class RecordVal;
 struct MultiClass;
 class RecordKeeper;
+class InitVisitor;
 
 //===----------------------------------------------------------------------===//
 //  Type Classes
@@ -102,7 +103,6 @@
   ListRecTy *getListTy();
 
 public:   // These methods should only be called from subclasses of Init
-  virtual Init *convertValue( UnsetInit *UI) { return 0; }
   virtual Init *convertValue(   BitInit *BI) { return 0; }
   virtual Init *convertValue(  BitsInit *BI) { return 0; }
   virtual Init *convertValue(   IntInit *II) { return 0; }
@@ -130,6 +130,8 @@
 
 public:
   virtual bool baseClassOf(const RecTy*) const;
+  
+  virtual void accept(InitVisitor*){};
 };
 
 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
@@ -150,7 +152,6 @@
 
   static BitRecTy *get() { return &Shared; }
 
-  virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
   virtual Init *convertValue(   BitInit *BI) { return (Init*)BI; }
   virtual Init *convertValue(  BitsInit *BI);
   virtual Init *convertValue(   IntInit *II);
@@ -172,6 +173,7 @@
     return RHS->baseClassOf(this);
   }
   virtual bool baseClassOf(const RecTy*) const;
+  virtual void accept(InitVisitor*);
 };
 
 
@@ -190,7 +192,6 @@
 
   unsigned getNumBits() const { return Size; }
 
-  virtual Init *convertValue( UnsetInit *UI);
   virtual Init *convertValue(   BitInit *UI);
   virtual Init *convertValue(  BitsInit *BI);
   virtual Init *convertValue(   IntInit *II);
@@ -212,6 +213,8 @@
     return RHS->baseClassOf(this);
   }
   virtual bool baseClassOf(const RecTy*) const;
+
+  virtual void accept(InitVisitor*);
 };
 
 
@@ -227,7 +230,6 @@
 
   static IntRecTy *get() { return &Shared; }
 
-  virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
   virtual Init *convertValue(   BitInit *BI);
   virtual Init *convertValue(  BitsInit *BI);
   virtual Init *convertValue(   IntInit *II) { return (Init*)II; }
@@ -250,6 +252,7 @@
   }
 
   virtual bool baseClassOf(const RecTy*) const;
+  virtual void accept(InitVisitor*);
 };
 
 /// StringRecTy - 'string' - Represent an string value
@@ -264,7 +267,6 @@
 
   static StringRecTy *get() { return &Shared; }
 
-  virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
   virtual Init *convertValue(   BitInit *BI) { return 0; }
   virtual Init *convertValue(  BitsInit *BI) { return 0; }
   virtual Init *convertValue(   IntInit *II) { return 0; }
@@ -286,6 +288,8 @@
   virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
   }
+  
+  virtual void accept(InitVisitor*);
 };
 
 // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
@@ -305,7 +309,6 @@
   static ListRecTy *get(RecTy *T) { return T->getListTy(); }
   RecTy *getElementType() const { return Ty; }
 
-  virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
   virtual Init *convertValue(   BitInit *BI) { return 0; }
   virtual Init *convertValue(  BitsInit *BI) { return 0; }
   virtual Init *convertValue(   IntInit *II) { return 0; }
@@ -328,6 +331,8 @@
   }
 
   virtual bool baseClassOf(const RecTy*) const;
+  
+  virtual void accept(InitVisitor*);
 };
 
 /// DagRecTy - 'dag' - Represent a dag fragment
@@ -342,7 +347,6 @@
 
   static DagRecTy *get() { return &Shared; }
 
-  virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
   virtual Init *convertValue(   BitInit *BI) { return 0; }
   virtual Init *convertValue(  BitsInit *BI) { return 0; }
   virtual Init *convertValue(   IntInit *II) { return 0; }
@@ -363,6 +367,8 @@
   virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
   }
+
+  virtual void accept(InitVisitor*);
 };
 
 
@@ -382,7 +388,6 @@
 
   Record *getRecord() const { return Rec; }
 
-  virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
   virtual Init *convertValue(   BitInit *BI) { return 0; }
   virtual Init *convertValue(  BitsInit *BI) { return 0; }
   virtual Init *convertValue(   IntInit *II) { return 0; }
@@ -404,6 +409,8 @@
     return RHS->baseClassOf(this);
   }
   virtual bool baseClassOf(const RecTy*) const;
+  
+  virtual void accept(InitVisitor*);
 };
 
 /// resolveTypes - Find a common type that T1 and T2 convert to.
@@ -605,9 +612,7 @@
   }
   static UnsetInit *get();
 
-  virtual Init *convertInitializerTo(RecTy *Ty) const {
-    return Ty->convertValue(const_cast<UnsetInit *>(this));
-  }
+  virtual Init *convertInitializerTo(RecTy *Ty) const;
 
   virtual Init *getBit(unsigned Bit) const {
     return const_cast<UnsetInit*>(this);
Index: lib/TableGen/Record.cpp
===================================================================
--- lib/TableGen/Record.cpp	(revision 173941)
+++ lib/TableGen/Record.cpp	(working copy)
@@ -23,6 +23,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
 #include "llvm/TableGen/Error.h"
+#include "InitVisitor.h"
 
 using namespace llvm;
 
@@ -127,6 +128,10 @@
   return false;
 }
 
+void BitRecTy::accept(InitVisitor* V){
+  V->toBit();
+}
+
 BitsRecTy *BitsRecTy::get(unsigned Sz) {
   static std::vector<BitsRecTy*> Shared;
   if (Sz >= Shared.size())
@@ -141,15 +146,6 @@
   return "bits<" + utostr(Size) + ">";
 }
 
-Init *BitsRecTy::convertValue(UnsetInit *UI) {
-  SmallVector<Init *, 16> NewBits(Size);
-
-  for (unsigned i = 0; i != Size; ++i)
-    NewBits[i] = UnsetInit::get();
-
-  return BitsInit::get(NewBits);
-}
-
 Init *BitsRecTy::convertValue(BitInit *UI) {
   if (Size != 1) return 0;  // Can only convert single bit.
           return BitsInit::get(UI);
@@ -209,6 +205,11 @@
   return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
 }
 
+void BitsRecTy::accept(InitVisitor *V){
+  V->toBits(Size);
+}
+
+
 Init *IntRecTy::convertValue(BitInit *BI) {
   return IntInit::get(BI->getValue());
 }
@@ -235,6 +236,10 @@
   return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
 }
 
+void IntRecTy::accept(InitVisitor *V){
+  V->toInt();
+}
+
 Init *StringRecTy::convertValue(UnOpInit *BO) {
   if (BO->getOpcode() == UnOpInit::CAST) {
     Init *L = BO->getOperand()->convertInitializerTo(this);
@@ -267,6 +272,10 @@
   return 0;
 }
 
+void StringRecTy::accept(InitVisitor *V){
+  V->toString();
+}
+
 std::string ListRecTy::getAsString() const {
   return "list<" + Ty->getAsString() + ">";
 }
@@ -288,6 +297,10 @@
   return ListInit::get(Elements, this);
 }
 
+void ListRecTy::accept(InitVisitor *V){
+  V->toList();
+}
+
 Init *ListRecTy::convertValue(TypedInit *TI) {
   // Ensure that TI is compatible with our class.
   if (ListRecTy *LRT = dyn_cast<ListRecTy>(TI->getType()))
@@ -331,6 +344,10 @@
   return 0;
 }
 
+void DagRecTy::accept(InitVisitor *V){
+  V->toDag();
+}
+
 RecordRecTy *RecordRecTy::get(Record *R) {
   return dyn_cast<RecordRecTy>(R->getDefInit()->getType());
 }
@@ -371,6 +388,10 @@
   return false;
 }
 
+void RecordRecTy::accept(InitVisitor *V){
+  V->toRecord();
+}
+
 /// resolveTypes - Find a common type that T1 and T2 convert to.
 /// Return 0 if no such type exists.
 ///
@@ -435,6 +456,12 @@
   return &TheInit;
 }
 
+Init *UnsetInit::convertInitializerTo(RecTy *Ty) const{
+  UnsetInitVisitor V(this);
+  Ty->accept(&V);
+  return V.getValue();
+}
+
 void BitInit::anchor() { }
 
 BitInit *BitInit::get(bool V) {
@@ -1622,13 +1649,13 @@
 
 RecordVal::RecordVal(Init *N, RecTy *T, unsigned P)
   : Name(N), Ty(T), Prefix(P) {
-  Value = Ty->convertValue(UnsetInit::get());
+  Value = UnsetInit::get()->convertInitializerTo(Ty);
   assert(Value && "Cannot create unset value for current type!");
 }
 
 RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P)
   : Name(StringInit::get(N)), Ty(T), Prefix(P) {
-  Value = Ty->convertValue(UnsetInit::get());
+  Value = UnsetInit::get()->convertInitializerTo(Ty);
   assert(Value && "Cannot create unset value for current type!");
 }
 
Index: lib/TableGen/InitVisitor.cpp
===================================================================
--- lib/TableGen/InitVisitor.cpp	(revision 0)
+++ lib/TableGen/InitVisitor.cpp	(revision 0)
@@ -0,0 +1,71 @@
+//===- InitVisitor.cpp - classes for Initializer conversions ---*- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "InitVisitor.h"
+
+namespace llvm{
+  
+void InitVisitor::srcToDst(){
+  Dst = const_cast<Init*>(Src);
+}
+
+InitVisitor::InitVisitor(const Init *I): Src(I), Dst(NULL){
+}
+
+const Init* InitVisitor::getValue()const{
+  return Dst;
+}
+
+Init* InitVisitor::getValue(){
+  return Dst;
+}
+
+void InitVisitor::toBit(){
+  srcToDst();
+}
+
+void InitVisitor::toBits(unsigned Size){
+  srcToDst();
+}
+
+void InitVisitor::toInt(){
+  srcToDst();
+}
+
+void InitVisitor::toString(){
+  srcToDst();
+}
+
+void InitVisitor::toList(){
+  srcToDst();
+}
+
+void InitVisitor::toDag(){
+  srcToDst();
+}
+
+void InitVisitor::toRecord(){
+  srcToDst();
+}
+
+//
+//UnsetInitVisitor
+//
+
+UnsetInitVisitor::UnsetInitVisitor(const Init *I): InitVisitor(I){
+}
+
+void UnsetInitVisitor::toBits(unsigned Size){
+  SmallVector<Init *, 16> NewBits(Size);
+  for (unsigned i = 0; i<Size; ++i)
+    NewBits[i] = UnsetInit::get();
+  Dst = BitsInit::get(NewBits);
+}
+
+}
Index: lib/TableGen/InitVisitor.h
===================================================================
--- lib/TableGen/InitVisitor.h	(revision 0)
+++ lib/TableGen/InitVisitor.h	(revision 0)
@@ -0,0 +1,52 @@
+//===- InitVisitor.h - classes for Initializer conversions ------- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __INIT_VISITOR_H__
+#define __INIT_VISITOR_H__
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm{
+
+//
+//InitVisitor
+//
+class InitVisitor{
+private:
+  void srcToDst();
+
+protected:
+  const Init* Src;
+  Init* Dst;
+
+public:
+  InitVisitor(const Init *Src);
+  
+  const Init* getValue()const;
+  Init* getValue();
+  
+  virtual void toBit();
+  virtual void toBits(unsigned Size);
+  virtual void toInt();
+  virtual void toString();
+  virtual void toList();
+  virtual void toDag();
+  virtual void toRecord();
+};
+
+class UnsetInitVisitor: public InitVisitor{
+public:
+  UnsetInitVisitor(const Init*);
+
+  virtual void toBits(unsigned Size);
+};
+
+}
+
+#endif
Index: lib/TableGen/CMakeLists.txt
===================================================================
--- lib/TableGen/CMakeLists.txt	(revision 173941)
+++ lib/TableGen/CMakeLists.txt	(working copy)
@@ -6,4 +6,5 @@
   TableGenBackend.cpp
   TGLexer.cpp
   TGParser.cpp
+  InitVisitor.cpp
   )
