Promote ModuleMap::Module to a namespace-scope class in the Basic
library, since modules cut across all of the libraries. Rename
serialization::Module to serialization::ModuleFile to side-step the
annoying naming conflict. Prune a bunch of ModuleMap.h includes that
are no longer needed (most files only needed the Module type).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145538 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 95a73c3..48912e3 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -731,7 +731,7 @@
   return std::make_pair(Start, Start + NumDecls);
 }
 
-bool ASTReader::ReadDeclContextStorage(Module &M,
+bool ASTReader::ReadDeclContextStorage(ModuleFile &M,
                                        llvm::BitstreamCursor &Cursor,
                                    const std::pair<uint64_t, uint64_t> &Offsets,
                                        DeclContextInfo &Info) {
@@ -805,7 +805,7 @@
 
 /// \brief Read the line table in the source manager block.
 /// \returns true if there was an error.
-bool ASTReader::ParseLineTable(Module &F,
+bool ASTReader::ParseLineTable(ModuleFile &F,
                                SmallVectorImpl<uint64_t> &Record) {
   unsigned Idx = 0;
   LineTableInfo &LineTable = SourceMgr.getLineTable();
@@ -949,7 +949,7 @@
 
 
 /// \brief Read a source manager block
-ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) {
+ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(ModuleFile &F) {
   using namespace SrcMgr;
 
   llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
@@ -1058,7 +1058,7 @@
     return Failure;
   }
 
-  Module *F = GlobalSLocEntryMap.find(-ID)->second;
+  ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
   F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]);
   llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
   unsigned BaseOffset = F->SLocEntryBaseOffset;
@@ -1217,7 +1217,7 @@
 }
 
 /// \brief Find the location where the module F is imported.
-SourceLocation ASTReader::getImportLocation(Module *F) {
+SourceLocation ASTReader::getImportLocation(ModuleFile *F) {
   if (F->ImportLoc.isValid())
     return F->ImportLoc;
   
@@ -1258,7 +1258,7 @@
   }
 }
 
-void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) {
+void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) {
   llvm::BitstreamCursor &Stream = F.MacroCursor;
 
   // Keep track of where we are in the stream, then jump back there
@@ -1385,7 +1385,7 @@
 }
 
 PreprocessedEntityID 
-ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) const {
+ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const {
   ContinuousRangeMap<uint32_t, int, 2>::const_iterator 
     I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS);
   assert(I != M.PreprocessedEntityRemap.end() 
@@ -1454,7 +1454,7 @@
   return HFI;
 }
 
-void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F,
+void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F,
                                      uint64_t LocalOffset) {
   // Note that this identifier has a macro definition.
   II->setHasMacroDefinition(true);
@@ -1545,7 +1545,7 @@
   public:
     explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { }
     
-    static bool visit(Module &M, void *UserData) {
+    static bool visit(ModuleFile &M, void *UserData) {
       IdentifierLookupVisitor *This
         = static_cast<IdentifierLookupVisitor *>(UserData);
       
@@ -1618,7 +1618,7 @@
 }
 
 ASTReader::ASTReadResult
-ASTReader::ReadASTBlock(Module &F) {
+ASTReader::ReadASTBlock(ModuleFile &F) {
   llvm::BitstreamCursor &Stream = F.Stream;
 
   if (Stream.EnterSubBlock(AST_BLOCK_ID)) {
@@ -2070,7 +2070,7 @@
         uint16_t Len = io::ReadUnalignedLE16(Data);
         StringRef Name = StringRef((const char*)Data, Len);
         Data += Len;
-        Module *OM = ModuleMgr.lookup(Name);
+        ModuleFile *OM = ModuleMgr.lookup(Name);
         if (!OM) {
           Error("SourceLocation remap refers to unknown module");
           return Failure;
@@ -2364,7 +2364,7 @@
   return Failure;
 }
 
-ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) {
+ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) {
   llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor;
 
   for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) {
@@ -2481,8 +2481,8 @@
 
 ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName,
                                                 ModuleKind Type,
-                                                Module *ImportedBy) {
-  Module *M;
+                                                ModuleFile *ImportedBy) {
+  ModuleFile *M;
   bool NewModule;
   std::string ErrorStr;
   llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy,
@@ -2508,7 +2508,7 @@
     if (CurrentDir.empty()) CurrentDir = ".";
   }
 
-  Module &F = *M;
+  ModuleFile &F = *M;
   llvm::BitstreamCursor &Stream = F.Stream;
   Stream.init(F.StreamFile);
   F.SizeInBits = F.Buffer->getBufferSize() * 8;
@@ -2572,7 +2572,7 @@
     }
   }
   
-  // Once read, set the Module bit base offset and update the size in 
+  // Once read, set the ModuleFile bit base offset and update the size in 
   // bits of all files we've seen.
   F.GlobalBitOffset = TotalModulesSizeInBits;
   TotalModulesSizeInBits += F.SizeInBits;
@@ -2820,7 +2820,7 @@
   return std::string();
 }
 
-ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(Module &F) {
+ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) {
   // Enter the submodule block.
   if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) {
     Error("malformed submodule block record in AST file");
@@ -2828,7 +2828,7 @@
   }
 
   ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap();
-  ModuleMap::Module *CurrentModule = 0;
+  Module *CurrentModule = 0;
   RecordData Record;
   while (true) {
     unsigned Code = F.Stream.ReadCode();
@@ -2869,7 +2869,7 @@
       bool IsFramework = Record[1];
       bool IsExplicit = Record[2];
 
-      ModuleMap::Module *ParentModule = 0;
+      Module *ParentModule = 0;
       if (Parent) {
         if (Parent > F.Submodules.size()) {
           Error("malformed submodule parent entry");
@@ -2952,21 +2952,21 @@
   return false;
 }
 
-std::pair<Module *, unsigned>
+std::pair<ModuleFile *, unsigned>
 ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) {
   GlobalPreprocessedEntityMapType::iterator
   I = GlobalPreprocessedEntityMap.find(GlobalIndex);
   assert(I != GlobalPreprocessedEntityMap.end() && 
          "Corrupted global preprocessed entity map");
-  Module *M = I->second;
+  ModuleFile *M = I->second;
   unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID;
   return std::make_pair(M, LocalIndex);
 }
 
 PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
   PreprocessedEntityID PPID = Index+1;
-  std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
-  Module &M = *PPInfo.first;
+  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
+  ModuleFile &M = *PPInfo.first;
   unsigned LocalIndex = PPInfo.second;
   const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
 
@@ -3072,7 +3072,7 @@
   ++SLocMapI;
   for (GlobalSLocOffsetMapType::const_iterator
          EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) {
-    Module &M = *SLocMapI->second;
+    ModuleFile &M = *SLocMapI->second;
     if (M.NumPreprocessedEntities)
       return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID);
   }
@@ -3085,9 +3085,9 @@
 template <unsigned PPEntityOffset::*PPLoc>
 struct PPEntityComp {
   const ASTReader &Reader;
-  Module &M;
+  ModuleFile &M;
 
-  PPEntityComp(const ASTReader &Reader, Module &M) : Reader(Reader), M(M) { }
+  PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { }
 
   bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const {
     SourceLocation LHS = getLoc(L);
@@ -3127,7 +3127,7 @@
   if (SLocMapI->second->NumPreprocessedEntities == 0)
     return findNextPreprocessedEntity(SLocMapI);
 
-  Module &M = *SLocMapI->second;
+  ModuleFile &M = *SLocMapI->second;
   typedef const PPEntityOffset *pp_iterator;
   pp_iterator pp_begin = M.PreprocessedEntityOffsets;
   pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities;
@@ -3176,7 +3176,7 @@
   if (SLocMapI->second->NumPreprocessedEntities == 0)
     return findNextPreprocessedEntity(SLocMapI);
 
-  Module &M = *SLocMapI->second;
+  ModuleFile &M = *SLocMapI->second;
   typedef const PPEntityOffset *pp_iterator;
   pp_iterator pp_begin = M.PreprocessedEntityOffsets;
   pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities;
@@ -3211,8 +3211,8 @@
   if (FID.isInvalid())
     return false;
 
-  std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
-  Module &M = *PPInfo.first;
+  std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
+  ModuleFile &M = *PPInfo.first;
   unsigned LocalIndex = PPInfo.second;
   const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
   
@@ -3238,7 +3238,7 @@
     HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE)
       : Reader(Reader), FE(FE) { }
     
-    static bool visit(Module &M, void *UserData) {
+    static bool visit(ModuleFile &M, void *UserData) {
       HeaderFileInfoVisitor *This
         = static_cast<HeaderFileInfoVisitor *>(UserData);
       
@@ -3280,7 +3280,7 @@
 
 void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
   for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) {
-    Module &F = *(*I);
+    ModuleFile &F = *(*I);
     unsigned Idx = 0;
     while (Idx < F.PragmaDiagMappings.size()) {
       SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]);
@@ -3311,7 +3311,7 @@
 ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) {
   GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index);
   assert(I != GlobalTypeMap.end() && "Corrupted global type map");
-  Module *M = I->second;
+  ModuleFile *M = I->second;
   return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]);
 }
 
@@ -3752,7 +3752,7 @@
 
 class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> {
   ASTReader &Reader;
-  Module &F;
+  ModuleFile &F;
   llvm::BitstreamCursor &DeclsCursor;
   const ASTReader::RecordData &Record;
   unsigned &Idx;
@@ -3768,7 +3768,7 @@
   }
   
 public:
-  TypeLocReader(ASTReader &Reader, Module &F,
+  TypeLocReader(ASTReader &Reader, ModuleFile &F,
                 const ASTReader::RecordData &Record, unsigned &Idx)
     : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx)
   { }
@@ -3985,7 +3985,7 @@
   TL.setRParenLoc(ReadSourceLocation(Record, Idx));
 }
 
-TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F,
+TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F,
                                              const RecordData &Record,
                                              unsigned &Idx) {
   QualType InfoTy = readType(F, Record, Idx);
@@ -4076,12 +4076,12 @@
   return TypesLoaded[Index].withFastQualifiers(FastQuals);
 }
 
-QualType ASTReader::getLocalType(Module &F, unsigned LocalID) {
+QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) {
   return GetType(getGlobalTypeID(F, LocalID));
 }
 
 serialization::TypeID 
-ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const {
+ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const {
   unsigned FastQuals = LocalID & Qualifiers::FastMask;
   unsigned LocalIndex = LocalID >> Qualifiers::FastWidth;
   
@@ -4097,7 +4097,7 @@
 }
 
 TemplateArgumentLocInfo
-ASTReader::GetTemplateArgumentLocInfo(Module &F,
+ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F,
                                       TemplateArgument::ArgKind Kind,
                                       const RecordData &Record,
                                       unsigned &Index) {
@@ -4132,7 +4132,7 @@
 }
 
 TemplateArgumentLoc
-ASTReader::ReadTemplateArgumentLoc(Module &F,
+ASTReader::ReadTemplateArgumentLoc(ModuleFile &F,
                                    const RecordData &Record, unsigned &Index) {
   TemplateArgument Arg = ReadTemplateArgument(F, Record, Index);
 
@@ -4148,7 +4148,7 @@
   return GetDecl(ID);
 }
 
-uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, 
+uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, 
                                           unsigned &Idx){
   if (Idx >= Record.size())
     return 0;
@@ -4181,7 +4181,7 @@
 }
 
 serialization::DeclID 
-ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const {
+ASTReader::getGlobalDeclID(ModuleFile &F, unsigned LocalID) const {
   if (LocalID < NUM_PREDEF_DECL_IDS)
     return LocalID;
 
@@ -4193,7 +4193,7 @@
 }
 
 bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID,
-                                   Module &M) const {
+                                   ModuleFile &M) const {
   GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID);
   assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
   return &M == I->second;
@@ -4265,7 +4265,7 @@
   return DeclsLoaded[Index];
 }
 
-serialization::DeclID ASTReader::ReadDeclID(Module &F, 
+serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, 
                                             const RecordData &Record,
                                             unsigned &Idx) {
   if (Idx >= Record.size()) {
@@ -4310,14 +4310,14 @@
         PredefsVisited[I] = false;
     }
 
-    static bool visit(Module &M, bool Preorder, void *UserData) {
+    static bool visit(ModuleFile &M, bool Preorder, void *UserData) {
       if (Preorder)
         return false;
 
       FindExternalLexicalDeclsVisitor *This
         = static_cast<FindExternalLexicalDeclsVisitor *>(UserData);
 
-      Module::DeclContextInfosMap::iterator Info
+      ModuleFile::DeclContextInfosMap::iterator Info
         = M.DeclContextInfos.find(This->DC);
       if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls)
         return false;
@@ -4364,10 +4364,10 @@
 
 class DeclIDComp {
   ASTReader &Reader;
-  Module &Mod;
+  ModuleFile &Mod;
 
 public:
-  DeclIDComp(ASTReader &Reader, Module &M) : Reader(Reader), Mod(M) {}
+  DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {}
 
   bool operator()(LocalDeclID L, LocalDeclID R) const {
     SourceLocation LHS = getLocation(L);
@@ -4437,7 +4437,7 @@
 }
 
 namespace {
-  /// \brief Module visitor used to perform name lookup into a
+  /// \brief ModuleFile visitor used to perform name lookup into a
   /// declaration context.
   class DeclContextNameLookupVisitor {
     ASTReader &Reader;
@@ -4451,13 +4451,13 @@
                                  SmallVectorImpl<NamedDecl *> &Decls)
       : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { }
 
-    static bool visit(Module &M, void *UserData) {
+    static bool visit(ModuleFile &M, void *UserData) {
       DeclContextNameLookupVisitor *This
         = static_cast<DeclContextNameLookupVisitor *>(UserData);
 
       // Check whether we have any visible declaration information for
       // this context in this module.
-      Module::DeclContextInfosMap::iterator Info
+      ModuleFile::DeclContextInfosMap::iterator Info
         = M.DeclContextInfos.find(This->DC);
       if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData)
         return false;
@@ -4628,15 +4628,15 @@
   std::fprintf(stderr, "\n");
 }
 
-template<typename Key, typename Module, unsigned InitialCapacity>
+template<typename Key, typename ModuleFile, unsigned InitialCapacity>
 static void 
 dumpModuleIDMap(StringRef Name,
-                const ContinuousRangeMap<Key, Module *, 
+                const ContinuousRangeMap<Key, ModuleFile *, 
                                          InitialCapacity> &Map) {
   if (Map.begin() == Map.end())
     return;
   
-  typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType;
+  typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType;
   llvm::errs() << Name << ":\n";
   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 
        I != IEnd; ++I) {
@@ -4646,7 +4646,7 @@
 }
 
 void ASTReader::dump() {
-  llvm::errs() << "*** PCH/Module Remappings:\n";
+  llvm::errs() << "*** PCH/ModuleFile Remappings:\n";
   dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap);
   dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap);
   dumpModuleIDMap("Global type map", GlobalTypeMap);
@@ -4821,7 +4821,7 @@
     ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel)
       : Reader(Reader), Sel(Sel) { }
     
-    static bool visit(Module &M, void *UserData) {
+    static bool visit(ModuleFile &M, void *UserData) {
       ReadMethodPoolVisitor *This
         = static_cast<ReadMethodPoolVisitor *>(UserData);
       
@@ -5079,7 +5079,7 @@
   if (!IdentifiersLoaded[ID]) {
     GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1);
     assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map");
-    Module *M = I->second;
+    ModuleFile *M = I->second;
     unsigned Index = ID - M->BaseIdentifierID;
     const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index];
 
@@ -5100,11 +5100,11 @@
   return IdentifiersLoaded[ID];
 }
 
-IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) {
+IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
   return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
 }
 
-IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) {
+IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
   if (LocalID < NUM_PREDEF_IDENT_IDS)
     return LocalID;
   
@@ -5120,7 +5120,7 @@
   return ReadSLocEntryRecord(ID) != Success;
 }
 
-Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) {
+Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
   return DecodeSelector(getGlobalSelectorID(M, LocalID));
 }
 
@@ -5137,7 +5137,7 @@
     // Load this selector from the selector table.
     GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
     assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
-    Module &M = *I->second;
+    ModuleFile &M = *I->second;
     ASTSelectorLookupTrait Trait(*this, M);
     unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS;
     SelectorsLoaded[ID - 1] =
@@ -5159,7 +5159,7 @@
 }
 
 serialization::SelectorID
-ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const {
+ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const {
   if (LocalID < NUM_PREDEF_SELECTOR_IDS)
     return LocalID;
   
@@ -5172,7 +5172,7 @@
 }
 
 DeclarationName
-ASTReader::ReadDeclarationName(Module &F, 
+ASTReader::ReadDeclarationName(ModuleFile &F, 
                                const RecordData &Record, unsigned &Idx) {
   DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++];
   switch (Kind) {
@@ -5212,7 +5212,7 @@
   return DeclarationName();
 }
 
-void ASTReader::ReadDeclarationNameLoc(Module &F,
+void ASTReader::ReadDeclarationNameLoc(ModuleFile &F,
                                        DeclarationNameLoc &DNLoc,
                                        DeclarationName Name,
                                       const RecordData &Record, unsigned &Idx) {
@@ -5244,7 +5244,7 @@
   }
 }
 
-void ASTReader::ReadDeclarationNameInfo(Module &F,
+void ASTReader::ReadDeclarationNameInfo(ModuleFile &F,
                                         DeclarationNameInfo &NameInfo,
                                       const RecordData &Record, unsigned &Idx) {
   NameInfo.setName(ReadDeclarationName(F, Record, Idx));
@@ -5254,7 +5254,7 @@
   NameInfo.setInfo(DNLoc);
 }
 
-void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info,
+void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
                                   const RecordData &Record, unsigned &Idx) {
   Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
   unsigned NumTPLists = Record[Idx++];
@@ -5267,7 +5267,7 @@
 }
 
 TemplateName
-ASTReader::ReadTemplateName(Module &F, const RecordData &Record, 
+ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, 
                             unsigned &Idx) {
   TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++];
   switch (Kind) {
@@ -5326,7 +5326,7 @@
 }
 
 TemplateArgument
-ASTReader::ReadTemplateArgument(Module &F,
+ASTReader::ReadTemplateArgument(ModuleFile &F,
                                 const RecordData &Record, unsigned &Idx) {
   TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++];
   switch (Kind) {
@@ -5365,7 +5365,7 @@
 }
 
 TemplateParameterList *
-ASTReader::ReadTemplateParameterList(Module &F,
+ASTReader::ReadTemplateParameterList(ModuleFile &F,
                                      const RecordData &Record, unsigned &Idx) {
   SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx);
   SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx);
@@ -5386,7 +5386,7 @@
 void
 ASTReader::
 ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs,
-                         Module &F, const RecordData &Record,
+                         ModuleFile &F, const RecordData &Record,
                          unsigned &Idx) {
   unsigned NumTemplateArgs = Record[Idx++];
   TemplArgs.reserve(NumTemplateArgs);
@@ -5395,7 +5395,7 @@
 }
 
 /// \brief Read a UnresolvedSet structure.
-void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set,
+void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set,
                                   const RecordData &Record, unsigned &Idx) {
   unsigned NumDecls = Record[Idx++];
   while (NumDecls--) {
@@ -5406,7 +5406,7 @@
 }
 
 CXXBaseSpecifier
-ASTReader::ReadCXXBaseSpecifier(Module &F,
+ASTReader::ReadCXXBaseSpecifier(ModuleFile &F,
                                 const RecordData &Record, unsigned &Idx) {
   bool isVirtual = static_cast<bool>(Record[Idx++]);
   bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
@@ -5422,7 +5422,7 @@
 }
 
 std::pair<CXXCtorInitializer **, unsigned>
-ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record,
+ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
                                    unsigned &Idx) {
   CXXCtorInitializer **CtorInitializers = 0;
   unsigned NumInitializers = Record[Idx++];
@@ -5503,7 +5503,7 @@
 }
 
 NestedNameSpecifier *
-ASTReader::ReadNestedNameSpecifier(Module &F,
+ASTReader::ReadNestedNameSpecifier(ModuleFile &F,
                                    const RecordData &Record, unsigned &Idx) {
   unsigned N = Record[Idx++];
   NestedNameSpecifier *NNS = 0, *Prev = 0;
@@ -5552,7 +5552,7 @@
 }
 
 NestedNameSpecifierLoc
-ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, 
+ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, 
                                       unsigned &Idx) {
   unsigned N = Record[Idx++];
   NestedNameSpecifierLocBuilder Builder;
@@ -5608,7 +5608,7 @@
 }
 
 SourceRange
-ASTReader::ReadSourceRange(Module &F, const RecordData &Record,
+ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record,
                            unsigned &Idx) {
   SourceLocation beg = ReadSourceLocation(F, Record, Idx);
   SourceLocation end = ReadSourceLocation(F, Record, Idx);
@@ -5655,7 +5655,7 @@
   return VersionTuple(Major, Minor - 1, Subminor - 1);
 }
 
-CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, 
+CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, 
                                           const RecordData &Record,
                                           unsigned &Idx) {
   CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx);
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index d242bc3..684c582 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -32,7 +32,7 @@
 namespace clang {
   class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
     ASTReader &Reader;
-    Module &F;
+    ModuleFile &F;
     llvm::BitstreamCursor &Cursor;
     const DeclID ThisDeclID;
     const unsigned RawLocation;
@@ -93,7 +93,7 @@
                                      CXXRecordDecl *DefinitionDecl,
                                      const RecordData &Record, unsigned &Idx);
   public:
-    ASTDeclReader(ASTReader &Reader, Module &F,
+    ASTDeclReader(ASTReader &Reader, ModuleFile &F,
                   llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
                   unsigned RawLocation,
                   const RecordData &Record, unsigned &Idx)
@@ -105,7 +105,7 @@
 
     void Visit(Decl *D);
 
-    void UpdateDecl(Decl *D, Module &Module,
+    void UpdateDecl(Decl *D, ModuleFile &ModuleFile,
                     const RecordData &Record);
 
     static void setNextObjCCategory(ObjCCategoryDecl *Cat,
@@ -1391,7 +1391,7 @@
 //===----------------------------------------------------------------------===//
 
 /// \brief Reads attributes from the current stream position.
-void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
+void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
                                const RecordData &Record, unsigned &Idx) {
   for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
     Attr *New = 0;
@@ -1456,7 +1456,7 @@
 
   GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
   assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
-  Module *M = I->second;
+  ModuleFile *M = I->second;
   const DeclOffset &
     DOffs =  M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
   RawLocation = DOffs.Loc;
@@ -1464,14 +1464,14 @@
 }
 
 ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
-  ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
+  ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
     = GlobalBitOffsetsMap.find(GlobalOffset);
 
   assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
   return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
 }
 
-uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
+uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
   return LocalOffset + M.GlobalBitOffset;
 }
 
@@ -1797,7 +1797,7 @@
     FileOffsetsTy &UpdateOffsets = UpdI->second;
     for (FileOffsetsTy::iterator
          I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
-      Module *F = I->first;
+      ModuleFile *F = I->first;
       uint64_t Offset = I->second;
       llvm::BitstreamCursor &Cursor = F->DeclsCursor;
       SavedStreamPosition SavedPosition(Cursor);
@@ -1832,16 +1832,16 @@
       : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
         GlobHeadCat(0), GlobTailCat(0) { }
 
-    static bool visit(Module &M, void *UserData) {
+    static bool visit(ModuleFile &M, void *UserData) {
       return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
     }
 
-    bool visit(Module &M) {
+    bool visit(ModuleFile &M) {
       if (Reader.isDeclIDFromModule(InterfaceID, M))
         return true; // We reached the module where the interface originated
                     // from. Stop traversing the imported modules.
 
-      Module::ChainedObjCCategoriesMap::iterator
+      ModuleFile::ChainedObjCCategoriesMap::iterator
         I = M.ChainedObjCCategories.find(InterfaceID);
       if (I == M.ChainedObjCCategories.end())
         return false;
@@ -1941,7 +1941,7 @@
   D->setCategoryList(Visitor.getHeadCategory());
 }
 
-void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
+void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
                                const RecordData &Record) {
   unsigned Idx = 0;
   while (Idx < Record.size()) {
@@ -1949,24 +1949,24 @@
     case UPD_CXX_SET_DEFINITIONDATA: {
       CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
       CXXRecordDecl *DefinitionDecl
-        = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
+        = Reader.ReadDeclAs<CXXRecordDecl>(ModuleFile, Record, Idx);
       assert(!RD->DefinitionData && "DefinitionData is already set!");
       InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
       break;
     }
 
     case UPD_CXX_ADDED_IMPLICIT_MEMBER:
-      cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
+      cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx));
       break;
 
     case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
       // It will be added to the template's specializations set when loaded.
-      (void)Reader.ReadDecl(Module, Record, Idx);
+      (void)Reader.ReadDecl(ModuleFile, Record, Idx);
       break;
 
     case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
       NamespaceDecl *Anon
-        = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
+        = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx);
       // Guard against these being loaded out of original order. Don't use
       // getNextNamespace(), since it tries to access the context and can't in
       // the middle of deserialization.
@@ -1981,7 +1981,7 @@
 
     case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
       cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
-          Reader.ReadSourceLocation(Module, Record, Idx));
+          Reader.ReadSourceLocation(ModuleFile, Record, Idx));
       break;
     }
   }
