diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index b249ce90779b..c2a66bdf1d6e 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_ #include "clang/Basic/LangOptions.h" +#include "clang/Frontend/CompileOptions.h" #include "clang/Frontend/DiagnosticOptions.h" #include "clang/Frontend/HeaderSearchOptions.h" #include "clang/Frontend/PreprocessorOptions.h" @@ -26,9 +27,8 @@ namespace clang { /// compiler, including data such as the include paths, the code generation /// options, the warning flags, and so on. class CompilerInvocation { - /// The location for the output file. This is optional only for compiler - /// invocations which have no output. - std::string OutputFile; + /// Options controlling IRgen and the backend. + CompileOptions CompileOpts; /// Options controlling the diagnostic engine. DiagnosticOptions DiagOpts; @@ -42,15 +42,36 @@ class CompilerInvocation { /// Options controlling the preprocessor (aside from #include handling). PreprocessorOptions PreprocessorOpts; + /// The location for the output file. This is optional only for compiler + /// invocations which have no output. + std::string OutputFile; + /// Set of target-specific code generation features to enable/disable. llvm::StringMap TargetFeatures; public: CompilerInvocation() {} + /// @name Invidual Options + /// @{ + std::string &getOutputFile() { return OutputFile; } const std::string &getOutputFile() const { return OutputFile; } + llvm::StringMap &getTargetFeatures() { return TargetFeatures; } + const llvm::StringMap &getTargetFeatures() const { + return TargetFeatures; + } + + /// @} + /// @name Option Subgroups + /// @{ + + CompileOptions &getCompileOpts() { return CompileOpts; } + const CompileOptions &getCompileOpts() const { + return CompileOpts; + } + DiagnosticOptions &getDiagnosticOpts() { return DiagOpts; } const DiagnosticOptions &getDiagnosticOpts() const { return DiagOpts; } @@ -67,10 +88,7 @@ public: return PreprocessorOpts; } - llvm::StringMap &getTargetFeatures() { return TargetFeatures; } - const llvm::StringMap &getTargetFeatures() const { - return TargetFeatures; - } + /// @} }; } // end namespace clang diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index b80d5f87a38e..ae1b32f71f57 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -1330,7 +1330,6 @@ static void InitializeCompileOptions(CompileOptions &Opts, Opts.Inlining = CompileOptions::OnlyAlwaysInlining; } - // FIXME: There are llvm-gcc options to control these selectively. Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize); Opts.SimplifyLibCalls = !LangOpts.NoBuiltin; @@ -1356,7 +1355,7 @@ static void InitializeCompileOptions(CompileOptions &Opts, Opts.DisableRedZone = DisableRedZone; Opts.NoImplicitFloat = NoImplicitFloat; - + Opts.MergeAllConstants = !NoMergeConstants; } @@ -1692,11 +1691,9 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, OS.reset(ComputeOutFile(CompOpts, InFile, "bc", true, OutPath)); } - CompileOptions Opts; - InitializeCompileOptions(Opts, PP.getLangOptions(), - CompOpts.getTargetFeatures()); return CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(), - Opts, InFile, OS.get(), Context); + CompOpts.getCompileOpts(), InFile, OS.get(), + Context); } case RewriteObjC: @@ -2177,10 +2174,10 @@ static void ConstructCompilerInvocation(CompilerInvocation &Opts, // Compute the feature set, which may effect the language. ComputeFeatureMap(Target, Opts.getTargetFeatures()); - + // Initialize language options. LangOptions LangInfo; - + // FIXME: These aren't used during operations on ASTs. Split onto a separate // code path to make this obvious. if (LK != langkind_ast) { @@ -2194,6 +2191,10 @@ static void ConstructCompilerInvocation(CompilerInvocation &Opts, // Initialize the other preprocessor options. InitializePreprocessorOptions(Opts.getPreprocessorOpts()); + + // Initialize backend options. + InitializeCompileOptions(Opts.getCompileOpts(), Opts.getLangOpts(), + Opts.getTargetFeatures()); } int main(int argc, char **argv) {