Fronted: Kill overly specialized RecordLayoutDumper, just make -dump-record-layouts a bit that Sema honors.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100747 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index fdf69d0..1dfc7a1 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -98,8 +98,8 @@
   unsigned ElideConstructors : 1; // Whether C++ copy constructors should be
                                   // elided if possible.
   unsigned CatchUndefined    : 1; // Generate code to check for undefined ops.
-  unsigned DumpVtableLayouts : 1; // Dump the layouts of all the emitted 
-                                  // vtables.
+  unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records.
+  unsigned DumpVtableLayouts : 1; /// Dump the layouts of emitted vtables.
 private:
   unsigned GC : 2;                // Objective-C Garbage Collection modes.  We
                                   // declare this enum as unsigned because MSVC
@@ -169,6 +169,7 @@
     CharIsSigned = 1;
     ShortWChar = 0;
     CatchUndefined = 0;
+    DumpRecordLayouts = 0;
     DumpVtableLayouts = 0;
   }
 
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 93cf495..3d73015 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -285,8 +285,6 @@
   HelpText<"Build ASTs and view them with GraphViz">;
 def print_decl_contexts : Flag<"-print-decl-contexts">,
   HelpText<"Print DeclContexts and their Decls">;
-def dump_record_layouts : Flag<"-dump-record-layouts">,
-  HelpText<"Dump record layout information">;
 def emit_pth : Flag<"-emit-pth">,
   HelpText<"Generate pre-tokenized header file">;
 def emit_pch : Flag<"-emit-pch">,
@@ -317,6 +315,9 @@
 def ftime_report : Flag<"-ftime-report">,
   HelpText<"Print the amount of time each phase of compilation takes">;
 
+def dump_record_layouts : Flag<"-dump-record-layouts">,
+  HelpText<"Dump record layout information">;
+
 //===----------------------------------------------------------------------===//
 // Language Options
 //===----------------------------------------------------------------------===//
diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h
index b5b09f5..9163a20 100644
--- a/include/clang/Frontend/ASTConsumers.h
+++ b/include/clang/Frontend/ASTConsumers.h
@@ -57,10 +57,6 @@
 // to stderr; this is intended for debugging.
 ASTConsumer *CreateDeclContextPrinter();
 
-// RecordLayout dumper: prints out the record layout information for all records
-// in the translation unit; this is intended for debugging.
-ASTConsumer *CreateRecordLayoutDumper();
-
 // ObjC rewriter: attempts tp rewrite ObjC constructs into pure C code.
 // This is considered experimental, and only works with Apple's ObjC runtime.
 ASTConsumer *CreateObjCRewriter(const std::string &InFile,
diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h
index a7b6aa7..8c9ebca 100644
--- a/include/clang/Frontend/FrontendActions.h
+++ b/include/clang/Frontend/FrontendActions.h
@@ -73,12 +73,6 @@
                                          llvm::StringRef InFile);
 };
 
