Move LLVM backend options to explicit clang-cc / clang -cc1 options, which we then manually pass to the command line library; eventually the latter grossness should be fixed by a real API when creating the target machine.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90063 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/CodeGen/CodeGenOptions.h b/include/clang/CodeGen/CodeGenOptions.h
index 4fd80dd..31fd7b4 100644
--- a/include/clang/CodeGen/CodeGenOptions.h
+++ b/include/clang/CodeGen/CodeGenOptions.h
@@ -29,7 +29,9 @@
OnlyAlwaysInlining // Only run the always inlining pass.
};
+ unsigned AsmVerbose : 1; /// -dA, -fverbose-asm
unsigned DebugInfo : 1; /// Should generate deubg info (-g).
+ unsigned DisableFPElim : 1; /// Set when -fomit-frame-pointer is enabled.
unsigned DisableLLVMOpts : 1; /// Don't run any optimizations, for use in
/// getting .bc files that correspond to the
/// internal state before optimizations are
@@ -38,6 +40,7 @@
unsigned MergeAllConstants : 1; /// Merge identical constants.
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled.
+ unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss
unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
unsigned OptimizeSize : 1; /// If -Os is specified.
unsigned SimplifyLibCalls : 1; /// Should standard library calls be treated
@@ -46,10 +49,19 @@
unsigned UnitAtATime : 1; /// Unused. For mirroring GCC optimization
/// selection.
unsigned UnrollLoops : 1; /// Control whether loops are unrolled.
+ unsigned UnwindTables : 1; /// Emit unwind tables.
unsigned VerifyModule : 1; /// Control whether the module should be run
/// through the LLVM Verifier.
- /// Inlining - The kind of inlining to perform.
+ /// The code model to use (-mcmodel).
+ std::string CodeModel;
+
+ std::string DebugPass;
+
+ /// The float precision limit to use, if non-empty.
+ std::string LimitFloatPrecision;
+
+ /// The kind of inlining to perform.
InliningMethod Inlining;
/// The user provided name for the "main file", if non-empty. This is useful
@@ -57,21 +69,30 @@
/// file, for example with -save-temps.
std::string MainFileName;
+ /// The name of the relocation model to use.
+ std::string RelocationModel;
+
public:
CodeGenOptions() {
+ AsmVerbose = 0;
+ DebugInfo = 0;
+ DisableFPElim = 0;
+ DisableLLVMOpts = 0;
+ DisableRedZone = 0;
+ MergeAllConstants = 1;
+ NoCommon = 0;
+ NoImplicitFloat = 0;
+ NoZeroInitializedInBSS = 0;
OptimizationLevel = 0;
OptimizeSize = 0;
- DebugInfo = 0;
- UnitAtATime = 1;
SimplifyLibCalls = UnrollLoops = 0;
- VerifyModule = 1;
TimePasses = 0;
- NoCommon = 0;
+ UnitAtATime = 1;
+ UnwindTables = 0;
+ VerifyModule = 1;
+
Inlining = NoInlining;
- DisableRedZone = 0;
- NoImplicitFloat = 0;
- MergeAllConstants = 1;
- DisableLLVMOpts = 0;
+ RelocationModel = "pic";
}
};
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index e597cb0..cdc31e9 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -108,6 +108,22 @@
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 masm_verbose : Flag<"-masm-verbose">,
+ HelpText<"Generate verbose assembly output">;
+def mcode_model : Separate<"-mcode-model">,
+ HelpText<"The code model to use">;
+def mdebug_pass : Separate<"-mdebug-pass">,
+ HelpText<"Enable additional debug output">;
+def mdisable_fp_elim : Flag<"-mdisable-fp-elim">,
+ HelpText<"Disable frame pointer elimination optimization">;
+def mlimit_float_precision : Separate<"-mlimit-float-precision">,
+ HelpText<"Limit float precision to the given value">;
+def mno_zero_initialized_in_bss : Flag<"-mno-zero-initialized-in-bss">,
+ HelpText<"Do not put zero initialized data in the BSS">;
+def mrelocation_model : Separate<"-mrelocation-model">,
+ HelpText<"The relocation model to use">;
+def munwind_tables : Flag<"-munwind-tables">,
+ HelpText<"Generate unwinding tables for all functions">;
def O : Joined<"-O">, HelpText<"Optimization level">;
def Os : Flag<"-Os">, HelpText<"Optimize for size">;
diff --git a/lib/Driver/CC1Options.cpp b/lib/Driver/CC1Options.cpp
index d4a8b3f..b9c4277 100644
--- a/lib/Driver/CC1Options.cpp
+++ b/lib/Driver/CC1Options.cpp
@@ -173,6 +173,15 @@
Opts.SimplifyLibCalls = 1;
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);
+ Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
+ Opts.CodeModel = getLastArgValue(Args, OPT_mcode_model);
+ Opts.DebugPass = getLastArgValue(Args, OPT_mdebug_pass);
+ Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
+ Opts.LimitFloatPrecision = getLastArgValue(Args, OPT_mlimit_float_precision);
+ Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
+ Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
+ Opts.RelocationModel = getLastArgValue(Args, OPT_mrelocation_model, "pic");
+
Opts.MainFileName = getLastArgValue(Args, OPT_main_file_name);
// FIXME: Implement!
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index c79b093..ed4d391 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -700,8 +700,10 @@
else
Model = getToolChain().GetDefaultRelocationModel();
}
- CmdArgs.push_back("-relocation-model");
- CmdArgs.push_back(Model);
+ if (llvm::StringRef(Model) != "pic") {
+ CmdArgs.push_back("-mrelocation-model");
+ CmdArgs.push_back(Model);
+ }
// Infer the __PIC__ value.
//
@@ -711,27 +713,30 @@
CmdArgs.push_back("-pic-level");
CmdArgs.push_back(Args.hasArg(options::OPT_fPIC) ? "2" : "1");
}
-
- if (Args.hasArg(options::OPT_ftime_report))
- CmdArgs.push_back("-time-passes");
- // FIXME: Set --enable-unsafe-fp-math.
- if (Args.hasFlag(options::OPT_fno_omit_frame_pointer,
- options::OPT_fomit_frame_pointer))
- CmdArgs.push_back("-disable-fp-elim");
- if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
- options::OPT_fno_zero_initialized_in_bss,
- true))
- CmdArgs.push_back("-nozero-initialized-in-bss");
- if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm))
- CmdArgs.push_back("-asm-verbose");
- if (Args.hasArg(options::OPT_fdebug_pass_structure))
- CmdArgs.push_back("-debug-pass=Structure");
- if (Args.hasArg(options::OPT_fdebug_pass_arguments))
- CmdArgs.push_back("-debug-pass=Arguments");
if (!Args.hasFlag(options::OPT_fmerge_all_constants,
options::OPT_fno_merge_all_constants))
CmdArgs.push_back("-no-merge-all-constants");
+ // LLVM Code Generator Options.
+
+ // FIXME: Set --enable-unsafe-fp-math.
+ if (Args.hasFlag(options::OPT_fno_omit_frame_pointer,
+ options::OPT_fomit_frame_pointer))
+ CmdArgs.push_back("-mdisable-fp-elim");
+ if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
+ options::OPT_fno_zero_initialized_in_bss))
+ CmdArgs.push_back("-mno-zero-initialized-in-bss");
+ if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm))
+ CmdArgs.push_back("-masm-verbose");
+ if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
+ CmdArgs.push_back("-mdebug-pass");
+ CmdArgs.push_back("Structure");
+ }
+ if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
+ CmdArgs.push_back("-mdebug-pass");
+ CmdArgs.push_back("Arguments");
+ }
+
// This is a coarse approximation of what llvm-gcc actually does, both
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
// complicated ways.
@@ -742,15 +747,18 @@
!Args.hasArg(options::OPT_mkernel));
if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
AsynchronousUnwindTables))
- CmdArgs.push_back("-unwind-tables=1");
- else
- CmdArgs.push_back("-unwind-tables=0");
+ CmdArgs.push_back("-munwind-tables");
+
+ if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
+ CmdArgs.push_back("-mlimit-float-precision");
+ CmdArgs.push_back(A->getValue(Args));
+ }
// FIXME: Handle -mtune=.
(void) Args.hasArg(options::OPT_mtune_EQ);
if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
- CmdArgs.push_back("-code-model");
+ CmdArgs.push_back("-mcode-model");
CmdArgs.push_back(A->getValue(Args));
}
@@ -776,11 +784,6 @@
getToolChain().IsMathErrnoDefault()))
CmdArgs.push_back("-fno-math-errno");
- if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
- CmdArgs.push_back("-limit-float-precision");
- CmdArgs.push_back(A->getValue(Args));
- }
-
Arg *Unsupported;
if ((Unsupported = Args.getLastArg(options::OPT_MG)) ||
(Unsupported = Args.getLastArg(options::OPT_MQ)) ||
diff --git a/lib/Frontend/Backend.cpp b/lib/Frontend/Backend.cpp
index 85aeaeb..12bb5a8 100644
--- a/lib/Frontend/Backend.cpp
+++ b/lib/Frontend/Backend.cpp
@@ -212,6 +212,39 @@
return false;
}
+ // FIXME: Expose these capabilities via actual APIs!!!! Aside from just
+ // being gross, this is also totally broken if we ever care about
+ // concurrency.
+ std::vector<const char *> BackendArgs;
+ BackendArgs.push_back("clang"); // Fake program name.
+ if (CodeGenOpts.AsmVerbose)
+ BackendArgs.push_back("-asm-verbose");
+ if (!CodeGenOpts.CodeModel.empty()) {
+ BackendArgs.push_back("-code-model");
+ BackendArgs.push_back(CodeGenOpts.CodeModel.c_str());
+ }
+ if (!CodeGenOpts.DebugPass.empty()) {
+ BackendArgs.push_back("-debug-pass");
+ BackendArgs.push_back(CodeGenOpts.DebugPass.c_str());
+ }
+ if (CodeGenOpts.DisableFPElim)
+ BackendArgs.push_back("-disable-fp-elim");
+ if (!CodeGenOpts.LimitFloatPrecision.empty()) {
+ BackendArgs.push_back("-limit-float-precision");
+ BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
+ }
+ if (CodeGenOpts.NoZeroInitializedInBSS)
+ BackendArgs.push_back("-nozero-initialized-in-bss");
+ BackendArgs.push_back("-relocation-model");
+ BackendArgs.push_back(CodeGenOpts.RelocationModel.c_str());
+ if (CodeGenOpts.TimePasses)
+ BackendArgs.push_back("-time-passes");
+ if (CodeGenOpts.UnwindTables)
+ BackendArgs.push_back("-unwind-tables");
+ BackendArgs.push_back(0);
+ llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
+ (char**) &BackendArgs[0]);
+
std::string FeaturesStr;
if (TargetOpts.CPU.size() || TargetOpts.Features.size()) {
SubtargetFeatures Features;
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index dc4452b..488eeac 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -121,6 +121,31 @@
// UnrollLoops is only derived.
// VerifyModule is only derived.
// Inlining is only derived.
+
+ if (Opts.AsmVerbose)
+ Res.push_back("-masm-verbose");
+ if (!Opts.CodeModel.empty()) {
+ Res.push_back("-mcode-model");
+ Res.push_back(Opts.CodeModel);
+ }
+ if (!Opts.DebugPass.empty()) {
+ Res.push_back("-mdebug-pass");
+ Res.push_back(Opts.DebugPass);
+ }
+ if (Opts.DisableFPElim)
+ Res.push_back("-mdisable-fp-elim");
+ if (!Opts.LimitFloatPrecision.empty()) {
+ Res.push_back("-mlimit-float-precision");
+ Res.push_back(Opts.LimitFloatPrecision);
+ }
+ if (Opts.NoZeroInitializedInBSS)
+ Res.push_back("-mno-zero-initialized-bss");
+ if (Opts.UnwindTables)
+ Res.push_back("-munwind-tables");
+ if (Opts.RelocationModel != "pic") {
+ Res.push_back("-mrelocation-model");
+ Res.push_back(Opts.RelocationModel);
+ }
}
static void DependencyOutputOptsToArgs(const DependencyOutputOptions &Opts,
diff --git a/test/Driver/clang-translation.c b/test/Driver/clang-translation.c
index 75578f3..f7f8b5e 100644
--- a/test/Driver/clang-translation.c
+++ b/test/Driver/clang-translation.c
@@ -1,13 +1,13 @@
-// RUN: clang -ccc-host-triple i386-unknown-unknown -### -S -O0 -Os %s -o %t.s -fverbose-asm 2> %t.log
+// RUN: clang -ccc-host-triple i386-unknown-unknown -### -S -O0 -Os %s -o %t.s -fverbose-asm -funwind-tables 2> %t.log
// RUN: grep '"-triple" "i386-unknown-unknown"' %t.log
// RUN: grep '"-S"' %t.log
// RUN: grep '"-disable-free"' %t.log
-// RUN: grep '"-relocation-model" "static"' %t.log
-// RUN: grep '"-disable-fp-elim"' %t.log
-// RUN: grep '"-unwind-tables=0"' %t.log
+// RUN: grep '"-mrelocation-model" "static"' %t.log
+// RUN: grep '"-mdisable-fp-elim"' %t.log
+// RUN: grep '"-munwind-tables"' %t.log
// RUN: grep '"-Os"' %t.log
// RUN: grep '"-o" .*clang-translation.*' %t.log
-// RUN: grep '"-asm-verbose"' %t.log
+// RUN: grep '"-masm-verbose"' %t.log
// RUN: clang -ccc-host-triple i386-apple-darwin9 -### -S %s -o %t.s 2> %t.log
// RUN: grep '"-mcpu" "yonah"' %t.log
// RUN: clang -ccc-host-triple x86_64-apple-darwin9 -### -S %s -o %t.s 2> %t.log
diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp
index 2bcad53..2436873 100644
--- a/tools/clang-cc/Options.cpp
+++ b/tools/clang-cc/Options.cpp
@@ -141,6 +141,36 @@
GenerateDebugInfo("g",
llvm::cl::desc("Generate source level debug information"));
+static llvm::cl::opt<bool>
+MAsmVerbose("masm-verbose", llvm::cl::desc("Generate verbose assembly output"));
+
+static llvm::cl::opt<std::string>
+MCodeModel("mcode-model", llvm::cl::desc("The code model to use"));
+
+static llvm::cl::opt<std::string>
+MDebugPass("mdebu-pass", llvm::cl::desc("Output additional debug information"));
+
+static llvm::cl::opt<bool>
+MDisableFPElim("mdisable-fp-elim",
+ llvm::cl::desc("Disable frame pointer elimination optimization"));
+
+static llvm::cl::opt<std::string>
+MLimitFloatPrecision("mlimit-float-precision",
+ llvm::cl::desc("Limit float precision to the given value"));
+
+static llvm::cl::opt<bool>
+MNoZeroInitializedInBSS("mno-zero-initialized-in-bss",
+ llvm::cl::desc("Do not put zero initialized data in the BSS"));
+
+static llvm::cl::opt<std::string>
+MRelocationModel("mrelocation-model",
+ llvm::cl::desc("The relocation model to use"),
+ llvm::cl::init("pic"));
+
+static llvm::cl::opt<bool>
+MUnwindTables("munwind-tables",
+ llvm::cl::desc("Generate unwinding tables for all functions"));
+
static llvm::cl::opt<std::string>
MainFileName("main-file-name",
llvm::cl::desc("Main file name to use for debug info"));
@@ -787,6 +817,17 @@
Opts.SimplifyLibCalls = 1;
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
+ // LLVM Code Generator options.
+
+ Opts.AsmVerbose = MAsmVerbose;
+ Opts.CodeModel = MCodeModel;
+ Opts.DebugPass = MDebugPass;
+ Opts.DisableFPElim = MDisableFPElim;
+ Opts.LimitFloatPrecision = MLimitFloatPrecision;
+ Opts.NoZeroInitializedInBSS = MNoZeroInitializedInBSS;
+ Opts.UnwindTables = MUnwindTables;
+ Opts.RelocationModel = MRelocationModel;
+
// FIXME: Eliminate this dependency?
if (Lang.NoBuiltin)
Opts.SimplifyLibCalls = 0;