[cfe-commits] r89464 - in /cfe/trunk: include/clang/Driver/CC1Options.td lib/Driver/CC1Options.cpp lib/Frontend/CompilerInvocation.cpp
Daniel Dunbar
daniel at zuster.org
Fri Nov 20 09:23:30 PST 2009
Author: ddunbar
Date: Fri Nov 20 11:23:30 2009
New Revision: 89464
URL: http://llvm.org/viewvc/llvm-project?rev=89464&view=rev
Log:
Add clang -cc1 parsing of CodeGenOptions.
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Driver/CC1Options.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=89464&r1=89463&r2=89464&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Nov 20 11:23:30 2009
@@ -24,3 +24,19 @@
HelpText<"Target specific attributes">;
def triple : Separate<"-triple">,
HelpText<"Specify target triple (e.g. i686-apple-darwin9)">;
+
+// CodeGen Options
+
+def disable_llvm_optzns : Flag<"-disable-llvm-optzns">,
+ HelpText<"Don't run LLVM optimization passes">;
+def disable_red_zone : Flag<"-disable-red-zone">,
+ HelpText<"Do not emit code that uses the red zone.">;
+def g : Flag<"-g">, HelpText<"Generate source level debug information">;
+def fno_common : Flag<"-fno-common">,
+ HelpText<"Compile common globals like normal definitions">;
+def no_implicit_float : Flag<"-no-implicit-float">,
+ HelpText<"Don't generate implicit floating point instructions (x86-only)">;
+def fno_merge_all_constants : Flag<"-fno-merge-all-constants">,
+ HelpText<"Disallow merging of constants.">;
+def O : Joined<"-O">, HelpText<"Optimization level">;
+def Os : Flag<"-Os">, HelpText<"Optimize for size">;
Modified: cfe/trunk/lib/Driver/CC1Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CC1Options.cpp?rev=89464&r1=89463&r2=89464&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/CC1Options.cpp (original)
+++ cfe/trunk/lib/Driver/CC1Options.cpp Fri Nov 20 11:23:30 2009
@@ -55,6 +55,21 @@
return Default;
}
+static int getLastArgIntValue(ArgList &Args, cc1options::ID ID,
+ int Default = 0) {
+ Arg *A = Args.getLastArg(ID);
+ if (!A)
+ return Default;
+
+ int Res = Default;
+ // FIXME: What to do about argument parsing errors?
+ if (llvm::StringRef(A->getValue(Args)).getAsInteger(10, Res))
+ llvm::errs() << "error: invalid integral argument in '"
+ << A->getAsString(Args) << "'\n";
+
+ return Res;
+}
+
static std::vector<std::string>
getAllArgValues(ArgList &Args, cc1options::ID ID) {
llvm::SmallVector<const char *, 16> Values;
@@ -62,6 +77,50 @@
return std::vector<std::string>(Values.begin(), Values.end());
}
+//
+
+static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args) {
+ // -Os implies -O2
+ if (Args.hasArg(cc1options::OPT_Os))
+ Opts.OptimizationLevel = 2;
+ else
+ Opts.OptimizationLevel = getLastArgIntValue(Args, cc1options::OPT_O);
+
+ // FIXME: What to do about argument parsing errors?
+ if (Opts.OptimizationLevel > 3) {
+ llvm::errs() << "error: invalid optimization level '"
+ << Opts.OptimizationLevel << "' (out of range)\n";
+ Opts.OptimizationLevel = 3;
+ }
+
+ // We must always run at least the always inlining pass.
+ Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
+ : CodeGenOptions::OnlyAlwaysInlining;
+
+ Opts.DebugInfo = Args.hasArg(cc1options::OPT_g);
+ Opts.DisableLLVMOpts = Args.hasArg(cc1options::OPT_disable_llvm_optzns);
+ Opts.DisableRedZone = Args.hasArg(cc1options::OPT_disable_red_zone);
+ Opts.MergeAllConstants = !Args.hasArg(cc1options::OPT_fno_merge_all_constants);
+ Opts.NoCommon = Args.hasArg(cc1options::OPT_fno_common);
+ Opts.NoImplicitFloat = Args.hasArg(cc1options::OPT_no_implicit_float);
+ Opts.OptimizeSize = Args.hasArg(cc1options::OPT_Os);
+ Opts.SimplifyLibCalls = 1;
+ Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);
+
+ // FIXME: Implement!
+ // FIXME: Eliminate this dependency?
+// if (Lang.NoBuiltin)
+// Opts.SimplifyLibCalls = 0;
+// if (Lang.CPlusPlus)
+// Opts.NoCommon = 1;
+// Opts.TimePasses = TimePasses;
+
+ // FIXME: Put elsewhere?
+#ifdef NDEBUG
+ Opts.VerifyModule = 0;
+#endif
+}
+
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
Opts.ABI = getLastArgValue(Args, cc1options::OPT_target_abi);
Opts.CPU = getLastArgValue(Args, cc1options::OPT_mcpu);
@@ -73,6 +132,8 @@
Opts.Triple = llvm::sys::getHostTriple();
}
+//
+
void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
const llvm::SmallVectorImpl<llvm::StringRef> &Args) {
// This is gratuitous, but until we switch the driver to using StringRe we
@@ -98,5 +159,6 @@
<< " value )\n";
}
+ ParseCodeGenArgs(Res.getCodeGenOpts(), *InputArgs);
ParseTargetArgs(Res.getTargetOpts(), *InputArgs);
}
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=89464&r1=89463&r2=89464&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Nov 20 11:23:30 2009
@@ -102,7 +102,8 @@
Res.push_back("-disable-red-zone");
if (!Opts.MergeAllConstants)
Res.push_back("-fno-merge-all-constants");
- // NoCommon is only derived.
+ if (Opts.NoCommon)
+ Res.push_back("-fno-common");
if (Opts.NoImplicitFloat)
Res.push_back("-no-implicit-float");
if (Opts.OptimizeSize) {
More information about the cfe-commits
mailing list