-class DumpRecordAction : public ASTFrontendAction {
-protected:
-  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
-                                         llvm::StringRef InFile);
-};
-
 class FixItAction : public ASTFrontendAction {
 private:
   llvm::OwningPtr<FixItRewriter> Rewriter;
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index ee3811a..7b4df1f 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -24,7 +24,6 @@
     ASTPrintXML,            ///< Parse ASTs and print them in XML.
     ASTView,                ///< Parse ASTs and view them in Graphviz.
     DumpRawTokens,          ///< Dump out raw tokens.
-    DumpRecordLayouts,      ///< Dump record layout information.
     DumpTokens,             ///< Dump out preprocessed tokens.
     EmitAssembly,           ///< Emit a .s file.
     EmitBC,                 ///< Emit a .bc file.
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp
index 9186e45..b53a80e 100644
--- a/lib/Frontend/ASTConsumers.cpp
+++ b/lib/Frontend/ASTConsumers.cpp
@@ -436,38 +436,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-/// RecordLayoutDumper - C++ Record Layout Dumping.
-namespace {
-class RecordLayoutDumper : public ASTConsumer {
-public:
-  RecordLayoutDumper() {}
-
-  void HandleTranslationUnit(ASTContext &C) {
-    for (ASTContext::type_iterator I = C.types_begin(), E = C.types_end();
-         I != E; ++I) {
-      const RecordType *RT = dyn_cast<RecordType>(*I);
-      if (!RT)
-        continue;
-
-      const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
-      if (!RD || RD->isImplicit() || RD->isDependentType() ||
-          RD->isInvalidDecl() || !RD->getDefinition())
-        continue;
-
-      // FIXME: Do we really need to hard code this?
-      if (RD->getQualifiedNameAsString() == "__va_list_tag")
-        continue;
-
-      C.DumpRecordLayout(RD, llvm::errs());
-   }
-  }
-};
-} // end anonymous namespace
-ASTConsumer *clang::CreateRecordLayoutDumper() {
-  return new RecordLayoutDumper();
-}
-
-//===----------------------------------------------------------------------===//
 /// InheritanceViewer - C++ Inheritance Visualization
 
 namespace {
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 8aaef80..0ab70a9 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -283,7 +283,6 @@
   case frontend::ASTPrintXML:            return "-ast-print-xml";
   case frontend::ASTView:                return "-ast-view";
   case frontend::DumpRawTokens:          return "-dump-raw-tokens";
-  case frontend::DumpRecordLayouts:      return "-dump-record-layouts";
   case frontend::DumpTokens:             return "-dump-tokens";
   case frontend::EmitAssembly:           return "-S";
   case frontend::EmitBC:                 return "-emit-llvm-bc";
@@ -865,8 +864,6 @@
       Opts.ProgramAction = frontend::ASTView; break;
     case OPT_dump_raw_tokens:
       Opts.ProgramAction = frontend::DumpRawTokens; break;
-    case OPT_dump_record_layouts:
-      Opts.ProgramAction = frontend::DumpRecordLayouts; break;
     case OPT_dump_tokens:
       Opts.ProgramAction = frontend::DumpTokens; break;
     case OPT_S:
@@ -1208,6 +1205,7 @@
   Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
   Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
   Opts.Static = Args.hasArg(OPT_static_define);
+  Opts.DumpRecordLayouts = Args.hasArg(OPT_dump_record_layouts);
   Opts.DumpVtableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
   Opts.OptimizeSize = 0;
 
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index 87badc7..6d7c6a8 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -74,11 +74,6 @@
   return CreateDeclContextPrinter();
 }
 
-ASTConsumer *DumpRecordAction::CreateASTConsumer(CompilerInstance &CI,
-                                                 llvm::StringRef InFile) {
-  return CreateRecordLayoutDumper();
-}
-
 ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI,
                                                   llvm::StringRef InFile) {
   const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index 7cd3989..f620927 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -24,6 +24,26 @@
 
 using namespace clang;
 
+static void DumpRecordLayouts(ASTContext &C) {
+  for (ASTContext::type_iterator I = C.types_begin(), E = C.types_end();
+       I != E; ++I) {
+    const RecordType *RT = dyn_cast<RecordType>(*I);
+    if (!RT)
+      continue;
+
+    const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
+    if (!RD || RD->isImplicit() || RD->isDependentType() ||
+        RD->isInvalidDecl() || !RD->getDefinition())
+      continue;
+
+    // FIXME: Do we really need to hard code this?
+    if (RD->getQualifiedNameAsString() == "__va_list_tag")
+      continue;
+
+    C.DumpRecordLayout(RD, llvm::errs());
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // Public interface to the file
 //===----------------------------------------------------------------------===//
@@ -82,6 +102,10 @@
         E = S.WeakTopLevelDecls().end(); I != E; ++I)
     Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
 
+  // Dump record layouts, if requested.
+  if (PP.getLangOptions().DumpRecordLayouts)
+    DumpRecordLayouts(Ctx);
+
   Consumer->HandleTranslationUnit(Ctx);
 
   if (ExternalSemaSource *ESS =
diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp
index d329c52..e9663f4 100644
--- a/tools/driver/cc1_main.cpp
+++ b/tools/driver/cc1_main.cpp
@@ -64,7 +64,6 @@
   case ASTPrintXML:            return new ASTPrintXMLAction();
   case ASTView:                return new ASTViewAction();
   case DumpRawTokens:          return new DumpRawTokensAction();
-  case DumpRecordLayouts:      return new DumpRecordAction();
   case DumpTokens:             return new DumpTokensAction();
   case EmitAssembly:           return new EmitAssemblyAction();
   case EmitBC:                 return new EmitBCAction();