Revert r280035 (and followups r280057, r280085), it caused PR30195

llvm-svn: 280091
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9081a64..9871f29 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -177,10 +177,6 @@
       (PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) {
     FinalPhase = phases::Preprocess;
 
-    // --precompile only runs up to precompilation.
-  } else if ((PhaseArg = DAL.getLastArg(options::OPT__precompile))) {
-    FinalPhase = phases::Precompile;
-
     // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
   } else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
              (PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
@@ -1689,14 +1685,12 @@
     if (YcArg) {
       // Add a separate precompile phase for the compile phase.
       if (FinalPhase >= phases::Compile) {
-        const types::ID HeaderInputType = types::TY_CXXHeader;
         llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PCHPL;
-        types::getCompilationPhases(HeaderInputType, PCHPL);
+        types::getCompilationPhases(types::TY_CXXHeader, PCHPL);
         Arg *PchInputArg = MakeInputArg(Args, Opts, YcArg->getValue());
 
         // Build the pipeline for the pch file.
-        Action *ClangClPch =
-            C.MakeAction<InputAction>(*PchInputArg, HeaderInputType);
+        Action *ClangClPch = C.MakeAction<InputAction>(*PchInputArg, InputType);
         for (phases::ID Phase : PCHPL)
           ClangClPch = ConstructPhaseAction(C, Args, Phase, ClangClPch);
         assert(ClangClPch);
@@ -1818,9 +1812,7 @@
     return C.MakeAction<PreprocessJobAction>(Input, OutputTy);
   }
   case phases::Precompile: {
-    types::ID OutputTy = getPrecompiledType(Input->getType());
-    assert(OutputTy != types::TY_INVALID &&
-           "Cannot precompile this input type!");
+    types::ID OutputTy = types::TY_PCH;
     if (Args.hasArg(options::OPT_fsyntax_only)) {
       // Syntax checks should not emit a PCH file
       OutputTy = types::TY_Nothing;
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 0d04e45..e3e0a61 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -3986,8 +3986,6 @@
 
     if (JA.getType() == types::TY_Nothing)
       CmdArgs.push_back("-fsyntax-only");
-    else if (JA.getType() == types::TY_ModuleFile)
-      CmdArgs.push_back("-emit-module-interface");
     else if (UsePCH)
       CmdArgs.push_back("-emit-pch");
     else
@@ -5398,26 +5396,20 @@
   // -fmodules enables the use of precompiled modules (off by default).
   // Users can pass -fno-cxx-modules to turn off modules support for
   // C++/Objective-C++ programs.
-  bool HaveClangModules = false;
+  bool HaveModules = false;
   if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) {
     bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
                                      options::OPT_fno_cxx_modules, true);
     if (AllowedInCXX || !types::isCXX(InputType)) {
       CmdArgs.push_back("-fmodules");
-      HaveClangModules = true;
+      HaveModules = true;
     }
   }
 
-  bool HaveAnyModules = HaveClangModules;
-  if (Args.hasArg(options::OPT_fmodules_ts)) {
-    CmdArgs.push_back("-fmodules-ts");
-    HaveAnyModules = true;
-  }
-
   // -fmodule-maps enables implicit reading of module map files. By default,
-  // this is enabled if we are using Clang's flavor of precompiled modules.
+  // this is enabled if we are using precompiled modules.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,
-                   options::OPT_fno_implicit_module_maps, HaveClangModules)) {
+                   options::OPT_fno_implicit_module_maps, HaveModules)) {
     CmdArgs.push_back("-fimplicit-module-maps");
   }
 
@@ -5437,10 +5429,9 @@
 
   // -fno-implicit-modules turns off implicitly compiling modules on demand.
   if (!Args.hasFlag(options::OPT_fimplicit_modules,
-                    options::OPT_fno_implicit_modules, HaveClangModules)) {
-    if (HaveAnyModules)
-      CmdArgs.push_back("-fno-implicit-modules");
-  } else if (HaveAnyModules) {
+                    options::OPT_fno_implicit_modules)) {
+    CmdArgs.push_back("-fno-implicit-modules");
+  } else if (HaveModules) {
     // -fmodule-cache-path specifies where our implicitly-built module files
     // should be written.
     SmallString<128> Path;
@@ -5464,7 +5455,7 @@
     CmdArgs.push_back(Args.MakeArgString(Path));
   }
 
