Move CompileOptions -> CodeGenOptions, and sink it into the CodeGen library.
This resolves the layering violation where CodeGen depended on Frontend.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86998 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 06cd05c..5d8e5c2 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -19,7 +19,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/Frontend/CompileOptions.h"
+#include "clang/CodeGen/CodeGenOptions.h"
 #include "llvm/Attributes.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Target/TargetData.h"
@@ -441,11 +441,11 @@
       RetAttrs |= llvm::Attribute::NoAlias;
   }
 
-  if (CompileOpts.OptimizeSize)
+  if (CodeGenOpts.OptimizeSize)
     FuncAttrs |= llvm::Attribute::OptimizeForSize;
-  if (CompileOpts.DisableRedZone)
+  if (CodeGenOpts.DisableRedZone)
     FuncAttrs |= llvm::Attribute::NoRedZone;
-  if (CompileOpts.NoImplicitFloat)
+  if (CodeGenOpts.NoImplicitFloat)
     FuncAttrs |= llvm::Attribute::NoImplicitFloat;
 
   if (Features.getStackProtectorMode() == LangOptions::SSPOn)
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 5926565..dd33ca3 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -21,7 +21,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/Version.h"
-#include "clang/Frontend/CompileOptions.h"
+#include "clang/CodeGen/CodeGenOptions.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instructions.h"
@@ -1010,8 +1010,8 @@
   // Do not emit variable debug information while generating optimized code.
   // The llvm optimizer and code generator are not yet ready to support
   // optimized code debugging.
-  const CompileOptions &CO = M->getCompileOpts();
-  if (CO.OptimizationLevel)
+  const CodeGenOptions &CGO = M->getCodeGenOpts();
+  if (CGO.OptimizationLevel)
     return;
 
   llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
@@ -1185,8 +1185,8 @@
   // Do not emit variable debug information while generating optimized code.
   // The llvm optimizer and code generator are not yet ready to support
   // optimized code debugging.
-  const CompileOptions &CO = M->getCompileOpts();
-  if (CO.OptimizationLevel || Builder.GetInsertBlock() == 0)
+  const CodeGenOptions &CGO = M->getCodeGenOpts();
+  if (CGO.OptimizationLevel || Builder.GetInsertBlock() == 0)
     return;
 
   uint64_t XOffset = 0;
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 2a28ef0..1d2040b 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -19,7 +19,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
-#include "clang/Frontend/CompileOptions.h"
+#include "clang/CodeGen/CodeGenOptions.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/Target/TargetData.h"
@@ -320,7 +320,7 @@
       
       // All constant structs and arrays should be global if
       // their initializer is constant and if the element type is POD.
