[cfe-commits] r68450 - in /cfe/trunk: include/clang/Basic/LangOptions.h lib/Lex/Preprocessor.cpp test/Preprocessor/optimize.c tools/clang-cc/clang-cc.cpp
Anders Carlsson
andersca at mac.com
Mon Apr 6 10:37:11 PDT 2009
Author: andersca
Date: Mon Apr 6 12:37:10 2009
New Revision: 68450
URL: http://llvm.org/viewvc/llvm-project?rev=68450&view=rev
Log:
Define __OPTIMIZE__ and __OPTIMIZE_SIZE__ if the -O[12] and -Os flags are passed to the compiler.
Added:
cfe/trunk/test/Preprocessor/optimize.c
Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=68450&r1=68449&r2=68450&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon Apr 6 12:37:10 2009
@@ -65,6 +65,9 @@
unsigned HeinousExtensions : 1; // Extensions that we really don't like and
// may be ripped out at any time.
+ unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
+ unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
+ // defined.
private:
unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
// this enum as unsigned because MSVC insists on making enums
@@ -100,6 +103,9 @@
OverflowChecking = 0;
InstantiationDepth = 99;
+
+ Optimize = 0;
+ OptimizeSize = 0;
}
GCMode getGCMode() const { return (GCMode) GC; }
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=68450&r1=68449&r2=68450&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Apr 6 12:37:10 2009
@@ -547,6 +547,11 @@
DefineBuiltinMacro(Buf, "__int64=__INT64_TYPE__");
}
+ if (PP.getLangOptions().Optimize)
+ DefineBuiltinMacro(Buf, "__OPTIMIZE__=1");
+ if (PP.getLangOptions().OptimizeSize)
+ DefineBuiltinMacro(Buf, "__OPTIMIZE_SIZE__=1");
+
// Initialize target-specific preprocessor defines.
const TargetInfo &TI = PP.getTargetInfo();
Added: cfe/trunk/test/Preprocessor/optimize.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/optimize.c?rev=68450&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/optimize.c (added)
+++ cfe/trunk/test/Preprocessor/optimize.c Mon Apr 6 12:37:10 2009
@@ -0,0 +1,29 @@
+// RUN: clang-cc -Eonly optimize.c -DOPT_O2 -O2 -verify &&
+#ifdef OPT_O2
+ #ifndef __OPTIMIZE__
+ #error "__OPTIMIZE__ not defined"
+ #endif
+ #ifdef __OPTIMIZE_SIZE
+ #error "__OPTIMIZE_SIZE__ defined"
+ #endif
+#endif
+
+// RUN: clang-cc -Eonly optimize.c -DOPT_O0 -O0 -verify &&
+#ifdef OPT_O0
+ #ifdef __OPTIMIZE__
+ #error "__OPTIMIZE__ defined"
+ #endif
+ #ifdef __OPTIMIZE_SIZE
+ #error "__OPTIMIZE_SIZE__ defined"
+ #endif
+#endif
+
+// RUN: clang-cc -Eonly optimize.c -DOPT_OS -Os -verify
+#ifdef OPT_OS
+ #ifndef __OPTIMIZE__
+ #error "__OPTIMIZE__ not defined"
+ #endif
+ #ifndef __OPTIMIZE_SIZE
+ #error "__OPTIMIZE_SIZE__ not defined"
+ #endif
+#endif
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68450&r1=68449&r2=68450&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon Apr 6 12:37:10 2009
@@ -601,6 +601,33 @@
llvm::cl::desc("Maximum depth of recursive template "
"instantiation"));
+
+static llvm::cl::opt<bool>
+OptSize("Os", llvm::cl::desc("Optimize for size"));
+
+static llvm::cl::opt<bool>
+NoCommon("fno-common",
+ llvm::cl::desc("Compile common globals like normal definitions"),
+ llvm::cl::ValueDisallowed);
+
+
+// It might be nice to add bounds to the CommandLine library directly.
+struct OptLevelParser : public llvm::cl::parser<unsigned> {
+ bool parse(llvm::cl::Option &O, const char *ArgName,
+ const std::string &Arg, unsigned &Val) {
+ if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
+ return true;
+ // FIXME: Support -O4.
+ if (Val > 3)
+ return O.error(": '" + Arg + "' invalid optimization level!");
+ return false;
+ }
+};
+static llvm::cl::opt<unsigned, false, OptLevelParser>
+OptLevel("O", llvm::cl::Prefix,
+ llvm::cl::desc("Optimization level"),
+ llvm::cl::init(0));
+
// FIXME: add:
// -fdollars-in-identifiers
static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
@@ -746,6 +773,13 @@
if (EmitAllDecls)
Options.EmitAllDecls = 1;
+
+ if (OptSize)
+ Options.OptimizeSize = 1;
+
+ // -Os implies -O2
+ if (Options.OptimizeSize || OptLevel)
+ Options.Optimize = 1;
}
static llvm::cl::opt<bool>
@@ -1308,31 +1342,6 @@
GenerateDebugInfo("g",
llvm::cl::desc("Generate source level debug information"));
-static llvm::cl::opt<bool>
-OptSize("Os", llvm::cl::desc("Optimize for size"));
-
-static llvm::cl::opt<bool>
-NoCommon("fno-common",
- llvm::cl::desc("Compile common globals like normal definitions"),
- llvm::cl::ValueDisallowed);
-
-// It might be nice to add bounds to the CommandLine library directly.
-struct OptLevelParser : public llvm::cl::parser<unsigned> {
- bool parse(llvm::cl::Option &O, const char *ArgName,
- const std::string &Arg, unsigned &Val) {
- if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
- return true;
- // FIXME: Support -O4.
- if (Val > 3)
- return O.error(": '" + Arg + "' invalid optimization level!");
- return false;
- }
-};
-static llvm::cl::opt<unsigned, false, OptLevelParser>
-OptLevel("O", llvm::cl::Prefix,
- llvm::cl::desc("Optimization level"),
- llvm::cl::init(0));
-
static llvm::cl::opt<std::string>
TargetCPU("mcpu",
llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
More information about the cfe-commits
mailing list