Put all LLVM code into the llvm namespace, as per bug 109.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9903 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 1ae8c1c..212a460 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -16,6 +16,7 @@
 dnl * Initialize
 dnl **************************************************************************
 AC_INIT([[[LLVM]]],[[[1.0]]],[llvmbugs@cs.uiuc.edu])
+dnl AC_CONFIG_SRC_DIR(lib/VMCore/Pass.cpp)
 
 dnl Place all of the extra autoconf files into the config subdirectory
 AC_CONFIG_AUX_DIR([autoconf])
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index 1d06c2d..a1b6844 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -12,6 +12,8 @@
 #include "llvm/Instructions.h"
 #include "llvm/Bytecode/Writer.h"
 
+using namespace llvm;
+
 int main() {
   // Create the "module" or "program" or "translation unit" to hold the
   // function
diff --git a/examples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
index 1d06c2d..a1b6844 100644
--- a/examples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
@@ -12,6 +12,8 @@
 #include "llvm/Instructions.h"
 #include "llvm/Bytecode/Writer.h"
 
+using namespace llvm;
+
 int main() {
   // Create the "module" or "program" or "translation unit" to hold the
   // function
diff --git a/include/Support/Annotation.h b/include/Support/Annotation.h
index 075ffc2..cee7ab7 100644
--- a/include/Support/Annotation.h
+++ b/include/Support/Annotation.h
@@ -25,6 +25,8 @@
 #include <string>
 #include <cassert>
 
+namespace llvm {
+
 class AnnotationID;
 class Annotation;
 class Annotable;
@@ -217,4 +219,6 @@
   return A;
 }
 
+} // End namespace llvm
+
 #endif
diff --git a/include/Support/BitSetVector.h b/include/Support/BitSetVector.h
index 08bafa1..72f55b3 100644
--- a/include/Support/BitSetVector.h
+++ b/include/Support/BitSetVector.h
@@ -30,6 +30,8 @@
 #include <functional>
 #include <iostream>
 
+namespace llvm {
+
 class BitSetVector {
   enum { BITSET_WORDSIZE = sizeof(long)*8 };
 
@@ -266,4 +268,5 @@
   return true;
 }
 
+} // End llvm namespace
 #endif
diff --git a/include/Support/Casting.h b/include/Support/Casting.h
index 065919c..4b070c1 100644
--- a/include/Support/Casting.h
+++ b/include/Support/Casting.h
@@ -15,6 +15,8 @@
 #ifndef SUPPORT_CASTING_H
 #define SUPPORT_CASTING_H
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                          isa<x> Support Templates
 //===----------------------------------------------------------------------===//
@@ -293,4 +295,6 @@
 
 #endif
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/CommandLine.h b/include/Support/CommandLine.h
index 01f55a8..df40d80 100644
--- a/include/Support/CommandLine.h
+++ b/include/Support/CommandLine.h
@@ -27,6 +27,7 @@
 #include <cassert>
 #include "boost/type_traits/object_traits.hpp"
 
+namespace llvm {
 /// cl Namespace - This namespace contains all of the command line option
 /// processing machinery.  It is intentionally a short name to make qualified
 /// usage concise.
@@ -1022,4 +1023,6 @@
 
 } // End namespace cl
 
+} // End namespace llvm
+
 #endif
diff --git a/include/Support/DOTGraphTraits.h b/include/Support/DOTGraphTraits.h
index 002a78e..63837b7 100644
--- a/include/Support/DOTGraphTraits.h
+++ b/include/Support/DOTGraphTraits.h
@@ -19,6 +19,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// DefaultDOTGraphTraits - This class provides the default implementations of
 /// all of the DOTGraphTraits methods.  If a specialization does not need to
 /// override all methods here it should inherit so that it can get the default
@@ -96,4 +98,6 @@
 template <typename Ty>
 class DOTGraphTraits : public DefaultDOTGraphTraits {};
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/Debug.h b/include/Support/Debug.h
index 8cba057..66a2088 100644
--- a/include/Support/Debug.h
+++ b/include/Support/Debug.h
@@ -26,6 +26,8 @@
 #ifndef SUPPORT_DEBUG_H
 #define SUPPORT_DEBUG_H
 
+namespace llvm {
+
 // DebugFlag - This boolean is set to true if the '-debug' command line option
 // is specified.  This should probably not be referenced directly, instead, use
 // the DEBUG macro below.
@@ -57,4 +59,6 @@
   do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
 #endif
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/DepthFirstIterator.h b/include/Support/DepthFirstIterator.h
index bb7673c..c465f4e 100644
--- a/include/Support/DepthFirstIterator.h
+++ b/include/Support/DepthFirstIterator.h
@@ -38,6 +38,8 @@
 #include <vector>
 #include <set>
 
+namespace llvm {
+
 // df_iterator_storage - A private class which is used to figure out where to
 // store the visited set.
 template<class SetType, bool External>   // Non-external set
@@ -223,5 +225,6 @@
   return idf_ext_iterator<T, SetTy>::end(G, S);
 }
 
+} // End llvm namespace
 
 #endif
diff --git a/include/Support/DynamicLinker.h b/include/Support/DynamicLinker.h
index 8f02708..fec9a45 100644
--- a/include/Support/DynamicLinker.h
+++ b/include/Support/DynamicLinker.h
@@ -18,6 +18,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// LinkDynamicObject - Load the named file as a dynamic library
 /// and link it with the currently running process. Returns false
 /// on success, true if there is an error (and sets ErrorMessage
@@ -33,4 +35,6 @@
 void *GetAddressOfSymbol (const char *symbolName);
 void *GetAddressOfSymbol (const std::string &symbolName);
 
+} // End llvm namespace
+
 #endif // SUPPORT_DYNAMICLINKER_H
diff --git a/include/Support/EquivalenceClasses.h b/include/Support/EquivalenceClasses.h
index 01e8c5e..46e626b 100644
--- a/include/Support/EquivalenceClasses.h
+++ b/include/Support/EquivalenceClasses.h
@@ -20,6 +20,8 @@
 #include <map>
 #include <vector>
 
+namespace llvm {
+
 template <class ElemTy>
 class EquivalenceClasses {
   // Maps each element to the element that is the leader of its 
@@ -89,4 +91,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/FileUtilities.h b/include/Support/FileUtilities.h
index 0dfa625..c276ec7 100644
--- a/include/Support/FileUtilities.h
+++ b/include/Support/FileUtilities.h
@@ -17,6 +17,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// CheckMagic - Returns true IFF the file named FN begins with Magic. FN must
 /// name a readable file.
 ///
@@ -95,4 +97,6 @@
 ///
 bool MakeFileReadable (const std::string & Filename);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/GraphTraits.h b/include/Support/GraphTraits.h
index 305f71e..4ff7417 100644
--- a/include/Support/GraphTraits.h
+++ b/include/Support/GraphTraits.h
@@ -18,6 +18,8 @@
 #ifndef SUPPORT_GRAPHTRAITS_H
 #define SUPPORT_GRAPHTRAITS_H
 
+namespace llvm {
+
 // GraphTraits - This class should be specialized by different graph types...
 // which is why the default version is empty.
 //
@@ -76,4 +78,6 @@
   inline Inverse(GraphType &G) : Graph(G) {}
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/GraphWriter.h b/include/Support/GraphWriter.h
index 2cb8fcc..7e5aa80 100644
--- a/include/Support/GraphWriter.h
+++ b/include/Support/GraphWriter.h
@@ -28,6 +28,8 @@
 #include <vector>
 #include <iostream>
 
+namespace llvm {
+
 namespace DOT {  // Private functions...
   inline std::string EscapeString(const std::string &Label) {
     std::string Str(Label);
@@ -206,4 +208,6 @@
   return O;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/LeakDetector.h b/include/Support/LeakDetector.h
index b39e0b5..e2ce9c5 100644
--- a/include/Support/LeakDetector.h
+++ b/include/Support/LeakDetector.h
@@ -23,6 +23,9 @@
 #define SUPPORT_LEAKDETECTOR_H
 
 #include <string>
+
+namespace llvm {
+
 class Value;
 
 struct LeakDetector {
@@ -83,4 +86,6 @@
   static void checkForGarbageImpl(const std::string &Message);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/MallocAllocator.h b/include/Support/MallocAllocator.h
index 1ba25b0..766a67f 100644
--- a/include/Support/MallocAllocator.h
+++ b/include/Support/MallocAllocator.h
@@ -23,6 +23,8 @@
 #include <cstdlib>
 #include <memory>
 
+namespace llvm {
+
 template<typename T>
 struct MallocAllocator {
   typedef size_t size_type;
@@ -79,5 +81,6 @@
   };
 }
 
+} // End llvm namespace
 
 #endif
diff --git a/include/Support/MathExtras.h b/include/Support/MathExtras.h
index ec74232..74958fb 100644
--- a/include/Support/MathExtras.h
+++ b/include/Support/MathExtras.h
@@ -16,6 +16,8 @@
 
 #include "Support/DataTypes.h"
 
+namespace llvm {
+
 inline unsigned log2(uint64_t C) {
   unsigned getPow;
   for (getPow = 0; C > 1; ++getPow)
@@ -33,4 +35,6 @@
   return false;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/PostOrderIterator.h b/include/Support/PostOrderIterator.h
index 9309554..d66c4b8 100644
--- a/include/Support/PostOrderIterator.h
+++ b/include/Support/PostOrderIterator.h
@@ -21,6 +21,8 @@
 #include <stack>
 #include <set>
 
+namespace llvm {
+
 template<class GraphT, class GT = GraphTraits<GraphT> >
 class po_iterator : public forward_iterator<typename GT::NodeType, ptrdiff_t> {
   typedef forward_iterator<typename GT::NodeType, ptrdiff_t> super;
@@ -149,4 +151,6 @@
   inline rpo_iterator end()   { return Blocks.rend(); }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/SCCIterator.h b/include/Support/SCCIterator.h
index cf137cd..f21c7d1 100644
--- a/include/Support/SCCIterator.h
+++ b/include/Support/SCCIterator.h
@@ -26,6 +26,8 @@
 #include <vector>
 #include <map>
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 ///
 /// scc_iterator - Enumerate the SCCs of a directed graph, in
@@ -197,4 +199,6 @@
   return scc_iterator<T>::end(G);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/STLExtras.h b/include/Support/STLExtras.h
index 28c46e3..06a1573 100644
--- a/include/Support/STLExtras.h
+++ b/include/Support/STLExtras.h
@@ -21,6 +21,8 @@
 #include "Support/iterator"
 #include "boost/type_traits/transform_traits.hpp"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //     Extra additions to <functional>
 //===----------------------------------------------------------------------===//
@@ -278,4 +280,6 @@
   return tier<T1, T2>(f, s);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/SetOperations.h b/include/Support/SetOperations.h
index dc6e0d6..bb1e68e 100644
--- a/include/Support/SetOperations.h
+++ b/include/Support/SetOperations.h
@@ -15,6 +15,8 @@
 #ifndef SUPPORT_SETOPERATIONS_H
 #define SUPPORT_SETOPERATIONS_H
 
+namespace llvm {
+
 // set_union(A, B) - Compute A := A u B, return whether A changed.
 //
 template <class S1Ty, class S2Ty>
@@ -64,4 +66,6 @@
     S1.erase(*SI);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/Signals.h b/include/Support/Signals.h
index ce12301..0cbf398 100644
--- a/include/Support/Signals.h
+++ b/include/Support/Signals.h
@@ -17,10 +17,13 @@
 
 #include <string>
 
+namespace llvm {
+
 // RemoveFileOnSignal - This function registers signal handlers to ensure that
 // if a signal gets delivered that the named file is removed.
 //
 void RemoveFileOnSignal(const std::string &Filename);
 
-#endif
+} // End llvm namespace
 
+#endif
diff --git a/include/Support/Statistic.h b/include/Support/Statistic.h
index d69809f..4e592d5 100644
--- a/include/Support/Statistic.h
+++ b/include/Support/Statistic.h
@@ -26,6 +26,8 @@
 
 #include <iosfwd>
 
+namespace llvm {
+
 // StatisticBase - Nontemplated base class for Statistic<> class...
 class StatisticBase {
   const char *Name;
@@ -78,4 +80,6 @@
   const Statistic &operator-=(const DataType &V) { Value -= V; return *this; }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/StringExtras.h b/include/Support/StringExtras.h
index 2c50c1c..2ebac81 100644
--- a/include/Support/StringExtras.h
+++ b/include/Support/StringExtras.h
@@ -18,6 +18,8 @@
 #include <string>
 #include <stdio.h>
 
+namespace llvm {
+
 static inline std::string utohexstr(uint64_t X) {
   char Buffer[40];
   char *BufPtr = Buffer+39;
@@ -95,4 +97,6 @@
   return Buffer;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/SystemUtils.h b/include/Support/SystemUtils.h
index ccde86c..c874d99 100644
--- a/include/Support/SystemUtils.h
+++ b/include/Support/SystemUtils.h
@@ -17,6 +17,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// isExecutableFile - This function returns true if the filename specified
 /// exists and is executable.
 ///
@@ -45,4 +47,7 @@
 /// wait for it to terminate.
 ///
 int ExecWait (const char * const argv[], const char * const envp[]);
+
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/Timer.h b/include/Support/Timer.h
index 57ef3f0..ac465bb 100644
--- a/include/Support/Timer.h
+++ b/include/Support/Timer.h
@@ -20,6 +20,8 @@
 #include <iosfwd>
 #include <cassert>
 
+namespace llvm {
+
 class TimerGroup;
 
 /// Timer - This class is used to track the amount of time spent between
@@ -157,4 +159,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/Tree.h b/include/Support/Tree.h
index e645431..bc5495f 100644
--- a/include/Support/Tree.h
+++ b/include/Support/Tree.h
@@ -17,6 +17,8 @@
 
 #include <vector>
 
+namespace llvm {
+
 template<class ConcreteTreeNode, class Payload>
 class Tree {
   std::vector<ConcreteTreeNode*> Children;        // This nodes children, if any
@@ -55,5 +57,6 @@
   inline const Payload &getTreeData() const { return Data; }
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/include/Support/TypeInfo.h b/include/Support/TypeInfo.h
index aa2093a..5d90350 100644
--- a/include/Support/TypeInfo.h
+++ b/include/Support/TypeInfo.h
@@ -18,6 +18,8 @@
 
 #include <typeinfo>
 
+namespace llvm {
+
 struct TypeInfo {
   TypeInfo() {                     // needed for containers
     struct Nil {};  // Anonymous class distinct from all others...
@@ -69,4 +71,6 @@
   return !(lhs < rhs);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/VectorExtras.h b/include/Support/VectorExtras.h
index 3277830..cf7cf5d 100644
--- a/include/Support/VectorExtras.h
+++ b/include/Support/VectorExtras.h
@@ -17,6 +17,8 @@
 
 #include <cstdarg>
 
+namespace llvm {
+
 /// make_vector - Helper function which is useful for building temporary vectors
 /// to pass into type construction of CallInst ctors.  This turns a null
 /// terminated list of pointers (or other value types) into a real live vector.
@@ -33,4 +35,6 @@
   return Result;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/Support/ilist b/include/Support/ilist
index 488a90f..7f4d265 100644
--- a/include/Support/ilist
+++ b/include/Support/ilist
@@ -41,6 +41,8 @@
 #include <Support/iterator>
 #include <cassert>
 
+namespace llvm {
+
 template<typename NodeTy, typename Traits> class iplist;
 template<typename NodeTy> class ilist_iterator;
 
@@ -522,10 +524,12 @@
   void resize(size_type newsize) { resize(newsize, NodeTy()); }
 };
 
+} // End llvm namespace
+
 namespace std {
   // Ensure that swap uses the fast list swap...
   template<class Ty>
-  void swap(iplist<Ty> &Left, iplist<Ty> &Right) {
+  void swap(llvm::iplist<Ty> &Left, llvm::iplist<Ty> &Right) {
     Left.swap(Right);
   }
 }  // End 'std' extensions...
diff --git a/include/llvm/ADT/BitSetVector.h b/include/llvm/ADT/BitSetVector.h
index 08bafa1..72f55b3 100644
--- a/include/llvm/ADT/BitSetVector.h
+++ b/include/llvm/ADT/BitSetVector.h
@@ -30,6 +30,8 @@
 #include <functional>
 #include <iostream>
 
+namespace llvm {
+
 class BitSetVector {
   enum { BITSET_WORDSIZE = sizeof(long)*8 };
 
@@ -266,4 +268,5 @@
   return true;
 }
 
+} // End llvm namespace
 #endif
diff --git a/include/llvm/ADT/DepthFirstIterator.h b/include/llvm/ADT/DepthFirstIterator.h
index bb7673c..c465f4e 100644
--- a/include/llvm/ADT/DepthFirstIterator.h
+++ b/include/llvm/ADT/DepthFirstIterator.h
@@ -38,6 +38,8 @@
 #include <vector>
 #include <set>
 
+namespace llvm {
+
 // df_iterator_storage - A private class which is used to figure out where to
 // store the visited set.
 template<class SetType, bool External>   // Non-external set
@@ -223,5 +225,6 @@
   return idf_ext_iterator<T, SetTy>::end(G, S);
 }
 
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/ADT/EquivalenceClasses.h b/include/llvm/ADT/EquivalenceClasses.h
index 01e8c5e..46e626b 100644
--- a/include/llvm/ADT/EquivalenceClasses.h
+++ b/include/llvm/ADT/EquivalenceClasses.h
@@ -20,6 +20,8 @@
 #include <map>
 #include <vector>
 
+namespace llvm {
+
 template <class ElemTy>
 class EquivalenceClasses {
   // Maps each element to the element that is the leader of its 
@@ -89,4 +91,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/GraphTraits.h b/include/llvm/ADT/GraphTraits.h
index 305f71e..4ff7417 100644
--- a/include/llvm/ADT/GraphTraits.h
+++ b/include/llvm/ADT/GraphTraits.h
@@ -18,6 +18,8 @@
 #ifndef SUPPORT_GRAPHTRAITS_H
 #define SUPPORT_GRAPHTRAITS_H
 
+namespace llvm {
+
 // GraphTraits - This class should be specialized by different graph types...
 // which is why the default version is empty.
 //
@@ -76,4 +78,6 @@
   inline Inverse(GraphType &G) : Graph(G) {}
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/PostOrderIterator.h b/include/llvm/ADT/PostOrderIterator.h
index 9309554..d66c4b8 100644
--- a/include/llvm/ADT/PostOrderIterator.h
+++ b/include/llvm/ADT/PostOrderIterator.h
@@ -21,6 +21,8 @@
 #include <stack>
 #include <set>
 
+namespace llvm {
+
 template<class GraphT, class GT = GraphTraits<GraphT> >
 class po_iterator : public forward_iterator<typename GT::NodeType, ptrdiff_t> {
   typedef forward_iterator<typename GT::NodeType, ptrdiff_t> super;
@@ -149,4 +151,6 @@
   inline rpo_iterator end()   { return Blocks.rend(); }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/SCCIterator.h b/include/llvm/ADT/SCCIterator.h
index cf137cd..f21c7d1 100644
--- a/include/llvm/ADT/SCCIterator.h
+++ b/include/llvm/ADT/SCCIterator.h
@@ -26,6 +26,8 @@
 #include <vector>
 #include <map>
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 ///
 /// scc_iterator - Enumerate the SCCs of a directed graph, in
@@ -197,4 +199,6 @@
   return scc_iterator<T>::end(G);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h
index 28c46e3..06a1573 100644
--- a/include/llvm/ADT/STLExtras.h
+++ b/include/llvm/ADT/STLExtras.h
@@ -21,6 +21,8 @@
 #include "Support/iterator"
 #include "boost/type_traits/transform_traits.hpp"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //     Extra additions to <functional>
 //===----------------------------------------------------------------------===//
@@ -278,4 +280,6 @@
   return tier<T1, T2>(f, s);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/SetOperations.h b/include/llvm/ADT/SetOperations.h
index dc6e0d6..bb1e68e 100644
--- a/include/llvm/ADT/SetOperations.h
+++ b/include/llvm/ADT/SetOperations.h
@@ -15,6 +15,8 @@
 #ifndef SUPPORT_SETOPERATIONS_H
 #define SUPPORT_SETOPERATIONS_H
 
+namespace llvm {
+
 // set_union(A, B) - Compute A := A u B, return whether A changed.
 //
 template <class S1Ty, class S2Ty>
@@ -64,4 +66,6 @@
     S1.erase(*SI);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/Statistic.h b/include/llvm/ADT/Statistic.h
index d69809f..4e592d5 100644
--- a/include/llvm/ADT/Statistic.h
+++ b/include/llvm/ADT/Statistic.h
@@ -26,6 +26,8 @@
 
 #include <iosfwd>
 
+namespace llvm {
+
 // StatisticBase - Nontemplated base class for Statistic<> class...
 class StatisticBase {
   const char *Name;
@@ -78,4 +80,6 @@
   const Statistic &operator-=(const DataType &V) { Value -= V; return *this; }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index 2c50c1c..2ebac81 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -18,6 +18,8 @@
 #include <string>
 #include <stdio.h>
 
+namespace llvm {
+
 static inline std::string utohexstr(uint64_t X) {
   char Buffer[40];
   char *BufPtr = Buffer+39;
@@ -95,4 +97,6 @@
   return Buffer;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/Tree.h b/include/llvm/ADT/Tree.h
index e645431..bc5495f 100644
--- a/include/llvm/ADT/Tree.h
+++ b/include/llvm/ADT/Tree.h
@@ -17,6 +17,8 @@
 
 #include <vector>
 
+namespace llvm {
+
 template<class ConcreteTreeNode, class Payload>
 class Tree {
   std::vector<ConcreteTreeNode*> Children;        // This nodes children, if any
@@ -55,5 +57,6 @@
   inline const Payload &getTreeData() const { return Data; }
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/ADT/VectorExtras.h b/include/llvm/ADT/VectorExtras.h
index 3277830..cf7cf5d 100644
--- a/include/llvm/ADT/VectorExtras.h
+++ b/include/llvm/ADT/VectorExtras.h
@@ -17,6 +17,8 @@
 
 #include <cstdarg>
 
+namespace llvm {
+
 /// make_vector - Helper function which is useful for building temporary vectors
 /// to pass into type construction of CallInst ctors.  This turns a null
 /// terminated list of pointers (or other value types) into a real live vector.
@@ -33,4 +35,6 @@
   return Result;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ADT/ilist b/include/llvm/ADT/ilist
index 488a90f..7f4d265 100644
--- a/include/llvm/ADT/ilist
+++ b/include/llvm/ADT/ilist
@@ -41,6 +41,8 @@
 #include <Support/iterator>
 #include <cassert>
 
+namespace llvm {
+
 template<typename NodeTy, typename Traits> class iplist;
 template<typename NodeTy> class ilist_iterator;
 
@@ -522,10 +524,12 @@
   void resize(size_type newsize) { resize(newsize, NodeTy()); }
 };
 
+} // End llvm namespace
+
 namespace std {
   // Ensure that swap uses the fast list swap...
   template<class Ty>
-  void swap(iplist<Ty> &Left, iplist<Ty> &Right) {
+  void swap(llvm::iplist<Ty> &Left, llvm::iplist<Ty> &Right) {
     Left.swap(Right);
   }
 }  // End 'std' extensions...
diff --git a/include/llvm/AbstractTypeUser.h b/include/llvm/AbstractTypeUser.h
index 9e3eddd..8a18f58 100644
--- a/include/llvm/AbstractTypeUser.h
+++ b/include/llvm/AbstractTypeUser.h
@@ -37,6 +37,8 @@
 //
 #include <cassert>
 
+namespace llvm {
+
 class Type;
 class DerivedType;
 
@@ -165,4 +167,6 @@
   void dropRef();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/AliasAnalysis.h b/include/llvm/Analysis/AliasAnalysis.h
index 4ce3f4b..dc484f5 100644
--- a/include/llvm/Analysis/AliasAnalysis.h
+++ b/include/llvm/Analysis/AliasAnalysis.h
@@ -31,6 +31,9 @@
 #define LLVM_ANALYSIS_ALIAS_ANALYSIS_H
 
 #include "llvm/Support/CallSite.h"
+
+namespace llvm {
+
 class LoadInst;
 class StoreInst;
 class TargetData;
@@ -156,4 +159,6 @@
                                  const Value *Ptr, unsigned Size);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/AliasSetTracker.h b/include/llvm/Analysis/AliasSetTracker.h
index 72168b4..fe57c28 100644
--- a/include/llvm/Analysis/AliasSetTracker.h
+++ b/include/llvm/Analysis/AliasSetTracker.h
@@ -21,6 +21,9 @@
 #include "Support/iterator"
 #include "Support/hash_map"
 #include "Support/ilist"
+
+namespace llvm {
+
 class AliasAnalysis;
 class LoadInst;
 class StoreInst;
@@ -283,4 +286,6 @@
   return OS;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h
index 3a51b05..60649f9 100644
--- a/include/llvm/Analysis/CallGraph.h
+++ b/include/llvm/Analysis/CallGraph.h
@@ -51,6 +51,9 @@
 #include "Support/GraphTraits.h"
 #include "Support/STLExtras.h"
 #include "llvm/Pass.h"
+
+namespace llvm {
+
 class Function;
 class Module;
 class CallGraphNode;
@@ -288,4 +291,6 @@
 static IncludeFile
 CALLGRAPH_INCLUDE_FILE((void*)&CallGraph::stub);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/ConstantsScanner.h b/include/llvm/Analysis/ConstantsScanner.h
index c7efd76..e1533c3 100644
--- a/include/llvm/Analysis/ConstantsScanner.h
+++ b/include/llvm/Analysis/ConstantsScanner.h
@@ -19,6 +19,9 @@
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Instruction.h"
 #include "Support/iterator"
+
+namespace llvm {
+
 class Constant;
 
 class constant_iterator : public forward_iterator<const Constant, ptrdiff_t> {
@@ -86,4 +89,6 @@
   return constant_iterator(F, true);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DSGraph.h b/include/llvm/Analysis/DSGraph.h
index 399da00..b7fdb10 100644
--- a/include/llvm/Analysis/DSGraph.h
+++ b/include/llvm/Analysis/DSGraph.h
@@ -15,6 +15,9 @@
 #define LLVM_ANALYSIS_DSGRAPH_H
 
 #include "llvm/Analysis/DSNode.h"
+
+namespace llvm {
+
 class GlobalValue;
 
 //===----------------------------------------------------------------------===//
@@ -332,4 +335,6 @@
   void removeTriviallyDeadNodes();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DSGraphTraits.h b/include/llvm/Analysis/DSGraphTraits.h
index 086835c..ad2cc6f 100644
--- a/include/llvm/Analysis/DSGraphTraits.h
+++ b/include/llvm/Analysis/DSGraphTraits.h
@@ -21,6 +21,8 @@
 #include "Support/iterator"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 template<typename NodeTy>
 class DSNodeIterator : public forward_iterator<const DSNode, ptrdiff_t> {
   friend class DSNode;
@@ -146,4 +148,6 @@
   static ChildIteratorType child_end(const NodeType *N) { return N->end(); }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DSNode.h b/include/llvm/Analysis/DSNode.h
index ba5328b..f206c3e 100644
--- a/include/llvm/Analysis/DSNode.h
+++ b/include/llvm/Analysis/DSNode.h
@@ -16,6 +16,8 @@
 
 #include "llvm/Analysis/DSSupport.h"
 
+namespace llvm {
+
 template<typename BaseType>
 class DSNodeIterator;          // Data structure graph traversal iterator
 class TargetData;
@@ -382,4 +384,6 @@
     *this = Node;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DSSupport.h b/include/llvm/Analysis/DSSupport.h
index e5662ff..4b57191 100644
--- a/include/llvm/Analysis/DSSupport.h
+++ b/include/llvm/Analysis/DSSupport.h
@@ -18,6 +18,8 @@
 #include "Support/hash_set"
 #include "llvm/Support/CallSite.h"
 
+namespace llvm {
+
 class Function;
 class CallInst;
 class Value;
@@ -122,10 +124,14 @@
   DSNode *HandleForwarding() const;
 };
 
+} // End llvm namespace
+
 namespace std {
-  inline void swap(DSNodeHandle &NH1, DSNodeHandle &NH2) { NH1.swap(NH2); }
+  inline void swap(llvm::DSNodeHandle &NH1, llvm::DSNodeHandle &NH2) { NH1.swap(NH2); }
 }
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 /// DSCallSite - Representation of a call site via its call instruction,
 /// the DSNode handle for the callee function (or function pointer), and
@@ -287,7 +293,9 @@
   }
 };
 
+} // End llvm namespace
+
 namespace std {
-  inline void swap(DSCallSite &CS1, DSCallSite &CS2) { CS1.swap(CS2); }
+  inline void swap(llvm::DSCallSite &CS1, llvm::DSCallSite &CS2) { CS1.swap(CS2); }
 }
 #endif
diff --git a/include/llvm/Analysis/DataStructure.h b/include/llvm/Analysis/DataStructure.h
index afea126..4d6e3a0 100644
--- a/include/llvm/Analysis/DataStructure.h
+++ b/include/llvm/Analysis/DataStructure.h
@@ -18,6 +18,8 @@
 #include "llvm/Target/TargetData.h"
 #include "Support/hash_set"
 
+namespace llvm {
+
 class Type;
 class Instruction;
 class DSGraph;
@@ -184,4 +186,6 @@
                         const BUDataStructures::ActualCalleesTy &ActualCallees);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DataStructure/DSGraph.h b/include/llvm/Analysis/DataStructure/DSGraph.h
index 399da00..b7fdb10 100644
--- a/include/llvm/Analysis/DataStructure/DSGraph.h
+++ b/include/llvm/Analysis/DataStructure/DSGraph.h
@@ -15,6 +15,9 @@
 #define LLVM_ANALYSIS_DSGRAPH_H
 
 #include "llvm/Analysis/DSNode.h"
+
+namespace llvm {
+
 class GlobalValue;
 
 //===----------------------------------------------------------------------===//
@@ -332,4 +335,6 @@
   void removeTriviallyDeadNodes();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DataStructure/DSGraphTraits.h b/include/llvm/Analysis/DataStructure/DSGraphTraits.h
index 086835c..ad2cc6f 100644
--- a/include/llvm/Analysis/DataStructure/DSGraphTraits.h
+++ b/include/llvm/Analysis/DataStructure/DSGraphTraits.h
@@ -21,6 +21,8 @@
 #include "Support/iterator"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 template<typename NodeTy>
 class DSNodeIterator : public forward_iterator<const DSNode, ptrdiff_t> {
   friend class DSNode;
@@ -146,4 +148,6 @@
   static ChildIteratorType child_end(const NodeType *N) { return N->end(); }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DataStructure/DSNode.h b/include/llvm/Analysis/DataStructure/DSNode.h
index ba5328b..f206c3e 100644
--- a/include/llvm/Analysis/DataStructure/DSNode.h
+++ b/include/llvm/Analysis/DataStructure/DSNode.h
@@ -16,6 +16,8 @@
 
 #include "llvm/Analysis/DSSupport.h"
 
+namespace llvm {
+
 template<typename BaseType>
 class DSNodeIterator;          // Data structure graph traversal iterator
 class TargetData;
@@ -382,4 +384,6 @@
     *this = Node;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DataStructure/DSSupport.h b/include/llvm/Analysis/DataStructure/DSSupport.h
index e5662ff..4b57191 100644
--- a/include/llvm/Analysis/DataStructure/DSSupport.h
+++ b/include/llvm/Analysis/DataStructure/DSSupport.h
@@ -18,6 +18,8 @@
 #include "Support/hash_set"
 #include "llvm/Support/CallSite.h"
 
+namespace llvm {
+
 class Function;
 class CallInst;
 class Value;
@@ -122,10 +124,14 @@
   DSNode *HandleForwarding() const;
 };
 
+} // End llvm namespace
+
 namespace std {
-  inline void swap(DSNodeHandle &NH1, DSNodeHandle &NH2) { NH1.swap(NH2); }
+  inline void swap(llvm::DSNodeHandle &NH1, llvm::DSNodeHandle &NH2) { NH1.swap(NH2); }
 }
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 /// DSCallSite - Representation of a call site via its call instruction,
 /// the DSNode handle for the callee function (or function pointer), and
@@ -287,7 +293,9 @@
   }
 };
 
+} // End llvm namespace
+
 namespace std {
-  inline void swap(DSCallSite &CS1, DSCallSite &CS2) { CS1.swap(CS2); }
+  inline void swap(llvm::DSCallSite &CS1, llvm::DSCallSite &CS2) { CS1.swap(CS2); }
 }
 #endif
diff --git a/include/llvm/Analysis/DataStructure/DataStructure.h b/include/llvm/Analysis/DataStructure/DataStructure.h
index afea126..4d6e3a0 100644
--- a/include/llvm/Analysis/DataStructure/DataStructure.h
+++ b/include/llvm/Analysis/DataStructure/DataStructure.h
@@ -18,6 +18,8 @@
 #include "llvm/Target/TargetData.h"
 #include "Support/hash_set"
 
+namespace llvm {
+
 class Type;
 class Instruction;
 class DSGraph;
@@ -184,4 +186,6 @@
                         const BUDataStructures::ActualCalleesTy &ActualCallees);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/DependenceGraph.h b/include/llvm/Analysis/DependenceGraph.h
index b5af0b9..b4c7aa1 100644
--- a/include/llvm/Analysis/DependenceGraph.h
+++ b/include/llvm/Analysis/DependenceGraph.h
@@ -30,6 +30,8 @@
 #include <utility>
 #include <cassert>
 
+namespace llvm {
+
 class Instruction;
 class Function;
 class Dependence;
@@ -264,4 +266,6 @@
 
 //===----------------------------------------------------------------------===//
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h
index b8ac9c3..5688d6e 100644
--- a/include/llvm/Analysis/Dominators.h
+++ b/include/llvm/Analysis/Dominators.h
@@ -28,6 +28,8 @@
 #include "llvm/Pass.h"
 #include <set>
 
+namespace llvm {
+
 class Instruction;
 
 template <typename GraphType> struct GraphTraits;
@@ -487,4 +489,6 @@
                               const DominatorTree::Node *Node);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/Expressions.h b/include/llvm/Analysis/Expressions.h
index 2920761..77475ff 100644
--- a/include/llvm/Analysis/Expressions.h
+++ b/include/llvm/Analysis/Expressions.h
@@ -17,6 +17,8 @@
 #ifndef LLVM_ANALYSIS_EXPRESSIONS_H
 #define LLVM_ANALYSIS_EXPRESSIONS_H
 
+namespace llvm {
+
 class Type;
 class Value;
 class ConstantInt;
@@ -56,4 +58,6 @@
   const Type *getExprType(const Type *Default) const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/FindUnsafePointerTypes.h b/include/llvm/Analysis/FindUnsafePointerTypes.h
index 8f1cdcf..62077f3 100644
--- a/include/llvm/Analysis/FindUnsafePointerTypes.h
+++ b/include/llvm/Analysis/FindUnsafePointerTypes.h
@@ -27,6 +27,8 @@
 #include "llvm/Pass.h"
 #include <set>
 
+namespace llvm {
+
 class PointerType;
 
 struct FindUnsafePointerTypes : public Pass {
@@ -55,4 +57,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/FindUsedTypes.h b/include/llvm/Analysis/FindUsedTypes.h
index a246084..6947179 100644
--- a/include/llvm/Analysis/FindUsedTypes.h
+++ b/include/llvm/Analysis/FindUsedTypes.h
@@ -16,6 +16,9 @@
 
 #include "llvm/Pass.h"
 #include <set>
+
+namespace llvm {
+
 class Type;
 
 class FindUsedTypes : public Pass {
@@ -59,4 +62,6 @@
 static IncludeFile
 FIND_USED_TYPES_INCLUDE_FILE((void*)&FindUsedTypes::stub);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/IPModRef.h b/include/llvm/Analysis/IPModRef.h
index 84e5519..cf70d58 100644
--- a/include/llvm/Analysis/IPModRef.h
+++ b/include/llvm/Analysis/IPModRef.h
@@ -50,6 +50,8 @@
 #include "Support/BitSetVector.h"
 #include "Support/hash_map"
 
+namespace llvm {
+
 class Module;
 class Function;
 class CallSite;
@@ -239,4 +241,6 @@
 
 //===----------------------------------------------------------------------===//
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/InductionVariable.h b/include/llvm/Analysis/InductionVariable.h
index 26deb83..6c06a6c 100644
--- a/include/llvm/Analysis/InductionVariable.h
+++ b/include/llvm/Analysis/InductionVariable.h
@@ -27,6 +27,9 @@
 #define LLVM_ANALYSIS_INDUCTIONVARIABLE_H
 
 #include <iosfwd>
+
+namespace llvm {
+
 class Value;
 class PHINode;
 class Instruction;
@@ -60,4 +63,6 @@
   void print(std::ostream &OS) const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h
index a034c92..82fc46e 100644
--- a/include/llvm/Analysis/InstForest.h
+++ b/include/llvm/Analysis/InstForest.h
@@ -25,6 +25,8 @@
 #include "Support/Tree.h"
 #include <map>
 
+namespace llvm {
+
 template<class Payload> class InstTreeNode;
 template<class Payload> class InstForest;
 
@@ -288,5 +290,7 @@
   getTreeData().first.second = InstructionNode;
 }
 
+} // End llvm namespace
+
 #endif
 
diff --git a/include/llvm/Analysis/Interval.h b/include/llvm/Analysis/Interval.h
index 9839cf5..0d59123 100644
--- a/include/llvm/Analysis/Interval.h
+++ b/include/llvm/Analysis/Interval.h
@@ -24,6 +24,8 @@
 #include <vector>
 #include <iosfwd>
 
+namespace llvm {
+
 class BasicBlock;
 
 //===----------------------------------------------------------------------===//
@@ -146,4 +148,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/IntervalIterator.h b/include/llvm/Analysis/IntervalIterator.h
index 2d67ded..091959f 100644
--- a/include/llvm/Analysis/IntervalIterator.h
+++ b/include/llvm/Analysis/IntervalIterator.h
@@ -40,6 +40,8 @@
 #include <set>
 #include <algorithm>
 
+namespace llvm {
+
 // getNodeHeader - Given a source graph node and the source graph, return the 
 // BasicBlock that is the header node.  This is the opposite of
 // getSourceGraphNode.
@@ -253,4 +255,6 @@
   return interval_part_interval_iterator();
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/IntervalPartition.h b/include/llvm/Analysis/IntervalPartition.h
index 45e282a..408ace2 100644
--- a/include/llvm/Analysis/IntervalPartition.h
+++ b/include/llvm/Analysis/IntervalPartition.h
@@ -26,6 +26,8 @@
 #include "llvm/Analysis/Interval.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //
 // IntervalPartition - This class builds and holds an "interval partition" for
@@ -102,4 +104,6 @@
   void updatePredecessors(Interval *Int);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/LoadValueNumbering.h b/include/llvm/Analysis/LoadValueNumbering.h
index 83aa5e9..6218133 100644
--- a/include/llvm/Analysis/LoadValueNumbering.h
+++ b/include/llvm/Analysis/LoadValueNumbering.h
@@ -21,6 +21,8 @@
 #ifndef LLVM_ANALYSIS_LOAD_VALUE_NUMBERING_H
 #define LLVM_ANALYSIS_LOAD_VALUE_NUMBERING_H
 
+namespace llvm {
+
 class Pass;
 
 /// createLoadValueNumberingPass - Create and return a new pass that implements
@@ -28,4 +30,6 @@
 ///
 Pass *createLoadValueNumberingPass();
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h
index 6a96834..1458b3b 100644
--- a/include/llvm/Analysis/LoopInfo.h
+++ b/include/llvm/Analysis/LoopInfo.h
@@ -29,6 +29,8 @@
 #include "Support/GraphTraits.h"
 #include <set>
 
+namespace llvm {
+
 class DominatorSet;
 class LoopInfo;
 
@@ -224,4 +226,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/MemoryDepAnalysis.h b/include/llvm/Analysis/MemoryDepAnalysis.h
index 6ecc3c8..10eb656 100644
--- a/include/llvm/Analysis/MemoryDepAnalysis.h
+++ b/include/llvm/Analysis/MemoryDepAnalysis.h
@@ -24,6 +24,8 @@
 #include "llvm/Pass.h"
 #include "Support/hash_map"
 
+namespace llvm {
+
 class ModRefTable;
 class DSGraph;
 class FunctionModRefInfo;
@@ -96,4 +98,6 @@
   void dump() const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/PgmDependenceGraph.h b/include/llvm/Analysis/PgmDependenceGraph.h
index edb5119..7012874 100644
--- a/include/llvm/Analysis/PgmDependenceGraph.h
+++ b/include/llvm/Analysis/PgmDependenceGraph.h
@@ -46,6 +46,8 @@
 #include "llvm/Pass.h"
 #include "Support/iterator"
 
+namespace llvm {
+
 class DSGraph;
 class DependenceGraph;
 class PgmDependenceGraph;
@@ -304,7 +306,8 @@
   void dump() const;
 };
 
-
 //===----------------------------------------------------------------------===//
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/PostDominators.h b/include/llvm/Analysis/PostDominators.h
index b1a9b8e..c8eb439 100644
--- a/include/llvm/Analysis/PostDominators.h
+++ b/include/llvm/Analysis/PostDominators.h
@@ -16,6 +16,8 @@
 
 #include "llvm/Analysis/Dominators.h"
 
+namespace llvm {
+
 
 /// PostDominatorSet Class - Concrete subclass of DominatorSetBase that is used
 /// to compute the post-dominator set.  Because there can be multiple exit nodes
@@ -117,4 +119,6 @@
 static IncludeFile
 POST_DOMINATOR_INCLUDE_FILE((void*)&PostDominanceFrontier::stub);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/SlotCalculator.h b/include/llvm/Analysis/SlotCalculator.h
index 7e56de9..596f932 100644
--- a/include/llvm/Analysis/SlotCalculator.h
+++ b/include/llvm/Analysis/SlotCalculator.h
@@ -22,6 +22,9 @@
 
 #include <vector>
 #include <map>
+
+namespace llvm {
+
 class Value;
 class Module;
 class Function;
@@ -92,4 +95,6 @@
   void processSymbolTableConstants(const SymbolTable *ST);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/ValueNumbering.h b/include/llvm/Analysis/ValueNumbering.h
index ff4680d..74b5c97 100644
--- a/include/llvm/Analysis/ValueNumbering.h
+++ b/include/llvm/Analysis/ValueNumbering.h
@@ -21,6 +21,9 @@
 #define LLVM_ANALYSIS_VALUE_NUMBERING_H
 
 #include <vector>
+
+namespace llvm {
+
 class Value;
 
 struct ValueNumbering {
@@ -34,4 +37,6 @@
   virtual ~ValueNumbering();    // We want to be subclassed
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Analysis/Verifier.h b/include/llvm/Analysis/Verifier.h
index 427015c..51da3a5 100644
--- a/include/llvm/Analysis/Verifier.h
+++ b/include/llvm/Analysis/Verifier.h
@@ -21,6 +21,8 @@
 #ifndef LLVM_ANALYSIS_VERIFIER_H
 #define LLVM_ANALYSIS_VERIFIER_H
 
+namespace llvm {
+
 class FunctionPass;
 class Module;
 class Function;
@@ -40,4 +42,6 @@
 // pass.
 bool verifyFunction(const Function &F);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Argument.h b/include/llvm/Argument.h
index 2d70f53..ab4ee1b 100644
--- a/include/llvm/Argument.h
+++ b/include/llvm/Argument.h
@@ -17,6 +17,8 @@
 
 #include "llvm/Value.h"
 
+namespace llvm {
+
 class Argument : public Value {  // Defined in the Function.cpp file
   Function *Parent;
 
@@ -56,4 +58,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Assembly/AsmAnnotationWriter.h b/include/llvm/Assembly/AsmAnnotationWriter.h
index 192cb3d..3beda6d 100644
--- a/include/llvm/Assembly/AsmAnnotationWriter.h
+++ b/include/llvm/Assembly/AsmAnnotationWriter.h
@@ -18,6 +18,9 @@
 #define LLVM_ASSEMBLY_ASMANNOTATIONWRITER_H
 
 #include <iosfwd>
+
+namespace llvm {
+
 class Function;
 class BasicBlock;
 class Instruction;
@@ -37,4 +40,6 @@
   virtual void emitInstructionAnnot(const Instruction *I, std::ostream &OS) {}
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Assembly/CWriter.h b/include/llvm/Assembly/CWriter.h
index cc7a358..3029787 100644
--- a/include/llvm/Assembly/CWriter.h
+++ b/include/llvm/Assembly/CWriter.h
@@ -16,7 +16,12 @@
 #define LLVM_ASSEMBLY_CWRITER_H
 
 #include <iosfwd>
+
+namespace llvm {
+
 class Pass;
 Pass *createWriteToCPass(std::ostream &o);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Assembly/CachedWriter.h b/include/llvm/Assembly/CachedWriter.h
index dbddacd..4acd3de 100644
--- a/include/llvm/Assembly/CachedWriter.h
+++ b/include/llvm/Assembly/CachedWriter.h
@@ -20,6 +20,8 @@
 #include "llvm/Value.h"
 #include <iostream>
 
+namespace llvm {
+
 class Module;
 class PointerType;
 class SlotCalculator;
@@ -82,4 +84,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Assembly/Parser.h b/include/llvm/Assembly/Parser.h
index 4f1863f..dc1b17e 100644
--- a/include/llvm/Assembly/Parser.h
+++ b/include/llvm/Assembly/Parser.h
@@ -16,6 +16,8 @@
 
 #include <string>
 
+namespace llvm {
+
 class Module;
 class ParseException;
 
@@ -70,4 +72,6 @@
   ParseException &operator=(const ParseException &E); // objects by reference
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Assembly/PrintModulePass.h b/include/llvm/Assembly/PrintModulePass.h
index e211e8b..2810080 100644
--- a/include/llvm/Assembly/PrintModulePass.h
+++ b/include/llvm/Assembly/PrintModulePass.h
@@ -21,6 +21,8 @@
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 
+namespace llvm {
+
 class PrintModulePass : public Pass {
   std::ostream *Out;      // ostream to print on
   bool DeleteStream;      // Delete the ostream in our dtor?
@@ -72,4 +74,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Assembly/Writer.h b/include/llvm/Assembly/Writer.h
index 5798ae8..9f89b31 100644
--- a/include/llvm/Assembly/Writer.h
+++ b/include/llvm/Assembly/Writer.h
@@ -24,6 +24,9 @@
 #define LLVM_ASSEMBLY_WRITER_H
 
 #include <iosfwd>
+
+namespace llvm {
+
 class Type;
 class Module;
 class Value;
@@ -43,4 +46,6 @@
 std::ostream &WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true,
                              bool PrintName = true, const Module *Context = 0);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h
index 1a996bc..9f78bc7 100644
--- a/include/llvm/BasicBlock.h
+++ b/include/llvm/BasicBlock.h
@@ -33,6 +33,8 @@
 #include "llvm/SymbolTableListTraits.h"
 #include "Support/ilist"
 
+namespace llvm {
+
 class TerminatorInst;
 template <class _Term, class _BB> class SuccIterator;  // Successor Iterator
 template <class _Ptr, class _USE_iterator> class PredIterator;
@@ -171,4 +173,6 @@
   BasicBlock *splitBasicBlock(iterator I, const std::string &BBName = "");
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Bytecode/Format.h b/include/llvm/Bytecode/Format.h
index 79cf9f0..380f4df 100644
--- a/include/llvm/Bytecode/Format.h
+++ b/include/llvm/Bytecode/Format.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_BYTECODE_FORMAT_H
 #define LLVM_BYTECODE_FORMAT_H
 
+namespace llvm {
+
 class BytecodeFormat {   // Throw the constants into a poorman's namespace...
   BytecodeFormat();      // do not implement
 public:
@@ -38,4 +40,7 @@
     BasicBlock = 0x31,        // May contain many basic blocks
   };
 };
+
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Bytecode/Primitives.h b/include/llvm/Bytecode/Primitives.h
index d9b29c0..3973ece 100644
--- a/include/llvm/Bytecode/Primitives.h
+++ b/include/llvm/Bytecode/Primitives.h
@@ -23,6 +23,8 @@
 #include <string>
 #include <deque>
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                             Reading Primitives
 //===----------------------------------------------------------------------===//
@@ -275,4 +277,6 @@
   if (Align) align32(Out);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Bytecode/Reader.h b/include/llvm/Bytecode/Reader.h
index 0de71002..1e9fa32 100644
--- a/include/llvm/Bytecode/Reader.h
+++ b/include/llvm/Bytecode/Reader.h
@@ -23,6 +23,8 @@
 #include <string>
 #include <vector>
 
+namespace llvm {
+
 /// getBytecodeModuleProvider - lazy function-at-a-time loading from a file
 ///
 ModuleProvider *getBytecodeModuleProvider(const std::string &Filename);
@@ -53,4 +55,6 @@
                      std::vector<Module*> &Objects,
                      std::string *ErrorStr = 0);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Bytecode/WriteBytecodePass.h b/include/llvm/Bytecode/WriteBytecodePass.h
index ba8bc71..b8863e6 100644
--- a/include/llvm/Bytecode/WriteBytecodePass.h
+++ b/include/llvm/Bytecode/WriteBytecodePass.h
@@ -19,6 +19,8 @@
 #include "llvm/Bytecode/Writer.h"
 #include <iostream>
 
+namespace llvm {
+
 class WriteBytecodePass : public Pass {
   std::ostream *Out;           // ostream to print on
   bool DeleteStream;
@@ -38,4 +40,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Bytecode/Writer.h b/include/llvm/Bytecode/Writer.h
index ba82f6a..9fadddb 100644
--- a/include/llvm/Bytecode/Writer.h
+++ b/include/llvm/Bytecode/Writer.h
@@ -26,7 +26,11 @@
 
 #include <iosfwd>
 
+namespace llvm {
+
 class Module;
 void WriteBytecodeToFile(const Module *C, std::ostream &Out);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CallGraphSCCPass.h b/include/llvm/CallGraphSCCPass.h
index bb97a27..86cdc29 100644
--- a/include/llvm/CallGraphSCCPass.h
+++ b/include/llvm/CallGraphSCCPass.h
@@ -23,6 +23,8 @@
 
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 class CallGraphNode;
 
 struct CallGraphSCCPass : public Pass {
@@ -46,4 +48,6 @@
   virtual void getAnalysisUsage(AnalysisUsage &Info) const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/FunctionLiveVarInfo.h b/include/llvm/CodeGen/FunctionLiveVarInfo.h
index e79d58f..23a9d93 100644
--- a/include/llvm/CodeGen/FunctionLiveVarInfo.h
+++ b/include/llvm/CodeGen/FunctionLiveVarInfo.h
@@ -39,6 +39,8 @@
 #include "llvm/Pass.h"
 #include "llvm/CodeGen/ValueSet.h"
 
+namespace llvm {
+
 class BBLiveVar;
 class MachineInstr;
 
@@ -104,4 +106,6 @@
                                           const BasicBlock *BB = 0);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/InstrForest.h b/include/llvm/CodeGen/InstrForest.h
index fc82d7c..4826671 100644
--- a/include/llvm/CodeGen/InstrForest.h
+++ b/include/llvm/CodeGen/InstrForest.h
@@ -29,16 +29,24 @@
 #include "llvm/Instruction.h"
 #include "Support/hash_map"
 
+namespace llvm {
+
 class Constant;
 class Function;
 class InstrTreeNode;
 class InstrForest;
 
+} // End llvm namespace
+
+using namespace llvm;
+
 //--------------------------------------------------------------------------
 // OpLabel values for special-case nodes created for instruction selection.
 // All op-labels not defined here are identical to the instruction
 // opcode returned by Instruction::getOpcode()
 //--------------------------------------------------------------------------
+//
+
 
 const int  InvalidOp	=  -1;
 const int  VRegListOp   =  97;
@@ -103,6 +111,7 @@
 extern int		treecost	(InstrTreeNode*, int, int);
 extern void		printMatches	(InstrTreeNode*);
 
+namespace llvm {
 
 //------------------------------------------------------------------------ 
 // class InstrTreeNode
@@ -325,4 +334,6 @@
   InstructionNode* buildTreeForInstruction(Instruction* instr);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/InstrScheduling.h b/include/llvm/CodeGen/InstrScheduling.h
index 40ce442..816aa7e 100644
--- a/include/llvm/CodeGen/InstrScheduling.h
+++ b/include/llvm/CodeGen/InstrScheduling.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_CODEGEN_INSTR_SCHEDULING_H
 #define LLVM_CODEGEN_INSTR_SCHEDULING_H
 
+namespace llvm {
+
 class FunctionPass;
 class TargetMachine;
 
@@ -30,4 +32,6 @@
 
 FunctionPass *createInstructionSchedulingWithSSAPass(const TargetMachine &TM);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/InstrSelection.h b/include/llvm/CodeGen/InstrSelection.h
index 89e827d..2f269ea 100644
--- a/include/llvm/CodeGen/InstrSelection.h
+++ b/include/llvm/CodeGen/InstrSelection.h
@@ -16,6 +16,8 @@
 
 #include "llvm/Instruction.h"
 
+namespace llvm {
+
 class Function;
 class InstrForest;
 class MachineInstr;
@@ -102,4 +104,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/InstrSelectionSupport.h b/include/llvm/CodeGen/InstrSelectionSupport.h
index 2ab23c7..c1fba48 100644
--- a/include/llvm/CodeGen/InstrSelectionSupport.h
+++ b/include/llvm/CodeGen/InstrSelectionSupport.h
@@ -17,6 +17,9 @@
 
 #include "llvm/CodeGen/MachineInstr.h"
 #include "Support/DataTypes.h"
+
+namespace llvm {
+
 class InstructionNode;
 class TargetMachine;
 class Instruction;
@@ -44,4 +47,6 @@
                                          unsigned& getMachineRegNum,
                                          int64_t& getImmedValue);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/LiveVariables.h b/include/llvm/CodeGen/LiveVariables.h
index 8d1306e..3a0d044 100644
--- a/include/llvm/CodeGen/LiveVariables.h
+++ b/include/llvm/CodeGen/LiveVariables.h
@@ -32,6 +32,8 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include <map>
 
+namespace llvm {
+
 class MRegisterInfo;
 
 class LiveVariables : public MachineFunctionPass {
@@ -207,4 +209,6 @@
   void HandlePhysRegDef(unsigned Reg, MachineInstr *MI);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h
index b3959e8..b8a0361 100644
--- a/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/include/llvm/CodeGen/MachineBasicBlock.h
@@ -15,6 +15,9 @@
 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
 
 #include <vector>
+
+namespace llvm {
+
 class BasicBlock;
 class MachineInstr;
 template <typename T> struct ilist_traits;
@@ -81,5 +84,6 @@
   void setNext(MachineBasicBlock *N) { Next = N; }
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h
index 4145851..2d01f45 100644
--- a/include/llvm/CodeGen/MachineCodeEmitter.h
+++ b/include/llvm/CodeGen/MachineCodeEmitter.h
@@ -19,6 +19,9 @@
 
 #include <string>
 #include "Support/DataTypes.h"
+
+namespace llvm {
+
 class MachineFunction;
 class MachineBasicBlock;
 class MachineConstantPool;
@@ -105,4 +108,6 @@
   static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineCodeForInstruction.h b/include/llvm/CodeGen/MachineCodeForInstruction.h
index d421f3e..9a08de7 100644
--- a/include/llvm/CodeGen/MachineCodeForInstruction.h
+++ b/include/llvm/CodeGen/MachineCodeForInstruction.h
@@ -28,6 +28,8 @@
 #include "Support/Annotation.h"
 #include <vector>
 
+namespace llvm {
+
 class MachineInstr;
 class Instruction;
 class Value;
@@ -96,4 +98,6 @@
   CallArgsDescriptor* getCallArgsDescriptor() const    { return callArgsDesc; }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineConstantPool.h b/include/llvm/CodeGen/MachineConstantPool.h
index 441a43a..edfd601 100644
--- a/include/llvm/CodeGen/MachineConstantPool.h
+++ b/include/llvm/CodeGen/MachineConstantPool.h
@@ -23,6 +23,9 @@
 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
 
 #include <vector>
+
+namespace llvm {
+
 class Constant;
 
 class MachineConstantPool {
@@ -54,4 +57,6 @@
   void dump() const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineFrameInfo.h b/include/llvm/CodeGen/MachineFrameInfo.h
index 48b9101..e48158e 100644
--- a/include/llvm/CodeGen/MachineFrameInfo.h
+++ b/include/llvm/CodeGen/MachineFrameInfo.h
@@ -38,12 +38,19 @@
 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H
 
+namespace llvm {
+
 class TargetData;
 class TargetRegisterClass;
 class Type;
 class MachineFunction;
+
+}
+
 #include <vector>
 
+namespace llvm {
+
 class MachineFrameInfo {
 
   // StackObject - Represent a single object allocated on the stack.
@@ -220,4 +227,6 @@
   void dump(const MachineFunction &MF) const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h
index 7474a6e..60478cf 100644
--- a/include/llvm/CodeGen/MachineFunction.h
+++ b/include/llvm/CodeGen/MachineFunction.h
@@ -22,6 +22,8 @@
 #include "Support/Annotation.h"
 #include "Support/ilist"
 
+namespace llvm {
+
 class Function;
 class TargetMachine;
 class FunctionPass;
@@ -141,4 +143,6 @@
         MachineBasicBlock & back()       { return BasicBlocks.back(); }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineFunctionInfo.h b/include/llvm/CodeGen/MachineFunctionInfo.h
index db73322..fdf135b 100644
--- a/include/llvm/CodeGen/MachineFunctionInfo.h
+++ b/include/llvm/CodeGen/MachineFunctionInfo.h
@@ -17,6 +17,9 @@
 
 #include "Support/HashExtras.h"
 #include "Support/hash_set"
+
+namespace llvm {
+
 class MachineFunction;
 class Value;
 class Constant;
@@ -112,4 +115,6 @@
   int allocateOptionalArg(const Type* type);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineFunctionPass.h b/include/llvm/CodeGen/MachineFunctionPass.h
index 6975b5e..390dcb8 100644
--- a/include/llvm/CodeGen/MachineFunctionPass.h
+++ b/include/llvm/CodeGen/MachineFunctionPass.h
@@ -22,6 +22,8 @@
 #include "llvm/Pass.h"
 #include "llvm/CodeGen/MachineFunction.h"
 
+namespace llvm {
+
 struct MachineFunctionPass : public FunctionPass {
 
   /// runOnMachineFunction - This method must be overloaded to perform the
@@ -37,4 +39,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h
index fc886d9..2eb373f 100644
--- a/include/llvm/CodeGen/MachineInstr.h
+++ b/include/llvm/CodeGen/MachineInstr.h
@@ -20,6 +20,8 @@
 #include "Support/Annotation.h"
 #include "Support/iterator"
 
+namespace llvm {
+
 class Value;
 class Function;
 class MachineBasicBlock;
@@ -715,4 +717,6 @@
 std::ostream& operator<<(std::ostream &OS, const MachineOperand &MO);
 void PrintMachineInstructions(const Function *F);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/MachineInstrAnnot.h b/include/llvm/CodeGen/MachineInstrAnnot.h
index 98dde59..19d93ab 100644
--- a/include/llvm/CodeGen/MachineInstrAnnot.h
+++ b/include/llvm/CodeGen/MachineInstrAnnot.h
@@ -17,6 +17,8 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/TargetRegInfo.h"
 
+namespace llvm {
+
 class Value;
 class TmpInstruction;
 class CallInst;
@@ -88,5 +90,6 @@
   static CallArgsDescriptor *get(const MachineInstr* MI);
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/CodeGen/MachineInstrBuilder.h b/include/llvm/CodeGen/MachineInstrBuilder.h
index 14c7fe0..6725521 100644
--- a/include/llvm/CodeGen/MachineInstrBuilder.h
+++ b/include/llvm/CodeGen/MachineInstrBuilder.h
@@ -25,6 +25,8 @@
 
 #include "llvm/CodeGen/MachineInstr.h"
 
+namespace llvm {
+
 class MachineInstrBuilder {
   MachineInstr *MI;
 public:
@@ -162,4 +164,6 @@
                                                                      MOTy::Def);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h
index 807257e..11fcf29 100644
--- a/include/llvm/CodeGen/Passes.h
+++ b/include/llvm/CodeGen/Passes.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_CODEGEN_PASSES_H
 #define LLVM_CODEGEN_PASSES_H
 
+namespace llvm {
+
 class FunctionPass;
 class PassInfo;
 class TargetMachine;
@@ -52,4 +54,6 @@
 /// for the Sparc.
 FunctionPass *getRegisterAllocator(TargetMachine &T);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/SSARegMap.h b/include/llvm/CodeGen/SSARegMap.h
index 7f5d5f9..c31911c 100644
--- a/include/llvm/CodeGen/SSARegMap.h
+++ b/include/llvm/CodeGen/SSARegMap.h
@@ -19,6 +19,8 @@
 
 #include "llvm/Target/MRegisterInfo.h"
 
+namespace llvm {
+
 class TargetRegisterClass;
 
 class SSARegMap {
@@ -44,4 +46,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/SchedGraphCommon.h b/include/llvm/CodeGen/SchedGraphCommon.h
index 874e53d..a422d9a 100644
--- a/include/llvm/CodeGen/SchedGraphCommon.h
+++ b/include/llvm/CodeGen/SchedGraphCommon.h
@@ -18,6 +18,8 @@
 #include "llvm/Value.h"
 #include <vector>
 
+namespace llvm {
+
 class SchedGraphEdge;
 class SchedGraphNode;
 
@@ -217,4 +219,6 @@
   ~SchedGraphCommon();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h
index f132f7b..4719bf9 100644
--- a/include/llvm/CodeGen/SelectionDAG.h
+++ b/include/llvm/CodeGen/SelectionDAG.h
@@ -27,6 +27,9 @@
 #include <map>
 #include <vector>
 #include <cassert>
+
+namespace llvm {
+
 class Value;
 class Type;
 class Instruction;
@@ -362,4 +365,6 @@
 typedef ReducedValue<float         , ISD::Constant_f32_Slot> ReducedValue_Constant_f32;
 typedef ReducedValue<double        , ISD::Constant_f64_Slot> ReducedValue_Constant_f64;
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/ValueSet.h b/include/llvm/CodeGen/ValueSet.h
index 1495065..f4bc6e8 100644
--- a/include/llvm/CodeGen/ValueSet.h
+++ b/include/llvm/CodeGen/ValueSet.h
@@ -17,6 +17,9 @@
 #define VALUE_SET_H
 
 #include <set>
+
+namespace llvm {
+
 class Value;
 
 // RAV - Used to print values in a form used by the register allocator.  
@@ -31,4 +34,6 @@
 typedef std::set<const Value*> ValueSet;
 void printSet(const ValueSet &S);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/CodeGen/ValueTypes.h b/include/llvm/CodeGen/ValueTypes.h
index dc85ee0..b523b71 100644
--- a/include/llvm/CodeGen/ValueTypes.h
+++ b/include/llvm/CodeGen/ValueTypes.h
@@ -16,6 +16,8 @@
 #ifndef LLVM_CODEGEN_VALUETYPES_H
 #define LLVM_CODEGEN_VALUETYPES_H
 
+namespace llvm {
+
 /// MVT namespace - This namespace defines the ValueType enum, which contains
 /// the various low-level value types.
 ///
@@ -40,5 +42,6 @@
   };
 };
 
-#endif
+} // End llvm namespace
 
+#endif
diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h
index ac4c820..fbed6ee 100644
--- a/include/llvm/Constant.h
+++ b/include/llvm/Constant.h
@@ -16,6 +16,8 @@
 
 #include "llvm/User.h"
 
+namespace llvm {
+
 class Constant : public User {
 protected:
   inline Constant(const Type *Ty) : User(Ty, Value::ConstantVal) {}
@@ -91,4 +93,6 @@
   // END WARNING!!
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ConstantHandling.h b/include/llvm/ConstantHandling.h
index a27283c..a0a01e5 100644
--- a/include/llvm/ConstantHandling.h
+++ b/include/llvm/ConstantHandling.h
@@ -42,6 +42,9 @@
 
 #include "llvm/Constants.h"
 #include "llvm/Type.h"
+
+namespace llvm {
+
 class PointerType;
 
 //===----------------------------------------------------------------------===//
@@ -244,4 +247,7 @@
                                        const Constant *V2);
 Constant *ConstantFoldGetElementPtr(const Constant *C,
                                     const std::vector<Constant*> &IdxList);
+
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 077c61c..5d65b2f 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -18,6 +18,8 @@
 #include "llvm/Constant.h"
 #include "Support/DataTypes.h"
 
+namespace llvm {
+
 class ArrayType;
 class StructType;
 class PointerType;
@@ -575,4 +577,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h
index 8efe269..8d23df1 100644
--- a/include/llvm/DerivedTypes.h
+++ b/include/llvm/DerivedTypes.h
@@ -21,6 +21,8 @@
 #include "llvm/Type.h"
 #include <vector>
 
+namespace llvm {
+
 template<class ValType, class TypeClass> class TypeMap;
 class FunctionValType;
 class ArrayValType;
@@ -490,4 +492,6 @@
   return *const_cast<PATypeHolder*>(this) = NewTy;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h
index c2a0a3a..5dd74b7 100644
--- a/include/llvm/ExecutionEngine/ExecutionEngine.h
+++ b/include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -19,6 +19,9 @@
 #include <string>
 #include <map>
 #include <cassert>
+
+namespace llvm {
+
 class Constant;
 class Function;
 union GenericValue;
@@ -92,4 +95,6 @@
   GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ExecutionEngine/GenericValue.h b/include/llvm/ExecutionEngine/GenericValue.h
index b64eb79..0446795 100644
--- a/include/llvm/ExecutionEngine/GenericValue.h
+++ b/include/llvm/ExecutionEngine/GenericValue.h
@@ -17,6 +17,8 @@
 
 #include "Support/DataTypes.h"
 
+namespace llvm {
+
 typedef uint64_t PointerTy;
 
 union GenericValue {
@@ -44,4 +46,6 @@
 inline void* GVTOP(const GenericValue &GV) {
   return (void*)(intptr_t)GV.PointerVal;
 }
+
+} // End llvm namespace
 #endif
diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index 3c44b36..4dd791e 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -22,6 +22,8 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Argument.h"
 
+namespace llvm {
+
 class FunctionType;
 
 // Traits for intrusive list of instructions...
@@ -95,7 +97,7 @@
   virtual bool isExternal() const { return BasicBlocks.empty(); }
 
   /// getIntrinsicID - This method returns the ID number of the specified
-  /// function, or LLVMIntrinsic::not_intrinsic if the function is not an
+  /// function, or Intrinsic::not_intrinsic if the function is not an
   /// instrinsic, or if the pointer is null.  This value is always defined to be
   /// zero to allow easy checking for whether a function is intrinsic or not.
   /// The particular intrinsic functions which correspond to this value are
@@ -220,4 +222,6 @@
   void dropAllReferences();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h
index f2349bc..47a2189 100644
--- a/include/llvm/GlobalValue.h
+++ b/include/llvm/GlobalValue.h
@@ -18,6 +18,9 @@
 #define LLVM_GLOBALVALUE_H
 
 #include "llvm/User.h"
+
+namespace llvm {
+
 class PointerType;
 class Module;
 
@@ -71,4 +74,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h
index d1a9a29..03c4f39 100644
--- a/include/llvm/GlobalVariable.h
+++ b/include/llvm/GlobalVariable.h
@@ -22,6 +22,8 @@
 
 #include "llvm/GlobalValue.h"
 
+namespace llvm {
+
 class Module;
 class Constant;
 class PointerType;
@@ -105,4 +107,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h
index e3d3d61..7938b48 100644
--- a/include/llvm/InstrTypes.h
+++ b/include/llvm/InstrTypes.h
@@ -18,6 +18,8 @@
 
 #include "llvm/Instruction.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
@@ -134,4 +136,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Instruction.def b/include/llvm/Instruction.def
index e069e2c..4208642 100644
--- a/include/llvm/Instruction.def
+++ b/include/llvm/Instruction.def
@@ -15,7 +15,7 @@
 
 // NOTE: NO INCLUDE GUARD DESIRED!
 
-// Provide definitions of macros so that users of this file don't have to define
+// Provide definitions of macros so that users of this file do not have to define
 // everything to use it...
 //
 #ifndef FIRST_TERM_INST
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 264356c..cc9a8ae 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -17,6 +17,8 @@
 
 #include "llvm/User.h"
 
+namespace llvm {
+
 class AssemblyAnnotationWriter;
 
 template<typename SC> struct ilist_traits;
@@ -151,4 +153,6 @@
   };
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Intrinsics.h b/include/llvm/Intrinsics.h
index 9d7c7bc..8ecb6c4 100644
--- a/include/llvm/Intrinsics.h
+++ b/include/llvm/Intrinsics.h
@@ -16,11 +16,13 @@
 #ifndef LLVM_INTRINSICS_H
 #define LLVM_INTRINSICS_H
 
-/// LLVMIntrinsic Namespace - This namespace contains an enum with a value for
+namespace llvm {
+
+/// Intrinsic Namespace - This namespace contains an enum with a value for
 /// every intrinsic/builtin function known by LLVM.  These enum values are
 /// returned by Function::getIntrinsicID().
 ///
-namespace LLVMIntrinsic {
+namespace Intrinsic {
   enum ID {
     not_intrinsic = 0,   // Must be zero
 
@@ -125,6 +127,9 @@
                     // second parameter, the possible values for which are
                     // defined in the AlphaSfpToSq enumeration
   };
-}
+
+} // End Intrinsic namespace
+
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h
index ac39903..9f4c8c2 100644
--- a/include/llvm/Linker.h
+++ b/include/llvm/Linker.h
@@ -15,6 +15,9 @@
 #define LLVM_TRANSFORMATIONS_UTILS_LINKER_H
 
 #include <string>
+
+namespace llvm {
+
 class Module;
 
 // LinkModules - This function links two modules together, with the resulting
@@ -24,5 +27,7 @@
 //
 bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0);
 
+} // End llvm namespace
+
 #endif
 
diff --git a/include/llvm/Module.h b/include/llvm/Module.h
index 19626ae..b38269d 100644
--- a/include/llvm/Module.h
+++ b/include/llvm/Module.h
@@ -21,6 +21,9 @@
 
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
+
+namespace llvm {
+
 class GlobalVariable;
 class GlobalValueRefMap;   // Used by ConstantVals.cpp
 class ConstantPointerRef;
@@ -213,4 +216,6 @@
   return O;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/ModuleProvider.h b/include/llvm/ModuleProvider.h
index 8d4b1d2..de9616f 100644
--- a/include/llvm/ModuleProvider.h
+++ b/include/llvm/ModuleProvider.h
@@ -18,6 +18,8 @@
 #ifndef MODULEPROVIDER_H
 #define MODULEPROVIDER_H
 
+namespace llvm {
+
 class Function;
 class Module;
 
@@ -52,4 +54,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h
index 0d0a6e6..8a10ead 100644
--- a/include/llvm/Pass.h
+++ b/include/llvm/Pass.h
@@ -34,6 +34,9 @@
 #include <iosfwd>
 #include <typeinfo>
 #include <cassert>
+
+namespace llvm {
+
 class Value;
 class BasicBlock;
 class Function;
@@ -329,6 +332,8 @@
   virtual void addToPassManager(PassManagerT<BasicBlock> *PM,AnalysisUsage &AU);
 };
 
+} // End llvm namespace
+
 // Include support files that contain important APIs commonly used by Passes,
 // but that we want to separate out to make it easier to read the header files.
 //
diff --git a/include/llvm/PassAnalysisSupport.h b/include/llvm/PassAnalysisSupport.h
index 61fb29f..f62465a 100644
--- a/include/llvm/PassAnalysisSupport.h
+++ b/include/llvm/PassAnalysisSupport.h
@@ -19,6 +19,8 @@
 #ifndef LLVM_PASS_ANALYSIS_SUPPORT_H
 #define LLVM_PASS_ANALYSIS_SUPPORT_H
 
+namespace llvm {
+
 // No need to include Pass.h, we are being included by it!
 
 //===----------------------------------------------------------------------===//
@@ -133,4 +135,6 @@
   return dynamic_cast<AnalysisType*>(Resolver->getAnalysisToUpdate(PI));
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/PassManager.h b/include/llvm/PassManager.h
index c47abda..b1d369b 100644
--- a/include/llvm/PassManager.h
+++ b/include/llvm/PassManager.h
@@ -17,6 +17,8 @@
 #ifndef LLVM_PASSMANAGER_H
 #define LLVM_PASSMANAGER_H
 
+namespace llvm {
+
 class Pass;
 class Module;
 class ModuleProvider;
@@ -72,4 +74,6 @@
   bool run(Function &F);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h
index 226ee29..d985bf1 100644
--- a/include/llvm/PassSupport.h
+++ b/include/llvm/PassSupport.h
@@ -23,6 +23,8 @@
 
 // No need to include Pass.h, we are being included by it!
 
+namespace llvm {
+
 class TargetMachine;
 
 //===---------------------------------------------------------------------------
@@ -395,4 +397,7 @@
 struct IncludeFile {
   IncludeFile(void *);
 };
+
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/SlotCalculator.h b/include/llvm/SlotCalculator.h
index 7e56de9..596f932 100644
--- a/include/llvm/SlotCalculator.h
+++ b/include/llvm/SlotCalculator.h
@@ -22,6 +22,9 @@
 
 #include <vector>
 #include <map>
+
+namespace llvm {
+
 class Value;
 class Module;
 class Function;
@@ -92,4 +95,6 @@
   void processSymbolTableConstants(const SymbolTable *ST);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/Annotation.h b/include/llvm/Support/Annotation.h
index 075ffc2..cee7ab7 100644
--- a/include/llvm/Support/Annotation.h
+++ b/include/llvm/Support/Annotation.h
@@ -25,6 +25,8 @@
 #include <string>
 #include <cassert>
 
+namespace llvm {
+
 class AnnotationID;
 class Annotation;
 class Annotable;
@@ -217,4 +219,6 @@
   return A;
 }
 
+} // End namespace llvm
+
 #endif
diff --git a/include/llvm/Support/CFG.h b/include/llvm/Support/CFG.h
index 26616db..bbe1701 100644
--- a/include/llvm/Support/CFG.h
+++ b/include/llvm/Support/CFG.h
@@ -20,6 +20,8 @@
 #include "llvm/InstrTypes.h"
 #include "Support/iterator"
 
+namespace llvm {
+
 //===--------------------------------------------------------------------===//
 // BasicBlock pred_iterator definition
 //===--------------------------------------------------------------------===//
@@ -264,4 +266,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/CallSite.h b/include/llvm/Support/CallSite.h
index 5e3fd3e..8f7cf1a 100644
--- a/include/llvm/Support/CallSite.h
+++ b/include/llvm/Support/CallSite.h
@@ -23,6 +23,8 @@
 
 #include "llvm/Instruction.h"
 
+namespace llvm {
+
 class CallInst;
 class InvokeInst;
 
@@ -100,4 +102,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/Casting.h b/include/llvm/Support/Casting.h
index 065919c..4b070c1 100644
--- a/include/llvm/Support/Casting.h
+++ b/include/llvm/Support/Casting.h
@@ -15,6 +15,8 @@
 #ifndef SUPPORT_CASTING_H
 #define SUPPORT_CASTING_H
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                          isa<x> Support Templates
 //===----------------------------------------------------------------------===//
@@ -293,4 +295,6 @@
 
 #endif
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h
index 01f55a8..df40d80 100644
--- a/include/llvm/Support/CommandLine.h
+++ b/include/llvm/Support/CommandLine.h
@@ -27,6 +27,7 @@
 #include <cassert>
 #include "boost/type_traits/object_traits.hpp"
 
+namespace llvm {
 /// cl Namespace - This namespace contains all of the command line option
 /// processing machinery.  It is intentionally a short name to make qualified
 /// usage concise.
@@ -1022,4 +1023,6 @@
 
 } // End namespace cl
 
+} // End namespace llvm
+
 #endif
diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h
index c173549..d97b73e 100644
--- a/include/llvm/Support/ConstantRange.h
+++ b/include/llvm/Support/ConstantRange.h
@@ -26,6 +26,9 @@
 
 #include "Support/DataTypes.h"
 #include <iosfwd>
+
+namespace llvm {
+
 class ConstantIntegral;
 class Type;
 
@@ -124,4 +127,6 @@
   return OS;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/DOTGraphTraits.h b/include/llvm/Support/DOTGraphTraits.h
index 002a78e..63837b7 100644
--- a/include/llvm/Support/DOTGraphTraits.h
+++ b/include/llvm/Support/DOTGraphTraits.h
@@ -19,6 +19,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// DefaultDOTGraphTraits - This class provides the default implementations of
 /// all of the DOTGraphTraits methods.  If a specialization does not need to
 /// override all methods here it should inherit so that it can get the default
@@ -96,4 +98,6 @@
 template <typename Ty>
 class DOTGraphTraits : public DefaultDOTGraphTraits {};
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/Debug.h b/include/llvm/Support/Debug.h
index 8cba057..66a2088 100644
--- a/include/llvm/Support/Debug.h
+++ b/include/llvm/Support/Debug.h
@@ -26,6 +26,8 @@
 #ifndef SUPPORT_DEBUG_H
 #define SUPPORT_DEBUG_H
 
+namespace llvm {
+
 // DebugFlag - This boolean is set to true if the '-debug' command line option
 // is specified.  This should probably not be referenced directly, instead, use
 // the DEBUG macro below.
@@ -57,4 +59,6 @@
   do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
 #endif
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/DynamicLinker.h b/include/llvm/Support/DynamicLinker.h
index 8f02708..fec9a45 100644
--- a/include/llvm/Support/DynamicLinker.h
+++ b/include/llvm/Support/DynamicLinker.h
@@ -18,6 +18,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// LinkDynamicObject - Load the named file as a dynamic library
 /// and link it with the currently running process. Returns false
 /// on success, true if there is an error (and sets ErrorMessage
@@ -33,4 +35,6 @@
 void *GetAddressOfSymbol (const char *symbolName);
 void *GetAddressOfSymbol (const std::string &symbolName);
 
+} // End llvm namespace
+
 #endif // SUPPORT_DYNAMICLINKER_H
diff --git a/include/llvm/Support/FileUtilities.h b/include/llvm/Support/FileUtilities.h
index 0dfa625..c276ec7 100644
--- a/include/llvm/Support/FileUtilities.h
+++ b/include/llvm/Support/FileUtilities.h
@@ -17,6 +17,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// CheckMagic - Returns true IFF the file named FN begins with Magic. FN must
 /// name a readable file.
 ///
@@ -95,4 +97,6 @@
 ///
 bool MakeFileReadable (const std::string & Filename);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h
index 2cb8fcc..7e5aa80 100644
--- a/include/llvm/Support/GraphWriter.h
+++ b/include/llvm/Support/GraphWriter.h
@@ -28,6 +28,8 @@
 #include <vector>
 #include <iostream>
 
+namespace llvm {
+
 namespace DOT {  // Private functions...
   inline std::string EscapeString(const std::string &Label) {
     std::string Str(Label);
@@ -206,4 +208,6 @@
   return O;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/InstIterator.h b/include/llvm/Support/InstIterator.h
index 4c2d185..31c8b66 100644
--- a/include/llvm/Support/InstIterator.h
+++ b/include/llvm/Support/InstIterator.h
@@ -22,6 +22,8 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Function.h"
 
+namespace llvm {
+
 // This class implements inst_begin() & inst_end() for
 // inst_iterator and const_inst_iterator's.
 //
@@ -137,4 +139,6 @@
   return const_inst_iterator(F, true);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/InstVisitor.h b/include/llvm/Support/InstVisitor.h
index de1bce9..9a34edb 100644
--- a/include/llvm/Support/InstVisitor.h
+++ b/include/llvm/Support/InstVisitor.h
@@ -52,6 +52,8 @@
 
 #include "llvm/Instruction.h"
 
+namespace llvm {
+
 class Module;
 
 // We operate on opaque instruction classes, so forward declare all instruction
@@ -64,7 +66,6 @@
 class TerminatorInst; class BinaryOperator;
 class AllocationInst;
 
-
 #define DELEGATE(CLASS_TO_VISIT) \
   return ((SubClass*)this)->visit##CLASS_TO_VISIT((CLASS_TO_VISIT&)I)
 
@@ -186,4 +187,6 @@
 
 #undef DELEGATE
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/LeakDetector.h b/include/llvm/Support/LeakDetector.h
index b39e0b5..e2ce9c5 100644
--- a/include/llvm/Support/LeakDetector.h
+++ b/include/llvm/Support/LeakDetector.h
@@ -23,6 +23,9 @@
 #define SUPPORT_LEAKDETECTOR_H
 
 #include <string>
+
+namespace llvm {
+
 class Value;
 
 struct LeakDetector {
@@ -83,4 +86,6 @@
   static void checkForGarbageImpl(const std::string &Message);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/Linker.h b/include/llvm/Support/Linker.h
index ac39903..9f4c8c2 100644
--- a/include/llvm/Support/Linker.h
+++ b/include/llvm/Support/Linker.h
@@ -15,6 +15,9 @@
 #define LLVM_TRANSFORMATIONS_UTILS_LINKER_H
 
 #include <string>
+
+namespace llvm {
+
 class Module;
 
 // LinkModules - This function links two modules together, with the resulting
@@ -24,5 +27,7 @@
 //
 bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0);
 
+} // End llvm namespace
+
 #endif
 
diff --git a/include/llvm/Support/MallocAllocator.h b/include/llvm/Support/MallocAllocator.h
index 1ba25b0..766a67f 100644
--- a/include/llvm/Support/MallocAllocator.h
+++ b/include/llvm/Support/MallocAllocator.h
@@ -23,6 +23,8 @@
 #include <cstdlib>
 #include <memory>
 
+namespace llvm {
+
 template<typename T>
 struct MallocAllocator {
   typedef size_t size_type;
@@ -79,5 +81,6 @@
   };
 }
 
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/Support/Mangler.h b/include/llvm/Support/Mangler.h
index 1f56ff3..5b312f8 100644
--- a/include/llvm/Support/Mangler.h
+++ b/include/llvm/Support/Mangler.h
@@ -14,12 +14,19 @@
 #ifndef LLVM_SUPPORT_MANGLER_H
 #define LLVM_SUPPORT_MANGLER_H
 
+namespace llvm {
+
 class Value;
 class Module;
+
+} // End llvm namespace
+
 #include <map>
 #include <set>
 #include <string>
 
+namespace llvm {
+
 class Mangler {
   /// This keeps track of which global values have had their names
   /// mangled in the current module.
@@ -54,4 +61,6 @@
   static std::string makeNameProper(const std::string &x);
 };
 
+} // End llvm namespace
+
 #endif // LLVM_SUPPORT_MANGLER_H
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h
index ec74232..74958fb 100644
--- a/include/llvm/Support/MathExtras.h
+++ b/include/llvm/Support/MathExtras.h
@@ -16,6 +16,8 @@
 
 #include "Support/DataTypes.h"
 
+namespace llvm {
+
 inline unsigned log2(uint64_t C) {
   unsigned getPow;
   for (getPow = 0; C > 1; ++getPow)
@@ -33,4 +35,6 @@
   return false;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/PassNameParser.h b/include/llvm/Support/PassNameParser.h
index f63666b..0ffcaba 100644
--- a/include/llvm/Support/PassNameParser.h
+++ b/include/llvm/Support/PassNameParser.h
@@ -28,6 +28,8 @@
 #include <algorithm>
 #include <iostream>
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 // PassNameParser class - Make use of the pass registration mechanism to
 // automatically add a command line argument to opt for each pass.
@@ -114,4 +116,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/SystemUtils.h b/include/llvm/Support/SystemUtils.h
index ccde86c..c874d99 100644
--- a/include/llvm/Support/SystemUtils.h
+++ b/include/llvm/Support/SystemUtils.h
@@ -17,6 +17,8 @@
 
 #include <string>
 
+namespace llvm {
+
 /// isExecutableFile - This function returns true if the filename specified
 /// exists and is executable.
 ///
@@ -45,4 +47,7 @@
 /// wait for it to terminate.
 ///
 int ExecWait (const char * const argv[], const char * const envp[]);
+
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/Timer.h b/include/llvm/Support/Timer.h
index 57ef3f0..ac465bb 100644
--- a/include/llvm/Support/Timer.h
+++ b/include/llvm/Support/Timer.h
@@ -20,6 +20,8 @@
 #include <iosfwd>
 #include <cassert>
 
+namespace llvm {
+
 class TimerGroup;
 
 /// Timer - This class is used to track the amount of time spent between
@@ -157,4 +159,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/ToolRunner.h b/include/llvm/Support/ToolRunner.h
index e23ec7f..8ce3f5d 100644
--- a/include/llvm/Support/ToolRunner.h
+++ b/include/llvm/Support/ToolRunner.h
@@ -20,6 +20,8 @@
 #include "Support/SystemUtils.h"
 #include <vector>
 
+namespace llvm {
+
 class CBE;
 class LLC;
 
@@ -137,4 +139,6 @@
   int OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/TypeInfo.h b/include/llvm/Support/TypeInfo.h
index aa2093a..5d90350 100644
--- a/include/llvm/Support/TypeInfo.h
+++ b/include/llvm/Support/TypeInfo.h
@@ -18,6 +18,8 @@
 
 #include <typeinfo>
 
+namespace llvm {
+
 struct TypeInfo {
   TypeInfo() {                     // needed for containers
     struct Nil {};  // Anonymous class distinct from all others...
@@ -69,4 +71,6 @@
   return !(lhs < rhs);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Support/ValueHolder.h b/include/llvm/Support/ValueHolder.h
index 62ab9d9..bab2012 100644
--- a/include/llvm/Support/ValueHolder.h
+++ b/include/llvm/Support/ValueHolder.h
@@ -20,6 +20,8 @@
 
 #include "llvm/User.h"
 
+namespace llvm {
+
 struct ValueHolder : public User {
   ValueHolder(Value *V = 0);
   ValueHolder(const ValueHolder &VH) : User(VH.getType(), Value::TypeVal) {
@@ -46,4 +48,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/SymbolTable.h b/include/llvm/SymbolTable.h
index 42f15aa..8502375 100644
--- a/include/llvm/SymbolTable.h
+++ b/include/llvm/SymbolTable.h
@@ -26,6 +26,8 @@
 #include "llvm/Value.h"
 #include <map>
 
+namespace llvm {
+
 class SymbolTable : public AbstractTypeUser,
 		    public std::map<const Type *, 
                                     std::map<const std::string, Value *> > {
@@ -132,4 +134,6 @@
   virtual void typeBecameConcrete(const DerivedType *AbsTy);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/SymbolTableListTraits.h b/include/llvm/SymbolTableListTraits.h
index 820f391..46be356 100644
--- a/include/llvm/SymbolTableListTraits.h
+++ b/include/llvm/SymbolTableListTraits.h
@@ -25,6 +25,8 @@
 #ifndef LLVM_SYMBOLTABLELISTTRAITS_H
 #define LLVM_SYMBOLTABLELISTTRAITS_H
 
+namespace llvm {
+
 template<typename NodeTy> class ilist_iterator;
 template<typename NodeTy, typename Traits> class iplist;
 template<typename Ty> struct ilist_traits;
@@ -72,4 +74,6 @@
   void setParent(SymTabClass *Parent);  // This is private!
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/System/Signals.h b/include/llvm/System/Signals.h
index ce12301..0cbf398 100644
--- a/include/llvm/System/Signals.h
+++ b/include/llvm/System/Signals.h
@@ -17,10 +17,13 @@
 
 #include <string>
 
+namespace llvm {
+
 // RemoveFileOnSignal - This function registers signal handlers to ensure that
 // if a signal gets delivered that the named file is removed.
 //
 void RemoveFileOnSignal(const std::string &Filename);
 
-#endif
+} // End llvm namespace
 
+#endif
diff --git a/include/llvm/Target/MRegisterInfo.h b/include/llvm/Target/MRegisterInfo.h
index a87c74f..3217b47 100644
--- a/include/llvm/Target/MRegisterInfo.h
+++ b/include/llvm/Target/MRegisterInfo.h
@@ -19,6 +19,8 @@
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include <cassert>
 
+namespace llvm {
+
 class Type;
 class MachineFunction;
 
@@ -280,4 +282,6 @@
                            MachineBasicBlock &MBB) const = 0;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetCacheInfo.h b/include/llvm/Target/TargetCacheInfo.h
index 56f20bf5..357adf0 100644
--- a/include/llvm/Target/TargetCacheInfo.h
+++ b/include/llvm/Target/TargetCacheInfo.h
@@ -16,6 +16,8 @@
 
 #include "Support/DataTypes.h"
 
+namespace llvm {
+
 class TargetMachine;
 
 struct TargetCacheInfo {
@@ -59,4 +61,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h
index 8dcb625..9be9564 100644
--- a/include/llvm/Target/TargetData.h
+++ b/include/llvm/Target/TargetData.h
@@ -24,6 +24,9 @@
 #include "Support/Annotation.h"
 #include "Support/DataTypes.h"
 #include <vector>
+
+namespace llvm {
+
 class Value;
 class Type;
 class StructType;
@@ -101,4 +104,6 @@
   inline StructLayout(const StructType *ST, const TargetData &TD);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetFrameInfo.h b/include/llvm/Target/TargetFrameInfo.h
index 0f82e27..2b968fa 100644
--- a/include/llvm/Target/TargetFrameInfo.h
+++ b/include/llvm/Target/TargetFrameInfo.h
@@ -14,6 +14,8 @@
 #ifndef LLVM_TARGET_TARGETFRAMEINFO_H
 #define LLVM_TARGET_TARGETFRAMEINFO_H
 
+namespace llvm {
+
 class MachineFunction;
 
 struct TargetFrameInfo {
@@ -99,4 +101,6 @@
   virtual int getDynamicAreaBaseRegNum()               const { abort(); }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetInstrInfo.h b/include/llvm/Target/TargetInstrInfo.h
index 76cfb39..c6afba5 100644
--- a/include/llvm/Target/TargetInstrInfo.h
+++ b/include/llvm/Target/TargetInstrInfo.h
@@ -18,6 +18,8 @@
 #include <vector>
 #include <cassert>
 
+namespace llvm {
+
 class MachineInstr;
 class TargetMachine;
 class Value;
@@ -415,4 +417,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetMachine.h b/include/llvm/Target/TargetMachine.h
index af06349..c0771a1 100644
--- a/include/llvm/Target/TargetMachine.h
+++ b/include/llvm/Target/TargetMachine.h
@@ -17,6 +17,8 @@
 #include "llvm/Target/TargetData.h"
 #include <cassert>
 
+namespace llvm {
+
 class TargetInstrInfo;
 class TargetInstrDescriptor;
 class TargetSchedInfo;
@@ -117,4 +119,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetMachineImpls.h b/include/llvm/Target/TargetMachineImpls.h
index 670b2dc..3ca20c7 100644
--- a/include/llvm/Target/TargetMachineImpls.h
+++ b/include/llvm/Target/TargetMachineImpls.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_TARGET_TARGETMACHINEIMPLS_H
 #define LLVM_TARGET_TARGETMACHINEIMPLS_H
 
+namespace llvm {
+
 class TargetMachine;
 class Module;
 
@@ -30,4 +32,6 @@
 //
 TargetMachine *allocateX86TargetMachine(const Module &M);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetRegInfo.h b/include/llvm/Target/TargetRegInfo.h
index 36bfc0b..f9f67c7 100644
--- a/include/llvm/Target/TargetRegInfo.h
+++ b/include/llvm/Target/TargetRegInfo.h
@@ -19,6 +19,8 @@
 #include <string>
 #include <cassert>
 
+namespace llvm {
+
 class TargetMachine;
 class IGNode;
 class Type;
@@ -289,4 +291,6 @@
   virtual int getSpilledRegSize(int RegType) const = 0;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Target/TargetSchedInfo.h b/include/llvm/Target/TargetSchedInfo.h
index dd8df32..ae97d10 100644
--- a/include/llvm/Target/TargetSchedInfo.h
+++ b/include/llvm/Target/TargetSchedInfo.h
@@ -18,6 +18,8 @@
 #include "Support/hash_map"
 #include <string>
 
+namespace llvm {
+
 typedef long long cycles_t; 
 static const cycles_t HUGE_LATENCY = ~((long long) 1 << (sizeof(cycles_t)-2));
 static const cycles_t INVALID_LATENCY = -HUGE_LATENCY; 
@@ -36,13 +38,17 @@
   OpCodePair();			// disable for now
 };
 
+} // End llvm namespace
+
 namespace HASH_NAMESPACE {
-  template <> struct hash<OpCodePair> {
-    size_t operator()(const OpCodePair& pair) const {
+  template <> struct hash<llvm::OpCodePair> {
+    size_t operator()(const llvm::OpCodePair& pair) const {
       return hash<long>()(pair.val);
     }
   };
-}
+} // End HASH_NAMESPACE (a macro) namespace
+
+namespace llvm {
 
 //---------------------------------------------------------------------------
 // class MachineResource 
@@ -321,4 +327,6 @@
   
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/IPO.h b/include/llvm/Transforms/IPO.h
index 62ed93c..80f5a52 100644
--- a/include/llvm/Transforms/IPO.h
+++ b/include/llvm/Transforms/IPO.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_TRANSFORMS_IPO_H
 #define LLVM_TRANSFORMS_IPO_H
 
+namespace llvm {
+
 class Pass;
 class Function;
 
@@ -119,4 +121,6 @@
 Pass *createSwapElementsPass();
 Pass *createSortElementsPass();
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/Instrumentation.h b/include/llvm/Transforms/Instrumentation.h
index abe4fc4..035b8d1 100644
--- a/include/llvm/Transforms/Instrumentation.h
+++ b/include/llvm/Transforms/Instrumentation.h
@@ -14,6 +14,8 @@
 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
 #define LLVM_TRANSFORMS_INSTRUMENTATION_H
 
+namespace llvm {
+
 class Pass;
 
 //===----------------------------------------------------------------------===//
@@ -23,4 +25,6 @@
 Pass *createTraceValuesPassForFunction();     // Just trace function entry/exit
 Pass *createTraceValuesPassForBasicBlocks();  // Trace BB's and methods
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/MutateStructTypes.h b/include/llvm/Transforms/MutateStructTypes.h
index f9b753c..c68f2dd 100644
--- a/include/llvm/Transforms/MutateStructTypes.h
+++ b/include/llvm/Transforms/MutateStructTypes.h
@@ -24,6 +24,8 @@
 #include "llvm/Pass.h"
 #include "llvm/AbstractTypeUser.h"
 
+namespace llvm {
+
 class Value;
 class Type;
 class StructType;
@@ -111,4 +113,6 @@
                      unsigned idx = 0);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h
index 81fd597..da17b8d 100644
--- a/include/llvm/Transforms/Scalar.h
+++ b/include/llvm/Transforms/Scalar.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_TRANSFORMS_SCALAR_H
 #define LLVM_TRANSFORMS_SCALAR_H
 
+namespace llvm {
+
 class Pass;
 class FunctionPass;
 class GetElementPtrInst;
@@ -268,4 +270,6 @@
 Pass *createSymbolStrippingPass();
 Pass *createFullSymbolStrippingPass();
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/Utils/BasicBlockUtils.h b/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 4630d53..155eae8 100644
--- a/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -19,6 +19,9 @@
 
 #include "llvm/BasicBlock.h"
 #include "llvm/Support/CFG.h"
+
+namespace llvm {
+
 class Instruction;
 class Pass;
 
@@ -50,7 +53,6 @@
 //
 void RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum);
 
-
 /// isCriticalEdge - Return true if the specified edge is a critical edge.
 /// Critical edges are edges from a block with multiple successors to a block
 /// with multiple predecessors.
@@ -82,5 +84,6 @@
   return MadeChange;
 }
 
+} // End llvm namespace
 
 #endif
diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
index 351deef..f6351d4 100644
--- a/include/llvm/Transforms/Utils/Cloning.h
+++ b/include/llvm/Transforms/Utils/Cloning.h
@@ -20,6 +20,9 @@
 
 #include <vector>
 #include <map>
+
+namespace llvm {
+
 class Module;
 class Function;
 class BasicBlock;
@@ -109,4 +112,6 @@
 /// no jump to it) and returns the new vector of basic blocks.
 std::vector<BasicBlock *> CloneTrace(const std::vector<BasicBlock*> &origTrace);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/Utils/DemoteRegToStack.h b/include/llvm/Transforms/Utils/DemoteRegToStack.h
index 1d6d2c6..5810087 100644
--- a/include/llvm/Transforms/Utils/DemoteRegToStack.h
+++ b/include/llvm/Transforms/Utils/DemoteRegToStack.h
@@ -24,7 +24,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+namespace llvm {
+
 class Instruction;
 class AllocaInst;
 
 AllocaInst *DemoteRegToStack(Instruction &X);
+
+} // End llvm namespace
diff --git a/include/llvm/Transforms/Utils/Linker.h b/include/llvm/Transforms/Utils/Linker.h
index ac39903..9f4c8c2 100644
--- a/include/llvm/Transforms/Utils/Linker.h
+++ b/include/llvm/Transforms/Utils/Linker.h
@@ -15,6 +15,9 @@
 #define LLVM_TRANSFORMATIONS_UTILS_LINKER_H
 
 #include <string>
+
+namespace llvm {
+
 class Module;
 
 // LinkModules - This function links two modules together, with the resulting
@@ -24,5 +27,7 @@
 //
 bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0);
 
+} // End llvm namespace
+
 #endif
 
diff --git a/include/llvm/Transforms/Utils/Local.h b/include/llvm/Transforms/Utils/Local.h
index 286aef9..2f83174 100644
--- a/include/llvm/Transforms/Utils/Local.h
+++ b/include/llvm/Transforms/Utils/Local.h
@@ -16,6 +16,9 @@
 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
 
 #include "llvm/Function.h"
+
+namespace llvm {
+
 class Pass;
 
 //===----------------------------------------------------------------------===//
@@ -67,4 +70,6 @@
 ///
 bool SimplifyCFG(BasicBlock *BB);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/Utils/PromoteMemToReg.h b/include/llvm/Transforms/Utils/PromoteMemToReg.h
index 57d5dae..38ea373 100644
--- a/include/llvm/Transforms/Utils/PromoteMemToReg.h
+++ b/include/llvm/Transforms/Utils/PromoteMemToReg.h
@@ -15,11 +15,14 @@
 #ifndef TRANSFORMS_UTILS_PROMOTEMEMTOREG_H
 #define TRANSFORMS_UTILS_PROMOTEMEMTOREG_H
 
+#include <vector>
+
+namespace llvm {
+
 class AllocaInst;
 class DominatorTree;
 class DominanceFrontier;
 class TargetData;
-#include <vector>
 
 /// isAllocaPromotable - Return true if this alloca is legal for promotion.
 /// This is true if there are only loads and stores to the alloca...
@@ -35,4 +38,6 @@
                      DominatorTree &DT, DominanceFrontier &DF,
                      const TargetData &TD);
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h b/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
index a59517c..590d510 100644
--- a/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
+++ b/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
@@ -20,6 +20,8 @@
 
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 struct UnifyFunctionExitNodes : public FunctionPass {
   BasicBlock *ReturnBlock, *UnwindBlock;
 public:
@@ -39,4 +41,6 @@
 
 Pass *createUnifyFunctionExitNodesPass();
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Type.def b/include/llvm/Type.def
index 566a9a3..6101cd0 100644
--- a/include/llvm/Type.def
+++ b/include/llvm/Type.def
@@ -16,7 +16,7 @@
 // NOTE: NO INCLUDE GUARD DESIRED!
 
 
-// If the user didn't specify one of the macros, give a default noop defn.
+// If the user did not specify one of the macros, give a default noop defn.
 //
 #ifndef HANDLE_PRIM_TYPE
 #define HANDLE_PRIM_TYPE(x,y)
diff --git a/include/llvm/Type.h b/include/llvm/Type.h
index 4c9fd1d..ba4ac34 100644
--- a/include/llvm/Type.h
+++ b/include/llvm/Type.h
@@ -37,6 +37,8 @@
 #include "Support/GraphTraits.h"
 #include "Support/iterator"
 
+namespace llvm {
+
 class DerivedType;
 class FunctionType;
 class ArrayType;
@@ -324,4 +326,6 @@
   return Ty.getPrimitiveID() == Type::PointerTyID;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Use.h b/include/llvm/Use.h
index 4deee30..f94045b 100644
--- a/include/llvm/Use.h
+++ b/include/llvm/Use.h
@@ -17,6 +17,9 @@
 #define LLVM_USE_H
 
 #include "Support/ilist"
+
+namespace llvm {
+
 template<typename NodeTy> struct ilist_traits;
 class Value;
 class User;
@@ -77,13 +80,13 @@
 };
 
 
-template<> struct simplify_type<Use> {
+template<> struct std::simplify_type<Use> {
   typedef Value* SimpleType;
   static SimpleType getSimplifiedValue(const Use &Val) {
     return (SimpleType)Val.get();
   }
 };
-template<> struct simplify_type<const Use> {
+template<> struct std::simplify_type<const Use> {
   typedef Value* SimpleType;
   static SimpleType getSimplifiedValue(const Use &Val) {
     return (SimpleType)Val.get();
@@ -150,4 +153,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/User.h b/include/llvm/User.h
index aba56d5..cdd9b53 100644
--- a/include/llvm/User.h
+++ b/include/llvm/User.h
@@ -22,6 +22,8 @@
 #include "llvm/Value.h"
 #include <vector>
 
+namespace llvm {
+
 class User : public Value {
   User(const User &);             // Do not implement
 protected:
@@ -110,4 +112,6 @@
 template<> struct simplify_type<const User::const_op_iterator>
   : public simplify_type<User::const_op_iterator> {};
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index 537bcba..e92d6fc 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -23,6 +23,8 @@
 #include "Support/Casting.h"
 #include <iostream>
 
+namespace llvm {
+
 class Type;
 class Constant;
 class Argument;
@@ -198,4 +200,6 @@
   return isa<GlobalVariable>(Val) || isa<Function>(Val);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h
index db82b54..e0a551a 100644
--- a/include/llvm/iMemory.h
+++ b/include/llvm/iMemory.h
@@ -16,6 +16,9 @@
 #define LLVM_IMEMORY_H
 
 #include "llvm/Instruction.h"
+
+namespace llvm {
+
 class PointerType;
 
 //===----------------------------------------------------------------------===//
@@ -296,4 +299,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif // LLVM_IMEMORY_H
diff --git a/include/llvm/iOperators.h b/include/llvm/iOperators.h
index 39bfe14..ecf9917 100644
--- a/include/llvm/iOperators.h
+++ b/include/llvm/iOperators.h
@@ -16,6 +16,8 @@
 
 #include "llvm/InstrTypes.h"
 
+namespace llvm {
+
 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
 /// le, or ge.
 ///
@@ -63,4 +65,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h
index 4e23afd..c611e06 100644
--- a/include/llvm/iOther.h
+++ b/include/llvm/iOther.h
@@ -17,6 +17,8 @@
 
 #include "llvm/InstrTypes.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                                 CastInst Class
 //===----------------------------------------------------------------------===//
@@ -195,4 +197,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/iPHINode.h b/include/llvm/iPHINode.h
index 54b867d..191de04 100644
--- a/include/llvm/iPHINode.h
+++ b/include/llvm/iPHINode.h
@@ -15,6 +15,9 @@
 #define LLVM_IPHINODE_H
 
 #include "llvm/Instruction.h"
+
+namespace llvm {
+
 class BasicBlock;
 
 //===----------------------------------------------------------------------===//
@@ -112,4 +115,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h
index 5f435a0..93e3adce 100644
--- a/include/llvm/iTerminators.h
+++ b/include/llvm/iTerminators.h
@@ -18,6 +18,8 @@
 
 #include "llvm/InstrTypes.h"
 
+namespace llvm {
+
 //===---------------------------------------------------------------------------
 // ReturnInst - Return a value (possibly void), from a function.  Execution does
 //              not continue in this function any longer.
@@ -306,4 +308,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp
index 3acdf78..c881ec2 100644
--- a/lib/Analysis/AliasAnalysis.cpp
+++ b/lib/Analysis/AliasAnalysis.cpp
@@ -29,6 +29,8 @@
 #include "llvm/iMemory.h"
 #include "llvm/Target/TargetData.h"
 
+namespace llvm {
+
 // Register the AliasAnalysis interface, providing a nice name to refer to.
 namespace {
   RegisterAnalysisGroup<AliasAnalysis> Z("Alias Analysis");
@@ -123,3 +125,5 @@
   // Declare that we implement the AliasAnalysis interface
   RegisterAnalysisGroup<AliasAnalysis, NoAA> Y;
 }  // End of anonymous namespace
+
+} // End llvm namespace
diff --git a/lib/Analysis/AliasAnalysisCounter.cpp b/lib/Analysis/AliasAnalysisCounter.cpp
index 5820565..59036a4 100644
--- a/lib/Analysis/AliasAnalysisCounter.cpp
+++ b/lib/Analysis/AliasAnalysisCounter.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Pass.h"
 #include <iostream>
 
+namespace llvm {
+
 namespace {
   class AliasAnalysisCounter : public Pass, public AliasAnalysis {
     unsigned No, May, Must;
@@ -108,3 +110,5 @@
   X("count-aa", "Count Alias Analysis Query Responses");
   RegisterAnalysisGroup<AliasAnalysis, AliasAnalysisCounter> Y;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/AliasAnalysisEvaluator.cpp b/lib/Analysis/AliasAnalysisEvaluator.cpp
index d4a7d18..2c967c5 100644
--- a/lib/Analysis/AliasAnalysisEvaluator.cpp
+++ b/lib/Analysis/AliasAnalysisEvaluator.cpp
@@ -26,6 +26,8 @@
 #include "Support/CommandLine.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   cl::opt<bool> PrintNo  ("print-no-aliases", cl::ReallyHidden);
   cl::opt<bool> PrintMay ("print-may-aliases", cl::ReallyHidden);
@@ -114,3 +116,5 @@
             << May*100/Sum << "%/" << Must*100/Sum<<"%\n";
   return false;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp
index c280032..4a29344 100644
--- a/lib/Analysis/AliasSetTracker.cpp
+++ b/lib/Analysis/AliasSetTracker.cpp
@@ -21,6 +21,8 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/InstIterator.h"
 
+namespace llvm {
+
 /// mergeSetIn - Merge the specified alias set into this alias set...
 ///
 void AliasSet::mergeSetIn(AliasSet &AS) {
@@ -294,7 +296,6 @@
 void AliasSet::dump() const { print (std::cerr); }
 void AliasSetTracker::dump() const { print(std::cerr); }
 
-
 //===----------------------------------------------------------------------===//
 //                            AliasSetPrinter Pass
 //===----------------------------------------------------------------------===//
@@ -328,3 +329,5 @@
   RegisterPass<AliasSetPrinter> X("print-alias-sets", "Alias Set Printer",
                                   PassInfo::Analysis | PassInfo::Optimization);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index e60922a..16512c0 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -23,10 +23,11 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Target/TargetData.h"
 
+namespace llvm {
+
 // Make sure that anything that uses AliasAnalysis pulls in this file...
 void BasicAAStub() {}
 
-
 namespace {
   struct BasicAliasAnalysis : public ImmutablePass, public AliasAnalysis {
     
@@ -60,8 +61,6 @@
   InitializeAliasAnalysis(this);
 }
 
-
-
 // hasUniqueAddress - Return true if the specified value points to something
 // with a unique, discernable, address.
 static inline bool hasUniqueAddress(const Value *V) {
@@ -364,3 +363,4 @@
   return MayAlias;
 }
 
+} // End llvm namespace
diff --git a/lib/Analysis/CFGPrinter.cpp b/lib/Analysis/CFGPrinter.cpp
index ac93d4c..bd11522 100644
--- a/lib/Analysis/CFGPrinter.cpp
+++ b/lib/Analysis/CFGPrinter.cpp
@@ -26,6 +26,8 @@
 #include <sstream>
 #include <fstream>
 
+namespace llvm {
+
 /// CFGOnly flag - This is used to control whether or not the CFG graph printer
 /// prints out the contents of basic blocks or not.  This is acceptable because
 /// this code is only really used for debugging purposes.
@@ -112,9 +114,6 @@
                                   "Print CFG of function to 'dot' file");
 };
 
-
-
-
 /// viewCFG - This function is meant for use from the debugger.  You can just
 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
 /// program, displaying the CFG of the current function.  This depends on there
@@ -154,3 +153,5 @@
   viewCFG();
   CFGOnly = false;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp
index a9e1204..e180f12 100644
--- a/lib/Analysis/ConstantRange.cpp
+++ b/lib/Analysis/ConstantRange.cpp
@@ -26,6 +26,8 @@
 #include "llvm/Instruction.h"
 #include "llvm/ConstantHandling.h"
 
+namespace llvm {
+
 /// Initialize a full (the default) or empty set for the specified type.
 ///
 ConstantRange::ConstantRange(const Type *Ty, bool Full) {
@@ -248,3 +250,5 @@
 void ConstantRange::dump() const {
   print(std::cerr);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/BottomUpClosure.cpp b/lib/Analysis/DataStructure/BottomUpClosure.cpp
index b4b2e48..66990fd 100644
--- a/lib/Analysis/DataStructure/BottomUpClosure.cpp
+++ b/lib/Analysis/DataStructure/BottomUpClosure.cpp
@@ -20,6 +20,8 @@
 #include "Support/Debug.h"
 #include "DSCallSiteIterator.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> MaxSCC("budatastructure", "Maximum SCC Size in Call Graph");
   Statistic<> NumBUInlines("budatastructures", "Number of graphs inlined");
@@ -316,3 +318,4 @@
   //Graph.writeGraphToFile(std::cerr, "bu_" + F.getName());
 }
 
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/DSCallSiteIterator.h b/lib/Analysis/DataStructure/DSCallSiteIterator.h
index 324111c..df9f369 100644
--- a/lib/Analysis/DataStructure/DSCallSiteIterator.h
+++ b/lib/Analysis/DataStructure/DSCallSiteIterator.h
@@ -19,6 +19,8 @@
 #include "llvm/Analysis/DSGraph.h"
 #include "llvm/Function.h"
 
+namespace llvm {
+
 struct DSCallSiteIterator {
   // FCs are the edges out of the current node are the call site targets...
   const std::vector<DSCallSite> *FCs;
@@ -129,4 +131,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp
index d53c7fa..9cf77ae 100644
--- a/lib/Analysis/DataStructure/DataStructure.cpp
+++ b/lib/Analysis/DataStructure/DataStructure.cpp
@@ -23,6 +23,8 @@
 #include "Support/Timer.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumFolds          ("dsnode", "Number of nodes completely folded");
   Statistic<> NumCallNodesMerged("dsnode", "Number of call nodes merged");
@@ -161,7 +163,6 @@
   return getSize() == 1 && Ty == Type::VoidTy && isArray();
 }
 
-
 namespace {
   /// TypeElementWalker Class - Used for implementation of physical subtyping...
   ///
@@ -252,7 +253,7 @@
       }
     }
   };
-}
+} // end anonymous namespace
 
 /// ElementTypesAreCompatible - Check to see if the specified types are
 /// "physically" compatible.  If so, return true, else return false.  We only
@@ -1639,6 +1640,7 @@
   removeTriviallyDeadNodes();
 }
 
+
 /// computeNodeMapping - Given roots in two different DSGraphs, traverse the
 /// nodes reachable from the two graphs, computing the mapping of nodes from
 /// the first to the second graph.
@@ -1669,3 +1671,4 @@
       computeNodeMapping(N1->getLink(i), N2->getLink(N2Idx+i), NodeMap);
 }
 
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/DataStructureAA.cpp b/lib/Analysis/DataStructure/DataStructureAA.cpp
index 99773e3..4b55da7 100644
--- a/lib/Analysis/DataStructure/DataStructureAA.cpp
+++ b/lib/Analysis/DataStructure/DataStructureAA.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Module.h"
 
+namespace llvm {
+
 namespace {
   class DSAA : public Pass, public AliasAnalysis {
     TDDataStructures *TD;
@@ -176,3 +178,5 @@
 #endif
   return getAnalysis<AliasAnalysis>().getMustAliases(P, RetVals);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/DataStructureOpt.cpp b/lib/Analysis/DataStructure/DataStructureOpt.cpp
index 0ca7d6b..d037b52 100644
--- a/lib/Analysis/DataStructure/DataStructureOpt.cpp
+++ b/lib/Analysis/DataStructure/DataStructureOpt.cpp
@@ -18,6 +18,8 @@
 #include "llvm/Constant.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<>
   NumGlobalsConstanted("ds-opt", "Number of globals marked constant");
@@ -47,7 +49,6 @@
   RegisterOpt<DSOpt> X("ds-opt", "DSA-based simple optimizations");
 }
 
-
 /// OptimizeGlobals - This method uses information taken from DSA to optimize
 /// global variables.
 ///
@@ -96,3 +97,5 @@
     }
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/DataStructureStats.cpp b/lib/Analysis/DataStructure/DataStructureStats.cpp
index 8d29848..3659c90 100644
--- a/lib/Analysis/DataStructure/DataStructureStats.cpp
+++ b/lib/Analysis/DataStructure/DataStructureStats.cpp
@@ -19,6 +19,8 @@
 #include "Support/Statistic.h"
 #include <vector>
 
+namespace llvm {
+
 namespace {
   Statistic<> TotalNumCallees("totalcallees",
                 "Total number of callee functions at all indirect call sites");
@@ -139,3 +141,5 @@
   visit(F);
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/GraphChecker.cpp b/lib/Analysis/DataStructure/GraphChecker.cpp
index b0164da..11ebc69 100644
--- a/lib/Analysis/DataStructure/GraphChecker.cpp
+++ b/lib/Analysis/DataStructure/GraphChecker.cpp
@@ -29,6 +29,8 @@
 #include "llvm/Value.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   enum DSPass { local, bu, td };
   cl::opt<DSPass>
@@ -193,3 +195,5 @@
       }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/IPModRef.cpp b/lib/Analysis/DataStructure/IPModRef.cpp
index 64b60d4..01b5bd0 100644
--- a/lib/Analysis/DataStructure/IPModRef.cpp
+++ b/lib/Analysis/DataStructure/IPModRef.cpp
@@ -23,6 +23,8 @@
 #include "Support/StringExtras.h"
 #include <vector>
 
+namespace llvm {
+
 //----------------------------------------------------------------------------
 // Private constants and data
 //----------------------------------------------------------------------------
@@ -441,3 +443,5 @@
 {
   print(std::cerr);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/Local.cpp b/lib/Analysis/DataStructure/Local.cpp
index 0aca21a..253cbf7 100644
--- a/lib/Analysis/DataStructure/Local.cpp
+++ b/lib/Analysis/DataStructure/Local.cpp
@@ -28,6 +28,8 @@
 //
 #include "llvm/Module.h"
 
+namespace llvm {
+
 static RegisterAnalysis<LocalDataStructures>
 X("datastructure", "Local Data Structure Analysis");
 
@@ -41,8 +43,8 @@
     return false;
   }
 }
-using namespace DS;
 
+using namespace DS;
 
 namespace {
   cl::opt<bool>
@@ -144,6 +146,8 @@
   };
 }
 
+using namespace DS;
+
 //===----------------------------------------------------------------------===//
 // DSGraph constructor - Simply use the GraphBuilder to construct the local
 // graph.
@@ -617,3 +621,5 @@
   delete GlobalsGraph;
   GlobalsGraph = 0;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/MemoryDepAnalysis.cpp b/lib/Analysis/DataStructure/MemoryDepAnalysis.cpp
index 076836a..e61c076 100644
--- a/lib/Analysis/DataStructure/MemoryDepAnalysis.cpp
+++ b/lib/Analysis/DataStructure/MemoryDepAnalysis.cpp
@@ -31,6 +31,7 @@
 #include "Support/hash_map"
 #include "Support/hash_set"
 
+namespace llvm {
 
 ///--------------------------------------------------------------------------
 /// struct ModRefTable:
@@ -122,7 +123,7 @@
 class ModRefInfoBuilder : public InstVisitor<ModRefInfoBuilder> {
   const DSGraph&            funcGraph;
   const FunctionModRefInfo& funcModRef;
-  ModRefTable&              modRefTable;
+  struct ModRefTable&       modRefTable;
 
   ModRefInfoBuilder();                         // DO NOT IMPLEMENT
   ModRefInfoBuilder(const ModRefInfoBuilder&); // DO NOT IMPLEMENT
@@ -498,3 +499,5 @@
 static RegisterAnalysis<MemoryDepAnalysis>
 Z("memdep", "Memory Dependence Analysis");
 
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/Parallelize.cpp b/lib/Analysis/DataStructure/Parallelize.cpp
index 77e6ed3..fd39b6b 100644
--- a/lib/Analysis/DataStructure/Parallelize.cpp
+++ b/lib/Analysis/DataStructure/Parallelize.cpp
@@ -53,6 +53,8 @@
 #include <functional>
 #include <algorithm>
 
+namespace llvm {
+
 //---------------------------------------------------------------------------- 
 // Global constants used in marking Cilk functions and function calls.
 //---------------------------------------------------------------------------- 
@@ -535,3 +537,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/PgmDependenceGraph.cpp b/lib/Analysis/DataStructure/PgmDependenceGraph.cpp
index ef44cb3..b861c89 100644
--- a/lib/Analysis/DataStructure/PgmDependenceGraph.cpp
+++ b/lib/Analysis/DataStructure/PgmDependenceGraph.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Function.h"
 
+namespace llvm {
 
 //----------------------------------------------------------------------------
 // class DepIterState
@@ -253,3 +254,5 @@
 
 static RegisterAnalysis<PgmDependenceGraph>
 Z("pgmdep", "Enumerate Program Dependence Graph (data and control)");
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp
index 9587979..9902906 100644
--- a/lib/Analysis/DataStructure/Printer.cpp
+++ b/lib/Analysis/DataStructure/Printer.cpp
@@ -23,6 +23,8 @@
 #include <fstream>
 #include <sstream>
 
+namespace llvm {
+
 // OnlyPrintMain - The DataStructure printer exposes this option to allow
 // printing of only the graph for "main".
 //
@@ -32,7 +34,6 @@
   Statistic<> NumFoldedNodes ("dsnode", "Number of folded nodes (in final graph)");
 }
 
-
 void DSNode::dump() const { print(std::cerr, 0); }
 
 static std::string getCaption(const DSNode *N, const DSGraph *G) {
@@ -280,3 +281,5 @@
 void TDDataStructures::print(std::ostream &O, const Module *M) const {
   printCollection(*this, O, M, "td.");
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/Steensgaard.cpp b/lib/Analysis/DataStructure/Steensgaard.cpp
index 8bf917f..d868d25 100644
--- a/lib/Analysis/DataStructure/Steensgaard.cpp
+++ b/lib/Analysis/DataStructure/Steensgaard.cpp
@@ -20,6 +20,8 @@
 #include "llvm/Module.h"
 #include "Support/Debug.h"
 
+namespace llvm {
+
 namespace {
   class Steens : public Pass, public AliasAnalysis {
     DSGraph *ResultGraph;
@@ -76,7 +78,6 @@
   RegisterAnalysisGroup<AliasAnalysis, Steens> Y;
 }
 
-
 /// ResolveFunctionCall - Resolve the actual arguments of a call to function F
 /// with the specified call site descriptor.  This function links the arguments
 /// and the return value for the call site context-insensitively.
@@ -235,3 +236,5 @@
   //
   return getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/DataStructure/TopDownClosure.cpp b/lib/Analysis/DataStructure/TopDownClosure.cpp
index ad5a9d72..696368a 100644
--- a/lib/Analysis/DataStructure/TopDownClosure.cpp
+++ b/lib/Analysis/DataStructure/TopDownClosure.cpp
@@ -21,6 +21,8 @@
 #include "Support/Debug.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   RegisterAnalysis<TDDataStructures>   // Register the pass
   Y("tddatastructure", "Top-down Data Structure Analysis");
@@ -310,3 +312,4 @@
         << Graph.getFunctionCalls().size() << "]\n");
 }
 
+} // End llvm namespace
diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp
index 4d8897e..b316390 100644
--- a/lib/Analysis/Expressions.cpp
+++ b/lib/Analysis/Expressions.cpp
@@ -18,6 +18,8 @@
 #include "llvm/ConstantHandling.h"
 #include "llvm/Function.h"
 
+namespace llvm {
+
 ExprType::ExprType(Value *Val) {
   if (Val) 
     if (ConstantInt *CPI = dyn_cast<ConstantInt>(Val)) {
@@ -352,3 +354,5 @@
   // Otherwise, I don't know anything about this value!
   return I;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp
index 8d44242..506198c 100644
--- a/lib/Analysis/IPA/CallGraph.cpp
+++ b/lib/Analysis/IPA/CallGraph.cpp
@@ -53,6 +53,8 @@
 #include "llvm/Support/CallSite.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 static RegisterAnalysis<CallGraph> X("callgraph", "Call Graph Construction");
 
 static const char * const KnownExternalFunctions[] = {
@@ -349,3 +351,5 @@
 }
 
 void CallGraph::stub() {}
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/CallGraphSCCPass.cpp b/lib/Analysis/IPA/CallGraphSCCPass.cpp
index 74da701..e9ab650 100644
--- a/lib/Analysis/IPA/CallGraphSCCPass.cpp
+++ b/lib/Analysis/IPA/CallGraphSCCPass.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Analysis/CallGraph.h"
 #include "Support/SCCIterator.h"
 
+namespace llvm {
+
 /// getAnalysisUsage - For this class, we declare that we require and preserve
 /// the call graph.  If the derived class implements this method, it should
 /// always explicitly call the implementation here.
@@ -35,3 +37,5 @@
     Changed = runOnSCC(*I);
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/DependenceGraph.cpp b/lib/Analysis/IPA/DependenceGraph.cpp
index ead777a..7d62ef0 100644
--- a/lib/Analysis/IPA/DependenceGraph.cpp
+++ b/lib/Analysis/IPA/DependenceGraph.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Analysis/DependenceGraph.h"
 #include "llvm/Function.h"
 
+namespace llvm {
 
 //----------------------------------------------------------------------------
 // class Dependence:
@@ -82,3 +83,5 @@
       if (const DepGraphNode* dgNode = this->getNode(*II))
         dgNode->print(O);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/FindUnsafePointerTypes.cpp b/lib/Analysis/IPA/FindUnsafePointerTypes.cpp
index 7eeff7d..45f5b72 100644
--- a/lib/Analysis/IPA/FindUnsafePointerTypes.cpp
+++ b/lib/Analysis/IPA/FindUnsafePointerTypes.cpp
@@ -30,6 +30,8 @@
 #include "llvm/Support/InstIterator.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 static RegisterAnalysis<FindUnsafePointerTypes>
 X("unsafepointertypes", "Find Unsafe Pointer Types");
 
@@ -99,3 +101,5 @@
     CW << " #" << Counter << ". " << (Value*)*I << "\n";
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/FindUsedTypes.cpp b/lib/Analysis/IPA/FindUsedTypes.cpp
index 80bf378..e930499 100644
--- a/lib/Analysis/IPA/FindUsedTypes.cpp
+++ b/lib/Analysis/IPA/FindUsedTypes.cpp
@@ -21,6 +21,8 @@
 #include "llvm/Assembly/CachedWriter.h"
 #include "llvm/Support/InstIterator.h"
 
+namespace llvm {
+
 static RegisterAnalysis<FindUsedTypes>
 X("printusedtypes", "Find Used Types");
 
@@ -106,3 +108,5 @@
            E = UsedTypes.end(); I != E; ++I)
       o << "  " << *I << "\n";
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/IPModRef.cpp b/lib/Analysis/IPA/IPModRef.cpp
index 64b60d4..01b5bd0 100644
--- a/lib/Analysis/IPA/IPModRef.cpp
+++ b/lib/Analysis/IPA/IPModRef.cpp
@@ -23,6 +23,8 @@
 #include "Support/StringExtras.h"
 #include <vector>
 
+namespace llvm {
+
 //----------------------------------------------------------------------------
 // Private constants and data
 //----------------------------------------------------------------------------
@@ -441,3 +443,5 @@
 {
   print(std::cerr);
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/MemoryDepAnalysis.cpp b/lib/Analysis/IPA/MemoryDepAnalysis.cpp
index 076836a..e61c076 100644
--- a/lib/Analysis/IPA/MemoryDepAnalysis.cpp
+++ b/lib/Analysis/IPA/MemoryDepAnalysis.cpp
@@ -31,6 +31,7 @@
 #include "Support/hash_map"
 #include "Support/hash_set"
 
+namespace llvm {
 
 ///--------------------------------------------------------------------------
 /// struct ModRefTable:
@@ -122,7 +123,7 @@
 class ModRefInfoBuilder : public InstVisitor<ModRefInfoBuilder> {
   const DSGraph&            funcGraph;
   const FunctionModRefInfo& funcModRef;
-  ModRefTable&              modRefTable;
+  struct ModRefTable&       modRefTable;
 
   ModRefInfoBuilder();                         // DO NOT IMPLEMENT
   ModRefInfoBuilder(const ModRefInfoBuilder&); // DO NOT IMPLEMENT
@@ -498,3 +499,5 @@
 static RegisterAnalysis<MemoryDepAnalysis>
 Z("memdep", "Memory Dependence Analysis");
 
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/PgmDependenceGraph.cpp b/lib/Analysis/IPA/PgmDependenceGraph.cpp
index ef44cb3..b861c89 100644
--- a/lib/Analysis/IPA/PgmDependenceGraph.cpp
+++ b/lib/Analysis/IPA/PgmDependenceGraph.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Function.h"
 
+namespace llvm {
 
 //----------------------------------------------------------------------------
 // class DepIterState
@@ -253,3 +254,5 @@
 
 static RegisterAnalysis<PgmDependenceGraph>
 Z("pgmdep", "Enumerate Program Dependence Graph (data and control)");
+
+} // End llvm namespace
diff --git a/lib/Analysis/IPA/PrintSCC.cpp b/lib/Analysis/IPA/PrintSCC.cpp
index 3459381..ce89fff 100644
--- a/lib/Analysis/IPA/PrintSCC.cpp
+++ b/lib/Analysis/IPA/PrintSCC.cpp
@@ -31,6 +31,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/SCCIterator.h"
 
+namespace llvm {
+
 namespace {
   struct CFGSCC : public FunctionPass {
     bool runOnFunction(Function& func);
@@ -101,3 +103,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/InductionVariable.cpp b/lib/Analysis/InductionVariable.cpp
index 3119d31..6e9a209 100644
--- a/lib/Analysis/InductionVariable.cpp
+++ b/lib/Analysis/InductionVariable.cpp
@@ -36,6 +36,8 @@
 #include "llvm/Assembly/Writer.h"
 #include "Support/Debug.h"
 
+namespace llvm {
+
 static bool isLoopInvariant(const Value *V, const Loop *L) {
   if (const Instruction *I = dyn_cast<Instruction>(V))
     return !L->contains(I->getParent());
@@ -299,3 +301,5 @@
   }
   o << "\n";
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/InstCount.cpp b/lib/Analysis/InstCount.cpp
index 4d49478..9177e44 100644
--- a/lib/Analysis/InstCount.cpp
+++ b/lib/Analysis/InstCount.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Support/InstVisitor.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> TotalInsts ("instcount", "Number of instructions (of all types)");
   Statistic<> TotalBlocks("instcount", "Number of basic blocks");
@@ -62,3 +64,5 @@
   visit(F);
   return false;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/Interval.cpp b/lib/Analysis/Interval.cpp
index 28cee83..8f0bdfa 100644
--- a/lib/Analysis/Interval.cpp
+++ b/lib/Analysis/Interval.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Support/CFG.h"
 #include <algorithm>
 
+using namespace llvm;
+
 //===----------------------------------------------------------------------===//
 // Interval Implementation
 //===----------------------------------------------------------------------===//
diff --git a/lib/Analysis/IntervalPartition.cpp b/lib/Analysis/IntervalPartition.cpp
index 2729930..12c196f 100644
--- a/lib/Analysis/IntervalPartition.cpp
+++ b/lib/Analysis/IntervalPartition.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Analysis/IntervalIterator.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 static RegisterAnalysis<IntervalPartition>
 X("intervals", "Interval Partition Construction", true);
 
@@ -108,3 +110,5 @@
   for_each(Intervals.begin(), Intervals.end(), 
 	   bind_obj(this, &IntervalPartition::updatePredecessors));
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp
index 68eaebf..758f1b1 100644
--- a/lib/Analysis/LiveVar/BBLiveVar.cpp
+++ b/lib/Analysis/LiveVar/BBLiveVar.cpp
@@ -21,6 +21,7 @@
 /// BROKEN: Should not include sparc stuff directly into here
 #include "../../Target/Sparc/SparcInternals.h"  //  Only for PHI defn
 
+namespace llvm {
 
 BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
   : BB(bb), MBB(mbb), POID(id) {
@@ -229,6 +230,4 @@
   std::cerr << "  Out: ";  printSet(OutSet);  std::cerr << "\n";
 }
 
-
-
-
+} // End llvm namespace
diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h
index 33a4faf..781143a 100644
--- a/lib/Analysis/LiveVar/BBLiveVar.h
+++ b/lib/Analysis/LiveVar/BBLiveVar.h
@@ -17,6 +17,9 @@
 
 #include "llvm/CodeGen/ValueSet.h"
 #include "Support/hash_map"
+
+namespace llvm {
+
 class BasicBlock;
 class Value;
 class MachineBasicBlock;
@@ -82,4 +85,6 @@
   void printInOutSets() const;    // for printing In/Out sets
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
index 588ec64..8f0e318 100644
--- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
@@ -23,6 +23,8 @@
 #include "Support/CommandLine.h"
 #include "BBLiveVar.h"
 
+namespace llvm {
+
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
 
@@ -318,3 +320,5 @@
     SetAI = NewSet;                 
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/LiveVar/ValueSet.cpp b/lib/Analysis/LiveVar/ValueSet.cpp
index ba944cb..fd82896 100644
--- a/lib/Analysis/LiveVar/ValueSet.cpp
+++ b/lib/Analysis/LiveVar/ValueSet.cpp
@@ -11,6 +11,8 @@
 #include "llvm/Value.h"
 #include <iostream>
 
+namespace llvm {
+
 std::ostream &operator<<(std::ostream &O, RAV V) { // func to print a Value 
   const Value &v = V.V;
   if (v.hasName())
@@ -26,3 +28,4 @@
     std::cerr << RAV(*I);
 }
 
+} // End llvm namespace
diff --git a/lib/Analysis/LoadValueNumbering.cpp b/lib/Analysis/LoadValueNumbering.cpp
index cbcdd0f..2d26379 100644
--- a/lib/Analysis/LoadValueNumbering.cpp
+++ b/lib/Analysis/LoadValueNumbering.cpp
@@ -31,6 +31,8 @@
 #include <algorithm>
 #include <set>
 
+namespace llvm {
+
 namespace {
   // FIXME: This should not be a FunctionPass.
   struct LoadVN : public FunctionPass, public ValueNumbering {
@@ -70,8 +72,6 @@
   RegisterAnalysisGroup<ValueNumbering, LoadVN> Y;
 }
 
-
-
 Pass *createLoadValueNumberingPass() { return new LoadVN(); }
 
 
@@ -340,3 +340,5 @@
     return true;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp
index c1f9788..68e7d2f 100644
--- a/lib/Analysis/LoopInfo.cpp
+++ b/lib/Analysis/LoopInfo.cpp
@@ -21,6 +21,8 @@
 #include "Support/DepthFirstIterator.h"
 #include <algorithm>
 
+namespace llvm {
+
 static RegisterAnalysis<LoopInfo>
 X("loops", "Natural Loop Construction", true);
 
@@ -367,3 +369,5 @@
     I = std::find(I+1, ExitBlocks.end(), Old);
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp
index ee31c36..2589c85 100644
--- a/lib/Analysis/PostDominators.cpp
+++ b/lib/Analysis/PostDominators.cpp
@@ -17,6 +17,8 @@
 #include "Support/DepthFirstIterator.h"
 #include "Support/SetOperations.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //  PostDominatorSet Implementation
 //===----------------------------------------------------------------------===//
@@ -214,3 +216,5 @@
 // stub - a dummy function to make linking work ok.
 void PostDominanceFrontier::stub() {
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/PrintSCC.cpp b/lib/Analysis/PrintSCC.cpp
index 3459381..ce89fff 100644
--- a/lib/Analysis/PrintSCC.cpp
+++ b/lib/Analysis/PrintSCC.cpp
@@ -31,6 +31,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/SCCIterator.h"
 
+namespace llvm {
+
 namespace {
   struct CFGSCC : public FunctionPass {
     bool runOnFunction(Function& func);
@@ -101,3 +103,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Analysis/ValueNumbering.cpp b/lib/Analysis/ValueNumbering.cpp
index 075c1c2..191e190 100644
--- a/lib/Analysis/ValueNumbering.cpp
+++ b/lib/Analysis/ValueNumbering.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Type.h"
 #include "llvm/iMemory.h"
 
+namespace llvm {
+
 // Register the ValueNumbering interface, providing a nice name to refer to.
 static RegisterAnalysisGroup<ValueNumbering> X("Value Numbering");
 
@@ -39,6 +41,7 @@
 // into the tool that uses it.  As such, we register and implement the class
 // here.
 //
+
 namespace {
   /// BasicVN - This class is the default implementation of the ValueNumbering
   /// interface.  It walks the SSA def-use chains to trivially identify
@@ -62,9 +65,7 @@
 
   // Declare that we implement the ValueNumbering interface
   RegisterAnalysisGroup<ValueNumbering, BasicVN, true> Y;
-}  // End of anonymous namespace
 
-namespace {
   /// BVNImpl - Implement BasicVN in terms of a visitor class that
   /// handles the different types of instructions as appropriate.
   ///
@@ -190,3 +191,5 @@
         RetVals.push_back(Other);
       }
 }
+
+} // End llvm namespace
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index d155b69..33ae24b 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -22,6 +22,8 @@
 #include "Config/sys/mman.h"
 #include "Config/fcntl.h"
 
+namespace llvm {
+
 namespace {
   struct ar_hdr {
     char name[16];
@@ -40,7 +42,6 @@
   };
 }
 
-
 // getObjectType - Determine the type of object that this header represents.
 // This is capable of parsing the variety of special sections used for various
 // purposes.
@@ -173,3 +174,5 @@
   
   return Result;
 }
+
+} // End llvm namespace
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l
index 6466cb7..b0e174a 100644
--- a/lib/AsmParser/Lexer.l
+++ b/lib/AsmParser/Lexer.l
@@ -35,6 +35,7 @@
 #define RET_TOK(type, Enum, sym) \
   llvmAsmlval.type = Instruction::Enum; return sym
 
+namespace llvm {
 
 // TODO: All of the static identifiers are figured out by the lexer, 
 // these should be hashed to reduce the lexer size
@@ -121,6 +122,10 @@
   return BOut;
 }
 
+} // End llvm namespace
+
+using namespace llvm;
+
 #define YY_NEVER_INTERACTIVE 1
 %}
 
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index e8a7bdb..2d6185e 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Module.h"
 #include "llvm/Analysis/Verifier.h"
 
+namespace llvm {
+
 // The useful interface defined by this file... Parse an ASCII file, and return
 // the internal representation in a nice slice'n'dice'able representation.
 //
@@ -82,3 +84,5 @@
   
   return Result + ": " + Message;
 }
+
+} // End llvm namespace
diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h
index c783795..c18434d 100644
--- a/lib/AsmParser/ParserInternals.h
+++ b/lib/AsmParser/ParserInternals.h
@@ -22,19 +22,23 @@
 #include "llvm/Assembly/Parser.h"
 #include "Support/StringExtras.h"
 
-class Module;
-
 // Global variables exported from the lexer...
 extern std::FILE *llvmAsmin;
 extern int llvmAsmlineno;
 
 // Globals exported by the parser...
-extern std::string CurFilename;
-Module *RunVMAsmParser(const std::string &Filename, FILE *F);
-
 extern char* llvmAsmtext;
 extern int   llvmAsmleng;
 
+namespace llvm {
+
+// Globals exported by the parser...
+extern std::string CurFilename;
+
+class Module;
+Module *RunVMAsmParser(const std::string &Filename, FILE *F);
+
+
 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
 // appropriate character.  If AllowNull is set to false, a \00 value will cause
 // an exception to be thrown.
@@ -209,4 +213,6 @@
   }
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index 96d2dae..a55e735 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -29,6 +29,8 @@
 int yylex();                       // declaration" of xxx warnings.
 int yyparse();
 
+namespace llvm {
+
 static Module *ParserResult;
 std::string CurFilename;
 
@@ -686,30 +688,34 @@
   return Result;
 }
 
+} // End llvm namespace
+
+using namespace llvm;
+
 %}
 
 %union {
-  Module                           *ModuleVal;
-  Function                         *FunctionVal;
-  std::pair<PATypeHolder*, char*>  *ArgVal;
-  BasicBlock                       *BasicBlockVal;
-  TerminatorInst                   *TermInstVal;
-  Instruction                      *InstVal;
-  Constant                         *ConstVal;
+  llvm::Module                           *ModuleVal;
+  llvm::Function                         *FunctionVal;
+  std::pair<llvm::PATypeHolder*, char*>  *ArgVal;
+  llvm::BasicBlock                       *BasicBlockVal;
+  llvm::TerminatorInst                   *TermInstVal;
+  llvm::Instruction                      *InstVal;
+  llvm::Constant                         *ConstVal;
 
-  const Type                       *PrimType;
-  PATypeHolder                     *TypeVal;
-  Value                            *ValueVal;
+  const llvm::Type                       *PrimType;
+  llvm::PATypeHolder                     *TypeVal;
+  llvm::Value                            *ValueVal;
 
-  std::vector<std::pair<PATypeHolder*,char*> > *ArgList;
-  std::vector<Value*>              *ValueList;
-  std::list<PATypeHolder>          *TypeList;
-  std::list<std::pair<Value*,
-                      BasicBlock*> > *PHIList; // Represent the RHS of PHI node
-  std::vector<std::pair<Constant*, BasicBlock*> > *JumpTable;
-  std::vector<Constant*>           *ConstVector;
+  std::vector<std::pair<llvm::PATypeHolder*,char*> > *ArgList;
+  std::vector<llvm::Value*>              *ValueList;
+  std::list<llvm::PATypeHolder>          *TypeList;
+  std::list<std::pair<llvm::Value*,
+                      llvm::BasicBlock*> > *PHIList; // Represent the RHS of PHI node
+  std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
+  std::vector<llvm::Constant*>           *ConstVector;
 
-  GlobalValue::LinkageTypes         Linkage;
+  llvm::GlobalValue::LinkageTypes         Linkage;
   int64_t                           SInt64Val;
   uint64_t                          UInt64Val;
   int                               SIntVal;
@@ -718,13 +724,13 @@
   bool                              BoolVal;
 
   char                             *StrVal;   // This memory is strdup'd!
-  ValID                             ValIDVal; // strdup'd memory maybe!
+  llvm::ValID                             ValIDVal; // strdup'd memory maybe!
 
-  Instruction::BinaryOps            BinaryOpVal;
-  Instruction::TermOps              TermOpVal;
-  Instruction::MemoryOps            MemOpVal;
-  Instruction::OtherOps             OtherOpVal;
-  Module::Endianness                Endianness;
+  llvm::Instruction::BinaryOps            BinaryOpVal;
+  llvm::Instruction::TermOps              TermOpVal;
+  llvm::Instruction::MemoryOps            MemOpVal;
+  llvm::Instruction::OtherOps             OtherOpVal;
+  llvm::Module::Endianness                Endianness;
 }
 
 %type <ModuleVal>     Module FunctionList
@@ -1892,6 +1898,7 @@
     delete $2; delete $4;
   };
 
+
 %%
 int yyerror(const char *ErrorMsg) {
   std::string where 
diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp
index d155b69..33ae24b 100644
--- a/lib/Bytecode/Archive/ArchiveReader.cpp
+++ b/lib/Bytecode/Archive/ArchiveReader.cpp
@@ -22,6 +22,8 @@
 #include "Config/sys/mman.h"
 #include "Config/fcntl.h"
 
+namespace llvm {
+
 namespace {
   struct ar_hdr {
     char name[16];
@@ -40,7 +42,6 @@
   };
 }
 
-
 // getObjectType - Determine the type of object that this header represents.
 // This is capable of parsing the variety of special sections used for various
 // purposes.
@@ -173,3 +174,5 @@
   
   return Result;
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Reader/ArchiveReader.cpp b/lib/Bytecode/Reader/ArchiveReader.cpp
index d155b69..33ae24b 100644
--- a/lib/Bytecode/Reader/ArchiveReader.cpp
+++ b/lib/Bytecode/Reader/ArchiveReader.cpp
@@ -22,6 +22,8 @@
 #include "Config/sys/mman.h"
 #include "Config/fcntl.h"
 
+namespace llvm {
+
 namespace {
   struct ar_hdr {
     char name[16];
@@ -40,7 +42,6 @@
   };
 }
 
-
 // getObjectType - Determine the type of object that this header represents.
 // This is capable of parsing the variety of special sections used for various
 // purposes.
@@ -173,3 +174,5 @@
   
   return Result;
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index 00f44b3..b455354 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -20,6 +20,8 @@
 #include "llvm/Constants.h"
 #include <algorithm>
 
+namespace llvm {
+
 const Type *BytecodeParser::parseTypeConstant(const unsigned char *&Buf,
 					      const unsigned char *EndBuf) {
   unsigned PrimType;
@@ -356,3 +358,5 @@
   
   if (Buf > EndBuf) throw std::string("Read past end of buffer.");
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index a409cee..ec8944e 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -22,6 +22,8 @@
 #include "llvm/iOther.h"
 #include "llvm/Module.h"
 
+namespace llvm {
+
 namespace {
   struct RawInst {       // The raw fields out of the bytecode stream...
     unsigned NumOperands;
@@ -33,8 +35,6 @@
   };
 }
 
-
-
 RawInst::RawInst(const unsigned char *&Buf, const unsigned char *EndBuf,
                  std::vector<unsigned> &Args) {
   unsigned Op, Typ;
@@ -389,3 +389,5 @@
   BB->getInstList().push_back(Result);
   BCR_TRACE(4, *Result);
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index a36ea7a..9acb93d 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -32,6 +32,8 @@
 #include <algorithm>
 #include <memory>
 
+namespace llvm {
+
 static inline void ALIGN32(const unsigned char *&begin,
                            const unsigned char *end) {
   if (align32(begin, end))
@@ -693,3 +695,5 @@
     throw;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h
index c890545..81ccde9 100644
--- a/lib/Bytecode/Reader/ReaderInternals.h
+++ b/lib/Bytecode/Reader/ReaderInternals.h
@@ -22,6 +22,8 @@
 #include <utility>
 #include <map>
 
+namespace llvm {
+
 // Enable to trace to figure out what the heck is going on when parsing fails
 //#define TRACE_LEVEL 10
 //#define DEBUG_OUTPUT
@@ -226,4 +228,6 @@
 #endif
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index 0df6ea5..1cbead0 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -21,6 +21,8 @@
 #include "Config/unistd.h"
 #include "Config/sys/mman.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 // BytecodeFileReader - Read from an mmap'able file descriptor.
 //
@@ -163,7 +165,7 @@
   unsigned char Buffer[4096*4];
 
   // Read in all of the data from stdin, we cannot mmap stdin...
-  while ((BlockSize = read(0 /*stdin*/, Buffer, 4096*4))) {
+  while ((BlockSize = ::read(0 /*stdin*/, Buffer, 4096*4))) {
     if (BlockSize == -1)
       throw std::string("Error reading from stdin!");
     
@@ -249,7 +251,6 @@
   return MP;
 }
 
-
 //===----------------------------------------------------------------------===//
 // Wrapper functions
 //===----------------------------------------------------------------------===//
@@ -296,3 +297,5 @@
     return 0;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Writer/ConstantWriter.cpp b/lib/Bytecode/Writer/ConstantWriter.cpp
index a9aaffe..303672d 100644
--- a/lib/Bytecode/Writer/ConstantWriter.cpp
+++ b/lib/Bytecode/Writer/ConstantWriter.cpp
@@ -17,6 +17,8 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
 
+namespace llvm {
+
 void BytecodeWriter::outputType(const Type *T) {
   output_vbr((unsigned)T->getPrimitiveID(), Out);
   
@@ -202,3 +204,5 @@
   }
   return false;
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp
index faa576e..d52f241 100644
--- a/lib/Bytecode/Writer/InstructionWriter.cpp
+++ b/lib/Bytecode/Writer/InstructionWriter.cpp
@@ -19,6 +19,8 @@
 #include "Support/Statistic.h"
 #include <algorithm>
 
+namespace llvm {
+
 static Statistic<> 
 NumInstrs("bytecodewriter", "Number of instructions");
 
@@ -295,3 +297,5 @@
   // operands or a large operand index that we are referring to.
   outputInstructionFormat0(&I, Opcode, Table, Type, Out);
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp
index aef7176..c6e44e8 100644
--- a/lib/Bytecode/Writer/SlotCalculator.cpp
+++ b/lib/Bytecode/Writer/SlotCalculator.cpp
@@ -27,6 +27,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 #if 0
 #define SC_DEBUG(X) std::cerr << X
 #else
@@ -361,3 +363,5 @@
   SC_DEBUG("]\n");
   return (int)DestSlot;
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Writer/SlotCalculator.h b/lib/Bytecode/Writer/SlotCalculator.h
index 7e56de9..596f932 100644
--- a/lib/Bytecode/Writer/SlotCalculator.h
+++ b/lib/Bytecode/Writer/SlotCalculator.h
@@ -22,6 +22,9 @@
 
 #include <vector>
 #include <map>
+
+namespace llvm {
+
 class Value;
 class Module;
 class Function;
@@ -92,4 +95,6 @@
   void processSymbolTableConstants(const SymbolTable *ST);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 9381e35..9c9e1ab 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -36,6 +36,8 @@
 #include "Config/string.h"
 #include <algorithm>
 
+namespace llvm {
+
 static RegisterPass<WriteBytecodePass> X("emitbytecode", "Bytecode Writer");
 
 static Statistic<> 
@@ -304,3 +306,5 @@
 
   Out.flush();
 }
+
+} // End llvm namespace
diff --git a/lib/Bytecode/Writer/WriterInternals.h b/lib/Bytecode/Writer/WriterInternals.h
index 5564f42..8cb4bfd 100644
--- a/lib/Bytecode/Writer/WriterInternals.h
+++ b/lib/Bytecode/Writer/WriterInternals.h
@@ -25,6 +25,8 @@
 #include "llvm/SlotCalculator.h"
 #include "llvm/Instruction.h"
 
+namespace llvm {
+
 class BytecodeWriter {
   std::deque<unsigned char> &Out;
   SlotCalculator Table;
@@ -79,5 +81,6 @@
   }
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/lib/CodeGen/InstrSched/InstrScheduling.cpp b/lib/CodeGen/InstrSched/InstrScheduling.cpp
index a50439d..4e2bf47 100644
--- a/lib/CodeGen/InstrSched/InstrScheduling.cpp
+++ b/lib/CodeGen/InstrSched/InstrScheduling.cpp
@@ -22,6 +22,8 @@
 #include "Support/CommandLine.h"
 #include <algorithm>
 
+namespace llvm {
+
 SchedDebugLevel_t SchedDebugLevel;
 
 static cl::opt<bool> EnableFillingDelaySlots("sched-fill-delay-slots",
@@ -1518,3 +1520,6 @@
 FunctionPass *createInstructionSchedulingWithSSAPass(const TargetMachine &tgt) {
   return new InstructionSchedulingWithSSA(tgt);
 }
+
+} // End llvm namespace
+
diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp
index e7cd478..3a80880 100644
--- a/lib/CodeGen/InstrSched/SchedGraph.cpp
+++ b/lib/CodeGen/InstrSched/SchedGraph.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 //*********************** Internal Data Structures *************************/
 
 // The following two types need to be classes, not typedefs, so we can use
@@ -737,3 +739,5 @@
       os << std::string(16, ' ') << *outEdges[i];
   }
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/InstrSched/SchedGraph.h b/lib/CodeGen/InstrSched/SchedGraph.h
index 50cc052..5aee9b2 100644
--- a/lib/CodeGen/InstrSched/SchedGraph.h
+++ b/lib/CodeGen/InstrSched/SchedGraph.h
@@ -25,6 +25,8 @@
 #include "Support/hash_map"
 #include "Support/GraphTraits.h"
 
+namespace llvm {
+
 class RegToRefVecMap;
 class ValueToDefVecMap;
 class RefVec;
@@ -317,4 +319,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/InstrSched/SchedGraphCommon.cpp b/lib/CodeGen/InstrSched/SchedGraphCommon.cpp
index b75e339..d96c201 100644
--- a/lib/CodeGen/InstrSched/SchedGraphCommon.cpp
+++ b/lib/CodeGen/InstrSched/SchedGraphCommon.cpp
@@ -15,6 +15,8 @@
 #include "llvm/CodeGen/SchedGraphCommon.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 class SchedGraphCommon;
 
 //
@@ -175,3 +177,4 @@
   this->eraseOutgoingEdges(node, addDummyEdges);	
 }
 
+} // End llvm namespace
diff --git a/lib/CodeGen/InstrSched/SchedPriorities.cpp b/lib/CodeGen/InstrSched/SchedPriorities.cpp
index 1644d5e..7e05d14 100644
--- a/lib/CodeGen/InstrSched/SchedPriorities.cpp
+++ b/lib/CodeGen/InstrSched/SchedPriorities.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 
+namespace llvm {
+
 std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) {
   return os << "Delay for node " << nd->node->getNodeId()
 	    << " = " << (long)nd->delay << "\n";
@@ -278,3 +280,4 @@
   return lastUseMap[MI] = hasLastUse;
 }
 
+} // End llvm namespace
diff --git a/lib/CodeGen/InstrSched/SchedPriorities.h b/lib/CodeGen/InstrSched/SchedPriorities.h
index de321f9..7470467 100644
--- a/lib/CodeGen/InstrSched/SchedPriorities.h
+++ b/lib/CodeGen/InstrSched/SchedPriorities.h
@@ -26,6 +26,8 @@
 #include "Support/hash_set"
 #include <list>
 
+namespace llvm {
+
 class Function;
 class MachineInstr;
 class SchedulingManager;
@@ -214,4 +216,6 @@
 
 std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd);
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp
index 5496502..fd5056d2 100644
--- a/lib/CodeGen/InstrSelection/InstrForest.cpp
+++ b/lib/CodeGen/InstrSelection/InstrForest.cpp
@@ -30,6 +30,8 @@
 #include "Support/STLExtras.h"
 #include "Config/alloca.h"
 
+namespace llvm {
+
 //------------------------------------------------------------------------ 
 // class InstrTreeNode
 //------------------------------------------------------------------------ 
@@ -330,3 +332,5 @@
   delete [] childArray;
   return treeNode;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp
index 0e3e2cd..7609765 100644
--- a/lib/CodeGen/InstrSelection/InstrSelection.cpp
+++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp
@@ -28,6 +28,8 @@
 #include "Support/LeakDetector.h"
 #include <vector>
 
+namespace llvm {
+
 std::vector<MachineInstr*>
 FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr,
                             TargetMachine& target);
@@ -82,6 +84,8 @@
   };
 }
 
+namespace llvm {
+
 TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
                                Value *s1, Value *s2, const std::string &name)
   : Instruction(s1->getType(), Instruction::UserOp1, name)
@@ -114,6 +118,7 @@
   LeakDetector::removeGarbageObject(this);
 }
 
+} // End llvm namespace
 
 bool InstructionSelection::runOnFunction(Function &F)
 {
@@ -375,7 +380,6 @@
 }
 
 
-
 //===----------------------------------------------------------------------===//
 // createInstructionSelectionPass - Public entrypoint for instruction selection
 // and this file as a whole...
@@ -383,3 +387,5 @@
 FunctionPass *createInstructionSelectionPass(TargetMachine &T) {
   return new InstructionSelection(T);
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp b/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp
index 93f7618..44a4359 100644
--- a/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp
+++ b/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp
@@ -25,6 +25,7 @@
 #include "llvm/DerivedTypes.h"
 #include "../../Target/Sparc/SparcInstrSelectionSupport.h"  // FIXME!
 
+namespace llvm {
 
 // Generate code to load the constant into a TmpInstruction (virtual reg) and
 // returns the virtual register.
@@ -257,3 +258,5 @@
   
   return MVec;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/LiveVariables.cpp b/lib/CodeGen/LiveVariables.cpp
index 50b90b1..7ec4d32 100644
--- a/lib/CodeGen/LiveVariables.cpp
+++ b/lib/CodeGen/LiveVariables.cpp
@@ -33,6 +33,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 
+namespace llvm {
+
 static RegisterAnalysis<LiveVariables> X("livevars", "Live Variable Analysis");
 
 const std::pair<MachineBasicBlock*, unsigned> &
@@ -307,3 +309,5 @@
   
   return false;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/MachineCodeEmitter.cpp b/lib/CodeGen/MachineCodeEmitter.cpp
index 6e56594..d9b1f7c 100644
--- a/lib/CodeGen/MachineCodeEmitter.cpp
+++ b/lib/CodeGen/MachineCodeEmitter.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Function.h"
 #include <fstream>
 
+namespace llvm {
+
 namespace {
   struct DebugMachineCodeEmitter : public MachineCodeEmitter {
     void startFunction(MachineFunction &F) {
@@ -54,18 +56,7 @@
       return 0;
     }
   };
-}
 
-
-/// createDebugMachineCodeEmitter - Return a dynamically allocated machine
-/// code emitter, which just prints the opcodes and fields out the cout.  This
-/// can be used for debugging users of the MachineCodeEmitter interface.
-///
-MachineCodeEmitter *MachineCodeEmitter::createDebugEmitter() {
-  return new DebugMachineCodeEmitter();
-}
-
-namespace {
   class FilePrinterEmitter : public MachineCodeEmitter {
     std::ofstream actual;
     std::ostream &o;
@@ -169,7 +160,18 @@
   };
 }
 
+/// createDebugMachineCodeEmitter - Return a dynamically allocated machine
+/// code emitter, which just prints the opcodes and fields out the cout.  This
+/// can be used for debugging users of the MachineCodeEmitter interface.
+///
+MachineCodeEmitter *
+MachineCodeEmitter::createDebugEmitter() {
+  return new DebugMachineCodeEmitter();
+}
+
 MachineCodeEmitter *
 MachineCodeEmitter::createFilePrinterEmitter(MachineCodeEmitter &MCE) {
   return new FilePrinterEmitter(MCE, std::cerr);
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/MachineCodeForInstruction.cpp b/lib/CodeGen/MachineCodeForInstruction.cpp
index 36bafe2..000f3d1 100644
--- a/lib/CodeGen/MachineCodeForInstruction.cpp
+++ b/lib/CodeGen/MachineCodeForInstruction.cpp
@@ -27,6 +27,8 @@
 #include "llvm/CodeGen/MachineInstrAnnot.h"
 #include "llvm/CodeGen/InstrSelection.h"
 
+namespace llvm {
+
 AnnotationID MCFI_AID(
              AnnotationManager::getID("CodeGen::MachineCodeForInstruction"));
 
@@ -68,3 +70,5 @@
   if (callArgsDesc)
     delete callArgsDesc;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index c1eb30a..790859b 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -28,6 +28,8 @@
 #include "llvm/Pass.h"
 #include "Config/limits.h"
 
+namespace llvm {
+
 const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max();
 
 static AnnotationID MF_AID(
@@ -414,3 +416,5 @@
   hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
   return (pair == offsets.end()) ? INVALID_FRAME_OFFSET : pair->second;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index 7fb8b45..ef31cc4 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/MRegisterInfo.h"
 
+namespace llvm {
+
 // Global variable holding an array of descriptors for machine instructions.
 // The actual object needs to be created separately for each target machine.
 // This variable is initialized and reset by class TargetInstrInfo.
@@ -289,7 +291,7 @@
    // Specialize printing if op#0 is definition
   if (getNumOperands() &&
       (getOperand(0).opIsDefOnly() || getOperand(0).opIsDefAndUse())) {
-    ::print(getOperand(0), OS, TM);
+      llvm::print(getOperand(0), OS, TM);
     OS << " = ";
     ++StartOp;   // Don't print this operand again!
   }
@@ -300,7 +302,7 @@
     if (i != StartOp)
       OS << ",";
     OS << " ";
-    ::print(mop, OS, TM);
+    llvm::print(mop, OS, TM);
     
     if (mop.opIsDefAndUse())
       OS << "<def&use>";
@@ -433,3 +435,5 @@
   
   return OS;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/MachineInstrAnnot.cpp b/lib/CodeGen/MachineInstrAnnot.cpp
index bf4e68e..b4b41ac 100644
--- a/lib/CodeGen/MachineInstrAnnot.cpp
+++ b/lib/CodeGen/MachineInstrAnnot.cpp
@@ -18,6 +18,7 @@
 #include "llvm/iOther.h"
 #include "llvm/Type.h"
 
+namespace llvm {
 
 CallArgsDescriptor::CallArgsDescriptor(CallInst* _callInstr,
                                        TmpInstruction* _retAddrReg,
@@ -76,3 +77,5 @@
   assert(desc->getCallInst()==callInstr && "Incorrect call args descriptor?");
   return desc;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp b/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp
index 6318c5a..8aaaa2b 100644
--- a/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp
+++ b/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp
@@ -13,6 +13,8 @@
 #include "ModuloSchedGraph.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned id, int index, 
 					   const Instruction *inst, 
 					   const TargetMachine &targ) 
@@ -135,3 +137,4 @@
   //delete all the graphs
 }
 
+} // End llvm namespace
diff --git a/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.h b/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.h
index 214e24c..552d699 100644
--- a/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.h
+++ b/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.h
@@ -22,6 +22,7 @@
 #include "Support/hash_map"
 #include <vector>
 
+namespace llvm {
 
 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
 
@@ -106,4 +107,6 @@
 
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp b/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp
index 91ec6c2..219d892 100644
--- a/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp
+++ b/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Function.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 namespace {
   
   class ModuloScheduling : public FunctionPass {
@@ -40,3 +42,5 @@
   bool Changed = false;
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp
index 5a988ba..c4b811a 100644
--- a/lib/CodeGen/PHIElimination.cpp
+++ b/lib/CodeGen/PHIElimination.cpp
@@ -21,6 +21,8 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/CFG.h"
 
+namespace llvm {
+
 namespace {
   struct PNE : public MachineFunctionPass {
     bool runOnMachineFunction(MachineFunction &Fn) {
@@ -52,6 +54,7 @@
 		      "Eliminate PHI nodes for register allocation");
 }
 
+
 const PassInfo *PHIEliminationID = X.getPassInfo();
 
 /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions in
@@ -260,3 +263,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/Passes.cpp b/lib/CodeGen/Passes.cpp
index 7a51a53..239eacd 100644
--- a/lib/CodeGen/Passes.cpp
+++ b/lib/CodeGen/Passes.cpp
@@ -15,6 +15,8 @@
 #include "llvm/CodeGen/Passes.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 namespace {
   enum RegAllocName { simple, local };
 
@@ -40,3 +42,5 @@
     return 0; // not reached
   }
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp
index a60b8b1..8fc9b5b 100644
--- a/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/lib/CodeGen/PrologEpilogInserter.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Target/TargetFrameInfo.h"
 #include "llvm/Target/TargetInstrInfo.h"
 
+namespace llvm {
+
 namespace {
   struct PEI : public MachineFunctionPass {
     const char *getPassName() const {
@@ -66,6 +68,7 @@
   };
 }
 
+
 /// createPrologEpilogCodeInserter - This function returns a pass that inserts
 /// prolog and epilog code, and eliminates abstract frame references.
 ///
@@ -258,3 +261,5 @@
 	  break;
 	}
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAlloc/AllocInfo.h b/lib/CodeGen/RegAlloc/AllocInfo.h
index f83f210..67f58a7 100644
--- a/lib/CodeGen/RegAlloc/AllocInfo.h
+++ b/lib/CodeGen/RegAlloc/AllocInfo.h
@@ -19,6 +19,8 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 
+namespace llvm {
+
 /// AllocInfo - Structure representing one instruction's operand's-worth of
 /// register allocation state. We create tables made out of these data
 /// structures to generate mapping information for this register allocator.
@@ -77,4 +79,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif // ALLOCINFO_H
diff --git a/lib/CodeGen/RegAlloc/IGNode.cpp b/lib/CodeGen/RegAlloc/IGNode.cpp
index f883fb1..a76fdea 100644
--- a/lib/CodeGen/RegAlloc/IGNode.cpp
+++ b/lib/CodeGen/RegAlloc/IGNode.cpp
@@ -16,6 +16,8 @@
 #include <algorithm>
 #include <iostream>
 
+namespace llvm {
+
 //-----------------------------------------------------------------------------
 // Sets this IGNode on stack and reduce the degree of neighbors  
 //-----------------------------------------------------------------------------
@@ -56,3 +58,5 @@
   std::vector<IGNode*>::iterator new_end = unique(nbrs.begin(), nbrs.end());
   return new_end - nbrs.begin();
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAlloc/IGNode.h b/lib/CodeGen/RegAlloc/IGNode.h
index 82f07e0..9fdc7a6 100644
--- a/lib/CodeGen/RegAlloc/IGNode.h
+++ b/lib/CodeGen/RegAlloc/IGNode.h
@@ -32,6 +32,9 @@
 
 #include "LiveRange.h"
 #include <vector>
+
+namespace llvm {
+
 class RegClass;
 
 //----------------------------------------------------------------------------
@@ -115,4 +118,6 @@
   inline LiveRange *getParentLR() const { return ParentLR; }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp
index 392a96c..3cef19e 100644
--- a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp
+++ b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp
@@ -17,6 +17,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 // for asserting this IG node is infact in the IGNodeList of this class
 inline static void assertIGNode(const InterferenceGraph *IG,
                                 const IGNode *Node) {
@@ -246,3 +248,5 @@
     }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.h b/lib/CodeGen/RegAlloc/InterferenceGraph.h
index 6b8cf3c..79850c1 100644
--- a/lib/CodeGen/RegAlloc/InterferenceGraph.h
+++ b/lib/CodeGen/RegAlloc/InterferenceGraph.h
@@ -30,6 +30,9 @@
 #define INTERFERENCEGRAPH_H
 
 #include <vector>
+
+namespace llvm {
+
 class LiveRange;
 class RegClass;
 class IGNode;
@@ -67,4 +70,6 @@
   void printIGNodeList() const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/RegAlloc/LiveRange.h b/lib/CodeGen/RegAlloc/LiveRange.h
index aa409c6..d6e2cf6 100644
--- a/lib/CodeGen/RegAlloc/LiveRange.h
+++ b/lib/CodeGen/RegAlloc/LiveRange.h
@@ -21,6 +21,8 @@
 #include "llvm/Value.h"
 #include "llvm/CodeGen/ValueSet.h"
 
+namespace llvm {
+
 class RegClass;
 class IGNode;
 
@@ -177,4 +179,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
index b9fcda7..9fd04d2 100644
--- a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
+++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include "Support/SetOperations.h"
 
+namespace llvm {
+
 unsigned LiveRange::getRegClassID() const { return getRegClass()->getID(); }
 
 LiveRangeInfo::LiveRangeInfo(const Function *F, const TargetMachine &tm,
@@ -411,3 +413,5 @@
     }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.h b/lib/CodeGen/RegAlloc/LiveRangeInfo.h
index 5c5244b..a8d0e71 100644
--- a/lib/CodeGen/RegAlloc/LiveRangeInfo.h
+++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.h
@@ -29,6 +29,8 @@
 #include "llvm/CodeGen/ValueSet.h"
 #include "Support/hash_map"
 
+namespace llvm {
+
 class LiveRange;
 class MachineInstr;
 class RegClass;
@@ -121,4 +123,6 @@
   void printLiveRanges();
 };
 
+} // End llvm namespace
+
 #endif 
diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
index 99917cd..332ae95 100644
--- a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
+++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
@@ -47,6 +47,8 @@
 #include "Support/STLExtras.h"
 #include <cmath>
 
+namespace llvm {
+
 RegAllocDebugLevel_t DEBUG_RA;
 
 /// The reoptimizer wants to be able to grovel through the register
@@ -1392,3 +1394,5 @@
   if (DEBUG_RA) std::cerr << "\nRegister allocation complete!\n"; 
   return false;     // Function was not modified
 } 
+
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.h b/lib/CodeGen/RegAlloc/PhyRegAlloc.h
index c524f9f..4ec083c 100644
--- a/lib/CodeGen/RegAlloc/PhyRegAlloc.h
+++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.h
@@ -31,6 +31,8 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include <map>
 
+namespace llvm {
+
 class MachineFunction;
 class FunctionLiveVarInfo;
 class MachineInstr;
@@ -179,4 +181,6 @@
   void addInterf4PseudoInstr(const MachineInstr *MI);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/RegAlloc/RegAllocCommon.h b/lib/CodeGen/RegAlloc/RegAllocCommon.h
index 97d102a..7dd86b2 100644
--- a/lib/CodeGen/RegAlloc/RegAllocCommon.h
+++ b/lib/CodeGen/RegAlloc/RegAllocCommon.h
@@ -14,6 +14,8 @@
 #ifndef REGALLOCCOMMON_H
 #define REGALLOCCOMMON_H
 
+namespace llvm {
+
 enum RegAllocDebugLevel_t {
   RA_DEBUG_None         = 0,
   RA_DEBUG_Results      = 1,
@@ -25,4 +27,6 @@
 
 extern RegAllocDebugLevel_t DEBUG_RA;
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/RegAlloc/RegClass.cpp b/lib/CodeGen/RegAlloc/RegClass.cpp
index 9c8603b..9af87ba 100644
--- a/lib/CodeGen/RegAlloc/RegClass.cpp
+++ b/lib/CodeGen/RegAlloc/RegClass.cpp
@@ -16,6 +16,8 @@
 #include "RegClass.h"
 #include "llvm/Target/TargetRegInfo.h"
 
+namespace llvm {
+
 //----------------------------------------------------------------------------
 // This constructor inits IG. The actual matrix is created by a call to 
 // createInterferenceGraph() above.
@@ -245,4 +247,4 @@
   IG.printIG(); 
 }
 
-
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAlloc/RegClass.h b/lib/CodeGen/RegAlloc/RegClass.h
index c861fba..0071f7c 100644
--- a/lib/CodeGen/RegAlloc/RegClass.h
+++ b/lib/CodeGen/RegAlloc/RegClass.h
@@ -20,6 +20,9 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include "InterferenceGraph.h"
 #include <stack>
+
+namespace llvm {
+
 class TargetRegClassInfo;
 
 
@@ -139,4 +142,6 @@
   void printIG();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp
index 8d19b69..080e6c6 100644
--- a/lib/CodeGen/RegAllocLocal.cpp
+++ b/lib/CodeGen/RegAllocLocal.cpp
@@ -26,6 +26,8 @@
 #include "Support/Statistic.h"
 #include <iostream>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumSpilled ("ra-local", "Number of registers spilled");
   Statistic<> NumReloaded("ra-local", "Number of registers reloaded");
@@ -203,7 +205,6 @@
   };
 }
 
-
 /// getStackSpaceFor - This allocates space for the specified virtual register
 /// to be held on the stack.
 int RA::getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC) {
@@ -674,3 +675,5 @@
 FunctionPass *createLocalRegisterAllocator() {
   return new RA();
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/RegAllocSimple.cpp b/lib/CodeGen/RegAllocSimple.cpp
index a210790..202123a 100644
--- a/lib/CodeGen/RegAllocSimple.cpp
+++ b/lib/CodeGen/RegAllocSimple.cpp
@@ -26,6 +26,8 @@
 #include "Support/Statistic.h"
 #include <iostream>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumSpilled ("ra-simple", "Number of registers spilled");
   Statistic<> NumReloaded("ra-simple", "Number of registers reloaded");
@@ -234,3 +236,5 @@
 FunctionPass *createSimpleRegisterAllocator() {
   return new RegAllocSimple();
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/SelectionDAG/DAGBuilder.cpp b/lib/CodeGen/SelectionDAG/DAGBuilder.cpp
index a972ddf..fd4e7a9 100644
--- a/lib/CodeGen/SelectionDAG/DAGBuilder.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGBuilder.cpp
@@ -21,6 +21,8 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/InstVisitor.h"
 
+namespace llvm {
+
 struct SelectionDAGBuilder : public InstVisitor<SelectionDAGBuilder> {
   // DAG - the current dag we are building.
   SelectionDAG &DAG;
@@ -270,3 +272,5 @@
     SDB.visitBB(const_cast<BasicBlock&>(*I));
   Root = SDB.CurRoot;
 }
+
+} // End llvm namespace
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 58a9639..db59410 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -15,6 +15,8 @@
 #include "llvm/CodeGen/SelectionDAG.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 SelectionDAG::~SelectionDAG() {
   for (unsigned i = 0, e = AllNodes.size(); i != e; ++i)
     delete AllNodes[i];
@@ -126,3 +128,5 @@
 
   std::cerr << "\n";
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index dd64724..b7da23c 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -27,6 +27,8 @@
 #include "Support/DynamicLinker.h"
 #include "Config/dlfcn.h"
 
+namespace llvm {
+
 Statistic<> NumInitBytes("lli", "Number of bytes of global vars initialized");
 
 ExecutionEngine::ExecutionEngine(ModuleProvider *P) : 
@@ -390,3 +392,4 @@
       InitializeMemory(I->getInitializer(), GlobalAddress[I]);
 }
 
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index b04f974..aa32983 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -18,12 +18,14 @@
 #include "Support/Statistic.h"
 #include <cmath>  // For fmod
 
-Interpreter *TheEE = 0;
+namespace llvm {
 
 namespace {
   Statistic<> NumDynamicInsts("lli", "Number of dynamic instructions executed");
 }
 
+Interpreter *TheEE = 0;
+
 //===----------------------------------------------------------------------===//
 //                     Value Manipulation code
 //===----------------------------------------------------------------------===//
@@ -910,3 +912,5 @@
     visit(I);   // Dispatch to one of the visit* methods...
   }
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index ecf19c2..f516f5d 100644
--- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -32,6 +32,8 @@
 #include <map>
 using std::vector;
 
+namespace llvm {
+
 typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
 static std::map<const Function *, ExFunc> Functions;
 static std::map<std::string, ExFunc> FuncNames;
@@ -767,3 +769,5 @@
   FuncNames["lle_X_llvm.va_end"]  = llvm_va_end;
   FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/lib/ExecutionEngine/Interpreter/Interpreter.cpp
index bcaa856..bb14cd2 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.cpp
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
 
+namespace llvm {
+
 /// create - Create a new interpreter object.  This can never fail.
 ///
 ExecutionEngine *Interpreter::create(Module *M){
@@ -97,3 +99,5 @@
   rv.IntVal = ExitCode;
   return rv;
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h
index 00784ad..e9015a2 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -22,6 +22,8 @@
 #include "llvm/Target/TargetData.h"
 #include "Support/DataTypes.h"
 
+namespace llvm {
+
 struct FunctionInfo;        // Defined in ExecutionAnnotations.h
 
 // AllocaHolder - Object to track all of the blocks of memory allocated by
@@ -166,4 +168,6 @@
   void popStackAndReturnValueToCaller(const Type *RetTy, GenericValue Result);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/ExecutionEngine/JIT/Intercept.cpp b/lib/ExecutionEngine/JIT/Intercept.cpp
index 6162e93..191b57d 100644
--- a/lib/ExecutionEngine/JIT/Intercept.cpp
+++ b/lib/ExecutionEngine/JIT/Intercept.cpp
@@ -19,6 +19,8 @@
 #include "Support/DynamicLinker.h"
 #include <iostream>
 
+namespace llvm {
+
 // AtExitHandlers - List of functions to call when the program exits,
 // registered with the atexit() library function.
 static std::vector<void (*)()> AtExitHandlers;
@@ -75,3 +77,5 @@
   
   return Ptr;
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index fedb6e4..61d9629 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -24,6 +24,8 @@
 #define NO_JITS_ENABLED
 #endif
 
+namespace llvm {
+
 namespace {
   enum ArchName { x86, Sparc };
 
@@ -118,3 +120,5 @@
   rv.IntVal = ExitCode;
   return rv;
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/JIT/JIT.h b/lib/ExecutionEngine/JIT/JIT.h
index 685c4bd..9a17c96 100644
--- a/lib/ExecutionEngine/JIT/JIT.h
+++ b/lib/ExecutionEngine/JIT/JIT.h
@@ -18,6 +18,8 @@
 #include "llvm/PassManager.h"
 #include <map>
 
+namespace llvm {
+
 class Function;
 class GlobalValue;
 class Constant;
@@ -78,4 +80,6 @@
   void runJITOnFunction (Function *F);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 98f526a..32d0651 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -27,6 +27,8 @@
 #include "Config/unistd.h"
 #include "Config/sys/mman.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumBytes("jit", "Number of bytes of machine code compiled");
   VM *TheVM = 0;
@@ -265,3 +267,5 @@
     return TheVM->getPointerToNamedFunction(Name);
   }
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/JIT/VM.cpp b/lib/ExecutionEngine/JIT/VM.cpp
index 2dda271..d7e7685 100644
--- a/lib/ExecutionEngine/JIT/VM.cpp
+++ b/lib/ExecutionEngine/JIT/VM.cpp
@@ -19,6 +19,8 @@
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/Target/TargetMachine.h"
 
+namespace llvm {
+
 VM::~VM() {
   delete MCE;
   delete &TM;
@@ -98,3 +100,5 @@
   TM.replaceMachineCodeForFunction (OldAddr, Addr);
   return Addr;
 }
+
+} // End llvm namespace
diff --git a/lib/ExecutionEngine/JIT/VM.h b/lib/ExecutionEngine/JIT/VM.h
index 685c4bd..9a17c96 100644
--- a/lib/ExecutionEngine/JIT/VM.h
+++ b/lib/ExecutionEngine/JIT/VM.h
@@ -18,6 +18,8 @@
 #include "llvm/PassManager.h"
 #include <map>
 
+namespace llvm {
+
 class Function;
 class GlobalValue;
 class Constant;
@@ -78,4 +80,6 @@
   void runJITOnFunction (Function *F);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp
index 06f0635..9c22891 100644
--- a/lib/Linker/LinkArchives.cpp
+++ b/lib/Linker/LinkArchives.cpp
@@ -30,6 +30,8 @@
 #include <memory>
 #include <set>
 
+namespace llvm {
+
 /// FindLib - Try to convert Filename into the name of a file that we can open,
 /// if it does not already name a file we can open, by first trying to open
 /// Filename, then libFilename.<suffix> for each of a set of several common
@@ -405,3 +407,5 @@
 
   return false;
 }
+
+} // End llvm namespace
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 0be840f..4bc78a4 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -23,6 +23,8 @@
 #include "llvm/iOther.h"
 #include "llvm/Constants.h"
 
+namespace llvm {
+
 // Error - Simple wrapper function to conditionally assign to E and return true.
 // This just makes error return conditions a little bit simpler...
 //
@@ -902,3 +904,4 @@
   return false;
 }
 
+} // End llvm namespace
diff --git a/lib/Support/Annotation.cpp b/lib/Support/Annotation.cpp
index 890b18d..b88624d 100644
--- a/lib/Support/Annotation.cpp
+++ b/lib/Support/Annotation.cpp
@@ -14,6 +14,8 @@
 #include <map>
 #include "Support/Annotation.h"
 
+namespace llvm {
+
 typedef std::map<const std::string, unsigned> IDMapType;
 static unsigned IDCounter = 0;  // Unique ID counter
 
@@ -94,3 +96,5 @@
   if (I == getFactMap().end()) return 0;
   return I->second.first(ID, Obj, I->second.second);
 }
+
+} // End llvm namespace
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index de895c9..235dc12 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -24,6 +24,8 @@
 #include <cstdlib>
 #include <cerrno>
 
+namespace llvm {
+
 using namespace cl;
 
 //===----------------------------------------------------------------------===//
@@ -887,3 +889,5 @@
      cl::location(HiddenPrinter), cl::Hidden, cl::ValueDisallowed);
 
 } // End anonymous namespace
+
+} // End llvm namespace
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index a9e1204..e180f12 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -26,6 +26,8 @@
 #include "llvm/Instruction.h"
 #include "llvm/ConstantHandling.h"
 
+namespace llvm {
+
 /// Initialize a full (the default) or empty set for the specified type.
 ///
 ConstantRange::ConstantRange(const Type *Ty, bool Full) {
@@ -248,3 +250,5 @@
 void ConstantRange::dump() const {
   print(std::cerr);
 }
+
+} // End llvm namespace
diff --git a/lib/Support/Debug.cpp b/lib/Support/Debug.cpp
index 895abbb..1af2338 100644
--- a/lib/Support/Debug.cpp
+++ b/lib/Support/Debug.cpp
@@ -26,6 +26,8 @@
 #include "Support/Statistic.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 bool DebugFlag;  // DebugFlag - Exported boolean set by the -debug option
 
 namespace {
@@ -62,3 +64,5 @@
   return false;
 #endif
 }
+
+} // End llvm namespace
diff --git a/lib/Support/DynamicLinker.cpp b/lib/Support/DynamicLinker.cpp
index 74b3603..1c9385e 100644
--- a/lib/Support/DynamicLinker.cpp
+++ b/lib/Support/DynamicLinker.cpp
@@ -23,6 +23,8 @@
 #include "Config/dlfcn.h"
 #include <cassert>
 
+namespace llvm {
+
 bool LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
 #if defined (HAVE_DLOPEN)
   if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) {
@@ -52,3 +54,5 @@
 void *GetAddressOfSymbol (const std::string &symbolName) {
   return GetAddressOfSymbol (symbolName.c_str ());
 }
+
+} // End llvm namespace
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index 3262ecc..cde2889 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -20,6 +20,9 @@
 #include <iostream>
 #include <cstdio>
 
+namespace llvm
+{
+
 /// CheckMagic - Returns true IFF the file named FN begins with Magic. FN must
 /// name a readable file.
 ///
@@ -182,3 +185,5 @@
 bool MakeFileReadable (const std::string &Filename) {
   return AddPermissionsBits (Filename, 0444);
 }
+
+} // End llvm namespace
diff --git a/lib/Support/LeakDetector.cpp b/lib/Support/LeakDetector.cpp
index 24c946a..ffb081a 100644
--- a/lib/Support/LeakDetector.cpp
+++ b/lib/Support/LeakDetector.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Value.h"
 #include <set>
 
+namespace llvm {
+
 // Lazily allocate set so that release build doesn't have to do anything.
 static std::set<const void*> *Objects = 0;
 static std::set<const Value*> *LLVMObjects = 0;
@@ -87,3 +89,5 @@
     Objects = 0; LLVMObjects = 0;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Support/Mangler.cpp b/lib/Support/Mangler.cpp
index 44c697d..567fe05 100644
--- a/lib/Support/Mangler.cpp
+++ b/lib/Support/Mangler.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Type.h"
 #include "Support/StringExtras.h"
 
+namespace llvm {
+
 static char HexDigit(int V) {
   return V < 10 ? V+'0' : V+'A'-10;
 }
@@ -99,3 +101,4 @@
         FoundNames.insert(I->getName());   // Otherwise, keep track of name
 }
 
+} // End llvm namespace
diff --git a/lib/Support/PluginLoader.cpp b/lib/Support/PluginLoader.cpp
index 1582a10..1729bb3 100644
--- a/lib/Support/PluginLoader.cpp
+++ b/lib/Support/PluginLoader.cpp
@@ -23,6 +23,8 @@
 #include "Config/link.h"
 #include <iostream>
 
+namespace llvm {
+
 namespace {
   struct PluginLoader {
     void operator=(const std::string &Filename) {
@@ -38,3 +40,5 @@
 static cl::opt<PluginLoader, false, cl::parser<std::string> >
 LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
         cl::desc("Load the specified plugin"));
+
+} // End llvm namespace
diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp
index efc5f71..73decfd 100644
--- a/lib/Support/Signals.cpp
+++ b/lib/Support/Signals.cpp
@@ -20,6 +20,8 @@
 #include <signal.h>
 #include "Config/config.h"     // Get the signal handler return type
 
+namespace llvm {
+
 static std::vector<std::string> FilesToRemove;
 
 // IntSigs - Signals that may interrupt the program at any time.
@@ -62,3 +64,5 @@
   std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
   std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
 }
+
+} // End llvm namespace
diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp
index c60a85c..3ac2bf9 100644
--- a/lib/Support/Statistic.cpp
+++ b/lib/Support/Statistic.cpp
@@ -27,8 +27,10 @@
 #include <iostream>
 #include <algorithm>
 
+namespace llvm {
+
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
-std::ostream *GetLibSupportInfoOutputFile();
+extern std::ostream *GetLibSupportInfoOutputFile();
 
 unsigned StatisticBase::NumStats = 0;
 
@@ -104,3 +106,5 @@
       delete OutStream;   // Close the file...
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index 8c009ff..ec535ad 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -24,6 +24,8 @@
 #include "Config/unistd.h"
 #include "Config/errno.h"
 
+namespace llvm {
+
 /// isExecutableFile - This function returns true if the filename specified
 /// exists and is executable.
 ///
@@ -272,3 +274,4 @@
   return 1;
 }
 
+} // End llvm namespace
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 5e84f38..d14a225 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -23,6 +23,8 @@
 #include <fstream>
 #include <map>
 
+namespace llvm {
+
 // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
 // of constructor/destructor ordering being unspecified by C++.  Basically the
 // problem is that a Statistic<> object gets destroyed, which ends up calling
@@ -265,7 +267,8 @@
 }
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
-std::ostream *GetLibSupportInfoOutputFile() {
+std::ostream *
+GetLibSupportInfoOutputFile() {
   std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
   if (LibSupportInfoOutputFilename.empty())
     return &std::cerr;
@@ -349,3 +352,5 @@
     DefaultTimerGroup = 0;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Support/ToolRunner.cpp b/lib/Support/ToolRunner.cpp
index a66b868..50a9ad2 100644
--- a/lib/Support/ToolRunner.cpp
+++ b/lib/Support/ToolRunner.cpp
@@ -18,6 +18,8 @@
 #include <iostream>
 #include <fstream>
 
+namespace llvm {
+
 //===---------------------------------------------------------------------===//
 // LLI Implementation of AbstractIntepreter interface
 //
@@ -391,3 +393,5 @@
   Message = "Found gcc: " + GCCPath + "\n";
   return new GCC(GCCPath);
 }
+
+} // End llvm namespace
diff --git a/lib/Support/ValueHolder.cpp b/lib/Support/ValueHolder.cpp
index 8661402..77fdaf6 100644
--- a/lib/Support/ValueHolder.cpp
+++ b/lib/Support/ValueHolder.cpp
@@ -18,6 +18,10 @@
 #include "llvm/Support/ValueHolder.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 ValueHolder::ValueHolder(Value *V) : User(Type::TypeTy, Value::TypeVal) {
   Operands.push_back(Use(V, this));
 }
+
+} // End llvm namespace
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 258c287..bac088a 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -31,6 +31,8 @@
 #include <algorithm>
 #include <sstream>
 
+namespace llvm {
+
 namespace {
   class CWriter : public Pass, public InstVisitor<CWriter> {
     std::ostream &Out; 
@@ -161,7 +163,6 @@
     void printIndexingExpression(Value *Ptr, User::op_iterator I,
                                  User::op_iterator E);
   };
-}
 
 // Pass the Type* and the variable name and this prints out the variable
 // declaration.
@@ -339,7 +340,7 @@
 // compiler agreeing on the conversion process (which is pretty likely since we
 // only deal in IEEE FP).
 //
-static bool isFPCSafeToPrint(const ConstantFP *CFP) {
+bool isFPCSafeToPrint(const ConstantFP *CFP) {
 #if HAVE_PRINTF_A
   char Buffer[100];
   sprintf(Buffer, "%a", CFP->getValue());
@@ -563,7 +564,7 @@
 // generateCompilerSpecificCode - This is where we add conditional compilation
 // directives to cater to specific compilers as need be.
 //
-static void generateCompilerSpecificCode(std::ostream& Out) {
+void generateCompilerSpecificCode(std::ostream& Out) {
   // Alloca is hard to get, and we don't want to include stdlib.h here...
   Out << "/* get a declaration for alloca */\n"
       << "#ifdef sun\n"
@@ -1058,7 +1059,7 @@
   emittedInvoke = true;
 }
 
-static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
+bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
   // If PHI nodes need copies, we need the copy code...
   if (isa<PHINode>(To->front()) ||
       From->getNext() != To)      // Not directly successor, need goto
@@ -1195,10 +1196,10 @@
 void CWriter::visitCallInst(CallInst &I) {
   // Handle intrinsic function calls first...
   if (Function *F = I.getCalledFunction())
-    if (LLVMIntrinsic::ID ID = (LLVMIntrinsic::ID)F->getIntrinsicID()) {
+    if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
       switch (ID) {
       default:  assert(0 && "Unknown LLVM intrinsic!");
-      case LLVMIntrinsic::va_start: 
+      case Intrinsic::va_start: 
         Out << "0; ";
         
         Out << "va_start(*(va_list*)&" << Mang->getValueName(&I) << ", ";
@@ -1212,28 +1213,28 @@
         writeOperand(&I.getParent()->getParent()->aback());
         Out << ")";
         return;
-      case LLVMIntrinsic::va_end:
+      case Intrinsic::va_end:
         Out << "va_end(*(va_list*)&";
         writeOperand(I.getOperand(1));
         Out << ")";
         return;
-      case LLVMIntrinsic::va_copy:
+      case Intrinsic::va_copy:
         Out << "0;";
         Out << "va_copy(*(va_list*)&" << Mang->getValueName(&I) << ", ";
         Out << "*(va_list*)&";
         writeOperand(I.getOperand(1));
         Out << ")";
         return;
-      case LLVMIntrinsic::setjmp:
-      case LLVMIntrinsic::sigsetjmp:
+      case Intrinsic::setjmp:
+      case Intrinsic::sigsetjmp:
         // This intrinsic should never exist in the program, but until we get
         // setjmp/longjmp transformations going on, we should codegen it to
         // something reasonable.  This will allow code that never calls longjmp
         // to work.
         Out << "0";
         return;
-      case LLVMIntrinsic::longjmp:
-      case LLVMIntrinsic::siglongjmp:
+      case Intrinsic::longjmp:
+      case Intrinsic::siglongjmp:
         // Longjmp is not implemented, and never will be.  It would cause an
         // exception throw.
         Out << "abort()";
@@ -1385,9 +1386,12 @@
   Out << ");\n  va_end(Tmp); }";
 }
 
+}
 
 //===----------------------------------------------------------------------===//
 //                       External Interface declaration
 //===----------------------------------------------------------------------===//
 
 Pass *createWriteToCPass(std::ostream &o) { return new CWriter(o); }
+
+} // End llvm namespace
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 258c287..bac088a 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -31,6 +31,8 @@
 #include <algorithm>
 #include <sstream>
 
+namespace llvm {
+
 namespace {
   class CWriter : public Pass, public InstVisitor<CWriter> {
     std::ostream &Out; 
@@ -161,7 +163,6 @@
     void printIndexingExpression(Value *Ptr, User::op_iterator I,
                                  User::op_iterator E);
   };
-}
 
 // Pass the Type* and the variable name and this prints out the variable
 // declaration.
@@ -339,7 +340,7 @@
 // compiler agreeing on the conversion process (which is pretty likely since we
 // only deal in IEEE FP).
 //
-static bool isFPCSafeToPrint(const ConstantFP *CFP) {
+bool isFPCSafeToPrint(const ConstantFP *CFP) {
 #if HAVE_PRINTF_A
   char Buffer[100];
   sprintf(Buffer, "%a", CFP->getValue());
@@ -563,7 +564,7 @@
 // generateCompilerSpecificCode - This is where we add conditional compilation
 // directives to cater to specific compilers as need be.
 //
-static void generateCompilerSpecificCode(std::ostream& Out) {
+void generateCompilerSpecificCode(std::ostream& Out) {
   // Alloca is hard to get, and we don't want to include stdlib.h here...
   Out << "/* get a declaration for alloca */\n"
       << "#ifdef sun\n"
@@ -1058,7 +1059,7 @@
   emittedInvoke = true;
 }
 
-static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
+bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
   // If PHI nodes need copies, we need the copy code...
   if (isa<PHINode>(To->front()) ||
       From->getNext() != To)      // Not directly successor, need goto
@@ -1195,10 +1196,10 @@
 void CWriter::visitCallInst(CallInst &I) {
   // Handle intrinsic function calls first...
   if (Function *F = I.getCalledFunction())
-    if (LLVMIntrinsic::ID ID = (LLVMIntrinsic::ID)F->getIntrinsicID()) {
+    if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
       switch (ID) {
       default:  assert(0 && "Unknown LLVM intrinsic!");
-      case LLVMIntrinsic::va_start: 
+      case Intrinsic::va_start: 
         Out << "0; ";
         
         Out << "va_start(*(va_list*)&" << Mang->getValueName(&I) << ", ";
@@ -1212,28 +1213,28 @@
         writeOperand(&I.getParent()->getParent()->aback());
         Out << ")";
         return;
-      case LLVMIntrinsic::va_end:
+      case Intrinsic::va_end:
         Out << "va_end(*(va_list*)&";
         writeOperand(I.getOperand(1));
         Out << ")";
         return;
-      case LLVMIntrinsic::va_copy:
+      case Intrinsic::va_copy:
         Out << "0;";
         Out << "va_copy(*(va_list*)&" << Mang->getValueName(&I) << ", ";
         Out << "*(va_list*)&";
         writeOperand(I.getOperand(1));
         Out << ")";
         return;
-      case LLVMIntrinsic::setjmp:
-      case LLVMIntrinsic::sigsetjmp:
+      case Intrinsic::setjmp:
+      case Intrinsic::sigsetjmp:
         // This intrinsic should never exist in the program, but until we get
         // setjmp/longjmp transformations going on, we should codegen it to
         // something reasonable.  This will allow code that never calls longjmp
         // to work.
         Out << "0";
         return;
-      case LLVMIntrinsic::longjmp:
-      case LLVMIntrinsic::siglongjmp:
+      case Intrinsic::longjmp:
+      case Intrinsic::siglongjmp:
         // Longjmp is not implemented, and never will be.  It would cause an
         // exception throw.
         Out << "abort()";
@@ -1385,9 +1386,12 @@
   Out << ");\n  va_end(Tmp); }";
 }
 
+}
 
 //===----------------------------------------------------------------------===//
 //                       External Interface declaration
 //===----------------------------------------------------------------------===//
 
 Pass *createWriteToCPass(std::ostream &o) { return new CWriter(o); }
+
+} // End llvm namespace
diff --git a/lib/Target/MRegisterInfo.cpp b/lib/Target/MRegisterInfo.cpp
index 6f35815..7c1028b 100644
--- a/lib/Target/MRegisterInfo.cpp
+++ b/lib/Target/MRegisterInfo.cpp
@@ -13,6 +13,8 @@
 
 #include "llvm/Target/MRegisterInfo.h"
 
+namespace llvm {
+
 MRegisterInfo::MRegisterInfo(const MRegisterDesc *D, unsigned NR,
                              regclass_iterator RCB, regclass_iterator RCE,
 			     int CFSO, int CFDO)
@@ -41,3 +43,5 @@
 MRegisterInfo::~MRegisterInfo() {
   delete[] PhysRegClasses;
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp b/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp
index 2c45021..a603e94 100644
--- a/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp
+++ b/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp
@@ -18,6 +18,8 @@
 #include "llvm/Bytecode/Writer.h"
 #include <iostream>
 
+namespace llvm {
+
 using std::ostream;
 
 namespace {
@@ -113,3 +115,5 @@
 Pass *UltraSparc::getBytecodeAsmPrinterPass(std::ostream &Out) {
   return new SparcBytecodeWriter(Out);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp b/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp
index a50439d..4e2bf47 100644
--- a/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp
+++ b/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp
@@ -22,6 +22,8 @@
 #include "Support/CommandLine.h"
 #include <algorithm>
 
+namespace llvm {
+
 SchedDebugLevel_t SchedDebugLevel;
 
 static cl::opt<bool> EnableFillingDelaySlots("sched-fill-delay-slots",
@@ -1518,3 +1520,6 @@
 FunctionPass *createInstructionSchedulingWithSSAPass(const TargetMachine &tgt) {
   return new InstructionSchedulingWithSSA(tgt);
 }
+
+} // End llvm namespace
+
diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp
index e7cd478..3a80880 100644
--- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp
+++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 //*********************** Internal Data Structures *************************/
 
 // The following two types need to be classes, not typedefs, so we can use
@@ -737,3 +739,5 @@
       os << std::string(16, ' ') << *outEdges[i];
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.h b/lib/Target/SparcV9/InstrSched/SchedGraph.h
index 50cc052..5aee9b2 100644
--- a/lib/Target/SparcV9/InstrSched/SchedGraph.h
+++ b/lib/Target/SparcV9/InstrSched/SchedGraph.h
@@ -25,6 +25,8 @@
 #include "Support/hash_map"
 #include "Support/GraphTraits.h"
 
+namespace llvm {
+
 class RegToRefVecMap;
 class ValueToDefVecMap;
 class RefVec;
@@ -317,4 +319,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/InstrSched/SchedGraphCommon.cpp b/lib/Target/SparcV9/InstrSched/SchedGraphCommon.cpp
index b75e339..d96c201 100644
--- a/lib/Target/SparcV9/InstrSched/SchedGraphCommon.cpp
+++ b/lib/Target/SparcV9/InstrSched/SchedGraphCommon.cpp
@@ -15,6 +15,8 @@
 #include "llvm/CodeGen/SchedGraphCommon.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 class SchedGraphCommon;
 
 //
@@ -175,3 +177,4 @@
   this->eraseOutgoingEdges(node, addDummyEdges);	
 }
 
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp b/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp
index 1644d5e..7e05d14 100644
--- a/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp
+++ b/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/PostOrderIterator.h"
 
+namespace llvm {
+
 std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) {
   return os << "Delay for node " << nd->node->getNodeId()
 	    << " = " << (long)nd->delay << "\n";
@@ -278,3 +280,4 @@
   return lastUseMap[MI] = hasLastUse;
 }
 
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/InstrSched/SchedPriorities.h b/lib/Target/SparcV9/InstrSched/SchedPriorities.h
index de321f9..7470467 100644
--- a/lib/Target/SparcV9/InstrSched/SchedPriorities.h
+++ b/lib/Target/SparcV9/InstrSched/SchedPriorities.h
@@ -26,6 +26,8 @@
 #include "Support/hash_set"
 #include <list>
 
+namespace llvm {
+
 class Function;
 class MachineInstr;
 class SchedulingManager;
@@ -214,4 +216,6 @@
 
 std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd);
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
index 5496502..fd5056d2 100644
--- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
+++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
@@ -30,6 +30,8 @@
 #include "Support/STLExtras.h"
 #include "Config/alloca.h"
 
+namespace llvm {
+
 //------------------------------------------------------------------------ 
 // class InstrTreeNode
 //------------------------------------------------------------------------ 
@@ -330,3 +332,5 @@
   delete [] childArray;
   return treeNode;
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
index 0e3e2cd..7609765 100644
--- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
+++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
@@ -28,6 +28,8 @@
 #include "Support/LeakDetector.h"
 #include <vector>
 
+namespace llvm {
+
 std::vector<MachineInstr*>
 FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr,
                             TargetMachine& target);
@@ -82,6 +84,8 @@
   };
 }
 
+namespace llvm {
+
 TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
                                Value *s1, Value *s2, const std::string &name)
   : Instruction(s1->getType(), Instruction::UserOp1, name)
@@ -114,6 +118,7 @@
   LeakDetector::removeGarbageObject(this);
 }
 
+} // End llvm namespace
 
 bool InstructionSelection::runOnFunction(Function &F)
 {
@@ -375,7 +380,6 @@
 }
 
 
-
 //===----------------------------------------------------------------------===//
 // createInstructionSelectionPass - Public entrypoint for instruction selection
 // and this file as a whole...
@@ -383,3 +387,5 @@
 FunctionPass *createInstructionSelectionPass(TargetMachine &T) {
   return new InstructionSelection(T);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp
index 93f7618..44a4359 100644
--- a/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp
+++ b/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp
@@ -25,6 +25,7 @@
 #include "llvm/DerivedTypes.h"
 #include "../../Target/Sparc/SparcInstrSelectionSupport.h"  // FIXME!
 
+namespace llvm {
 
 // Generate code to load the constant into a TmpInstruction (virtual reg) and
 // returns the virtual register.
@@ -257,3 +258,5 @@
   
   return MVec;
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
index 68eaebf..758f1b1 100644
--- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
+++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
@@ -21,6 +21,7 @@
 /// BROKEN: Should not include sparc stuff directly into here
 #include "../../Target/Sparc/SparcInternals.h"  //  Only for PHI defn
 
+namespace llvm {
 
 BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
   : BB(bb), MBB(mbb), POID(id) {
@@ -229,6 +230,4 @@
   std::cerr << "  Out: ";  printSet(OutSet);  std::cerr << "\n";
 }
 
-
-
-
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h
index 33a4faf..781143a 100644
--- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h
+++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h
@@ -17,6 +17,9 @@
 
 #include "llvm/CodeGen/ValueSet.h"
 #include "Support/hash_map"
+
+namespace llvm {
+
 class BasicBlock;
 class Value;
 class MachineBasicBlock;
@@ -82,4 +85,6 @@
   void printInOutSets() const;    // for printing In/Out sets
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
index 588ec64..8f0e318 100644
--- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
@@ -23,6 +23,8 @@
 #include "Support/CommandLine.h"
 #include "BBLiveVar.h"
 
+namespace llvm {
+
 static RegisterAnalysis<FunctionLiveVarInfo>
 X("livevar", "Live Variable Analysis");
 
@@ -318,3 +320,5 @@
     SetAI = NewSet;                 
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/LiveVar/ValueSet.cpp b/lib/Target/SparcV9/LiveVar/ValueSet.cpp
index ba944cb..fd82896 100644
--- a/lib/Target/SparcV9/LiveVar/ValueSet.cpp
+++ b/lib/Target/SparcV9/LiveVar/ValueSet.cpp
@@ -11,6 +11,8 @@
 #include "llvm/Value.h"
 #include <iostream>
 
+namespace llvm {
+
 std::ostream &operator<<(std::ostream &O, RAV V) { // func to print a Value 
   const Value &v = V.V;
   if (v.hasName())
@@ -26,3 +28,4 @@
     std::cerr << RAV(*I);
 }
 
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/MachineCodeForInstruction.h b/lib/Target/SparcV9/MachineCodeForInstruction.h
index d421f3e..9a08de7 100644
--- a/lib/Target/SparcV9/MachineCodeForInstruction.h
+++ b/lib/Target/SparcV9/MachineCodeForInstruction.h
@@ -28,6 +28,8 @@
 #include "Support/Annotation.h"
 #include <vector>
 
+namespace llvm {
+
 class MachineInstr;
 class Instruction;
 class Value;
@@ -96,4 +98,6 @@
   CallArgsDescriptor* getCallArgsDescriptor() const    { return callArgsDesc; }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/MachineFunctionInfo.h b/lib/Target/SparcV9/MachineFunctionInfo.h
index db73322..fdf135b 100644
--- a/lib/Target/SparcV9/MachineFunctionInfo.h
+++ b/lib/Target/SparcV9/MachineFunctionInfo.h
@@ -17,6 +17,9 @@
 
 #include "Support/HashExtras.h"
 #include "Support/hash_set"
+
+namespace llvm {
+
 class MachineFunction;
 class Value;
 class Constant;
@@ -112,4 +115,6 @@
   int allocateOptionalArg(const Type* type);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/MachineInstrAnnot.h b/lib/Target/SparcV9/MachineInstrAnnot.h
index 98dde59..19d93ab 100644
--- a/lib/Target/SparcV9/MachineInstrAnnot.h
+++ b/lib/Target/SparcV9/MachineInstrAnnot.h
@@ -17,6 +17,8 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/TargetRegInfo.h"
 
+namespace llvm {
+
 class Value;
 class TmpInstruction;
 class CallInst;
@@ -88,5 +90,6 @@
   static CallArgsDescriptor *get(const MachineInstr* MI);
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/lib/Target/SparcV9/MappingInfo.cpp b/lib/Target/SparcV9/MappingInfo.cpp
index db03f13..2afde6b 100644
--- a/lib/Target/SparcV9/MappingInfo.cpp
+++ b/lib/Target/SparcV9/MappingInfo.cpp
@@ -49,6 +49,8 @@
 #include "llvm/CodeGen/MachineCodeForInstruction.h"
 #include "Support/StringExtras.h"
 
+namespace llvm {
+
 namespace {
   class MappingInfoAsmPrinter : public FunctionPass { 
     std::ostream &Out;
@@ -293,3 +295,5 @@
   return false;
 }
 
+} // End llvm namespace
+
diff --git a/lib/Target/SparcV9/MappingInfo.h b/lib/Target/SparcV9/MappingInfo.h
index f86e2b4..6af116a 100644
--- a/lib/Target/SparcV9/MappingInfo.h
+++ b/lib/Target/SparcV9/MappingInfo.h
@@ -18,6 +18,9 @@
 #include <iosfwd>
 #include <vector>
 #include <string>
+
+namespace llvm {
+
 class Pass;
 
 Pass *getMappingInfoAsmPrinterPass(std::ostream &out);
@@ -41,4 +44,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.cpp b/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.cpp
index 6318c5a..8aaaa2b 100644
--- a/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.cpp
+++ b/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.cpp
@@ -13,6 +13,8 @@
 #include "ModuloSchedGraph.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned id, int index, 
 					   const Instruction *inst, 
 					   const TargetMachine &targ) 
@@ -135,3 +137,4 @@
   //delete all the graphs
 }
 
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.h b/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.h
index 214e24c..552d699 100644
--- a/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.h
+++ b/lib/Target/SparcV9/ModuloScheduling/ModuloSchedGraph.h
@@ -22,6 +22,7 @@
 #include "Support/hash_map"
 #include <vector>
 
+namespace llvm {
 
 class ModuloSchedGraphNode : public SchedGraphNodeCommon {
 
@@ -106,4 +107,6 @@
 
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp
index 91ec6c2..219d892 100644
--- a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp
+++ b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Function.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 namespace {
   
   class ModuloScheduling : public FunctionPass {
@@ -40,3 +42,5 @@
   bool Changed = false;
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/RegAlloc/AllocInfo.h b/lib/Target/SparcV9/RegAlloc/AllocInfo.h
index f83f210..67f58a7 100644
--- a/lib/Target/SparcV9/RegAlloc/AllocInfo.h
+++ b/lib/Target/SparcV9/RegAlloc/AllocInfo.h
@@ -19,6 +19,8 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 
+namespace llvm {
+
 /// AllocInfo - Structure representing one instruction's operand's-worth of
 /// register allocation state. We create tables made out of these data
 /// structures to generate mapping information for this register allocator.
@@ -77,4 +79,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif // ALLOCINFO_H
diff --git a/lib/Target/SparcV9/RegAlloc/IGNode.cpp b/lib/Target/SparcV9/RegAlloc/IGNode.cpp
index f883fb1..a76fdea 100644
--- a/lib/Target/SparcV9/RegAlloc/IGNode.cpp
+++ b/lib/Target/SparcV9/RegAlloc/IGNode.cpp
@@ -16,6 +16,8 @@
 #include <algorithm>
 #include <iostream>
 
+namespace llvm {
+
 //-----------------------------------------------------------------------------
 // Sets this IGNode on stack and reduce the degree of neighbors  
 //-----------------------------------------------------------------------------
@@ -56,3 +58,5 @@
   std::vector<IGNode*>::iterator new_end = unique(nbrs.begin(), nbrs.end());
   return new_end - nbrs.begin();
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/RegAlloc/IGNode.h b/lib/Target/SparcV9/RegAlloc/IGNode.h
index 82f07e0..9fdc7a6 100644
--- a/lib/Target/SparcV9/RegAlloc/IGNode.h
+++ b/lib/Target/SparcV9/RegAlloc/IGNode.h
@@ -32,6 +32,9 @@
 
 #include "LiveRange.h"
 #include <vector>
+
+namespace llvm {
+
 class RegClass;
 
 //----------------------------------------------------------------------------
@@ -115,4 +118,6 @@
   inline LiveRange *getParentLR() const { return ParentLR; }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp
index 392a96c..3cef19e 100644
--- a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp
+++ b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp
@@ -17,6 +17,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 // for asserting this IG node is infact in the IGNodeList of this class
 inline static void assertIGNode(const InterferenceGraph *IG,
                                 const IGNode *Node) {
@@ -246,3 +248,5 @@
     }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h
index 6b8cf3c..79850c1 100644
--- a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h
+++ b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h
@@ -30,6 +30,9 @@
 #define INTERFERENCEGRAPH_H
 
 #include <vector>
+
+namespace llvm {
+
 class LiveRange;
 class RegClass;
 class IGNode;
@@ -67,4 +70,6 @@
   void printIGNodeList() const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/RegAlloc/LiveRange.h b/lib/Target/SparcV9/RegAlloc/LiveRange.h
index aa409c6..d6e2cf6 100644
--- a/lib/Target/SparcV9/RegAlloc/LiveRange.h
+++ b/lib/Target/SparcV9/RegAlloc/LiveRange.h
@@ -21,6 +21,8 @@
 #include "llvm/Value.h"
 #include "llvm/CodeGen/ValueSet.h"
 
+namespace llvm {
+
 class RegClass;
 class IGNode;
 
@@ -177,4 +179,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp
index b9fcda7..9fd04d2 100644
--- a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp
+++ b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include "Support/SetOperations.h"
 
+namespace llvm {
+
 unsigned LiveRange::getRegClassID() const { return getRegClass()->getID(); }
 
 LiveRangeInfo::LiveRangeInfo(const Function *F, const TargetMachine &tm,
@@ -411,3 +413,5 @@
     }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h
index 5c5244b..a8d0e71 100644
--- a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h
+++ b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h
@@ -29,6 +29,8 @@
 #include "llvm/CodeGen/ValueSet.h"
 #include "Support/hash_map"
 
+namespace llvm {
+
 class LiveRange;
 class MachineInstr;
 class RegClass;
@@ -121,4 +123,6 @@
   void printLiveRanges();
 };
 
+} // End llvm namespace
+
 #endif 
diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
index 99917cd..332ae95 100644
--- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
+++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
@@ -47,6 +47,8 @@
 #include "Support/STLExtras.h"
 #include <cmath>
 
+namespace llvm {
+
 RegAllocDebugLevel_t DEBUG_RA;
 
 /// The reoptimizer wants to be able to grovel through the register
@@ -1392,3 +1394,5 @@
   if (DEBUG_RA) std::cerr << "\nRegister allocation complete!\n"; 
   return false;     // Function was not modified
 } 
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h
index c524f9f..4ec083c 100644
--- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h
+++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h
@@ -31,6 +31,8 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include <map>
 
+namespace llvm {
+
 class MachineFunction;
 class FunctionLiveVarInfo;
 class MachineInstr;
@@ -179,4 +181,6 @@
   void addInterf4PseudoInstr(const MachineInstr *MI);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/RegAlloc/RegAllocCommon.h b/lib/Target/SparcV9/RegAlloc/RegAllocCommon.h
index 97d102a..7dd86b2 100644
--- a/lib/Target/SparcV9/RegAlloc/RegAllocCommon.h
+++ b/lib/Target/SparcV9/RegAlloc/RegAllocCommon.h
@@ -14,6 +14,8 @@
 #ifndef REGALLOCCOMMON_H
 #define REGALLOCCOMMON_H
 
+namespace llvm {
+
 enum RegAllocDebugLevel_t {
   RA_DEBUG_None         = 0,
   RA_DEBUG_Results      = 1,
@@ -25,4 +27,6 @@
 
 extern RegAllocDebugLevel_t DEBUG_RA;
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/RegAlloc/RegClass.cpp b/lib/Target/SparcV9/RegAlloc/RegClass.cpp
index 9c8603b..9af87ba 100644
--- a/lib/Target/SparcV9/RegAlloc/RegClass.cpp
+++ b/lib/Target/SparcV9/RegAlloc/RegClass.cpp
@@ -16,6 +16,8 @@
 #include "RegClass.h"
 #include "llvm/Target/TargetRegInfo.h"
 
+namespace llvm {
+
 //----------------------------------------------------------------------------
 // This constructor inits IG. The actual matrix is created by a call to 
 // createInterferenceGraph() above.
@@ -245,4 +247,4 @@
   IG.printIG(); 
 }
 
-
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/RegAlloc/RegClass.h b/lib/Target/SparcV9/RegAlloc/RegClass.h
index c861fba..0071f7c 100644
--- a/lib/Target/SparcV9/RegAlloc/RegClass.h
+++ b/lib/Target/SparcV9/RegAlloc/RegClass.h
@@ -20,6 +20,9 @@
 #include "llvm/Target/TargetRegInfo.h"
 #include "InterferenceGraph.h"
 #include <stack>
+
+namespace llvm {
+
 class TargetRegClassInfo;
 
 
@@ -139,4 +142,6 @@
   void printIG();
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/SparcV9.burg.in b/lib/Target/SparcV9/SparcV9.burg.in
index a5bc98f..38dc243 100644
--- a/lib/Target/SparcV9/SparcV9.burg.in
+++ b/lib/Target/SparcV9/SparcV9.burg.in
@@ -11,7 +11,7 @@
 Xinclude <cstdio>
 Xinclude <llvm/CodeGen/InstrForest.h>
 
-typedef InstrTreeNode* NODEPTR_TYPE;
+typedef llvm::InstrTreeNode* NODEPTR_TYPE;
 Xdefine OP_LABEL(p)	((p)->opLabel)
 Xdefine LEFT_CHILD(p)	((p)->LeftChild)
 Xdefine RIGHT_CHILD(p)	((p)->RightChild)
diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
index 2503417..6af9836 100644
--- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
+++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
@@ -33,6 +33,8 @@
 #include "SparcInternals.h"
 #include <string>
 
+namespace llvm {
+
 namespace {
 
 Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
@@ -877,12 +879,13 @@
 
 }  // End anonymous namespace
 
+namespace llvm {
+
 Pass *UltraSparc::getFunctionAsmPrinterPass(std::ostream &Out) {
   return new SparcFunctionAsmPrinter(Out, *this);
 }
 
-
-
+} // End llvm namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -954,3 +957,5 @@
 Pass *UltraSparc::getModuleAsmPrinterPass(std::ostream &Out) {
   return new SparcModuleAsmPrinter(Out, *this);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9CodeEmitter.cpp b/lib/Target/SparcV9/SparcV9CodeEmitter.cpp
index d60d915..c50dca5 100644
--- a/lib/Target/SparcV9/SparcV9CodeEmitter.cpp
+++ b/lib/Target/SparcV9/SparcV9CodeEmitter.cpp
@@ -38,6 +38,8 @@
 #include "SparcV9CodeEmitter.h"
 #include "Config/alloca.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> OverwrittenCalls("call-ovwr", "Number of over-written calls");
   Statistic<> UnmodifiedCalls("call-skip", "Number of unmodified calls");
@@ -443,7 +445,6 @@
   return (intptr_t)MCE.finishFunctionStub(*F)+4; /* 1 instr past the restore */
 }
 
-
 SparcV9CodeEmitter::SparcV9CodeEmitter(TargetMachine &tm,
                                        MachineCodeEmitter &M): TM(tm), MCE(M)
 {
@@ -809,4 +810,6 @@
   }
 }
 
+} // End llvm namespace
+
 #include "SparcV9CodeEmitter.inc"
diff --git a/lib/Target/SparcV9/SparcV9CodeEmitter.h b/lib/Target/SparcV9/SparcV9CodeEmitter.h
index 7e19c44..d21345e 100644
--- a/lib/Target/SparcV9/SparcV9CodeEmitter.h
+++ b/lib/Target/SparcV9/SparcV9CodeEmitter.h
@@ -19,6 +19,8 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Target/TargetMachine.h"
 
+namespace llvm {
+
 class GlobalValue;
 class MachineInstr;
 class MachineOperand;
@@ -81,4 +83,6 @@
 
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/SparcV9InstrInfo.cpp b/lib/Target/SparcV9/SparcV9InstrInfo.cpp
index d92e3be..11b0c7b 100644
--- a/lib/Target/SparcV9/SparcV9InstrInfo.cpp
+++ b/lib/Target/SparcV9/SparcV9InstrInfo.cpp
@@ -23,6 +23,8 @@
 #include "llvm/CodeGen/MachineCodeForInstruction.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 
+namespace llvm {
+
 static const uint32_t MAXLO   = (1 << 10) - 1; // set bits set by %lo(*)
 static const uint32_t MAXSIMM = (1 << 12) - 1; // set bits in simm13 field of OR
 
@@ -792,3 +794,5 @@
   CreateBitExtensionInstructions(/*signExtend*/ false, target, F, srcVal,
                                  destVal, numLowBits, mvec, mcfi);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp
index b377658..21e884b 100644
--- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp
+++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp
@@ -32,6 +32,8 @@
 #include <algorithm>
 #include <cmath>
 
+namespace llvm {
+
 static inline void Add3OperandInstr(unsigned Opcode, InstructionNode* Node,
                                     std::vector<MachineInstr*>& mvec) {
   mvec.push_back(BuildMI(Opcode, 3).addReg(Node->leftChild()->getValue())
@@ -1390,12 +1392,12 @@
 // instead of a regular call.  If not that kind of intrinsic, do nothing.
 // Returns true if code was generated, otherwise false.
 // 
-bool CodeGenIntrinsic(LLVMIntrinsic::ID iid, CallInst &callInstr,
+bool CodeGenIntrinsic(Intrinsic::ID iid, CallInst &callInstr,
                       TargetMachine &target,
                       std::vector<MachineInstr*>& mvec)
 {
   switch (iid) {
-  case LLVMIntrinsic::va_start: {
+  case Intrinsic::va_start: {
     // Get the address of the first incoming vararg argument on the stack
     bool ignore;
     Function* func = cast<Function>(callInstr.getParent()->getParent());
@@ -1409,10 +1411,10 @@
     return true;
   }
 
-  case LLVMIntrinsic::va_end:
+  case Intrinsic::va_end:
     return true;                        // no-op on Sparc
 
-  case LLVMIntrinsic::va_copy:
+  case Intrinsic::va_copy:
     // Simple copy of current va_list (arg1) to new va_list (result)
     mvec.push_back(BuildMI(V9::ORr, 3).
                    addMReg(target.getRegInfo().getZeroRegNum()).
@@ -1420,8 +1422,8 @@
                    addRegDef(&callInstr));
     return true;
 
-  case LLVMIntrinsic::sigsetjmp:
-  case LLVMIntrinsic::setjmp: {
+  case Intrinsic::sigsetjmp:
+  case Intrinsic::setjmp: {
     // act as if we return 0
     unsigned g0 = target.getRegInfo().getZeroRegNum();
     mvec.push_back(BuildMI(V9::ORr,3).addMReg(g0).addMReg(g0)
@@ -1429,8 +1431,8 @@
     return true;
   }
 
-  case LLVMIntrinsic::siglongjmp:
-  case LLVMIntrinsic::longjmp: {
+  case Intrinsic::siglongjmp:
+  case Intrinsic::longjmp: {
     // call abort()
     Module* M = callInstr.getParent()->getParent()->getParent();
     const FunctionType *voidvoidFuncTy =
@@ -2474,8 +2476,8 @@
         // sequence (e.g., va_start).  Indirect calls cannot be special.
         // 
         bool specialIntrinsic = false;
-        LLVMIntrinsic::ID iid;
-        if (calledFunc && (iid=(LLVMIntrinsic::ID)calledFunc->getIntrinsicID()))
+        Intrinsic::ID iid;
+        if (calledFunc && (iid=(Intrinsic::ID)calledFunc->getIntrinsicID()))
           specialIntrinsic = CodeGenIntrinsic(iid, *callInstr, target, mvec);
 
         // If not, generate the normal call sequence for the function.
@@ -2929,3 +2931,5 @@
     }
   }
 }
+
+}
diff --git a/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h b/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h
index d49863c..b69c5c2 100644
--- a/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h
+++ b/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h
@@ -17,6 +17,8 @@
 #include "llvm/DerivedTypes.h"
 #include "SparcInternals.h"
 
+namespace llvm {
+
 // Choose load instruction opcode based on type of value
 inline MachineOpCode
 ChooseLoadInstruction(const Type *DestTy)
@@ -220,4 +222,6 @@
   }
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/SparcV9Internals.h b/lib/Target/SparcV9/SparcV9Internals.h
index 4d0a48e..5e5f155 100644
--- a/lib/Target/SparcV9/SparcV9Internals.h
+++ b/lib/Target/SparcV9/SparcV9Internals.h
@@ -25,6 +25,8 @@
 #include "SparcRegClassInfo.h"
 #include "Config/sys/types.h"
 
+namespace llvm {
+
 class LiveRange;
 class UltraSparc;
 class Pass;
@@ -693,4 +695,6 @@
   Pass* getBytecodeAsmPrinterPass(std::ostream &Out);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp b/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp
index 83081b7..9713a02 100644
--- a/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp
+++ b/lib/Target/SparcV9/SparcV9PeepholeOpts.cpp
@@ -20,6 +20,8 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 //************************* Internal Functions *****************************/
 
 static inline void
@@ -163,3 +165,5 @@
 FunctionPass* createPeepholeOptsPass(const TargetMachine &TM) {
   return new PeepholeOpts(TM);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9PreSelection.cpp b/lib/Target/SparcV9/SparcV9PreSelection.cpp
index 9078dc1..205ecd3 100644
--- a/lib/Target/SparcV9/SparcV9PreSelection.cpp
+++ b/lib/Target/SparcV9/SparcV9PreSelection.cpp
@@ -29,6 +29,8 @@
 #include "llvm/Transforms/Scalar.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
 
   //===--------------------------------------------------------------------===//
@@ -71,6 +73,7 @@
                                "Specialize LLVM code for a target machine"
                                createPreselectionPass);
 #endif
+
 }  // end anonymous namespace
 
 
@@ -236,7 +239,6 @@
   visitOperands(I, (/*firstOp=*/ I.getCalledFunction()? 1 : 0));
 }
 
-
 //===----------------------------------------------------------------------===//
 // createPreSelectionPass - Public entrypoint for pre-selection pass
 // and this file as a whole...
@@ -244,3 +246,5 @@
 FunctionPass* createPreSelectionPass(const TargetMachine &TM) {
   return new PreSelection(TM);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp b/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp
index ff7bd7d..555b6b1 100644
--- a/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp
+++ b/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp
@@ -27,6 +27,8 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Intrinsics.h"
 
+namespace llvm {
+
 namespace {
   struct InsertPrologEpilogCode : public MachineFunctionPass {
     const char *getPassName() const { return "Sparc Prolog/Epilog Inserter"; }
@@ -177,3 +179,5 @@
 FunctionPass *UltraSparc::getPrologEpilogInsertionPass() {
   return new InsertPrologEpilogCode();
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9RegClassInfo.cpp b/lib/Target/SparcV9/SparcV9RegClassInfo.cpp
index d6de5f9..564e59c 100644
--- a/lib/Target/SparcV9/SparcV9RegClassInfo.cpp
+++ b/lib/Target/SparcV9/SparcV9RegClassInfo.cpp
@@ -17,6 +17,8 @@
 #include "../../CodeGen/RegAlloc/RegAllocCommon.h"   // FIXME!
 #include "../../CodeGen/RegAlloc/IGNode.h"           // FIXME!
 
+namespace llvm {
+
 //-----------------------------------------------------------------------------
 // Int Register Class - method for coloring a node in the interference graph.
 //
@@ -390,3 +392,5 @@
   return -1;
 
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9RegClassInfo.h b/lib/Target/SparcV9/SparcV9RegClassInfo.h
index 321ce60..cc492e7 100644
--- a/lib/Target/SparcV9/SparcV9RegClassInfo.h
+++ b/lib/Target/SparcV9/SparcV9RegClassInfo.h
@@ -16,6 +16,8 @@
 
 #include "llvm/Target/TargetRegInfo.h"
 
+namespace llvm {
+
 //-----------------------------------------------------------------------------
 // Integer Register Class
 //-----------------------------------------------------------------------------
@@ -217,4 +219,6 @@
   const char * const getRegName(unsigned reg) const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/SparcV9/SparcV9RegInfo.cpp b/lib/Target/SparcV9/SparcV9RegInfo.cpp
index 84dc92e..5edbbe0 100644
--- a/lib/Target/SparcV9/SparcV9RegInfo.cpp
+++ b/lib/Target/SparcV9/SparcV9RegInfo.cpp
@@ -27,6 +27,8 @@
 #include "llvm/Function.h"
 #include "llvm/DerivedTypes.h"
 
+namespace llvm {
+
 enum {
   BadRegClass = ~0
 };
@@ -967,3 +969,5 @@
     std::cerr << "+" << getUnifiedRegName(uRegName+1);
   std::cerr << "]\n";
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9SchedInfo.cpp b/lib/Target/SparcV9/SparcV9SchedInfo.cpp
index fd03ad6..7d8ea05 100644
--- a/lib/Target/SparcV9/SparcV9SchedInfo.cpp
+++ b/lib/Target/SparcV9/SparcV9SchedInfo.cpp
@@ -13,6 +13,8 @@
 
 #include "SparcInternals.h"
 
+using namespace llvm;
+
 /*---------------------------------------------------------------------------
 Scheduling guidelines for SPARC IIi:
 
diff --git a/lib/Target/SparcV9/SparcV9StackSlots.cpp b/lib/Target/SparcV9/SparcV9StackSlots.cpp
index 551dd92..5fd0ba1 100644
--- a/lib/Target/SparcV9/SparcV9StackSlots.cpp
+++ b/lib/Target/SparcV9/SparcV9StackSlots.cpp
@@ -20,6 +20,8 @@
 #include "llvm/CodeGen/MachineFunctionInfo.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 
+namespace llvm {
+
 namespace {
   class StackSlots : public MachineFunctionPass {
     const TargetMachine &Target;
@@ -48,3 +50,5 @@
 Pass *createStackSlotsPass(const TargetMachine &Target) {
   return new StackSlots(Target);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/SparcV9/SparcV9TargetMachine.cpp b/lib/Target/SparcV9/SparcV9TargetMachine.cpp
index d20fc75..73f2fd8 100644
--- a/lib/Target/SparcV9/SparcV9TargetMachine.cpp
+++ b/lib/Target/SparcV9/SparcV9TargetMachine.cpp
@@ -27,6 +27,8 @@
 #include "llvm/Target/TargetMachineImpls.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */
 // Build the MachineInstruction Description Array...
 const TargetInstrDescriptor SparcMachineInstrDesc[] = {
@@ -267,3 +269,5 @@
 
   return false; // success!
 }
+
+} // End llvm namespace
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index a377fd0..ed6936d 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -22,13 +22,14 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 
+namespace llvm {
+
 // Handle the Pass registration stuff necessary to use TargetData's.
 namespace {
   // Register the default SparcV9 implementation...
   RegisterPass<TargetData> X("targetdata", "Target Data Layout");
 }
 
-
 static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
 			       uint64_t &Size, unsigned char &Alignment);
 
@@ -221,3 +222,5 @@
 
   return Result;
 }
+
+} // End llvm namespace
diff --git a/lib/Target/TargetInstrInfo.cpp b/lib/Target/TargetInstrInfo.cpp
index f377d67..0f9015f 100644
--- a/lib/Target/TargetInstrInfo.cpp
+++ b/lib/Target/TargetInstrInfo.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Constant.h"
 #include "llvm/DerivedTypes.h"
 
+namespace llvm {
+
 // External object describing the machine instructions
 // Initialized only when the TargetMachine class is created
 // and reset when that class is destroyed.
@@ -59,3 +61,5 @@
   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
 }
+
+} // End llvm namespace
diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp
index b7c1b34..e7630b4 100644
--- a/lib/Target/TargetMachine.cpp
+++ b/lib/Target/TargetMachine.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Target/TargetCacheInfo.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 //---------------------------------------------------------------------------
 // class TargetMachine
 // 
@@ -49,3 +51,5 @@
   cacheSizes.push_back(1 << 15); cacheSizes.push_back(1 << 20);
   cacheAssoc.push_back(1);       cacheAssoc.push_back(4);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/TargetSchedInfo.cpp b/lib/Target/TargetSchedInfo.cpp
index 0dbde45..f33223c 100644
--- a/lib/Target/TargetSchedInfo.cpp
+++ b/lib/Target/TargetSchedInfo.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Target/TargetSchedInfo.h"
 #include "llvm/Target/TargetMachine.h"
 
+namespace llvm {
+
 resourceId_t MachineResource::nextId = 0;
 
 // Check if fromRVec and toRVec have *any* common entries.
@@ -249,3 +251,5 @@
       assert(r >= 0 && "Resource to remove was unused in cycle c!");
     }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/FloatingPoint.cpp b/lib/Target/X86/FloatingPoint.cpp
index 07e58ba..5c6e6eb 100644
--- a/lib/Target/X86/FloatingPoint.cpp
+++ b/lib/Target/X86/FloatingPoint.cpp
@@ -25,6 +25,8 @@
 #include <algorithm>
 #include <iostream>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumFXCH("x86-codegen", "Number of fxch instructions inserted");
   Statistic<> NumFP  ("x86-codegen", "Number of floating point instructions");
@@ -70,7 +72,7 @@
     // getSTReg - Return the X86::ST(i) register which contains the specified
     // FP<RegNo> register
     unsigned getSTReg(unsigned RegNo) const {
-      return StackTop - 1 - getSlot(RegNo) + X86::ST0;
+      return StackTop - 1 - getSlot(RegNo) + llvm::X86::ST0;
     }
 
     // pushReg - Push the specifiex FP<n> register onto the stack
@@ -598,3 +600,5 @@
 
   I = MBB->erase(I)-1;  // Remove the pseudo instruction
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/InstSelectPattern.cpp b/lib/Target/X86/InstSelectPattern.cpp
index 434ceee..e518294 100644
--- a/lib/Target/X86/InstSelectPattern.cpp
+++ b/lib/Target/X86/InstSelectPattern.cpp
@@ -28,6 +28,8 @@
 // Include the generated instruction selector...
 #include "X86GenInstrSelector.inc"
 
+namespace llvm {
+
 namespace {
   struct ISel : public FunctionPass, SelectionDAGTargetBuilder {
     TargetMachine &TM;
@@ -114,7 +116,6 @@
   assert(0 && "ISel::expandCall not implemented!");
 }
 
-
 /// createX86PatternInstructionSelector - This pass converts an LLVM function
 /// into a machine code representation using pattern matching and a machine
 /// description file.
@@ -122,3 +123,5 @@
 FunctionPass *createX86PatternInstructionSelector(TargetMachine &TM) {
   return new ISel(TM);  
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index 1242545..de341c4 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -29,6 +29,8 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/InstVisitor.h"
 
+namespace llvm {
+
 /// BMI - A special BuildMI variant that takes an iterator to insert the
 /// instruction at as well as a basic block.  This is the version for when you
 /// have a destination register in mind.
@@ -138,7 +140,7 @@
     void doCall(const ValueRecord &Ret, MachineInstr *CallMI,
                 const std::vector<ValueRecord> &Args);
     void visitCallInst(CallInst &I);
-    void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
+    void visitIntrinsicCall(Intrinsic::ID ID, CallInst &I);
 
     // Arithmetic operators
     void visitSimpleBinary(BinaryOperator &B, unsigned OpcodeClass);
@@ -1045,7 +1047,7 @@
   MachineInstr *TheCall;
   if (Function *F = CI.getCalledFunction()) {
     // Is it an intrinsic function call?
-    if (LLVMIntrinsic::ID ID = (LLVMIntrinsic::ID)F->getIntrinsicID()) {
+    if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
       visitIntrinsicCall(ID, CI);   // Special intrinsics are not handled here
       return;
     }
@@ -1066,29 +1068,29 @@
 }         
 
 
-void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
+void ISel::visitIntrinsicCall(Intrinsic::ID ID, CallInst &CI) {
   unsigned TmpReg1, TmpReg2;
   switch (ID) {
-  case LLVMIntrinsic::va_start:
+  case Intrinsic::va_start:
     // Get the address of the first vararg value...
     TmpReg1 = getReg(CI);
     addFrameReference(BuildMI(BB, X86::LEAr32, 5, TmpReg1), VarArgsFrameIndex);
     return;
 
-  case LLVMIntrinsic::va_copy:
+  case Intrinsic::va_copy:
     TmpReg1 = getReg(CI);
     TmpReg2 = getReg(CI.getOperand(1));
     BuildMI(BB, X86::MOVrr32, 1, TmpReg1).addReg(TmpReg2);
     return;
-  case LLVMIntrinsic::va_end: return;   // Noop on X86
+  case Intrinsic::va_end: return;   // Noop on X86
 
-  case LLVMIntrinsic::longjmp:
-  case LLVMIntrinsic::siglongjmp:
+  case Intrinsic::longjmp:
+  case Intrinsic::siglongjmp:
     BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true); 
     return;
 
-  case LLVMIntrinsic::setjmp:
-  case LLVMIntrinsic::sigsetjmp:
+  case Intrinsic::setjmp:
+  case Intrinsic::sigsetjmp:
     // Setjmp always returns zero...
     BuildMI(BB, X86::MOVir32, 1, getReg(CI)).addZImm(0);
     return;
@@ -2127,7 +2129,6 @@
   doCall(ValueRecord(0, Type::VoidTy), TheCall, Args);
 }
    
-
 /// createX86SimpleInstructionSelector - This pass converts an LLVM function
 /// into a machine code representation is a very simple peep-hole fashion.  The
 /// generated code sucks but the implementation is nice and simple.
@@ -2135,3 +2136,5 @@
 FunctionPass *createX86SimpleInstructionSelector(TargetMachine &TM) {
   return new ISel(TM);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/PeepholeOptimizer.cpp b/lib/Target/X86/PeepholeOptimizer.cpp
index fbc84f7..2f3280a 100644
--- a/lib/Target/X86/PeepholeOptimizer.cpp
+++ b/lib/Target/X86/PeepholeOptimizer.cpp
@@ -15,6 +15,8 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 
+namespace llvm {
+
 namespace {
   struct PH : public MachineFunctionPass {
     virtual bool runOnMachineFunction(MachineFunction &MF);
@@ -131,3 +133,5 @@
     return false;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/Printer.cpp b/lib/Target/X86/Printer.cpp
index 3d073f7..292a465 100644
--- a/lib/Target/X86/Printer.cpp
+++ b/lib/Target/X86/Printer.cpp
@@ -29,6 +29,8 @@
 #include "Support/StringExtras.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
@@ -960,3 +962,5 @@
   delete Mang;
   return false; // success
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86.h b/lib/Target/X86/X86.h
index 01041f8..5cf897f 100644
--- a/lib/Target/X86/X86.h
+++ b/lib/Target/X86/X86.h
@@ -16,6 +16,9 @@
 #define TARGET_X86_H
 
 #include <iosfwd>
+
+namespace llvm {
+
 class TargetMachine;
 class FunctionPass;
 
@@ -58,6 +61,8 @@
 // Defines symbolic names for X86 registers.  This defines a mapping from
 // register name to register number.
 //
+} // End llvm namespace
+
 #include "X86GenRegisterNames.inc"
 
 // Defines symbolic names for the X86 instructions.
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
index 3d073f7..292a465 100644
--- a/lib/Target/X86/X86AsmPrinter.cpp
+++ b/lib/Target/X86/X86AsmPrinter.cpp
@@ -29,6 +29,8 @@
 #include "Support/StringExtras.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
@@ -960,3 +962,5 @@
   delete Mang;
   return false; // success
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp
index f49fde5..e24e290 100644
--- a/lib/Target/X86/X86CodeEmitter.cpp
+++ b/lib/Target/X86/X86CodeEmitter.cpp
@@ -24,6 +24,8 @@
 #include "Support/Statistic.h"
 #include "Config/alloca.h"
 
+namespace llvm {
+
 namespace {
   Statistic<>
   NumEmitted("x86-emitter", "Number of machine instructions emitted");
@@ -589,3 +591,5 @@
     break;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86FloatingPoint.cpp b/lib/Target/X86/X86FloatingPoint.cpp
index 07e58ba..5c6e6eb 100644
--- a/lib/Target/X86/X86FloatingPoint.cpp
+++ b/lib/Target/X86/X86FloatingPoint.cpp
@@ -25,6 +25,8 @@
 #include <algorithm>
 #include <iostream>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumFXCH("x86-codegen", "Number of fxch instructions inserted");
   Statistic<> NumFP  ("x86-codegen", "Number of floating point instructions");
@@ -70,7 +72,7 @@
     // getSTReg - Return the X86::ST(i) register which contains the specified
     // FP<RegNo> register
     unsigned getSTReg(unsigned RegNo) const {
-      return StackTop - 1 - getSlot(RegNo) + X86::ST0;
+      return StackTop - 1 - getSlot(RegNo) + llvm::X86::ST0;
     }
 
     // pushReg - Push the specifiex FP<n> register onto the stack
@@ -598,3 +600,5 @@
 
   I = MBB->erase(I)-1;  // Remove the pseudo instruction
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86ISelPattern.cpp b/lib/Target/X86/X86ISelPattern.cpp
index 434ceee..e518294 100644
--- a/lib/Target/X86/X86ISelPattern.cpp
+++ b/lib/Target/X86/X86ISelPattern.cpp
@@ -28,6 +28,8 @@
 // Include the generated instruction selector...
 #include "X86GenInstrSelector.inc"
 
+namespace llvm {
+
 namespace {
   struct ISel : public FunctionPass, SelectionDAGTargetBuilder {
     TargetMachine &TM;
@@ -114,7 +116,6 @@
   assert(0 && "ISel::expandCall not implemented!");
 }
 
-
 /// createX86PatternInstructionSelector - This pass converts an LLVM function
 /// into a machine code representation using pattern matching and a machine
 /// description file.
@@ -122,3 +123,5 @@
 FunctionPass *createX86PatternInstructionSelector(TargetMachine &TM) {
   return new ISel(TM);  
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index 1242545..de341c4 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.cpp
@@ -29,6 +29,8 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/InstVisitor.h"
 
+namespace llvm {
+
 /// BMI - A special BuildMI variant that takes an iterator to insert the
 /// instruction at as well as a basic block.  This is the version for when you
 /// have a destination register in mind.
@@ -138,7 +140,7 @@
     void doCall(const ValueRecord &Ret, MachineInstr *CallMI,
                 const std::vector<ValueRecord> &Args);
     void visitCallInst(CallInst &I);
-    void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
+    void visitIntrinsicCall(Intrinsic::ID ID, CallInst &I);
 
     // Arithmetic operators
     void visitSimpleBinary(BinaryOperator &B, unsigned OpcodeClass);
@@ -1045,7 +1047,7 @@
   MachineInstr *TheCall;
   if (Function *F = CI.getCalledFunction()) {
     // Is it an intrinsic function call?
-    if (LLVMIntrinsic::ID ID = (LLVMIntrinsic::ID)F->getIntrinsicID()) {
+    if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
       visitIntrinsicCall(ID, CI);   // Special intrinsics are not handled here
       return;
     }
@@ -1066,29 +1068,29 @@
 }         
 
 
-void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
+void ISel::visitIntrinsicCall(Intrinsic::ID ID, CallInst &CI) {
   unsigned TmpReg1, TmpReg2;
   switch (ID) {
-  case LLVMIntrinsic::va_start:
+  case Intrinsic::va_start:
     // Get the address of the first vararg value...
     TmpReg1 = getReg(CI);
     addFrameReference(BuildMI(BB, X86::LEAr32, 5, TmpReg1), VarArgsFrameIndex);
     return;
 
-  case LLVMIntrinsic::va_copy:
+  case Intrinsic::va_copy:
     TmpReg1 = getReg(CI);
     TmpReg2 = getReg(CI.getOperand(1));
     BuildMI(BB, X86::MOVrr32, 1, TmpReg1).addReg(TmpReg2);
     return;
-  case LLVMIntrinsic::va_end: return;   // Noop on X86
+  case Intrinsic::va_end: return;   // Noop on X86
 
-  case LLVMIntrinsic::longjmp:
-  case LLVMIntrinsic::siglongjmp:
+  case Intrinsic::longjmp:
+  case Intrinsic::siglongjmp:
     BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true); 
     return;
 
-  case LLVMIntrinsic::setjmp:
-  case LLVMIntrinsic::sigsetjmp:
+  case Intrinsic::setjmp:
+  case Intrinsic::sigsetjmp:
     // Setjmp always returns zero...
     BuildMI(BB, X86::MOVir32, 1, getReg(CI)).addZImm(0);
     return;
@@ -2127,7 +2129,6 @@
   doCall(ValueRecord(0, Type::VoidTy), TheCall, Args);
 }
    
-
 /// createX86SimpleInstructionSelector - This pass converts an LLVM function
 /// into a machine code representation is a very simple peep-hole fashion.  The
 /// generated code sucks but the implementation is nice and simple.
@@ -2135,3 +2136,5 @@
 FunctionPass *createX86SimpleInstructionSelector(TargetMachine &TM) {
   return new ISel(TM);
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86InstrBuilder.h b/lib/Target/X86/X86InstrBuilder.h
index a6d65d4..a5643bd 100644
--- a/lib/Target/X86/X86InstrBuilder.h
+++ b/lib/Target/X86/X86InstrBuilder.h
@@ -26,6 +26,8 @@
 
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 
+namespace llvm {
+
 /// addDirectMem - This function is used to add a direct memory reference to the
 /// current instruction -- that is, a dereference of an address in a register,
 /// with no scale, index or displacement. An example is: DWORD PTR [EAX].
@@ -69,4 +71,6 @@
   return MIB.addConstantPoolIndex(CPI).addZImm(1).addReg(0).addSImm(Offset);
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp
index 012cead..681bf02 100644
--- a/lib/Target/X86/X86InstrInfo.cpp
+++ b/lib/Target/X86/X86InstrInfo.cpp
@@ -17,6 +17,8 @@
 
 #include "X86GenInstrInfo.inc"
 
+using namespace llvm;
+
 X86InstrInfo::X86InstrInfo()
   : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0]), 0) {
 }
diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h
index 26b2618..2bf82d1 100644
--- a/lib/Target/X86/X86InstrInfo.h
+++ b/lib/Target/X86/X86InstrInfo.h
@@ -17,6 +17,8 @@
 #include "llvm/Target/TargetInstrInfo.h"
 #include "X86RegisterInfo.h"
 
+namespace llvm {
+
 /// X86II - This namespace holds all of the target specific flags that
 /// instruction info tracks.
 ///
@@ -181,4 +183,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/X86/X86PeepholeOpt.cpp b/lib/Target/X86/X86PeepholeOpt.cpp
index fbc84f7..2f3280a 100644
--- a/lib/Target/X86/X86PeepholeOpt.cpp
+++ b/lib/Target/X86/X86PeepholeOpt.cpp
@@ -15,6 +15,8 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 
+namespace llvm {
+
 namespace {
   struct PH : public MachineFunctionPass {
     virtual bool runOnMachineFunction(MachineFunction &MF);
@@ -131,3 +133,5 @@
     return false;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index fd8a615..0e8b889 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Target/TargetFrameInfo.h"
 #include "Support/CommandLine.h"
 
+namespace llvm {
+
 namespace {
   cl::opt<bool>
   NoFPElim("disable-fp-elim",
@@ -253,8 +255,12 @@
   return MBB.size() - oldSize;
 }
 
+} // End llvm namespace
+
 #include "X86GenRegisterInfo.inc"
 
+namespace llvm {
+
 const TargetRegisterClass*
 X86RegisterInfo::getRegClassForType(const Type* Ty) const {
   switch (Ty->getPrimitiveID()) {
@@ -274,3 +280,5 @@
   case Type::DoubleTyID: return &RFPInstance;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86RegisterInfo.h b/lib/Target/X86/X86RegisterInfo.h
index 0db8e18..77a8a1a 100644
--- a/lib/Target/X86/X86RegisterInfo.h
+++ b/lib/Target/X86/X86RegisterInfo.h
@@ -16,10 +16,12 @@
 
 #include "llvm/Target/MRegisterInfo.h"
 
-class Type;
+class llvm::Type;
 
 #include "X86GenRegisterInfo.h.inc"
 
+namespace llvm {
+
 struct X86RegisterInfo : public X86GenRegisterInfo {
   X86RegisterInfo();
   const TargetRegisterClass* getRegClassForType(const Type* Ty) const;
@@ -52,4 +54,6 @@
   int emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp
index 954d4f4..31eb4bd 100644
--- a/lib/Target/X86/X86TargetMachine.cpp
+++ b/lib/Target/X86/X86TargetMachine.cpp
@@ -22,6 +22,8 @@
 #include "Support/CommandLine.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   cl::opt<bool> PrintCode("print-machineinstrs",
 			  cl::desc("Print generated machine code"));
@@ -153,3 +155,5 @@
   int32_t OldAddr = (intptr_t) OldWord;
   *OldWord = NewAddr - OldAddr - 4; // Emit PC-relative addr of New code.
 }
+
+} // End llvm namespace
diff --git a/lib/Target/X86/X86TargetMachine.h b/lib/Target/X86/X86TargetMachine.h
index 5581da4..12f5c0e6 100644
--- a/lib/Target/X86/X86TargetMachine.h
+++ b/lib/Target/X86/X86TargetMachine.h
@@ -19,6 +19,8 @@
 #include "llvm/PassManager.h"
 #include "X86InstrInfo.h"
 
+namespace llvm {
+
 class X86TargetMachine : public TargetMachine {
   X86InstrInfo InstrInfo;
   TargetFrameInfo FrameInfo;
@@ -55,4 +57,6 @@
   virtual void replaceMachineCodeForFunction (void *Old, void *New);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index d3e9287..970be52 100644
--- a/lib/Transforms/ExprTypeConvert.cpp
+++ b/lib/Transforms/ExprTypeConvert.cpp
@@ -23,6 +23,8 @@
 #include "Support/Debug.h"
 #include <algorithm>
 
+namespace llvm {
+
 static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
                                      ValueTypeCache &ConvertedTypes,
                                      const TargetData &TD);
@@ -1298,3 +1300,5 @@
     //                << Operands[0]->use_size() << " " << Operands[0]);
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Hello/Hello.cpp b/lib/Transforms/Hello/Hello.cpp
index a71bd34..4ed281a 100644
--- a/lib/Transforms/Hello/Hello.cpp
+++ b/lib/Transforms/Hello/Hello.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Pass.h"
 #include "llvm/Function.h"
 
+namespace llvm {
+
 namespace {
   // Hello - The first implementation, without getAnalysisUsage.
   struct Hello : public FunctionPass {
@@ -39,3 +41,5 @@
   }; 
   RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp
index a452682..498cd7b 100644
--- a/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/lib/Transforms/IPO/ConstantMerge.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Pass.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumMerged("constmerge", "Number of global constants merged");
 
@@ -37,7 +39,6 @@
 
 Pass *createConstantMergePass() { return new ConstantMerge(); }
 
-
 bool ConstantMerge::run(Module &M) {
   std::map<Constant*, GlobalVariable*> CMap;
   bool MadeChanges = false;
@@ -78,3 +79,5 @@
 
   return MadeChanges;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 9003f88..197710d 100644
--- a/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -30,6 +30,8 @@
 #include "Support/iterator"
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumArgumentsEliminated("deadargelim",
                                      "Number of unread args removed");
@@ -576,3 +578,6 @@
     RemoveDeadArgumentsFromFunction(*DeadRetVal.begin());
   return true;
 }
+
+} // End llvm namespace
+
diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp
index c3eb416..126991d 100644
--- a/lib/Transforms/IPO/DeadTypeElimination.cpp
+++ b/lib/Transforms/IPO/DeadTypeElimination.cpp
@@ -19,6 +19,8 @@
 #include "llvm/DerivedTypes.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   struct DTE : public Pass {
     // doPassInitialization - For this pass, it removes global symbol table
@@ -45,7 +47,6 @@
 }
 
 
-
 // ShouldNukeSymtabEntry - Return true if this module level symbol table entry
 // should be eliminated.
 //
@@ -95,3 +96,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/ExtractFunction.cpp b/lib/Transforms/IPO/ExtractFunction.cpp
index 1656c51..c1ae2d4 100644
--- a/lib/Transforms/IPO/ExtractFunction.cpp
+++ b/lib/Transforms/IPO/ExtractFunction.cpp
@@ -10,6 +10,8 @@
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 
+namespace llvm {
+
 namespace {
   class FunctionExtractorPass : public Pass {
     Function *Named;
@@ -90,3 +92,5 @@
 Pass *createFunctionExtractionPass(Function *F) {
   return new FunctionExtractorPass(F);
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp
index a21853d..2a366c8 100644
--- a/lib/Transforms/IPO/FunctionResolution.cpp
+++ b/lib/Transforms/IPO/FunctionResolution.cpp
@@ -29,6 +29,8 @@
 #include "Support/Statistic.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   Statistic<>NumResolved("funcresolve", "Number of varargs functions resolved");
   Statistic<> NumGlobals("funcresolve", "Number of global variables resolved");
@@ -329,3 +331,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp
index dc40026..8e7920d 100644
--- a/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/lib/Transforms/IPO/GlobalDCE.cpp
@@ -22,6 +22,8 @@
 #include "Support/Statistic.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumFunctions("globaldce","Number of functions removed");
   Statistic<> NumVariables("globaldce","Number of global variables removed");
@@ -195,3 +197,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp
index b592138..b0135d1 100644
--- a/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Support/CallSite.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumArgumentsProped("ipconstprop",
                                  "Number of args turned into constants");
@@ -121,3 +123,5 @@
     }
   return MadeChange;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index 169e577..715f446 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Support/CallSite.h"
 #include "llvm/Transforms/IPO.h"
 
+namespace llvm {
+
 namespace {
   // FunctionInfo - For each function, calculate the size of it in blocks and
   // instructions.
@@ -114,3 +116,5 @@
   InlineCost += CalleeFI.NumInsts*10 + CalleeFI.NumBlocks*20;
   return InlineCost;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp
index 8ad72ab..bd1bd83 100644
--- a/lib/Transforms/IPO/Inliner.cpp
+++ b/lib/Transforms/IPO/Inliner.cpp
@@ -24,6 +24,8 @@
 #include "Support/Debug.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumInlined("inline", "Number of functions inlined");
   Statistic<> NumDeleted("inline", "Number of functions deleted because all callers found");
@@ -134,3 +136,5 @@
   }
   return true; 
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/Inliner.h b/lib/Transforms/IPO/Inliner.h
index 1f3d0d2..805876c 100644
--- a/lib/Transforms/IPO/Inliner.h
+++ b/lib/Transforms/IPO/Inliner.h
@@ -20,6 +20,9 @@
 #define DEBUG_TYPE "inline"
 #include "llvm/CallGraphSCCPass.h"
 #include <set>
+
+namespace llvm {
+
 class CallSite;
 
 /// Inliner - This class contains all of the helper code which is used to
@@ -61,5 +64,6 @@
   bool performInlining(CallSite CS, std::set<Function*> &SCC);
 };
 
+} // End llvm namespace
 
 #endif
diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp
index 92d389a..574c8bf 100644
--- a/lib/Transforms/IPO/Internalize.cpp
+++ b/lib/Transforms/IPO/Internalize.cpp
@@ -22,6 +22,8 @@
 #include <fstream>
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumFunctions("internalize", "Number of functions internalized");
   Statistic<> NumGlobals  ("internalize", "Number of global vars internalized");
@@ -119,3 +121,5 @@
 Pass *createInternalizePass() {
   return new InternalizePass();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp
index abbc2c9..276523b 100644
--- a/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -47,6 +47,8 @@
 #include "Support/StringExtras.h"
 #include "Support/VectorExtras.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> LongJmpsTransformed("lowersetjmp",
                                   "Number of longjmps transformed");
@@ -538,3 +540,5 @@
 {
   return new LowerSetJmp();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp
index dfaf8a8..41835ad 100644
--- a/lib/Transforms/IPO/MutateStructTypes.cpp
+++ b/lib/Transforms/IPO/MutateStructTypes.cpp
@@ -28,6 +28,8 @@
 #include "Support/Debug.h"
 #include <algorithm>
 
+using namespace llvm;
+
 // ValuePlaceHolder - A stupid little marker value.  It appears as an
 // instruction of type Instruction::UserOp1.
 //
diff --git a/lib/Transforms/IPO/Parallelize.cpp b/lib/Transforms/IPO/Parallelize.cpp
index 77e6ed3..fd39b6b 100644
--- a/lib/Transforms/IPO/Parallelize.cpp
+++ b/lib/Transforms/IPO/Parallelize.cpp
@@ -53,6 +53,8 @@
 #include <functional>
 #include <algorithm>
 
+namespace llvm {
+
 //---------------------------------------------------------------------------- 
 // Global constants used in marking Cilk functions and function calls.
 //---------------------------------------------------------------------------- 
@@ -535,3 +537,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp
index b377a8b..30e2514 100644
--- a/lib/Transforms/IPO/PruneEH.cpp
+++ b/lib/Transforms/IPO/PruneEH.cpp
@@ -23,6 +23,8 @@
 #include "Support/Statistic.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumRemoved("prune-eh", "Number of invokes removed");
 
@@ -104,3 +106,5 @@
 
   return MadeChange; 
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp
index 81abda0..fd5b7fb 100644
--- a/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Support/CallSite.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumRaised("raiseallocs", "Number of allocations raised");
 
@@ -194,3 +196,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp
index 012fa22..0c70916 100644
--- a/lib/Transforms/IPO/SimpleStructMutation.cpp
+++ b/lib/Transforms/IPO/SimpleStructMutation.cpp
@@ -23,6 +23,8 @@
 using std::set;
 using std::pair;
 
+namespace llvm {
+
 namespace {
   struct SimpleStructMutation : public MutateStructTypes {
     enum Transform { SwapElements, SortElements };
@@ -188,3 +190,5 @@
   
   return Transforms;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp
index c371a9f..90ef14d 100644
--- a/lib/Transforms/Instrumentation/BlockProfiling.cpp
+++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 static void insertInitializationCall(Function *MainFn, const char *FnName,
                                      GlobalValue *Array) {
   const Type *ArgVTy = PointerType::get(PointerType::get(Type::SByteTy));
@@ -181,3 +183,5 @@
   insertInitializationCall(Main, "llvm_start_block_profiling", Counters);
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/EmitFunctions.cpp b/lib/Transforms/Instrumentation/EmitFunctions.cpp
index 9c395a9..57254b9 100644
--- a/lib/Transforms/Instrumentation/EmitFunctions.cpp
+++ b/lib/Transforms/Instrumentation/EmitFunctions.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/CFG.h"
 
+namespace llvm {
+
 enum Color{
   WHITE,
   GREY,
@@ -104,3 +106,5 @@
   M.getGlobalList().push_back(fnCount);
   return true;  // Always modifies program
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp b/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp
index 6c7bb5f..0420782 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp
@@ -27,6 +27,8 @@
 #include "llvm/Function.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 //this is used to color vertices
 //during DFS
 
@@ -36,7 +38,7 @@
   BLACK
 };
 
-namespace{
+namespace {
   struct CombineBranches : public FunctionPass {
   private:
     //DominatorSet *DS;
@@ -225,3 +227,5 @@
   
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
index 6a7f50e..3cb5698 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
@@ -27,8 +27,10 @@
 #define INSERT_LOAD_COUNT
 #define INSERT_STORE
 
+
 using std::vector;
 
+namespace llvm {
 
 static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
                            Value *cnt, Instruction *rInst){ 
@@ -369,3 +371,4 @@
   }
 }
 
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp b/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp
index cae699a..d69c4c3 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp
@@ -19,6 +19,8 @@
 
 using std::vector;
 
+namespace llvm {
+
 const graphListElement *findNodeInList(const Graph::nodeList &NL,
 					      Node *N) {
   for(Graph::nodeList::const_iterator NI = NL.begin(), NE=NL.end(); NI != NE; 
@@ -564,4 +566,4 @@
   color[u]=BLACK;//done with visiting the node and its neighbors
 }
 
-
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/Graph.h b/lib/Transforms/Instrumentation/ProfilePaths/Graph.h
index 5597b59..44b63a9 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/Graph.h
+++ b/lib/Transforms/Instrumentation/ProfilePaths/Graph.h
@@ -19,6 +19,8 @@
 #include <map>
 #include <cstdlib>
 
+namespace llvm {
+
 class Module;
 class Function;
 
@@ -112,8 +114,13 @@
   }
 };
 
+} // End llvm namespace
+
 
 namespace std {
+
+using namespace llvm;
+
   template<>
   struct less<Node *> : public binary_function<Node *, Node *,bool> {
     bool operator()(Node *n1, Node *n2) const {
@@ -135,6 +142,8 @@
   };
 }
 
+namespace llvm {
+
 struct BBSort{
   bool operator()(BasicBlock *BB1, BasicBlock *BB2) const{
     std::string name1=BB1->getName();
@@ -465,6 +474,7 @@
                            std::vector<Edge> &be);
 
 void getBBtrace(std::vector<BasicBlock *> &vBB, int pathNo, Function *M);
+
+} // End llvm namespace
+
 #endif
-
-
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp b/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp
index 66b8ccd..d9dc011 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp
@@ -24,6 +24,8 @@
 using std::vector;
 using std::cerr;
 
+namespace llvm {
+
 //check if 2 edges are equal (same endpoints and same weight)
 static bool edgesEqual(Edge  ed1, Edge ed2){
   return ((ed1==ed2) && ed1.getWeight()==ed2.getWeight());
@@ -673,3 +675,5 @@
   }
   cerr<<"--------------------Graph\n";
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
index b5e9d8c..9d6107c 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
@@ -27,6 +27,8 @@
 #include "llvm/Function.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 //this is used to color vertices
 //during DFS
 
@@ -181,3 +183,5 @@
   findAndInstrumentBackEdges(F);
   return true;  // Function was modified.
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
index d4973be..5728265 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
@@ -43,6 +43,8 @@
 #include <fstream>
 #include <cstdio>
 
+namespace llvm {
+
 struct ProfilePaths : public FunctionPass {
   bool runOnFunction(Function &F);
 
@@ -245,3 +247,5 @@
    
   return true;  // Always modifies function
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp b/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp
index 58b3840..cbb2ae6 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp
@@ -21,6 +21,8 @@
 using std::map;
 using std::cerr;
 
+namespace llvm {
+
 //Routines to get the path trace!
 
 void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g, 
@@ -303,3 +305,5 @@
   }
   */
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp
index f19ba74..c802f73 100644
--- a/lib/Transforms/Instrumentation/TraceValues.cpp
+++ b/lib/Transforms/Instrumentation/TraceValues.cpp
@@ -26,6 +26,8 @@
 #include <algorithm>
 #include <sstream>
 
+namespace llvm {
+
 static cl::opt<bool>
 DisablePtrHashing("tracedisablehashdisable", cl::Hidden,
                   cl::desc("Disable pointer hashing in the -trace or -tracem "
@@ -433,3 +435,5 @@
   
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp
index cf64aea..c5be82f 100644
--- a/lib/Transforms/LevelRaise.cpp
+++ b/lib/Transforms/LevelRaise.cpp
@@ -29,6 +29,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 // StartInst - This enables the -raise-start-inst=foo option to cause the level
 // raising pass to start at instruction "foo", which is immensely useful for
 // debugging!
@@ -55,7 +57,6 @@
 static Statistic<>
 NumVarargCallChanges("raise", "Number of vararg call peepholes");
 
-
 #define PRINT_PEEPHOLE(ID, NUM, I)            \
   DEBUG(std::cerr << "Inst P/H " << ID << "[" << NUM << "] " << I)
 
@@ -86,12 +87,12 @@
   RegisterOpt<RPR> X("raise", "Raise Pointer References");
 }
 
+
 Pass *createRaisePointerReferencesPass() {
   return new RPR();
 }
 
 
-
 // isReinterpretingCast - Return true if the cast instruction specified will
 // cause the operand to be "reinterpreted".  A value is reinterpreted if the
 // cast instruction would cause the underlying bits to change.
@@ -617,3 +618,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp
index 2735f95..e45b273 100644
--- a/lib/Transforms/Scalar/ADCE.cpp
+++ b/lib/Transforms/Scalar/ADCE.cpp
@@ -28,6 +28,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumBlockRemoved("adce", "Number of basic blocks removed");
   Statistic<> NumInstRemoved ("adce", "Number of instructions removed");
@@ -456,3 +458,5 @@
 
   return MadeChanges;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index ceef34e..66e7896 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -27,6 +27,8 @@
 #include "Support/Statistic.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumInstKilled("constprop", "Number of instructions killed");
 
@@ -73,3 +75,5 @@
   }
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index aad9b7f..a0358b5 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -42,6 +42,8 @@
 #include "Support/Statistic.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumSetCCRemoved("cee", "Number of setcc instruction eliminated");
   Statistic<> NumOperandsCann("cee", "Number of operands canonicalized");
@@ -1314,3 +1316,5 @@
 void Relation::dump() const { print(std::cerr); }
 void ValueInfo::dump() const { print(std::cerr, 0); }
 void RegionInfo::dump() const { print(std::cerr); }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp
index e3fc8de..3e63cad 100644
--- a/lib/Transforms/Scalar/DCE.cpp
+++ b/lib/Transforms/Scalar/DCE.cpp
@@ -24,6 +24,8 @@
 #include "Support/Statistic.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> DIEEliminated("die", "Number of insts removed");
   Statistic<> DCEEliminated("dce", "Number of insts removed");
@@ -57,7 +59,6 @@
 }
 
 
-
 //===----------------------------------------------------------------------===//
 // DeadCodeElimination pass implementation
 //
@@ -124,3 +125,5 @@
 Pass *createDeadCodeEliminationPass() {
   return new DCE();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp b/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
index d6aee14..e110cda 100644
--- a/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
+++ b/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Pass.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumAdded("lowerrefs", "# of getelementptr instructions added");
 
@@ -36,13 +38,6 @@
 RegisterOpt<DecomposePass> X("lowerrefs", "Decompose multi-dimensional "
                              "structure/array references");
 
-FunctionPass
-*createDecomposeMultiDimRefsPass()
-{
-  return new DecomposePass();
-}
-
-
 // runOnBasicBlock - Entry point for array or structure references with multiple
 // indices.
 //
@@ -57,6 +52,11 @@
   return changed;
 }
 
+FunctionPass
+*createDecomposeMultiDimRefsPass()
+{
+  return new DecomposePass();
+}
 
 // Function: DecomposeArrayRef()
 //  
@@ -134,3 +134,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/GCSE.cpp b/lib/Transforms/Scalar/GCSE.cpp
index e1654e5..b00d300 100644
--- a/lib/Transforms/Scalar/GCSE.cpp
+++ b/lib/Transforms/Scalar/GCSE.cpp
@@ -23,6 +23,8 @@
 #include "Support/Statistic.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumInstRemoved("gcse", "Number of instructions removed");
   Statistic<> NumLoadRemoved("gcse", "Number of loads removed");
@@ -56,7 +58,6 @@
 // createGCSEPass - The public interface to this file...
 FunctionPass *createGCSEPass() { return new GCSE(); }
 
-
 // GCSE::runOnFunction - This is the main transformation entry point for a
 // function.
 //
@@ -269,3 +270,5 @@
 
   return Ret;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 1744fe4..0777a1e 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -26,6 +26,8 @@
 #include "Support/Statistic.h"
 #include "Support/STLExtras.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumRemoved ("indvars", "Number of aux indvars removed");
   Statistic<> NumInserted("indvars", "Number of canonical indvars added");
@@ -217,3 +219,5 @@
 Pass *createIndVarSimplifyPass() {
   return new InductionVariableSimplify();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 07736b5..8522b61 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -49,6 +49,8 @@
 #include "Support/Statistic.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumCombined ("instcombine", "Number of insts combined");
   Statistic<> NumConstProp("instcombine", "Number of constant folds");
@@ -2196,3 +2198,5 @@
 Pass *createInstructionCombiningPass() {
   return new InstCombiner();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp
index 0f582c1..be635df 100644
--- a/lib/Transforms/Scalar/LICM.cpp
+++ b/lib/Transforms/Scalar/LICM.cpp
@@ -44,6 +44,8 @@
 #include "llvm/Assembly/Writer.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {
   cl::opt<bool>
   DisablePromotion("disable-licm-promotion", cl::Hidden,
@@ -466,3 +468,5 @@
     }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/PRE.cpp b/lib/Transforms/Scalar/PRE.cpp
index fad5789..770cd44 100644
--- a/lib/Transforms/Scalar/PRE.cpp
+++ b/lib/Transforms/Scalar/PRE.cpp
@@ -36,10 +36,12 @@
 #include "Support/Statistic.h"
 #include "Support/hash_set"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumExprsEliminated("pre", "Number of expressions constantified");
   Statistic<> NumRedundant      ("pre", "Number of redundant exprs eliminated");
-  Statistic<> NumInserted       ("pre", "Number of expressions inserted");
+  static Statistic<> NumInserted       ("pre", "Number of expressions inserted");
 
   struct PRE : public FunctionPass {
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -630,3 +632,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/PiNodeInsertion.cpp b/lib/Transforms/Scalar/PiNodeInsertion.cpp
index b5011af..89ec20e 100644
--- a/lib/Transforms/Scalar/PiNodeInsertion.cpp
+++ b/lib/Transforms/Scalar/PiNodeInsertion.cpp
@@ -42,6 +42,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumInserted("pinodes", "Number of Pi nodes inserted");
 
@@ -182,3 +184,5 @@
   return true;
 }
 
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index befdcfe..9e22ec4 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -34,6 +34,8 @@
 #include "Support/PostOrderIterator.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumLinear ("reassociate","Number of insts linearized");
   Statistic<> NumChanged("reassociate","Number of insts reassociated");
@@ -58,6 +60,7 @@
   RegisterOpt<Reassociate> X("reassociate", "Reassociate expressions");
 }
 
+// Public interface to the Reassociate pass
 FunctionPass *createReassociatePass() { return new Reassociate(); }
 
 void Reassociate::BuildRankMap(Function &F) {
@@ -291,3 +294,5 @@
   ValueRankMap.clear();
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 01e3e26..44a553a 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -33,6 +33,8 @@
 #include <algorithm>
 #include <set>
 
+namespace llvm {
+
 // InstVal class - This class represents the different lattice values that an 
 // instruction may occupy.  It is a simple class with value semantics.
 //
@@ -253,7 +255,6 @@
 
 
 // createSCCPPass - This is the public interface to this file...
-//
 Pass *createSCCPPass() {
   return new SCCP();
 }
@@ -585,3 +586,5 @@
 
   markConstant(&I, ConstantExpr::getGetElementPtr(Ptr, Operands));  
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 9342a5c..d291190 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -32,6 +32,8 @@
 #include "Support/Statistic.h"
 #include "Support/StringExtras.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumReplaced("scalarrepl", "Number of allocas broken up");
   Statistic<> NumPromoted("scalarrepl", "Number of allocas promoted");
@@ -61,6 +63,7 @@
   RegisterOpt<SROA> X("scalarrepl", "Scalar Replacement of Aggregates");
 }
 
+// Public interface to the ScalarReplAggregates pass
 Pass *createScalarReplAggregatesPass() { return new SROA(); }
 
 
@@ -298,3 +301,5 @@
     }
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/SimplifyCFG.cpp b/lib/Transforms/Scalar/SimplifyCFG.cpp
index 224d6c5..5a8d428 100644
--- a/lib/Transforms/Scalar/SimplifyCFG.cpp
+++ b/lib/Transforms/Scalar/SimplifyCFG.cpp
@@ -26,6 +26,8 @@
 #include "Support/Statistic.h"
 #include <set>
 
+namespace llvm {
+
 namespace {
   Statistic<> NumSimpl("cfgsimplify", "Number of blocks simplified");
 
@@ -35,6 +37,7 @@
   RegisterOpt<CFGSimplifyPass> X("simplifycfg", "Simplify the CFG");
 }
 
+// Public interface to the CFGSimplification pass
 FunctionPass *createCFGSimplificationPass() {
   return new CFGSimplifyPass();
 }
@@ -100,3 +103,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/SymbolStripping.cpp b/lib/Transforms/Scalar/SymbolStripping.cpp
index 58395c5..9e058e7 100644
--- a/lib/Transforms/Scalar/SymbolStripping.cpp
+++ b/lib/Transforms/Scalar/SymbolStripping.cpp
@@ -26,6 +26,8 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/Pass.h"
 
+namespace llvm {
+
 static bool StripSymbolTable(SymbolTable &SymTab) {
   bool RemovedSymbol = false;
 
@@ -74,3 +76,5 @@
 Pass *createFullSymbolStrippingPass() {
   return new FullSymbolStripping();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/TailDuplication.cpp b/lib/Transforms/Scalar/TailDuplication.cpp
index d0a7765..07a3b1e 100644
--- a/lib/Transforms/Scalar/TailDuplication.cpp
+++ b/lib/Transforms/Scalar/TailDuplication.cpp
@@ -31,6 +31,8 @@
 #include "Support/Debug.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumEliminated("tailduplicate",
                             "Number of unconditional branches eliminated");
@@ -53,6 +55,7 @@
   RegisterOpt<TailDup> X("tailduplicate", "Tail Duplication");
 }
 
+// Public interface to the Tail Duplication pass
 Pass *createTailDuplicationPass() { return new TailDup(); }
 
 /// runOnFunction - Top level algorithm - Loop over each unconditional branch in
@@ -339,3 +342,5 @@
 
   return GetValueInBlock(BB, OrigVal, ValueMap, OutValueMap);
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp
index d07f4e8..dbe91a7 100644
--- a/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -33,6 +33,8 @@
 #include "llvm/Pass.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumEliminated("tailcallelim", "Number of tail calls removed");
 
@@ -42,6 +44,7 @@
   RegisterOpt<TailCallElim> X("tailcallelim", "Tail Call Elimination");
 }
 
+// Public interface to the TailCallElimination pass
 FunctionPass *createTailCallEliminationPass() { return new TailCallElim(); }
 
 
@@ -105,3 +108,4 @@
   return MadeChange;
 }
 
+} // End llvm namespace
diff --git a/lib/Transforms/TransformInternals.cpp b/lib/Transforms/TransformInternals.cpp
index 3a1d51c..b553f03 100644
--- a/lib/Transforms/TransformInternals.cpp
+++ b/lib/Transforms/TransformInternals.cpp
@@ -18,6 +18,8 @@
 #include "llvm/Function.h"
 #include "llvm/iOther.h"
 
+namespace llvm {
+
 static const Type *getStructOffsetStep(const StructType *STy, uint64_t &Offset,
                                        std::vector<Value*> &Indices,
                                        const TargetData &TD) {
@@ -193,3 +195,5 @@
 
   return NextTy;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/TransformInternals.h b/lib/Transforms/TransformInternals.h
index 4f92dc4..3b80146 100644
--- a/lib/Transforms/TransformInternals.h
+++ b/lib/Transforms/TransformInternals.h
@@ -22,6 +22,8 @@
 #include <map>
 #include <set>
 
+namespace llvm {
+
 static inline int64_t getConstantValue(const ConstantInt *CPI) {
   return (int64_t)cast<ConstantInt>(CPI)->getRawValue();
 }
@@ -139,4 +141,6 @@
                                 std::vector<Value*> &Offsets,
                                 const TargetData &TD, bool StopEarly = true);
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 22fd555..5fb5469 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Type.h"
 #include <algorithm>
 
+namespace llvm {
+
 // ReplaceInstWithValue - Replace all uses of an instruction (specified by BI)
 // with a value, then remove and delete the original instruction.
 //
@@ -112,3 +114,5 @@
   if (NewTI)   // If it's a different instruction, replace.
     ReplaceInstWithInst(TI, NewTI);
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp
index de59db2..e8201cc 100644
--- a/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumBroken("break-crit-edges", "Number of blocks inserted");
 
@@ -168,3 +170,5 @@
   }
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index e0312f2..d8aa9ae 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Function.h"
 #include "ValueMapper.h"
 
+namespace llvm {
+
 // RemapInstruction - Convert the instruction operands from referencing the 
 // current values into those specified by ValueMap.
 //
@@ -140,3 +142,5 @@
   CloneFunctionInto(NewF, F, ValueMap, Returns);
   return NewF;                    
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
index cc22c72..21a8675 100644
--- a/lib/Transforms/Utils/CloneModule.cpp
+++ b/lib/Transforms/Utils/CloneModule.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Constant.h"
 #include "ValueMapper.h"
 
+namespace llvm {
+
 /// CloneModule - Return an exact copy of the specified module.  This is not as
 /// easy as it might seem because we have to worry about making copies of global
 /// variables and functions, and making their (initializers and references,
@@ -88,3 +90,5 @@
 
   return New;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/CloneTrace.cpp b/lib/Transforms/Utils/CloneTrace.cpp
index 9d99546..990e54c 100644
--- a/lib/Transforms/Utils/CloneTrace.cpp
+++ b/lib/Transforms/Utils/CloneTrace.cpp
@@ -20,6 +20,8 @@
 #include "llvm/Function.h"
 
 
+namespace llvm {
+
 //Clones the trace (a vector of basic blocks)
 std::vector<BasicBlock *> CloneTrace(const std::vector<BasicBlock*> &origTrace) {
 
@@ -86,3 +88,5 @@
   //return new vector of basic blocks
   return clonedTrace;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/DemoteRegToStack.cpp b/lib/Transforms/Utils/DemoteRegToStack.cpp
index bd605ca..e35dca4 100644
--- a/lib/Transforms/Utils/DemoteRegToStack.cpp
+++ b/lib/Transforms/Utils/DemoteRegToStack.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Type.h"
 #include "Support/hash_set"
 
+namespace llvm {
+
 typedef hash_set<PHINode*>           PhiSet;
 typedef hash_set<PHINode*>::iterator PhiSetIterator;
 
@@ -160,3 +162,5 @@
 
   return XSlot;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 1481324..265d5c4 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -24,6 +24,8 @@
 #include "llvm/Support/CallSite.h"
 #include "llvm/Transforms/Utils/Local.h"
 
+namespace llvm {
+
 bool InlineFunction(CallInst *CI) { return InlineFunction(CallSite(CI)); }
 bool InlineFunction(InvokeInst *II) { return InlineFunction(CallSite(II)); }
 
@@ -278,3 +280,5 @@
   SimplifyCFG(AfterCallBB);
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp
index 0be840f..4bc78a4 100644
--- a/lib/Transforms/Utils/Linker.cpp
+++ b/lib/Transforms/Utils/Linker.cpp
@@ -23,6 +23,8 @@
 #include "llvm/iOther.h"
 #include "llvm/Constants.h"
 
+namespace llvm {
+
 // Error - Simple wrapper function to conditionally assign to E and return true.
 // This just makes error return conditions a little bit simpler...
 //
@@ -902,3 +904,4 @@
   return false;
 }
 
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 2f9b07c..8946995 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -17,6 +17,8 @@
 #include "llvm/iOperators.h"
 #include "llvm/ConstantHandling.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //  Local constant propagation...
 //
@@ -180,3 +182,5 @@
   }
   return false;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index a1f8648..b999ed4 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -43,6 +43,8 @@
 #include "Support/Statistic.h"
 #include "Support/DepthFirstIterator.h"
 
+namespace llvm {
+
 namespace {
   Statistic<>
   NumInserted("loopsimplify", "Number of pre-header blocks inserted");
@@ -82,7 +84,6 @@
 const PassInfo *LoopSimplifyID = X.getPassInfo();
 Pass *createLoopSimplifyPass() { return new LoopSimplify(); }
 
-
 /// runOnFunction - Run down all loops in the CFG (recursively, but we could do
 /// it in any convenient order) inserting preheaders...
 ///
@@ -566,3 +567,5 @@
     }
   }
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index 9600888..eea800a 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Target/TargetData.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumLowered("lowerallocs", "Number of allocations lowered");
 
@@ -131,3 +133,5 @@
 
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index 4885d96..ec97ca2 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -23,6 +23,8 @@
 #include "llvm/Constant.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumLowered("lowerinvoke", "Number of invoke & unwinds replaced");
 
@@ -37,6 +39,7 @@
   X("lowerinvoke", "Lower invoke and unwind, for unwindless code generators");
 }
 
+// Public Interface To the LowerInvoke pass.
 FunctionPass *createLowerInvokePass() { return new LowerInvoke(); }
 
 // doInitialization - Make sure that there is a prototype for abort in the
@@ -79,3 +82,5 @@
     }
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index a45192b..1d0e471 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -23,6 +23,8 @@
 #include "Support/Debug.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumLowered("lowerswitch", "Number of SwitchInst's replaced");
 
@@ -224,3 +226,5 @@
   // We are now done with the switch instruction, delete it.
   delete SI;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/Mem2Reg.cpp b/lib/Transforms/Utils/Mem2Reg.cpp
index d915155..4d99280 100644
--- a/lib/Transforms/Utils/Mem2Reg.cpp
+++ b/lib/Transforms/Utils/Mem2Reg.cpp
@@ -20,6 +20,8 @@
 #include "llvm/Target/TargetData.h"
 #include "Support/Statistic.h"
 
+namespace llvm {
+
 namespace {
   Statistic<> NumPromoted("mem2reg", "Number of alloca's promoted");
 
@@ -78,3 +80,5 @@
 Pass *createPromoteMemoryToRegister() {
   return new PromotePass();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index f920718..0859f69 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/StringExtras.h"
 
+namespace llvm {
+
 /// isAllocaPromotable - Return true if this alloca is legal for promotion.
 /// This is true if there are only loads and stores to the alloca...
 ///
@@ -459,3 +461,5 @@
   if (Allocas.empty()) return;
   PromoteMem2Reg(Allocas, DT, DF, TD).run();
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index a5f54b1..158d911 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -21,6 +21,8 @@
 #include <algorithm>
 #include <functional>
 
+namespace llvm {
+
 // PropagatePredecessors - This gets "Succ" ready to have the predecessors from
 // "BB".  This is a little tricky because "Succ" has PHI nodes, which need to
 // have extra slots added to them to hold the merge edges from BB's
@@ -298,3 +300,5 @@
   
   return Changed;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index 180871b..2591ffd 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -22,6 +22,8 @@
 #include "llvm/iPHINode.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 static RegisterOpt<UnifyFunctionExitNodes>
 X("mergereturn", "Unify function exit nodes");
 
@@ -112,3 +114,5 @@
   ReturnBlock = NewRetBlock;
   return true;
 }
+
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index 6590498..248ebac 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Constants.h"
 #include "llvm/Instruction.h"
 
+namespace llvm {
+
 Value *MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
   Value *&VMSlot = VM[V];
   if (VMSlot) return VMSlot;      // Does it exist in the map yet?
@@ -105,3 +107,4 @@
   return 0;
 }
 
+} // End llvm namespace
diff --git a/lib/Transforms/Utils/ValueMapper.h b/lib/Transforms/Utils/ValueMapper.h
index 8264ade..e67b326 100644
--- a/lib/Transforms/Utils/ValueMapper.h
+++ b/lib/Transforms/Utils/ValueMapper.h
@@ -16,8 +16,13 @@
 #define LIB_TRANSFORMS_UTILS_VALUE_MAPPER_H
 
 #include <map>
+
+namespace llvm {
+
 class Value;
 
 Value *MapValue(const Value *V, std::map<const Value*, Value*> &VM);
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index c9c4dde..67ccdd0 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -33,6 +33,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 static RegisterPass<PrintModulePass>
 X("printm", "Print module to stderr",PassInfo::Analysis|PassInfo::Optimization);
 static RegisterPass<PrintFunctionPass>
@@ -1052,3 +1054,5 @@
   }
   return *this;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index 2458cda..63a722b 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -22,6 +22,8 @@
 #include "SymbolTableListTraitsImpl.h"
 #include <algorithm>
 
+namespace llvm {
+
 // DummyInst - An instance of this class is used to mark the end of the
 // instruction list.  This is not a real instruction.
 //
@@ -141,7 +143,7 @@
 //
 bool BasicBlock::hasConstantReferences() const {
   for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
-    if (::isa<Constant>((Value*)*I))
+    if (isa<Constant>((Value*)*I))
       return true;
 
   return false;
@@ -263,3 +265,5 @@
   }
   return New;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 32b9ebb..7fb7a05 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -17,6 +17,8 @@
 #include "llvm/DerivedTypes.h"
 #include <cmath>
 
+namespace llvm {
+
 AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
 						      &ConstRules::find));
 
@@ -638,3 +640,5 @@
   static EmptyRules CERules;
   return &CERules;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/ConstantFold.h b/lib/VMCore/ConstantFold.h
index a27283c..a0a01e5 100644
--- a/lib/VMCore/ConstantFold.h
+++ b/lib/VMCore/ConstantFold.h
@@ -42,6 +42,9 @@
 
 #include "llvm/Constants.h"
 #include "llvm/Type.h"
+
+namespace llvm {
+
 class PointerType;
 
 //===----------------------------------------------------------------------===//
@@ -244,4 +247,7 @@
                                        const Constant *V2);
 Constant *ConstantFoldGetElementPtr(const Constant *C,
                                     const std::vector<Constant*> &IdxList);
+
+} // End llvm namespace
+
 #endif
diff --git a/lib/VMCore/ConstantFolding.h b/lib/VMCore/ConstantFolding.h
index a27283c..a0a01e5 100644
--- a/lib/VMCore/ConstantFolding.h
+++ b/lib/VMCore/ConstantFolding.h
@@ -42,6 +42,9 @@
 
 #include "llvm/Constants.h"
 #include "llvm/Type.h"
+
+namespace llvm {
+
 class PointerType;
 
 //===----------------------------------------------------------------------===//
@@ -244,4 +247,7 @@
                                        const Constant *V2);
 Constant *ConstantFoldGetElementPtr(const Constant *C,
                                     const std::vector<Constant*> &IdxList);
+
+} // End llvm namespace
+
 #endif
diff --git a/lib/VMCore/ConstantRange.cpp b/lib/VMCore/ConstantRange.cpp
index a9e1204..e180f12 100644
--- a/lib/VMCore/ConstantRange.cpp
+++ b/lib/VMCore/ConstantRange.cpp
@@ -26,6 +26,8 @@
 #include "llvm/Instruction.h"
 #include "llvm/ConstantHandling.h"
 
+namespace llvm {
+
 /// Initialize a full (the default) or empty set for the specified type.
 ///
 ConstantRange::ConstantRange(const Type *Ty, bool Full) {
@@ -248,3 +250,5 @@
 void ConstantRange::dump() const {
   print(std::cerr);
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 28cc9d2..527eff5 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -20,6 +20,8 @@
 #include "Support/StringExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 ConstantBool *ConstantBool::True  = new ConstantBool(true);
 ConstantBool *ConstantBool::False = new ConstantBool(false);
 
@@ -1029,3 +1031,5 @@
     return NumReplaced;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp
index c3bce78..cad6685 100644
--- a/lib/VMCore/Dominators.cpp
+++ b/lib/VMCore/Dominators.cpp
@@ -20,6 +20,8 @@
 #include "Support/DepthFirstIterator.h"
 #include "Support/SetOperations.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //  DominatorSet Implementation
 //===----------------------------------------------------------------------===//
@@ -358,3 +360,5 @@
     o << " is:\t" << I->second << "\n";
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index f47ecea..364cc6f 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -19,6 +19,8 @@
 #include "Support/LeakDetector.h"
 #include "SymbolTableListTraitsImpl.h"
 
+namespace llvm {
+
 BasicBlock *ilist_traits<BasicBlock>::createNode() {
   BasicBlock *Ret = new BasicBlock();
   // This should not be garbage monitored.
@@ -158,7 +160,7 @@
 }
 
 /// getIntrinsicID - This method returns the ID number of the specified
-/// function, or LLVMIntrinsic::not_intrinsic if the function is not an
+/// function, or Intrinsic::not_intrinsic if the function is not an
 /// intrinsic, or if the pointer is null.  This value is always defined to be
 /// zero to allow easy checking for whether a function is intrinsic or not.  The
 /// particular intrinsic functions which correspond to this value are defined in
@@ -176,21 +178,21 @@
    std::string name;  // The name of the intrinsic 
    unsigned id;       // Its ID number
   } alpha_intrinsics[] = {
-     { "llvm.alpha.ctlz",      LLVMIntrinsic::alpha_ctlz },
-     { "llvm.alpha.cttz",      LLVMIntrinsic::alpha_cttz },
-     { "llvm.alpha.ctpop",     LLVMIntrinsic::alpha_ctpop },
-     { "llvm.alpha.umulh",     LLVMIntrinsic::alpha_umulh },
-     { "llvm.alpha.vecop",     LLVMIntrinsic::alpha_vecop },
-     { "llvm.alpha.pup",       LLVMIntrinsic::alpha_pup },
-     { "llvm.alpha.bytezap",   LLVMIntrinsic::alpha_bytezap },
-     { "llvm.alpha.bytemanip", LLVMIntrinsic::alpha_bytemanip },
-     { "llvm.alpha.dfp_bop",   LLVMIntrinsic::alpha_dfpbop }, 
-     { "llvm.alpha.dfp_uop",   LLVMIntrinsic::alpha_dfpuop },
-     { "llvm.alpha.unordered", LLVMIntrinsic::alpha_unordered },
-     { "llvm.alpha.uqtodfp",   LLVMIntrinsic::alpha_uqtodfp },
-     { "llvm.alpha.uqtosfp",   LLVMIntrinsic::alpha_uqtosfp },
-     { "llvm.alpha.dfptosq",   LLVMIntrinsic::alpha_dfptosq },
-     { "llvm.alpha.sfptosq",   LLVMIntrinsic::alpha_sfptosq },
+     { "llvm.alpha.ctlz",      Intrinsic::alpha_ctlz },
+     { "llvm.alpha.cttz",      Intrinsic::alpha_cttz },
+     { "llvm.alpha.ctpop",     Intrinsic::alpha_ctpop },
+     { "llvm.alpha.umulh",     Intrinsic::alpha_umulh },
+     { "llvm.alpha.vecop",     Intrinsic::alpha_vecop },
+     { "llvm.alpha.pup",       Intrinsic::alpha_pup },
+     { "llvm.alpha.bytezap",   Intrinsic::alpha_bytezap },
+     { "llvm.alpha.bytemanip", Intrinsic::alpha_bytemanip },
+     { "llvm.alpha.dfp_bop",   Intrinsic::alpha_dfpbop }, 
+     { "llvm.alpha.dfp_uop",   Intrinsic::alpha_dfpuop },
+     { "llvm.alpha.unordered", Intrinsic::alpha_unordered },
+     { "llvm.alpha.uqtodfp",   Intrinsic::alpha_uqtodfp },
+     { "llvm.alpha.uqtosfp",   Intrinsic::alpha_uqtosfp },
+     { "llvm.alpha.dfptosq",   Intrinsic::alpha_dfptosq },
+     { "llvm.alpha.sfptosq",   Intrinsic::alpha_sfptosq },
   };
   const unsigned num_alpha_intrinsics = 
                  sizeof(alpha_intrinsics) / sizeof(*alpha_intrinsics);
@@ -204,17 +206,17 @@
           return alpha_intrinsics[i].id;
     break;
   case 'l':
-    if (getName() == "llvm.longjmp")  return LLVMIntrinsic::longjmp;
+    if (getName() == "llvm.longjmp")  return Intrinsic::longjmp;
     break;
   case 's':
-    if (getName() == "llvm.setjmp")     return LLVMIntrinsic::setjmp;
-    if (getName() == "llvm.sigsetjmp")  return LLVMIntrinsic::sigsetjmp;
-    if (getName() == "llvm.siglongjmp") return LLVMIntrinsic::siglongjmp;
+    if (getName() == "llvm.setjmp")     return Intrinsic::setjmp;
+    if (getName() == "llvm.sigsetjmp")  return Intrinsic::sigsetjmp;
+    if (getName() == "llvm.siglongjmp") return Intrinsic::siglongjmp;
     break;
   case 'v':
-    if (getName() == "llvm.va_copy")  return LLVMIntrinsic::va_copy;
-    if (getName() == "llvm.va_end")   return LLVMIntrinsic::va_end;
-    if (getName() == "llvm.va_start") return LLVMIntrinsic::va_start;
+    if (getName() == "llvm.va_copy")  return Intrinsic::va_copy;
+    if (getName() == "llvm.va_end")   return Intrinsic::va_end;
+    if (getName() == "llvm.va_start") return Intrinsic::va_start;
     break;
   }
   // The "llvm." namespace is reserved!
@@ -257,3 +259,5 @@
   Value::setName(name);
   if (P && getName() != "") P->getSymbolTable().insert(this);
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp
index ba1d4b7..17e16fa 100644
--- a/lib/VMCore/InstrTypes.cpp
+++ b/lib/VMCore/InstrTypes.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Type.h"
 #include <algorithm>  // find
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
@@ -56,3 +58,5 @@
   }
   return Removed;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index b72656b..9ca2fed 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Type.h"
 #include "Support/LeakDetector.h"
 
+namespace llvm {
+
 Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
                          Instruction *InsertBefore)
   : User(ty, Value::InstructionVal, Name) {
@@ -163,3 +165,5 @@
     return false;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/LeakDetector.cpp b/lib/VMCore/LeakDetector.cpp
index 24c946a..ffb081a 100644
--- a/lib/VMCore/LeakDetector.cpp
+++ b/lib/VMCore/LeakDetector.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Value.h"
 #include <set>
 
+namespace llvm {
+
 // Lazily allocate set so that release build doesn't have to do anything.
 static std::set<const void*> *Objects = 0;
 static std::set<const Value*> *LLVMObjects = 0;
@@ -87,3 +89,5 @@
     Objects = 0; LLVMObjects = 0;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp
index 0be840f..4bc78a4 100644
--- a/lib/VMCore/Linker.cpp
+++ b/lib/VMCore/Linker.cpp
@@ -23,6 +23,8 @@
 #include "llvm/iOther.h"
 #include "llvm/Constants.h"
 
+namespace llvm {
+
 // Error - Simple wrapper function to conditionally assign to E and return true.
 // This just makes error return conditions a little bit simpler...
 //
@@ -902,3 +904,4 @@
   return false;
 }
 
+} // End llvm namespace
diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp
index 44c697d..567fe05 100644
--- a/lib/VMCore/Mangler.cpp
+++ b/lib/VMCore/Mangler.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Type.h"
 #include "Support/StringExtras.h"
 
+namespace llvm {
+
 static char HexDigit(int V) {
   return V < 10 ? V+'0' : V+'A'-10;
 }
@@ -99,3 +101,4 @@
         FoundNames.insert(I->getName());   // Otherwise, keep track of name
 }
 
+} // End llvm namespace
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index e62c83f..6b15929 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -22,6 +22,8 @@
 #include <cstdarg>
 #include <map>
 
+namespace llvm {
+
 Function *ilist_traits<Function>::createNode() {
   FunctionType *FTy =
     FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
@@ -307,3 +309,5 @@
     delete Ref;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/ModuleProvider.cpp b/lib/VMCore/ModuleProvider.cpp
index ba324d0..8be0336 100644
--- a/lib/VMCore/ModuleProvider.cpp
+++ b/lib/VMCore/ModuleProvider.cpp
@@ -14,6 +14,8 @@
 #include "llvm/ModuleProvider.h"
 #include "llvm/Module.h"
 
+namespace llvm {
+
 /// ctor - always have a valid Module
 ///
 ModuleProvider::ModuleProvider() : TheModule(0) { }
@@ -35,3 +37,5 @@
 
   return TheModule;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp
index 96ad3c9..b387fc3 100644
--- a/lib/VMCore/Pass.cpp
+++ b/lib/VMCore/Pass.cpp
@@ -21,6 +21,8 @@
 #include "Support/TypeInfo.h"
 #include <set>
 
+namespace llvm {
+
 // IncludeFile - Stub function used to help linking out.
 IncludeFile::IncludeFile(void*) {}
 
@@ -467,3 +469,5 @@
            E = PassInfoMap->end(); I != E; ++I)
       passEnumerate(I->second);
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/PassManagerT.h b/lib/VMCore/PassManagerT.h
index a715f51..c5cac1d 100644
--- a/lib/VMCore/PassManagerT.h
+++ b/lib/VMCore/PassManagerT.h
@@ -28,6 +28,9 @@
 #include "Support/Timer.h"
 #include <algorithm>
 #include <iostream>
+
+namespace llvm {
+
 class Annotable;
 
 //===----------------------------------------------------------------------===//
@@ -792,4 +795,6 @@
   return Changed;
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp
index aef7176..c6e44e8 100644
--- a/lib/VMCore/SlotCalculator.cpp
+++ b/lib/VMCore/SlotCalculator.cpp
@@ -27,6 +27,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 #if 0
 #define SC_DEBUG(X) std::cerr << X
 #else
@@ -361,3 +363,5 @@
   SC_DEBUG("]\n");
   return (int)DestSlot;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp
index 9452cdf..834d619 100644
--- a/lib/VMCore/SymbolTable.cpp
+++ b/lib/VMCore/SymbolTable.cpp
@@ -17,6 +17,8 @@
 #include "Support/StringExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 #define DEBUG_SYMBOL_TABLE 0
 #define DEBUG_ABSTYPE 0
 
@@ -354,3 +356,5 @@
   std::cout << "Symbol table dump:\n";
   for_each(begin(), end(), DumpPlane);
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/SymbolTableListTraitsImpl.h b/lib/VMCore/SymbolTableListTraitsImpl.h
index aec7520..22d2e1d 100644
--- a/lib/VMCore/SymbolTableListTraitsImpl.h
+++ b/lib/VMCore/SymbolTableListTraitsImpl.h
@@ -19,6 +19,8 @@
 #include "llvm/SymbolTableListTraits.h"
 #include "llvm/SymbolTable.h"
 
+namespace llvm {
+
 template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass,
          typename SubClass>
 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
@@ -94,4 +96,6 @@
   }
 }
 
+} // End llvm namespace
+
 #endif
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index ed46802..9e33303 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -18,6 +18,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
 // created and later destroyed, all in an effort to make sure that there is only
 // a single canonical version of a type.
@@ -1114,3 +1116,4 @@
   refineAbstractType(AbsTy, AbsTy);
 }
 
+} // End llvm namespace
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index 709ae3e..f389eb0 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -18,6 +18,8 @@
 #include "Support/LeakDetector.h"
 #include <algorithm>
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                                Value Class
 //===----------------------------------------------------------------------===//
@@ -107,3 +109,5 @@
       setOperand(i, To); // Fix it now...
     }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 14c14f3..1362eaa 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -57,6 +57,8 @@
 #include "Support/STLExtras.h"
 #include <algorithm>
 
+namespace llvm {
+
 namespace {  // Anonymous namespace for class
 
   struct Verifier : public FunctionPass, InstVisitor<Verifier> {
@@ -149,7 +151,7 @@
     void visitReturnInst(ReturnInst &RI);
     void visitUserOp1(Instruction &I);
     void visitUserOp2(Instruction &I) { visitUserOp1(I); }
-    void visitIntrinsicFunctionCall(LLVMIntrinsic::ID ID, CallInst &CI);
+    void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI);
 
     // CheckFailed - A check failed, so print out the condition and the message
     // that failed.  This provides a nice place to put a breakpoint if you want
@@ -168,7 +170,6 @@
   };
 
   RegisterPass<Verifier> X("verify", "Module Verifier");
-}
 
 // Assert - We know that cond should be true, if not print an error message.
 #define Assert(C, M) \
@@ -368,7 +369,7 @@
             CI.getOperand(i+1), FTy->getParamType(i));
 
   if (Function *F = CI.getCalledFunction())
-    if (LLVMIntrinsic::ID ID = (LLVMIntrinsic::ID)F->getIntrinsicID())
+    if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID())
       visitIntrinsicFunctionCall(ID, CI);
 
   visitInstruction(CI);
@@ -500,7 +501,7 @@
 }
 
 /// visitIntrinsicFunction - Allow intrinsics to be verified in different ways.
-void Verifier::visitIntrinsicFunctionCall(LLVMIntrinsic::ID ID, CallInst &CI) {
+void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
   Function *IF = CI.getCalledFunction();
   const FunctionType *FT = IF->getFunctionType();
   Assert1(IF->isExternal(), "Intrinsic functions should never be defined!", IF);
@@ -509,37 +510,37 @@
   // FIXME: this should check the return type of each intrinsic as well, also
   // arguments!
   switch (ID) {
-  case LLVMIntrinsic::va_start:
+  case Intrinsic::va_start:
     Assert1(CI.getParent()->getParent()->getFunctionType()->isVarArg(),
             "llvm.va_start intrinsic may only occur in function with variable"
             " args!", &CI);
     NumArgs = 0;
     break;
-  case LLVMIntrinsic::va_end:          NumArgs = 1; break;
-  case LLVMIntrinsic::va_copy:         NumArgs = 1; break;
+  case Intrinsic::va_end:          NumArgs = 1; break;
+  case Intrinsic::va_copy:         NumArgs = 1; break;
 
-  case LLVMIntrinsic::setjmp:          NumArgs = 1; break;
-  case LLVMIntrinsic::longjmp:         NumArgs = 2; break;
-  case LLVMIntrinsic::sigsetjmp:       NumArgs = 2; break;
-  case LLVMIntrinsic::siglongjmp:      NumArgs = 2; break;
+  case Intrinsic::setjmp:          NumArgs = 1; break;
+  case Intrinsic::longjmp:         NumArgs = 2; break;
+  case Intrinsic::sigsetjmp:       NumArgs = 2; break;
+  case Intrinsic::siglongjmp:      NumArgs = 2; break;
  
-  case LLVMIntrinsic::alpha_ctlz:      NumArgs = 1; break;
-  case LLVMIntrinsic::alpha_cttz:      NumArgs = 1; break;
-  case LLVMIntrinsic::alpha_ctpop:     NumArgs = 1; break;
-  case LLVMIntrinsic::alpha_umulh:     NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_vecop:     NumArgs = 4; break;
-  case LLVMIntrinsic::alpha_pup:       NumArgs = 3; break;
-  case LLVMIntrinsic::alpha_bytezap:   NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_bytemanip: NumArgs = 3; break;
-  case LLVMIntrinsic::alpha_dfpbop:    NumArgs = 3; break;
-  case LLVMIntrinsic::alpha_dfpuop:    NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_unordered: NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_uqtodfp:   NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_uqtosfp:   NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_dfptosq:   NumArgs = 2; break;
-  case LLVMIntrinsic::alpha_sfptosq:   NumArgs = 2; break;
+  case Intrinsic::alpha_ctlz:      NumArgs = 1; break;
+  case Intrinsic::alpha_cttz:      NumArgs = 1; break;
+  case Intrinsic::alpha_ctpop:     NumArgs = 1; break;
+  case Intrinsic::alpha_umulh:     NumArgs = 2; break;
+  case Intrinsic::alpha_vecop:     NumArgs = 4; break;
+  case Intrinsic::alpha_pup:       NumArgs = 3; break;
+  case Intrinsic::alpha_bytezap:   NumArgs = 2; break;
+  case Intrinsic::alpha_bytemanip: NumArgs = 3; break;
+  case Intrinsic::alpha_dfpbop:    NumArgs = 3; break;
+  case Intrinsic::alpha_dfpuop:    NumArgs = 2; break;
+  case Intrinsic::alpha_unordered: NumArgs = 2; break;
+  case Intrinsic::alpha_uqtodfp:   NumArgs = 2; break;
+  case Intrinsic::alpha_uqtosfp:   NumArgs = 2; break;
+  case Intrinsic::alpha_dfptosq:   NumArgs = 2; break;
+  case Intrinsic::alpha_sfptosq:   NumArgs = 2; break;
 
-  case LLVMIntrinsic::not_intrinsic: 
+  case Intrinsic::not_intrinsic: 
     assert(0 && "Invalid intrinsic!"); NumArgs = 0; break;
   }
 
@@ -548,6 +549,7 @@
           "Illegal # arguments for intrinsic function!", IF);
 }
 
+} // End anonymous namespace
 
 //===----------------------------------------------------------------------===//
 //  Implement the public interfaces to this file...
@@ -585,3 +587,5 @@
   PM.run((Module&)M);
   return V->Broken;
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/iBranch.cpp b/lib/VMCore/iBranch.cpp
index bcba714..59dc303 100644
--- a/lib/VMCore/iBranch.cpp
+++ b/lib/VMCore/iBranch.cpp
@@ -16,6 +16,8 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Type.h"
 
+namespace llvm {
+
 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
                        Instruction *InsertBefore) 
   : TerminatorInst(Instruction::Br, InsertBefore) {
@@ -49,3 +51,5 @@
     Operands.push_back(Use(BI.Operands[2], this));
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp
index b99c9e7..c385afc 100644
--- a/lib/VMCore/iCall.cpp
+++ b/lib/VMCore/iCall.cpp
@@ -17,6 +17,8 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                        CallInst Implementation
 //===----------------------------------------------------------------------===//
@@ -144,8 +146,12 @@
   return 0;
 }
 
+} // End llvm namespace
+
 #include "llvm/Support/CallSite.h"
 
+namespace llvm {
+
 Function *CallSite::getCalledFunction() const {
   Value *Callee = getCalledValue();
   if (Function *F = dyn_cast<Function>(Callee))
@@ -155,3 +161,4 @@
   return 0;
 }
 
+} // End llvm namespace
diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp
index 75309ad..c1a0657 100644
--- a/lib/VMCore/iMemory.cpp
+++ b/lib/VMCore/iMemory.cpp
@@ -15,6 +15,8 @@
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 
+using namespace llvm;
+
 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
                                const std::string &Name, Instruction *InsertBef)
   : Instruction(PointerType::get(Ty), iTy, Name, InsertBef) {
diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp
index d893290..79fac33 100644
--- a/lib/VMCore/iOperators.cpp
+++ b/lib/VMCore/iOperators.cpp
@@ -16,6 +16,8 @@
 #include "llvm/Constants.h"
 #include "llvm/BasicBlock.h"
 
+namespace llvm {
+
 //===----------------------------------------------------------------------===//
 //                             BinaryOperator Class
 //===----------------------------------------------------------------------===//
@@ -194,3 +196,5 @@
   case SetLE: return SetGE;
   }
 }
+
+} // End llvm namespace
diff --git a/lib/VMCore/iSwitch.cpp b/lib/VMCore/iSwitch.cpp
index e6a4f48..4386b7b 100644
--- a/lib/VMCore/iSwitch.cpp
+++ b/lib/VMCore/iSwitch.cpp
@@ -14,6 +14,8 @@
 #include "llvm/iTerminators.h"
 #include "llvm/BasicBlock.h"
 
+namespace llvm {
+
 SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
                        Instruction *InsertBefore) 
   : TerminatorInst(Instruction::Switch, InsertBefore) {
@@ -48,3 +50,5 @@
   assert(idx*2 < Operands.size() && "Successor index out of range!!!");
   Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2);  
 }
+
+} // End llvm namespace
diff --git a/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp b/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
index 1d06c2d..a1b6844 100644
--- a/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
+++ b/projects/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
@@ -12,6 +12,8 @@
 #include "llvm/Instructions.h"
 #include "llvm/Bytecode/Writer.h"
 
+using namespace llvm;
+
 int main() {
   // Create the "module" or "program" or "translation unit" to hold the
   // function
diff --git a/projects/SmallExamples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp b/projects/SmallExamples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
index 1d06c2d..a1b6844 100644
--- a/projects/SmallExamples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
+++ b/projects/SmallExamples/ModuleMaker/tools/ModuleMaker/ModuleMaker.cpp
@@ -12,6 +12,8 @@
 #include "llvm/Instructions.h"
 #include "llvm/Bytecode/Writer.h"
 
+using namespace llvm;
+
 int main() {
   // Create the "module" or "program" or "translation unit" to hold the
   // function
diff --git a/tools/analyze/AnalysisWrappers.cpp b/tools/analyze/AnalysisWrappers.cpp
index 6c4c99f..a9b9cd0 100644
--- a/tools/analyze/AnalysisWrappers.cpp
+++ b/tools/analyze/AnalysisWrappers.cpp
@@ -26,6 +26,8 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Support/InstIterator.h"
 
+using namespace llvm;
+
 namespace {
   struct InstForestHelper : public FunctionPass {
     Function *F;
diff --git a/tools/analyze/GraphPrinters.cpp b/tools/analyze/GraphPrinters.cpp
index 34c937f..6d2750f 100644
--- a/tools/analyze/GraphPrinters.cpp
+++ b/tools/analyze/GraphPrinters.cpp
@@ -20,6 +20,8 @@
 #include "llvm/Analysis/CallGraph.h"
 #include <fstream>
 
+namespace llvm {
+
 template<typename GraphType>
 static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
                              const GraphType &GT) {
@@ -72,3 +74,5 @@
   RegisterAnalysis<CallGraphPrinter> P2("print-callgraph",
                                         "Print Call Graph to 'dot' file");
 };
+
+} // End llvm namespace
diff --git a/tools/analyze/PrintSCC.cpp b/tools/analyze/PrintSCC.cpp
index 3459381..ce89fff 100644
--- a/tools/analyze/PrintSCC.cpp
+++ b/tools/analyze/PrintSCC.cpp
@@ -31,6 +31,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/SCCIterator.h"
 
+namespace llvm {
+
 namespace {
   struct CFGSCC : public FunctionPass {
     bool runOnFunction(Function& func);
@@ -101,3 +103,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp
index 836b6aa..3e1e516 100644
--- a/tools/analyze/analyze.cpp
+++ b/tools/analyze/analyze.cpp
@@ -26,6 +26,7 @@
 #include "Support/Timer.h"
 #include <algorithm>
 
+using namespace llvm;
 
 struct ModulePassPrinter : public Pass {
   const PassInfo *PassToPrint;
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index f0fb785..1284358 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -23,6 +23,8 @@
 #include "Support/FileUtilities.h"
 #include <memory>
 
+using namespace llvm;
+
 // Anonymous namespace to define command line options for debugging.
 //
 namespace {
@@ -36,6 +38,8 @@
                                 "(for miscompilation detection)"));
 }
 
+namespace llvm {
+
 /// getPassesString - Turn a list of passes into a string which indicates the
 /// command line options that must be passed to add the passes.
 ///
@@ -179,3 +183,5 @@
   }
   std::cout << std::flush;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index e1af721..af04a7d 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -19,6 +19,8 @@
 #include <vector>
 #include <string>
 
+namespace llvm {
+
 class PassInfo;
 class Module;
 class Function;
@@ -207,4 +209,6 @@
 //
 void DeleteFunctionBody(Function *F);
 
+} // End llvm namespace
+
 #endif
diff --git a/tools/bugpoint/CodeGeneratorBug.cpp b/tools/bugpoint/CodeGeneratorBug.cpp
index 41df79a..b24620e 100644
--- a/tools/bugpoint/CodeGeneratorBug.cpp
+++ b/tools/bugpoint/CodeGeneratorBug.cpp
@@ -33,6 +33,8 @@
 #include <algorithm>
 #include <set>
 
+namespace llvm {
+
 extern cl::list<std::string> InputArgv;
 
 class ReduceMisCodegenFunctions : public ListReducer<Function*> {
@@ -408,3 +410,5 @@
 
   return false;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp
index 0b2851f..8c29ea2 100644
--- a/tools/bugpoint/CrashDebugger.cpp
+++ b/tools/bugpoint/CrashDebugger.cpp
@@ -29,6 +29,8 @@
 #include <fstream>
 #include <set>
 
+namespace llvm {
+
 class DebugCrashes : public ListReducer<const PassInfo*> {
   BugDriver &BD;
 public:
@@ -397,3 +399,5 @@
 
   return false;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp
index 596aeb9..9a3bd55 100644
--- a/tools/bugpoint/ExecutionDriver.cpp
+++ b/tools/bugpoint/ExecutionDriver.cpp
@@ -30,6 +30,8 @@
 #include <fstream>
 #include <iostream>
 
+using namespace llvm;
+
 namespace {
   // OutputType - Allow the user to specify the way code should be run, to test
   // for miscompilation.
@@ -58,6 +60,8 @@
                          "into executing programs"));
 }
 
+namespace llvm {
+
 // Anything specified after the --args option are taken as arguments to the
 // program being debugged.
 cl::list<std::string>
@@ -232,3 +236,5 @@
 bool BugDriver::isExecutingJIT() {
   return InterpreterSel == RunJIT;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index 38e2586..4c671be 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -25,8 +25,15 @@
 #include "llvm/Target/TargetData.h"
 #include "Support/CommandLine.h"
 
+
+namespace llvm {
+
 bool DisableSimplifyCFG = false;
 
+} // End llvm namespace
+
+using namespace llvm;
+
 namespace {
   cl::opt<bool>
   NoADCE("disable-adce",
@@ -39,6 +46,8 @@
          cl::desc("Do not use the -simplifycfg pass to reduce testcases"));
 }
 
+namespace llvm {
+
 /// deleteInstructionFromProgram - This method clones the current Program and
 /// deletes the specified instruction from the cloned module.  It then runs a
 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code which
@@ -125,3 +134,5 @@
   }
   return M;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/ListReducer.h b/tools/bugpoint/ListReducer.h
index 0ab2ef9..0ad2406 100644
--- a/tools/bugpoint/ListReducer.h
+++ b/tools/bugpoint/ListReducer.h
@@ -17,6 +17,8 @@
 
 #include <vector>
 
+namespace llvm {
+
 template<typename ElTy>
 struct ListReducer {
   enum TestResult {
@@ -109,4 +111,6 @@
   }
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index 5ec8b15..1fb46a6 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Transforms/Utils/Linker.h"
 #include "Support/FileUtilities.h"
 
+namespace llvm {
+
 class ReduceMiscompilingPasses : public ListReducer<const PassInfo*> {
   BugDriver &BD;
 public:
@@ -308,3 +310,5 @@
 
   return false;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index 600a25a..af9d1e5 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -26,6 +26,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+namespace llvm {
+
 /// writeProgramToFile - This writes the current "Program" to the named bytecode
 /// file.  If an error occurs, true is returned.
 ///
@@ -159,3 +161,5 @@
   // Was the child successful?
   return !ExitedOK;
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/TestPasses.cpp b/tools/bugpoint/TestPasses.cpp
index af5c045..ee2c0d7 100644
--- a/tools/bugpoint/TestPasses.cpp
+++ b/tools/bugpoint/TestPasses.cpp
@@ -18,6 +18,8 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/InstVisitor.h"
 
+using namespace llvm;
+
 namespace {
   /// CrashOnCalls - This pass is used to test bugpoint.  It intentionally
   /// crashes on any call instructions.
diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp
index a66b868..50a9ad2 100644
--- a/tools/bugpoint/ToolRunner.cpp
+++ b/tools/bugpoint/ToolRunner.cpp
@@ -18,6 +18,8 @@
 #include <iostream>
 #include <fstream>
 
+namespace llvm {
+
 //===---------------------------------------------------------------------===//
 // LLI Implementation of AbstractIntepreter interface
 //
@@ -391,3 +393,5 @@
   Message = "Found gcc: " + GCCPath + "\n";
   return new GCC(GCCPath);
 }
+
+} // End llvm namespace
diff --git a/tools/bugpoint/ToolRunner.h b/tools/bugpoint/ToolRunner.h
index e23ec7f..8ce3f5d 100644
--- a/tools/bugpoint/ToolRunner.h
+++ b/tools/bugpoint/ToolRunner.h
@@ -20,6 +20,8 @@
 #include "Support/SystemUtils.h"
 #include <vector>
 
+namespace llvm {
+
 class CBE;
 class LLC;
 
@@ -137,4 +139,6 @@
   int OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp
index 8f55804..9bca7fd 100644
--- a/tools/bugpoint/bugpoint.cpp
+++ b/tools/bugpoint/bugpoint.cpp
@@ -19,6 +19,8 @@
 #include "Config/unistd.h"
 #include <sys/resource.h>
 
+using namespace llvm;
+
 static cl::list<std::string>
 InputFilenames(cl::Positional, cl::OneOrMore,
                cl::desc("<input llvm ll/bc files>"));
diff --git a/tools/extract/extract.cpp b/tools/extract/extract.cpp
index 272d473..72412b8 100644
--- a/tools/extract/extract.cpp
+++ b/tools/extract/extract.cpp
@@ -21,6 +21,8 @@
 #include "Support/CommandLine.h"
 #include <memory>
 
+using namespace llvm;
+
 // InputFilename - The filename to read from.
 static cl::opt<std::string>
 InputFilename(cl::Positional, cl::desc("<input bytecode file>"),
diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp
index d97c716..c7a2204 100644
--- a/tools/gccas/gccas.cpp
+++ b/tools/gccas/gccas.cpp
@@ -27,6 +27,8 @@
 #include <memory>
 #include <fstream>
 
+using namespace llvm;
+
 namespace {
   cl::opt<std::string>
   InputFilename(cl::Positional,cl::desc("<input llvm assembly>"),cl::init("-"));
diff --git a/tools/gccld/GenerateCode.cpp b/tools/gccld/GenerateCode.cpp
index bf32400..aac1f93 100644
--- a/tools/gccld/GenerateCode.cpp
+++ b/tools/gccld/GenerateCode.cpp
@@ -25,11 +25,14 @@
 #include "Support/SystemUtils.h"
 #include "Support/CommandLine.h"
 
+using namespace llvm;
+
 namespace {
   cl::opt<bool>
   DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
 }
 
+namespace llvm {
 
 /// GenerateBytecode - generates a bytecode file from the specified module.
 ///
@@ -221,3 +224,5 @@
   // Run the compiler to assembly and link together the program.
   return ExecWait(&(cmd[0]), clean_env);
 }
+
+} // End llvm namespace
diff --git a/tools/gccld/Linker.cpp b/tools/gccld/Linker.cpp
index 06f0635..9c22891 100644
--- a/tools/gccld/Linker.cpp
+++ b/tools/gccld/Linker.cpp
@@ -30,6 +30,8 @@
 #include <memory>
 #include <set>
 
+namespace llvm {
+
 /// FindLib - Try to convert Filename into the name of a file that we can open,
 /// if it does not already name a file we can open, by first trying to open
 /// Filename, then libFilename.<suffix> for each of a set of several common
@@ -405,3 +407,5 @@
 
   return false;
 }
+
+} // End llvm namespace
diff --git a/tools/gccld/gccld.cpp b/tools/gccld/gccld.cpp
index 45163f4..5a1b261 100644
--- a/tools/gccld/gccld.cpp
+++ b/tools/gccld/gccld.cpp
@@ -36,6 +36,8 @@
 #include <fstream>
 #include <memory>
 
+using namespace llvm;
+
 namespace {
   cl::list<std::string> 
   InputFilenames(cl::Positional, cl::desc("<input bytecode files>"),
@@ -86,6 +88,8 @@
   CO5("eh-frame-hdr", cl::Hidden, cl::desc("Compatibility option: ignored"));
 }
 
+namespace llvm {
+
 //
 // Function: PrintAndReturn ()
 //
@@ -211,6 +215,7 @@
   return;
 }
 
+} // End llvm namespace
 
 int main(int argc, char **argv, char **envp) {
   cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n");
diff --git a/tools/gccld/gccld.h b/tools/gccld/gccld.h
index e3c5504..9b7eb1e 100644
--- a/tools/gccld/gccld.h
+++ b/tools/gccld/gccld.h
@@ -17,6 +17,8 @@
 #include <set>
 #include <ostream>
 
+namespace llvm {
+
 int
 PrintAndReturn (const char *progname,
                 const std::string &Message,
@@ -69,3 +71,4 @@
            const std::vector<std::string> & Files,
            bool Verbose);
 
+} // End llvm namespace
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 0143d08..f219b6e 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -23,6 +23,8 @@
 #include <memory>
 #include <fstream>
 
+using namespace llvm;
+
 // General options for llc.  Other pass-specific options are specified
 // within the corresponding llc passes, and target-specific options
 // and back-end code generation options are specified with the target machine.
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 87fe461..82b354d 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -28,6 +28,8 @@
 #include "Support/Debug.h"
 #include "Support/SystemUtils.h"
 
+using namespace llvm;
+
 namespace {
   cl::opt<std::string>
   InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index 879d847..e9a4dbf 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -25,6 +25,8 @@
 #include <unistd.h>
 #include <sys/mman.h>
 
+using namespace llvm;
+
 using std::string;
 using std::vector;
 using std::cout;
@@ -69,7 +71,7 @@
 
 //Option to generate symbol table or not
 //running llvm-ar -s is the same as ranlib
-cl::opt<bool> SymbolTable ("s", cl::desc("Generate an archive symbol table"));
+cl::opt<bool> SymbolTableOption ("s", cl::desc("Generate an archive symbol table"));
 
 //Archive name
 cl::opt<string> Archive (cl::Positional, cl::desc("<archive file>"), 
@@ -335,7 +337,7 @@
   ArchiveFile << ARMAG;
 
   //If the '-s' option was specified, generate symbol table.
-  if(SymbolTable) {
+  if(SymbolTableOption) {
     cout << "Symbol Table Start: " << ArchiveFile.tellp() << "\n";
     if(!WriteSymbolTable(ArchiveFile)) {
       std::cerr << "Error creating symbol table. Exiting program.";
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index 0905466..9be5aff 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -24,6 +24,8 @@
 #include <fstream>
 #include <memory>
 
+using namespace llvm;
+
 static cl::opt<std::string> 
 InputFilename(cl::Positional, cl::desc("<input .llvm file>"), cl::init("-"));
 
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 9157559..8d0ca7b 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -29,10 +29,12 @@
 
 // OutputMode - The different orderings to print basic blocks in...
 enum OutputMode {
-  llvm = 0,           // Generate LLVM assembly (the default)
+  LLVM = 0,           // Generate LLVM assembly (the default)
   c,                  // Generate C code
 };
 
+using namespace llvm;
+
 static cl::opt<std::string>
 InputFilename(cl::Positional, cl::desc("<input bytecode>"), cl::init("-"));
 
@@ -45,8 +47,8 @@
 
 static cl::opt<enum OutputMode>
 WriteMode(cl::desc("Specify the output format:"),
-          cl::values(clEnumVal(llvm, "Output LLVM assembly"),
-                     clEnumVal(c   , "Output C code for program"),
+          cl::values(clEnumVal(LLVM, "Output LLVM assembly"),
+                     clEnumVal(c, "Output C code for program"),
                     0));
 
 int main(int argc, char **argv) {
@@ -116,7 +118,7 @@
   PassManager Passes;
 
   switch (WriteMode) {
-  case llvm:           // Output LLVM assembly
+  case LLVM:           // Output LLVM assembly
     Passes.add(new PrintModulePass(Out));
     break;
   case c:              // Convert LLVM to C
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp
index 272d473..72412b8 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -21,6 +21,8 @@
 #include "Support/CommandLine.h"
 #include <memory>
 
+using namespace llvm;
+
 // InputFilename - The filename to read from.
 static cl::opt<std::string>
 InputFilename(cl::Positional, cl::desc("<input bytecode file>"),
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp
index 764b59b..3b49214 100644
--- a/tools/llvm-link/llvm-link.cpp
+++ b/tools/llvm-link/llvm-link.cpp
@@ -24,6 +24,8 @@
 #include <sys/types.h>     // For FileExists
 #include <sys/stat.h>
 
+using namespace llvm;
+
 static cl::list<std::string>
 InputFilenames(cl::Positional, cl::OneOrMore,
                cl::desc("<input bytecode files>"));
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index f7a0ef6..878aa24 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -21,6 +21,8 @@
 #include "Support/CommandLine.h"
 #include <cctype>
 
+using namespace llvm;
+
 namespace {
   enum OutputFormatTy { bsd, sysv, posix };
   cl::opt<OutputFormatTy>
diff --git a/tools/llvm-prof/ProfileInfo.cpp b/tools/llvm-prof/ProfileInfo.cpp
index 78de9c1..1d37c42 100644
--- a/tools/llvm-prof/ProfileInfo.cpp
+++ b/tools/llvm-prof/ProfileInfo.cpp
@@ -20,6 +20,8 @@
 #include <fcntl.h>
 #include <stdio.h>
 
+using namespace llvm;
+
 enum ProfilingType {
   ArgumentInfo = 1,   // The command line argument block
   FunctionInfo = 2,   // Function profiling information
diff --git a/tools/llvm-prof/ProfileInfo.h b/tools/llvm-prof/ProfileInfo.h
index 24e4296..db45001 100644
--- a/tools/llvm-prof/ProfileInfo.h
+++ b/tools/llvm-prof/ProfileInfo.h
@@ -18,6 +18,9 @@
 #include <vector>
 #include <string>
 #include <utility>
+
+namespace llvm {
+
 class Module;
 class Function;
 class BasicBlock;
@@ -55,4 +58,6 @@
   void getBlockCounts(std::vector<std::pair<BasicBlock*, unsigned> > &Counts);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp
index 4492fd6..438fecf 100644
--- a/tools/llvm-prof/llvm-prof.cpp
+++ b/tools/llvm-prof/llvm-prof.cpp
@@ -23,6 +23,8 @@
 #include <map>
 #include <set>
 
+using namespace llvm;
+
 namespace {
   cl::opt<std::string> 
   BytecodeFile(cl::Positional, cl::desc("<program bytecode file>"),
diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp
index 6c4c99f..a9b9cd0 100644
--- a/tools/opt/AnalysisWrappers.cpp
+++ b/tools/opt/AnalysisWrappers.cpp
@@ -26,6 +26,8 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Support/InstIterator.h"
 
+using namespace llvm;
+
 namespace {
   struct InstForestHelper : public FunctionPass {
     Function *F;
diff --git a/tools/opt/GraphPrinters.cpp b/tools/opt/GraphPrinters.cpp
index 34c937f..6d2750f 100644
--- a/tools/opt/GraphPrinters.cpp
+++ b/tools/opt/GraphPrinters.cpp
@@ -20,6 +20,8 @@
 #include "llvm/Analysis/CallGraph.h"
 #include <fstream>
 
+namespace llvm {
+
 template<typename GraphType>
 static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
                              const GraphType &GT) {
@@ -72,3 +74,5 @@
   RegisterAnalysis<CallGraphPrinter> P2("print-callgraph",
                                         "Print Call Graph to 'dot' file");
 };
+
+} // End llvm namespace
diff --git a/tools/opt/PrintSCC.cpp b/tools/opt/PrintSCC.cpp
index 3459381..ce89fff 100644
--- a/tools/opt/PrintSCC.cpp
+++ b/tools/opt/PrintSCC.cpp
@@ -31,6 +31,8 @@
 #include "llvm/Support/CFG.h"
 #include "Support/SCCIterator.h"
 
+namespace llvm {
+
 namespace {
   struct CFGSCC : public FunctionPass {
     bool runOnFunction(Function& func);
@@ -101,3 +103,5 @@
 
   return true;
 }
+
+} // End llvm namespace
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index bc0a5fc..30c72f1 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -27,6 +27,7 @@
 #include <memory>
 #include <algorithm>
 
+using namespace llvm;
 
 // The OptimizationList is automatically populated with registered Passes by the
 // PassNameParser.
diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp
index bd3d2ff..2c3e374 100644
--- a/utils/TableGen/CodeEmitterGen.cpp
+++ b/utils/TableGen/CodeEmitterGen.cpp
@@ -15,6 +15,8 @@
 #include "Record.h"
 #include "Support/Debug.h"
 
+namespace llvm {
+
 void CodeEmitterGen::run(std::ostream &o) {
   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
 
@@ -221,4 +223,8 @@
     << "  }\n"
     << "  return Value;\n"
     << "}\n";
+
+  EmitSourceFileTail(o);
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/CodeEmitterGen.h b/utils/TableGen/CodeEmitterGen.h
index d7b4bc1..19ca545 100644
--- a/utils/TableGen/CodeEmitterGen.h
+++ b/utils/TableGen/CodeEmitterGen.h
@@ -16,6 +16,8 @@
 
 #include "TableGenBackend.h"
 
+namespace llvm {
+
 class CodeEmitterGen : public TableGenBackend {
   RecordKeeper &Records;
 public:
@@ -28,4 +30,6 @@
   void emitGetValueBit(std::ostream &o, const std::string &Namespace);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp
index 5039cca..bf641fa 100644
--- a/utils/TableGen/CodeGenTarget.cpp
+++ b/utils/TableGen/CodeGenTarget.cpp
@@ -17,6 +17,8 @@
 #include "CodeGenWrappers.h"
 #include "Record.h"
 
+namespace llvm {
+
 /// getValueType - Return the MCV::ValueType that the specified TableGen record
 /// corresponds to.
 MVT::ValueType getValueType(Record *Rec) {
@@ -94,3 +96,5 @@
 Record *CodeGenTarget::getInstructionSet() const {
   return TargetRec->getValueAsDef("InstructionSet");
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/CodeGenTarget.h b/utils/TableGen/CodeGenTarget.h
index f0b7200..948360e 100644
--- a/utils/TableGen/CodeGenTarget.h
+++ b/utils/TableGen/CodeGenTarget.h
@@ -21,6 +21,9 @@
 #include <iosfwd>
 #include <string>
 #include <vector>
+
+namespace llvm {
+
 class Record;
 class RecordKeeper;
 
@@ -60,4 +63,6 @@
   // CodeGenInstructionSet *getInstructionSet -
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/CodeGenWrappers.cpp b/utils/TableGen/CodeGenWrappers.cpp
index 5039cca..bf641fa 100644
--- a/utils/TableGen/CodeGenWrappers.cpp
+++ b/utils/TableGen/CodeGenWrappers.cpp
@@ -17,6 +17,8 @@
 #include "CodeGenWrappers.h"
 #include "Record.h"
 
+namespace llvm {
+
 /// getValueType - Return the MCV::ValueType that the specified TableGen record
 /// corresponds to.
 MVT::ValueType getValueType(Record *Rec) {
@@ -94,3 +96,5 @@
 Record *CodeGenTarget::getInstructionSet() const {
   return TargetRec->getValueAsDef("InstructionSet");
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/CodeGenWrappers.h b/utils/TableGen/CodeGenWrappers.h
index f0b7200..948360e 100644
--- a/utils/TableGen/CodeGenWrappers.h
+++ b/utils/TableGen/CodeGenWrappers.h
@@ -21,6 +21,9 @@
 #include <iosfwd>
 #include <string>
 #include <vector>
+
+namespace llvm {
+
 class Record;
 class RecordKeeper;
 
@@ -60,4 +63,6 @@
   // CodeGenInstructionSet *getInstructionSet -
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/FileLexer.l b/utils/TableGen/FileLexer.l
index 0858a8c..48070b34 100644
--- a/utils/TableGen/FileLexer.l
+++ b/utils/TableGen/FileLexer.l
@@ -28,9 +28,13 @@
 
 %{
 #include "Record.h"
-typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
+typedef std::pair<llvm::Record*, std::vector<llvm::Init*>*> SubClassRefTy;
 #include "FileParser.h"
 
+int Fileparse();
+
+namespace llvm {
+
 // Global variable recording the location of the include directory
 std::string IncludeDirectory;
 
@@ -69,7 +73,6 @@
 }
 
 
-int Fileparse();
 
 //
 // Function: ParseFile()
@@ -171,6 +174,10 @@
   return 0;
 }
 
+} // End llvm namespace
+
+using namespace llvm;
+
 %}
 
 Comment      \/\/.*
diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y
index 491cca3..e95e597 100644
--- a/utils/TableGen/FileParser.y
+++ b/utils/TableGen/FileParser.y
@@ -20,6 +20,9 @@
 
 int yyerror(const char *ErrorMsg);
 int yylex();
+
+namespace llvm {
+
 extern int Filelineno;
 static Record *CurRec = 0;
 
@@ -160,20 +163,23 @@
   addSuperClass(SC);
 }
 
+} // End llvm namespace
+
+using namespace llvm;
 
 %}
 
 %union {
-  std::string          *StrVal;
-  int                   IntVal;
-  RecTy                *Ty;
-  Init                 *Initializer;
-  std::vector<Init*>   *FieldList;
-  std::vector<unsigned>*BitList;
-  Record               *Rec;
-  SubClassRefTy        *SubClassRef;
-  std::vector<SubClassRefTy> *SubClassList;
-  std::vector<std::pair<Init*, std::string> > *DagValueList;
+  std::string*                StrVal;
+  int                         IntVal;
+  llvm::RecTy*                Ty;
+  llvm::Init*                 Initializer;
+  std::vector<llvm::Init*>*   FieldList;
+  std::vector<unsigned>*      BitList;
+  llvm::Record*               Rec;
+  SubClassRefTy*              SubClassRef;
+  std::vector<SubClassRefTy>* SubClassList;
+  std::vector<std::pair<llvm::Init*, std::string> >* DagValueList;
 };
 
 %token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
@@ -193,6 +199,7 @@
 %type <StrVal>       Declaration OptID OptVarName
 
 %start File
+
 %%
 
 ClassID : ID {
diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp
index a11244d..ed040b1 100644
--- a/utils/TableGen/InstrInfoEmitter.cpp
+++ b/utils/TableGen/InstrInfoEmitter.cpp
@@ -16,6 +16,8 @@
 #include "CodeGenWrappers.h"
 #include "Record.h"
 
+namespace llvm {
+
 // runEnums - Print out enum values for all of the instructions.
 void InstrInfoEmitter::runEnums(std::ostream &OS) {
   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
@@ -47,6 +49,7 @@
   OS << "  };\n";
   if (!Namespace.empty())
     OS << "}\n";
+  EmitSourceFileTail(OS);
 }
 
 void InstrInfoEmitter::printDefList(ListInit *LI, const std::string &Name,
@@ -93,6 +96,7 @@
     if (Instructions[i] != PHI)
       emitRecord(Instructions[i], i+1, InstrInfo, OS);
   OS << "};\n";
+  EmitSourceFileTail(OS);
 }
 
 void InstrInfoEmitter::emitRecord(Record *R, unsigned Num, Record *InstrInfo,
@@ -169,3 +173,5 @@
   std::cerr << "Unhandled initializer: " << *Val << "\n";
   throw "In record '" + R->getName() + "' for TSFlag emission.";
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/InstrInfoEmitter.h b/utils/TableGen/InstrInfoEmitter.h
index 4adac31..2a6b063 100644
--- a/utils/TableGen/InstrInfoEmitter.h
+++ b/utils/TableGen/InstrInfoEmitter.h
@@ -16,6 +16,9 @@
 #define INSTRINFO_EMITTER_H
 
 #include "TableGenBackend.h"
+
+namespace llvm {
+
 class StringInit;
 class IntInit;
 class ListInit;
@@ -38,4 +41,6 @@
                         std::ostream &OS);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/InstrSelectorEmitter.cpp b/utils/TableGen/InstrSelectorEmitter.cpp
index 9988d55..5d945bb 100644
--- a/utils/TableGen/InstrSelectorEmitter.cpp
+++ b/utils/TableGen/InstrSelectorEmitter.cpp
@@ -19,6 +19,8 @@
 #include "Support/StringExtras.h"
 #include <set>
 
+namespace llvm {
+
 NodeType::ArgResultTypes NodeType::Translate(Record *R) {
   const std::string &Name = R->getName();
   if (Name == "DNVT_any")  return Any;
@@ -978,9 +980,10 @@
 
   CalculateComputableValues();
   
+  OS << "#include \"llvm/CodeGen/MachineInstrBuilder.h\"\n";
+
   EmitSourceFileHeader("Instruction Selector for the " + Target.getName() +
                        " target", OS);
-  OS << "#include \"llvm/CodeGen/MachineInstrBuilder.h\"\n";
 
   // Output the slot number enums...
   OS << "\nenum { // Slot numbers...\n"
@@ -1290,5 +1293,7 @@
        << "  }\n\n  N->addValue(Val);  // Do not ever recalculate this\n"
        << "  return Val;\n}\n\n";
   }
+  EmitSourceFileTail(OS);
 }
 
+} // End llvm namespace
diff --git a/utils/TableGen/InstrSelectorEmitter.h b/utils/TableGen/InstrSelectorEmitter.h
index 2f9175c..a0fbbcf 100644
--- a/utils/TableGen/InstrSelectorEmitter.h
+++ b/utils/TableGen/InstrSelectorEmitter.h
@@ -21,6 +21,8 @@
 #include <map>
 #include <cassert>
 
+namespace llvm {
+
 class DagInit;
 class Init;
 class InstrSelectorEmitter;
@@ -391,4 +393,6 @@
                             bool PrintArg, std::ostream &OS);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 32ffe62..00751a1 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -16,6 +16,8 @@
 //    Type implementations
 //===----------------------------------------------------------------------===//
 
+namespace llvm {
+
 void RecTy::dump() const { print(std::cerr); }
 
 Init *BitRecTy::convertValue(BitsInit *BI) {
@@ -681,3 +683,5 @@
 
   return Defs;
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index e2233f8..d8a9649 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -21,6 +21,8 @@
 #include <iostream>
 #include <cassert>
 
+namespace llvm {
+
 // RecTy subclasses...
 class BitRecTy;
 class BitsRecTy;
@@ -853,4 +855,6 @@
 
 extern RecordKeeper Records;
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp
index 67acc3f..4e7aa9b 100644
--- a/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/utils/TableGen/RegisterInfoEmitter.cpp
@@ -19,6 +19,8 @@
 #include "Support/StringExtras.h"
 #include <set>
 
+namespace llvm {
+
 // runEnums - Print out enum values for all of the registers.
 void RegisterInfoEmitter::runEnums(std::ostream &OS) {
   std::vector<Record*> Registers = Records.getAllDerivedDefinitions("Register");
@@ -40,6 +42,7 @@
   OS << "  };\n";
   if (!Namespace.empty())
     OS << "}\n";
+  EmitSourceFileTail(OS);
 }
 
 void RegisterInfoEmitter::runHeader(std::ostream &OS) {
@@ -68,6 +71,7 @@
       OS << "  extern TargetRegisterClass *" << Name << "RegisterClass;\n";
   }
   OS << "} // end of namespace " << TargetName << "\n\n";
+  EmitSourceFileTail(OS);
 }
 
 // RegisterInfoEmitter::run - Main register file description emitter.
@@ -240,4 +244,7 @@
   for (unsigned i = 0, e = CSR.size(); i != e; ++i)
     OS << getQualifiedName(CSR[i]) << ", ";  
   OS << " 0\n  };\n  return CalleeSaveRegs;\n}\n\n";
+  EmitSourceFileTail(OS);
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/RegisterInfoEmitter.h b/utils/TableGen/RegisterInfoEmitter.h
index 22c759f..1e6380b 100644
--- a/utils/TableGen/RegisterInfoEmitter.h
+++ b/utils/TableGen/RegisterInfoEmitter.h
@@ -18,6 +18,8 @@
 
 #include "TableGenBackend.h"
 
+namespace llvm {
+
 class RegisterInfoEmitter : public TableGenBackend {
   RecordKeeper &Records;
 public:
@@ -33,4 +35,6 @@
   void runEnums(std::ostream &o);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index 803d0f0..c05ccb0 100644
--- a/utils/TableGen/TableGen.cpp
+++ b/utils/TableGen/TableGen.cpp
@@ -27,6 +27,8 @@
 #include <cstdio>
 #include <fstream>
 
+namespace llvm {
+
 enum ActionType {
   PrintRecords,
   GenEmitter,
@@ -406,6 +408,9 @@
   }
 }
 
+} // End llvm namespace
+
+using namespace llvm;
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv);
@@ -459,12 +464,17 @@
       InstrSelectorEmitter(Records).run(*Out);
       break;
     case PrintEnums:
+    {
       std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
       for (unsigned i = 0, e = Recs.size(); i != e; ++i)
         *Out << Recs[i] << ", ";
       *Out << "\n";
       break;
     }
+    default:
+      assert(1 && "Invalid Action");
+      return 1;
+    }
   } catch (const std::string &Error) {
     std::cerr << Error << "\n";
     if (Out != &std::cout) {
diff --git a/utils/TableGen/TableGenBackend.cpp b/utils/TableGen/TableGenBackend.cpp
index 161b2ee..67a3788 100644
--- a/utils/TableGen/TableGenBackend.cpp
+++ b/utils/TableGen/TableGenBackend.cpp
@@ -15,12 +15,18 @@
 #include "Record.h"
 #include <iostream>
 
+namespace llvm {
+
 void TableGenBackend::EmitSourceFileHeader(const std::string &Desc,
                                            std::ostream &OS) const {
   OS << "//===- TableGen'erated file -------------------------------------*-"
        " C++ -*-===//\n//\n// " << Desc << "\n//\n// Automatically generate"
        "d file, do not edit!\n//\n//===------------------------------------"
-       "----------------------------------===//\n\n";
+       "----------------------------------===//\n\nnamespace llvm {\n\n";
+}
+
+void TableGenBackend::EmitSourceFileTail( std::ostream& OS ) const {
+  OS << "} // End llvm namespace \n";
 }
 
 /// getQualifiedName - Return the name of the specified record, with a
@@ -32,3 +38,4 @@
   return Namespace + "::" + R->getName();
 }
 
+} // End llvm namespace
diff --git a/utils/TableGen/TableGenBackend.h b/utils/TableGen/TableGenBackend.h
index 23b83ca..869d7e9 100644
--- a/utils/TableGen/TableGenBackend.h
+++ b/utils/TableGen/TableGenBackend.h
@@ -17,6 +17,9 @@
 
 #include <string>
 #include <iosfwd>
+
+namespace llvm {
+
 class Record;
 class RecordKeeper;
 
@@ -33,9 +36,15 @@
   /// ostream.
   void EmitSourceFileHeader(const std::string &Desc, std::ostream &OS) const;
 
+  /// EmitSourceFileTail - Output an LLVm styelf ile tail to the specified
+  /// ostream.
+  void EmitSourceFileTail( std::ostream& OS ) const;
+
   /// getQualifiedName - Return the name of the specified record, with a
   /// namespace qualifier if the record contains one.
   std::string getQualifiedName(Record *R) const;
 };
 
+} // End llvm namespace
+
 #endif