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
This commit is contained in:
Joerg Sonnenberger 2011-05-06 14:35:16 +00:00
parent 47061ee5bc
commit ef317a27ff
1 changed files with 37 additions and 14 deletions

View File

@ -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.