-      if (CGM.getCompileOpts().MergeAllConstants) {
+      if (CGM.getCodeGenOpts().MergeAllConstants) {
         if (Ty.isConstant(getContext())
             && (Ty->isArrayType() || Ty->isRecordType())
             && (D.getInit() 
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index ff193fb..45637af 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -17,7 +17,7 @@
 #include "CGCall.h"
 #include "CGObjCRuntime.h"
 #include "Mangle.h"
-#include "clang/Frontend/CompileOptions.h"
+#include "clang/CodeGen/CodeGenOptions.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclCXX.h"
@@ -35,11 +35,11 @@
 using namespace CodeGen;
 
 
-CodeGenModule::CodeGenModule(ASTContext &C, const CompileOptions &compileOpts,
+CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
                              llvm::Module &M, const llvm::TargetData &TD,
                              Diagnostic &diags)
   : BlockModule(C, M, TD, Types, *this), Context(C),
-    Features(C.getLangOptions()), CompileOpts(compileOpts), TheModule(M),
+    Features(C.getLangOptions()), CodeGenOpts(CGO), TheModule(M),
     TheTargetData(TD), Diags(diags), Types(C, M, TD), MangleCtx(C), 
     VtableInfo(*this), Runtime(0),
     MemCpyFn(0), MemMoveFn(0), MemSetFn(0), CFConstantStringClassRef(0),
@@ -55,7 +55,7 @@
     Runtime = CreateMacObjCRuntime(*this);
 
   // If debug info generation is enabled, create the CGDebugInfo object.
-  DebugInfo = CompileOpts.DebugInfo ? new CGDebugInfo(this) : 0;
+  DebugInfo = CodeGenOpts.DebugInfo ? new CGDebugInfo(this) : 0;
 }
 
 CodeGenModule::~CodeGenModule() {
@@ -1082,7 +1082,7 @@
       GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
   } else if (Linkage == GVA_TemplateInstantiation)
     GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);   
-  else if (!CompileOpts.NoCommon &&
+  else if (!CodeGenOpts.NoCommon &&
            !D->hasExternalStorage() && !D->getInit() &&
            !D->getAttr<SectionAttr>()) {
     GV->setLinkage(llvm::GlobalVariable::CommonLinkage);
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index 990706d..cf7a9d6 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -61,7 +61,7 @@
   class ValueDecl;
   class VarDecl;
   class LangOptions;
-  class CompileOptions;
+  class CodeGenOptions;
   class Diagnostic;
   class AnnotateAttr;
   class CXXDestructorDecl;
@@ -122,7 +122,7 @@
 
   ASTContext &Context;
   const LangOptions &Features;
-  const CompileOptions &CompileOpts;
+  const CodeGenOptions &CodeGenOpts;
   llvm::Module &TheModule;
   const llvm::TargetData &TheTargetData;
   Diagnostic &Diags;
@@ -201,7 +201,7 @@
 
   llvm::LLVMContext &VMContext;
 public:
-  CodeGenModule(ASTContext &C, const CompileOptions &CompileOpts,
+  CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
                 llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
 
   ~CodeGenModule();
@@ -222,7 +222,7 @@
 
   CGDebugInfo *getDebugInfo() { return DebugInfo; }
   ASTContext &getContext() const { return Context; }
-  const CompileOptions &getCompileOpts() const { return CompileOpts; }
+  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
   const LangOptions &getLangOptions() const { return Features; }
   llvm::Module &getModule() const { return TheModule; }
   CodeGenTypes &getTypes() { return Types; }
diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp
index c8f686a..1d8f31d 100644
--- a/lib/CodeGen/ModuleBuilder.cpp
+++ b/lib/CodeGen/ModuleBuilder.cpp
@@ -13,7 +13,7 @@
 
 #include "clang/CodeGen/ModuleBuilder.h"
 #include "CodeGenModule.h"
-#include "clang/Frontend/CompileOptions.h"
+#include "clang/CodeGen/CodeGenOptions.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
@@ -32,14 +32,14 @@
     Diagnostic &Diags;
     llvm::OwningPtr<const llvm::TargetData> TD;
     ASTContext *Ctx;
-    const CompileOptions CompileOpts;  // Intentionally copied in.
+    const CodeGenOptions CodeGenOpts;  // Intentionally copied in.
   protected:
     llvm::OwningPtr<llvm::Module> M;
     llvm::OwningPtr<CodeGen::CodeGenModule> Builder;
   public:
     CodeGeneratorImpl(Diagnostic &diags, const std::string& ModuleName,
-                      const CompileOptions &CO, llvm::LLVMContext& C)
-      : Diags(diags), CompileOpts(CO), M(new llvm::Module(ModuleName, C)) {}
+                      const CodeGenOptions &CGO, llvm::LLVMContext& C)
+      : Diags(diags), CodeGenOpts(CGO), M(new llvm::Module(ModuleName, C)) {}
 
     virtual ~CodeGeneratorImpl() {}
 
@@ -57,7 +57,7 @@
       M->setTargetTriple(Ctx->Target.getTriple().getTriple());
       M->setDataLayout(Ctx->Target.getTargetDescription());
       TD.reset(new llvm::TargetData(Ctx->Target.getTargetDescription()));
-      Builder.reset(new CodeGen::CodeGenModule(Context, CompileOpts,
+      Builder.reset(new CodeGen::CodeGenModule(Context, CodeGenOpts,
                                                *M, *TD, Diags));
     }
 
@@ -96,7 +96,7 @@
 
 CodeGenerator *clang::CreateLLVMCodeGen(Diagnostic &Diags,
                                         const std::string& ModuleName,
-                                        const CompileOptions &CO,
+                                        const CodeGenOptions &CGO,
                                         llvm::LLVMContext& C) {
-  return new CodeGeneratorImpl(Diags, ModuleName, CO, C);
+  return new CodeGeneratorImpl(Diags, ModuleName, CGO, C);
 }
diff --git a/lib/Frontend/Backend.cpp b/lib/Frontend/Backend.cpp
index af6dbaf..23d59cf 100644
--- a/lib/Frontend/Backend.cpp
+++ b/lib/Frontend/Backend.cpp
@@ -9,7 +9,7 @@
 
 #include "clang/Frontend/ASTConsumers.h"
 #include "clang/CodeGen/ModuleBuilder.h"
-#include "clang/Frontend/CompileOptions.h"
+#include "clang/CodeGen/CodeGenOptions.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclGroup.h"
@@ -40,7 +40,7 @@
 namespace {
   class VISIBILITY_HIDDEN BackendConsumer : public ASTConsumer {
     BackendAction Action;
-    CompileOptions CompileOpts;
+    CodeGenOptions CodeGenOpts;
     llvm::raw_ostream *AsmOutStream;
     llvm::formatted_raw_ostream FormattedOutStream;
     ASTContext *Context;
@@ -75,11 +75,11 @@
 
   public:
     BackendConsumer(BackendAction action, Diagnostic &Diags,
-                    const LangOptions &langopts, const CompileOptions &compopts,
+                    const LangOptions &langopts, const CodeGenOptions &compopts,
                     const std::string &infile, llvm::raw_ostream* OS,
                     LLVMContext& C) :
       Action(action),
-      CompileOpts(compopts),
+      CodeGenOpts(compopts),
       AsmOutStream(OS),
       LLVMIRGeneration("LLVM IR Generation Time"),
       CodeGenerationTime("Code Generation Time"),
@@ -92,7 +92,7 @@
                                      formatted_raw_ostream::PRESERVE_STREAM);
 
       // Enable -time-passes if -ftime-report is enabled.
-      llvm::TimePassesIsEnabled = CompileOpts.TimePasses;
+      llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses;
     }
 
     ~BackendConsumer() {
@@ -106,7 +106,7 @@
     virtual void Initialize(ASTContext &Ctx) {
       Context = &Ctx;
 
-      if (CompileOpts.TimePasses)
+      if (CodeGenOpts.TimePasses)
         LLVMIRGeneration.startTimer();
 
       Gen->Initialize(Ctx);
@@ -115,7 +115,7 @@
       ModuleProvider = new ExistingModuleProvider(TheModule);
       TheTargetData = new llvm::TargetData(Ctx.Target.getTargetDescription());
 
-      if (CompileOpts.TimePasses)
+      if (CodeGenOpts.TimePasses)
         LLVMIRGeneration.stopTimer();
     }
 
@@ -124,24 +124,24 @@
                                      Context->getSourceManager(),
                                      "LLVM IR generation of declaration");
 
-      if (CompileOpts.TimePasses)
+      if (CodeGenOpts.TimePasses)
         LLVMIRGeneration.startTimer();
 
       Gen->HandleTopLevelDecl(D);
 
-      if (CompileOpts.TimePasses)
+      if (CodeGenOpts.TimePasses)
         LLVMIRGeneration.stopTimer();
     }
 
     virtual void HandleTranslationUnit(ASTContext &C) {
       {
         PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
-        if (CompileOpts.TimePasses)
+        if (CodeGenOpts.TimePasses)
           LLVMIRGeneration.startTimer();
 
         Gen->HandleTranslationUnit(C);
 
-        if (CompileOpts.TimePasses)
+        if (CodeGenOpts.TimePasses)
           LLVMIRGeneration.stopTimer();
       }
 
@@ -202,7 +202,7 @@
   } else if (Action == Backend_EmitLL) {
     getPerModulePasses()->add(createPrintModulePass(&FormattedOutStream));
   } else {
-    bool Fast = CompileOpts.OptimizationLevel == 0;
+    bool Fast = CodeGenOpts.OptimizationLevel == 0;
 
     // Create the TargetMachine for generating code.
     std::string Triple = TheModule->getTargetTriple();
@@ -213,12 +213,12 @@
     }
 
     std::string FeaturesStr;
-    if (CompileOpts.CPU.size() || CompileOpts.Features.size()) {
+    if (CodeGenOpts.CPU.size() || CodeGenOpts.Features.size()) {
       SubtargetFeatures Features;
-      Features.setCPU(CompileOpts.CPU);
+      Features.setCPU(CodeGenOpts.CPU);
       for (std::vector<std::string>::iterator
-             it = CompileOpts.Features.begin(),
-             ie = CompileOpts.Features.end(); it != ie; ++it)
+             it = CodeGenOpts.Features.begin(),
+             ie = CodeGenOpts.Features.end(); it != ie; ++it)
         Features.AddFeature(*it);
       FeaturesStr = Features.getString();
     }
@@ -237,7 +237,7 @@
     FunctionPassManager *PM = getCodeGenPasses();
     CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
 
-    switch (CompileOpts.OptimizationLevel) {
+    switch (CodeGenOpts.OptimizationLevel) {
     default: break;
     case 0: OptLevel = CodeGenOpt::None; break;
     case 3: OptLevel = CodeGenOpt::Aggressive; break;
@@ -266,18 +266,18 @@
 }
 
 void BackendConsumer::CreatePasses() {
-  unsigned OptLevel = CompileOpts.OptimizationLevel;
-  CompileOptions::InliningMethod Inlining = CompileOpts.Inlining;
+  unsigned OptLevel = CodeGenOpts.OptimizationLevel;
+  CodeGenOptions::InliningMethod Inlining = CodeGenOpts.Inlining;
 
   // Handle disabling of LLVM optimization, where we want to preserve the
   // internal module before any optimization.
-  if (CompileOpts.DisableLLVMOpts) {
+  if (CodeGenOpts.DisableLLVMOpts) {
     OptLevel = 0;
-    Inlining = CompileOpts.NoInlining;
+    Inlining = CodeGenOpts.NoInlining;
   }
 
   // In -O0 if checking is disabled, we don't even have per-function passes.
-  if (CompileOpts.VerifyModule)
+  if (CodeGenOpts.VerifyModule)
     getPerFunctionPasses()->add(createVerifierPass());
 
   // Assume that standard function passes aren't run for -O0.
@@ -286,24 +286,24 @@
 
   llvm::Pass *InliningPass = 0;
   switch (Inlining) {
-  case CompileOptions::NoInlining: break;
-  case CompileOptions::NormalInlining: {
+  case CodeGenOptions::NoInlining: break;
+  case CodeGenOptions::NormalInlining: {
     // Inline small functions
-    unsigned Threshold = (CompileOpts.OptimizeSize || OptLevel < 3) ? 50 : 200;
+    unsigned Threshold = (CodeGenOpts.OptimizeSize || OptLevel < 3) ? 50 : 200;
     InliningPass = createFunctionInliningPass(Threshold);
     break;
   }
-  case CompileOptions::OnlyAlwaysInlining:
+  case CodeGenOptions::OnlyAlwaysInlining:
     InliningPass = createAlwaysInlinerPass();         // Respect always_inline
     break;
   }
 
   // For now we always create per module passes.
   PassManager *PM = getPerModulePasses();
-  llvm::createStandardModulePasses(PM, OptLevel, CompileOpts.OptimizeSize,
-                                   CompileOpts.UnitAtATime,
-                                   CompileOpts.UnrollLoops,
-                                   CompileOpts.SimplifyLibCalls,
+  llvm::createStandardModulePasses(PM, OptLevel, CodeGenOpts.OptimizeSize,
+                                   CodeGenOpts.UnitAtATime,
+                                   CodeGenOpts.UnrollLoops,
+                                   CodeGenOpts.SimplifyLibCalls,
                                    /*HaveExceptions=*/true,
                                    InliningPass);
 }
@@ -315,7 +315,7 @@
   if (!TheModule || !TheTargetData)
     return;
 
-  TimeRegion Region(CompileOpts.TimePasses ? &CodeGenerationTime : 0);
+  TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime : 0);
 
   // Make sure IR generation is happy with the module. This is
   // released by the module provider.
@@ -370,10 +370,10 @@
 ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,
                                           Diagnostic &Diags,
                                           const LangOptions &LangOpts,
-                                          const CompileOptions &CompileOpts,
+                                          const CodeGenOptions &CodeGenOpts,
                                           const std::string& InFile,
                                           llvm::raw_ostream* OS,
                                           LLVMContext& C) {
-  return new BackendConsumer(Action, Diags, LangOpts, CompileOpts,
+  return new BackendConsumer(Action, Diags, LangOpts, CodeGenOpts,
                              InFile, OS, C);
 }