summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2011-05-06 14:35:16 +0000
committerJoerg Sonnenberger <joerg@bec.de>2011-05-06 14:35:16 +0000
commitef317a27ff27c8f22cf65af85a5ebd6f9dd0836f (patch)
treeebdf17407f0e99f0365eaca7b89a88aedcc66c11 /clang/lib/Driver/Tools.cpp
parent47061ee5bc64f7621838ad954e6e887cd95d0721 (diff)
downloadbcm5719-llvm-ef317a27ff27c8f22cf65af85a5ebd6f9dd0836f.tar.gz
bcm5719-llvm-ef317a27ff27c8f22cf65af85a5ebd6f9dd0836f.zip
Move logic for passing down -mrelax-all / -relax-all into a common
function. Extend the logic to check if the input was compiled. Use -relax-all as default only if -O0 is used for compilation. Fixes bug 9290. llvm-svn: 130983
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r--clang/lib/Driver/Tools.cpp51
1 files changed, 37 insertions, 14 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 239edb5db4f..b140a15d18b 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -924,6 +924,41 @@ static bool ShouldDisableCFI(const ArgList &Args,
return !UseCFI;
}
+/// \brief Check whether the given input tree contains any compilation actions.
+static bool ContainsCompileAction(const Action *A) {
+ if (isa<CompileJobAction>(A))
+ return true;
+
+ for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it)
+ if (ContainsCompileAction(*it))
+ return true;
+
+ return false;
+}
+
+/// \brief Check if -relax-all should be passed to the internal assembler.
+/// This is done by default when compiling non-assembler source with -O0.
+static bool UseRelaxAll(Compilation &C, const ArgList &Args) {
+ bool RelaxDefault = true;
+
+ if (Arg *A = Args.getLastArg(options::OPT_O_Group))
+ RelaxDefault = A->getOption().matches(options::OPT_O0);
+
+ if (RelaxDefault) {
+ RelaxDefault = false;
+ for (ActionList::const_iterator it = C.getActions().begin(),
+ ie = C.getActions().end(); it != ie; ++it) {
+ if (ContainsCompileAction(*it)) {
+ RelaxDefault = true;
+ break;
+ }
+ }
+ }
+
+ return Args.hasFlag(options::OPT_mrelax_all, options::OPT_mno_relax_all,
+ RelaxDefault);
+}
+
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -959,13 +994,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
} else if (isa<AssembleJobAction>(JA)) {
CmdArgs.push_back("-emit-obj");
- // At -O0, we use -mrelax-all by default.
- bool IsOpt = false;
- if (Arg *A = Args.getLastArg(options::OPT_O_Group))
- IsOpt = !A->getOption().matches(options::OPT_O0);
- if (Args.hasFlag(options::OPT_mrelax_all,
- options::OPT_mno_relax_all,
- !IsOpt))
+ if (UseRelaxAll(C, Args))
CmdArgs.push_back("-mrelax-all");
// When using an integrated assembler, translate -Wa, and -Xassembler
@@ -2019,13 +2048,7 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-filetype");
CmdArgs.push_back("obj");
- // At -O0, we use -mrelax-all by default.
- bool IsOpt = false;
- if (Arg *A = Args.getLastArg(options::OPT_O_Group))
- IsOpt = !A->getOption().matches(options::OPT_O0);
- if (Args.hasFlag(options::OPT_mrelax_all,
- options::OPT_mno_relax_all,
- !IsOpt))
+ if (UseRelaxAll(C, Args))
CmdArgs.push_back("-relax-all");
// Ignore explicit -force_cpusubtype_ALL option.
OpenPOWER on IntegriCloud