diff --git a/lib/Serialization/ASTReaderInternals.h b/lib/Serialization/ASTReaderInternals.h
index 99e8be5..fb6c830 100644
--- a/lib/Serialization/ASTReaderInternals.h
+++ b/lib/Serialization/ASTReaderInternals.h
@@ -26,7 +26,7 @@
   
 namespace serialization {
 
-class Module;
+class ModuleFile;
 
 namespace reader {
 
@@ -34,7 +34,7 @@
 /// in an AST file.
 class ASTDeclContextNameLookupTrait {
   ASTReader &Reader;
-  Module &F;
+  ModuleFile &F;
   
 public:
   /// \brief Pair of begin/end iterators for DeclIDs.
@@ -56,7 +56,7 @@
   typedef DeclNameKey internal_key_type;
 
   explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, 
-                                         Module &F) 
+                                         ModuleFile &F) 
     : Reader(Reader), F(F) { }
 
   static bool EqualKey(const internal_key_type& a,
@@ -84,7 +84,7 @@
 /// \brief Class that performs lookup for an identifier stored in an AST file.
 class ASTIdentifierLookupTrait {
   ASTReader &Reader;
-  Module &F;
+  ModuleFile &F;
   
   // If we know the IdentifierInfo in advance, it is here and we will
   // not build a new one. Used when deserializing information about an
@@ -98,7 +98,7 @@
   
   typedef external_key_type internal_key_type;
   
-  ASTIdentifierLookupTrait(ASTReader &Reader, Module &F,
+  ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
                            IdentifierInfo *II = 0)
     : Reader(Reader), F(F), KnownII(II) { }
   
@@ -138,7 +138,7 @@
 /// method pool stored in an AST file.
 class ASTSelectorLookupTrait {
   ASTReader &Reader;
-  Module &F;
+  ModuleFile &F;
   
 public:
   struct data_type {
@@ -150,7 +150,7 @@
   typedef Selector external_key_type;
   typedef external_key_type internal_key_type;
   
-  ASTSelectorLookupTrait(ASTReader &Reader, Module &F) 
+  ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F) 
     : Reader(Reader), F(F) { }
   
   static bool EqualKey(const internal_key_type& a,
@@ -185,7 +185,7 @@
 /// and symlinks.
 class HeaderFileInfoTrait {
   ASTReader &Reader;
-  Module &M;
+  ModuleFile &M;
   HeaderSearch *HS;
   const char *FrameworkStrings;
   const char *SearchPath;
@@ -210,7 +210,7 @@
   
   typedef HeaderFileInfo data_type;
   
-  HeaderFileInfoTrait(ASTReader &Reader, Module &M, HeaderSearch *HS,
+  HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS,
                       const char *FrameworkStrings,
                       const char *SearchPath = 0) 
   : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings), 
diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp
index cd51b06..91a6e19 100644
--- a/lib/Serialization/ASTReaderStmt.cpp
+++ b/lib/Serialization/ASTReaderStmt.cpp
@@ -25,7 +25,7 @@
     typedef ASTReader::RecordData RecordData;
     
     ASTReader &Reader;
-    Module &F;
+    ModuleFile &F;
     llvm::BitstreamCursor &DeclsCursor;
     const ASTReader::RecordData &Record;
     unsigned &Idx;
@@ -66,7 +66,7 @@
     }
 
   public:
-    ASTStmtReader(ASTReader &Reader, Module &F,
+    ASTStmtReader(ASTReader &Reader, ModuleFile &F,
                   llvm::BitstreamCursor &Cursor,
                   const ASTReader::RecordData &Record, unsigned &Idx)
       : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
@@ -1440,7 +1440,7 @@
 // ASTReader Implementation
 //===----------------------------------------------------------------------===//
 
-Stmt *ASTReader::ReadStmt(Module &F) {
+Stmt *ASTReader::ReadStmt(ModuleFile &F) {
   switch (ReadingKind) {
   case Read_Decl:
   case Read_Type:
@@ -1453,7 +1453,7 @@
   return 0;
 }
 
-Expr *ASTReader::ReadExpr(Module &F) {
+Expr *ASTReader::ReadExpr(ModuleFile &F) {
   return cast_or_null<Expr>(ReadStmt(F));
 }
 
@@ -1468,7 +1468,7 @@
 // the stack, with expressions having operands removing those operands from the
 // stack. Evaluation terminates when we see a STMT_STOP record, and
 // the single remaining expression on the stack is our result.
-Stmt *ASTReader::ReadStmtFromStream(Module &F) {
+Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
 
   ReadingKindTracker ReadingKind(Read_Stmt, *this);
   llvm::BitstreamCursor &Cursor = F.DeclsCursor;
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index cf4ea41..0acc760 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1845,7 +1845,7 @@
   }
 }
 
-void ASTWriter::WriteSubmodules(ModuleMap::Module *WritingModule) {
+void ASTWriter::WriteSubmodules(Module *WritingModule) {
   // Enter the submodule description block.
   Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
   
@@ -1871,11 +1871,11 @@
 
   // Write all of the submodules.
   unsigned SubmoduleID = 1;
-  std::queue<ModuleMap::Module *> Q;
+  std::queue<Module *> Q;
   Q.push(WritingModule);
   RecordData Record;
   while (!Q.empty()) {
-    ModuleMap::Module *Mod = Q.front();
+    Module *Mod = Q.front();
     Q.pop();
     SubmoduleIDs[Mod] = SubmoduleID++;
     
@@ -1913,7 +1913,7 @@
     
     // Sort the submodules first, so we get a predictable ordering in the AST
     // file.
-    for (llvm::StringMap<ModuleMap::Module *>::iterator 
+    for (llvm::StringMap<Module *>::iterator 
               Sub = Mod->SubModules.begin(),
            SubEnd = Mod->SubModules.end();
          Sub != SubEnd; ++Sub)
@@ -2873,7 +2873,7 @@
 
 void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
                          const std::string &OutputFile,
-                         ModuleMap::Module *WritingModule, StringRef isysroot) {
+                         Module *WritingModule, StringRef isysroot) {
   WritingAST = true;
   
   // Emit the file header.
@@ -2903,7 +2903,7 @@
 void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
                              StringRef isysroot,
                              const std::string &OutputFile, 
-                             ModuleMap::Module *WritingModule) {
+                             Module *WritingModule) {
   using namespace llvm;
 
   ASTContext &Context = SemaRef.Context;
diff --git a/lib/Serialization/GeneratePCH.cpp b/lib/Serialization/GeneratePCH.cpp
index d24424f..437598d 100644
--- a/lib/Serialization/GeneratePCH.cpp
+++ b/lib/Serialization/GeneratePCH.cpp
@@ -28,7 +28,7 @@
 
 PCHGenerator::PCHGenerator(const Preprocessor &PP,
                            StringRef OutputFile,
-                           ModuleMap::Module *Module,
+                           clang::Module *Module,
                            StringRef isysroot,
                            raw_ostream *OS)
   : PP(PP), OutputFile(OutputFile), Module(Module), 
diff --git a/lib/Serialization/Module.cpp b/lib/Serialization/Module.cpp
index fd18fb7..241b6ba 100644
--- a/lib/Serialization/Module.cpp
+++ b/lib/Serialization/Module.cpp
@@ -20,7 +20,7 @@
 using namespace serialization;
 using namespace reader;
 
-Module::Module(ModuleKind Kind)
+ModuleFile::ModuleFile(ModuleKind Kind)
   : Kind(Kind), DirectlyImported(false), SizeInBits(0), 
     LocalNumSLocEntries(0), SLocEntryBaseID(0),
     SLocEntryBaseOffset(0), SLocEntryOffsets(0),
@@ -39,7 +39,7 @@
     LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0)
 {}
 
-Module::~Module() {
+ModuleFile::~ModuleFile() {
   for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
        E = DeclContextInfos.end();
        I != E; ++I) {
@@ -68,7 +68,7 @@
   }
 }
 
-void Module::dump() {
+void ModuleFile::dump() {
   llvm::errs() << "\nModule: " << FileName << "\n";
   if (!Imports.empty()) {
     llvm::errs() << "  Imports: ";
diff --git a/lib/Serialization/ModuleManager.cpp b/lib/Serialization/ModuleManager.cpp
index c4b1f71..4470855 100644
--- a/lib/Serialization/ModuleManager.cpp
+++ b/lib/Serialization/ModuleManager.cpp
@@ -23,7 +23,7 @@
 using namespace clang;
 using namespace serialization;
 
-Module *ModuleManager::lookup(StringRef Name) {
+ModuleFile *ModuleManager::lookup(StringRef Name) {
   const FileEntry *Entry = FileMgr.getFile(Name);
   return Modules[Entry];
 }
@@ -33,21 +33,21 @@
   return InMemoryBuffers[Entry];
 }
 
-std::pair<Module *, bool>
+std::pair<ModuleFile *, bool>
 ModuleManager::addModule(StringRef FileName, ModuleKind Type, 
-                         Module *ImportedBy, std::string &ErrorStr) {
+                         ModuleFile *ImportedBy, std::string &ErrorStr) {
   const FileEntry *Entry = FileMgr.getFile(FileName);
   if (!Entry && FileName != "-") {
     ErrorStr = "file not found";
-    return std::make_pair(static_cast<Module*>(0), false);
+    return std::make_pair(static_cast<ModuleFile*>(0), false);
   }
   
   // Check whether we already loaded this module, before 
-  Module *&ModuleEntry = Modules[Entry];
+  ModuleFile *&ModuleEntry = Modules[Entry];
   bool NewModule = false;
   if (!ModuleEntry) {
     // Allocate a new module.
-    Module *New = new Module(Type);
+    ModuleFile *New = new ModuleFile(Type);
     New->FileName = FileName.str();
     Chain.push_back(New);
     NewModule = true;
@@ -69,7 +69,7 @@
         New->Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrorStr));
       
       if (!New->Buffer)
-        return std::make_pair(static_cast<Module*>(0), false);
+        return std::make_pair(static_cast<ModuleFile*>(0), false);
     }
     
     // Initialize the stream
@@ -101,16 +101,16 @@
     delete Chain[e - i - 1];
 }
 
-void ModuleManager::visit(bool (*Visitor)(Module &M, void *UserData), 
+void ModuleManager::visit(bool (*Visitor)(ModuleFile &M, void *UserData), 
                           void *UserData) {
   unsigned N = size();
   
   // Record the number of incoming edges for each module. When we
   // encounter a module with no incoming edges, push it into the queue
   // to seed the queue.
-  SmallVector<Module *, 4> Queue;
+  SmallVector<ModuleFile *, 4> Queue;
   Queue.reserve(N);
-  llvm::DenseMap<Module *, unsigned> UnusedIncomingEdges; 
+  llvm::DenseMap<ModuleFile *, unsigned> UnusedIncomingEdges; 
   for (ModuleIterator M = begin(), MEnd = end(); M != MEnd; ++M) {
     if (unsigned Size = (*M)->ImportedBy.size())
       UnusedIncomingEdges[*M] = Size;
@@ -118,10 +118,10 @@
       Queue.push_back(*M);
   }
   
-  llvm::SmallPtrSet<Module *, 4> Skipped;
+  llvm::SmallPtrSet<ModuleFile *, 4> Skipped;
   unsigned QueueStart = 0;
   while (QueueStart < Queue.size()) {
-    Module *CurrentModule = Queue[QueueStart++];
+    ModuleFile *CurrentModule = Queue[QueueStart++];
     
     // Check whether this module should be skipped.
     if (Skipped.count(CurrentModule))
@@ -132,16 +132,16 @@
       // module that the current module depends on. To indicate this
       // behavior, we mark all of the reachable modules as having N
       // incoming edges (which is impossible otherwise).
-      SmallVector<Module *, 4> Stack;
+      SmallVector<ModuleFile *, 4> Stack;
       Stack.push_back(CurrentModule);
       Skipped.insert(CurrentModule);
       while (!Stack.empty()) {
-        Module *NextModule = Stack.back();
+        ModuleFile *NextModule = Stack.back();
         Stack.pop_back();
         
         // For any module that this module depends on, push it on the
         // stack (if it hasn't already been marked as visited).
-        for (llvm::SetVector<Module *>::iterator 
+        for (llvm::SetVector<ModuleFile *>::iterator 
              M = NextModule->Imports.begin(),
              MEnd = NextModule->Imports.end();
              M != MEnd; ++M) {
@@ -154,7 +154,7 @@
     
     // For any module that this module depends on, push it on the
     // stack (if it hasn't already been marked as visited).
-    for (llvm::SetVector<Module *>::iterator M = CurrentModule->Imports.begin(),
+    for (llvm::SetVector<ModuleFile *>::iterator M = CurrentModule->Imports.begin(),
          MEnd = CurrentModule->Imports.end();
          M != MEnd; ++M) {
       
@@ -170,17 +170,17 @@
 }
 
 /// \brief Perform a depth-first visit of the current module.
-static bool visitDepthFirst(Module &M, 
-                            bool (*Visitor)(Module &M, bool Preorder, 
+static bool visitDepthFirst(ModuleFile &M, 
+                            bool (*Visitor)(ModuleFile &M, bool Preorder, 
                                             void *UserData), 
                             void *UserData,
-                            llvm::SmallPtrSet<Module *, 4> &Visited) {
+                            llvm::SmallPtrSet<ModuleFile *, 4> &Visited) {
   // Preorder visitation
   if (Visitor(M, /*Preorder=*/true, UserData))
     return true;
   
   // Visit children
-  for (llvm::SetVector<Module *>::iterator IM = M.Imports.begin(),
+  for (llvm::SetVector<ModuleFile *>::iterator IM = M.Imports.begin(),
        IMEnd = M.Imports.end();
        IM != IMEnd; ++IM) {
     if (!Visited.insert(*IM))
@@ -194,10 +194,10 @@
   return Visitor(M, /*Preorder=*/false, UserData);
 }
 
-void ModuleManager::visitDepthFirst(bool (*Visitor)(Module &M, bool Preorder, 
+void ModuleManager::visitDepthFirst(bool (*Visitor)(ModuleFile &M, bool Preorder, 
                                                     void *UserData), 
                                     void *UserData) {
-  llvm::SmallPtrSet<Module *, 4> Visited;
+  llvm::SmallPtrSet<ModuleFile *, 4> Visited;
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
     if (!Visited.insert(Chain[I]))
       continue;
@@ -211,8 +211,8 @@
 namespace llvm {
   template<>
   struct GraphTraits<ModuleManager> {
-    typedef Module NodeType;
-    typedef llvm::SetVector<Module *>::const_iterator ChildIteratorType;
+    typedef ModuleFile NodeType;
+    typedef llvm::SetVector<ModuleFile *>::const_iterator ChildIteratorType;
     typedef ModuleManager::ModuleConstIterator nodes_iterator;
     
     static ChildIteratorType child_begin(NodeType *Node) {
@@ -241,7 +241,7 @@
       return true;
     }
 
-    std::string getNodeLabel(Module *M, const ModuleManager&) {
+    std::string getNodeLabel(ModuleFile *M, const ModuleManager&) {
       return llvm::sys::path::stem(M->FileName);
     }
   };