-  if (HaveAnyModules) {
+  if (HaveModules) {
     // -fprebuilt-module-path specifies where to load the prebuilt module files.
     for (const Arg *A : Args.filtered(options::OPT_fprebuilt_module_path))
       CmdArgs.push_back(Args.MakeArgString(
@@ -5480,14 +5471,14 @@
   Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
 
   // -fmodule-file can be used to specify files containing precompiled modules.
-  if (HaveAnyModules)
+  if (HaveModules)
     Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file);
   else
     Args.ClaimAllArgs(options::OPT_fmodule_file);
 
   // When building modules and generating crashdumps, we need to dump a module
   // dependency VFS alongside the output.
-  if (HaveClangModules && C.isForDiagnostics()) {
+  if (HaveModules && C.isForDiagnostics()) {
     SmallString<128> VFSDir(Output.getFilename());
     llvm::sys::path::replace_extension(VFSDir, ".cache");
     // Add the cache directory as a temp so the crash diagnostics pick it up.
@@ -5498,7 +5489,7 @@
     CmdArgs.push_back(Args.MakeArgString(VFSDir));
   }
 
-  if (HaveClangModules)
+  if (HaveModules)
     Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path);
 
   // Pass through all -fmodules-ignore-macro arguments.
@@ -6039,7 +6030,7 @@
   // nice to enable this when doing a crashdump for modules as well.
   if (Args.hasFlag(options::OPT_frewrite_includes,
                    options::OPT_fno_rewrite_includes, false) ||
-      (C.isForDiagnostics() && !HaveAnyModules))
+      (C.isForDiagnostics() && !HaveModules))
     CmdArgs.push_back("-frewrite-includes");
 
   // Only allow -traditional or -traditional-cpp outside in preprocessing modes.
diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 36ac082..e6072de 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -44,14 +44,6 @@
   return getInfo(Id).PreprocessedType;
 }
 
-types::ID types::getPrecompiledType(ID Id) {
-  if (strchr(getInfo(Id).Flags, 'm'))
-    return TY_ModuleFile;
-  if (onlyPrecompileType(Id))
-    return TY_PCH;
-  return TY_INVALID;
-}
-
 const char *types::getTypeTempSuffix(ID Id, bool CLMode) {
   if (Id == TY_Object && CLMode)
     return "obj";
@@ -103,7 +95,6 @@
   case TY_ObjCHeader: case TY_PP_ObjCHeader:
   case TY_CXXHeader: case TY_PP_CXXHeader:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
-  case TY_CXXModule: case TY_PP_CXXModule:
   case TY_AST: case TY_ModuleFile:
   case TY_LLVM_IR: case TY_LLVM_BC:
     return true;
@@ -132,7 +123,6 @@
   case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias:
   case TY_CXXHeader: case TY_PP_CXXHeader:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
-  case TY_CXXModule: case TY_PP_CXXModule:
   case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE:
     return true;
   }
@@ -193,7 +183,6 @@
            .Case("ads", TY_Ada)
            .Case("asm", TY_PP_Asm)
            .Case("ast", TY_AST)
-           .Case("ccm", TY_CXXModule)
            .Case("cpp", TY_CXX)
            .Case("CPP", TY_CXX)
            .Case("c++", TY_CXX)
@@ -211,15 +200,11 @@
            .Case("FPP", TY_Fortran)
            .Case("gch", TY_PCH)
            .Case("hpp", TY_CXXHeader)
-           .Case("iim", TY_PP_CXXModule)
            .Case("lib", TY_Object)
            .Case("mii", TY_PP_ObjCXX)
            .Case("obj", TY_Object)
            .Case("pch", TY_PCH)
            .Case("pcm", TY_ModuleFile)
-           .Case("c++m", TY_CXXModule)
-           .Case("cppm", TY_CXXModule)
-           .Case("cxxm", TY_CXXModule)
            .Default(TY_INVALID);
 }
 
@@ -241,11 +226,9 @@
       P.push_back(phases::Preprocess);
     }
 
-    if (getPrecompiledType(Id) != TY_INVALID) {
+    if (onlyPrecompileType(Id)) {
       P.push_back(phases::Precompile);
-    }
-
-    if (!onlyPrecompileType(Id)) {
+    } else {
       if (!onlyAssembleType(Id)) {
         P.push_back(phases::Compile);
         P.push_back(phases::Backend);