Driver: Handle -flto, -O4, and tweak -emit-llvm to match llvm-gcc.
- -emit-llvm no longer changes what compilation steps are done.
- -emit-llvm and -emit-llvm -S write output files with .o and .s
suffixes, respectively.
- <rdar://problem/6714125> clang-driver should support -O4 and -flto,
like llvm-gcc
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67645 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index c8ea4f8..2ffd641 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -532,7 +532,6 @@
// -{fsyntax-only,-analyze,emit-llvm,S} only run up to the compiler.
} else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) ||
(FinalPhaseArg = Args.getLastArg(options::OPT__analyze)) ||
- (FinalPhaseArg = Args.getLastArg(options::OPT_emit_llvm)) ||
(FinalPhaseArg = Args.getLastArg(options::OPT_S))) {
FinalPhase = phases::Compile;
@@ -588,6 +587,12 @@
break;
}
+ // Some types skip the assembler phase (e.g., llvm-bc), but we
+ // can't encode this in the steps because the intermediate type
+ // depends on arguments. Just special case here.
+ if (Phase == phases::Assemble && Current->getType() != types::TY_PP_Asm)
+ continue;
+
// Otherwise construct the appropriate action.
Current = ConstructPhaseAction(Args, Phase, Current);
if (Current->getType() == types::TY_Nothing)
@@ -623,7 +628,9 @@
return new CompileJobAction(Input, types::TY_Nothing);
} else if (Args.hasArg(options::OPT__analyze)) {
return new AnalyzeJobAction(Input, types::TY_Plist);
- } else if (Args.hasArg(options::OPT_emit_llvm)) {
+ } else if (Args.hasArg(options::OPT_emit_llvm) ||
+ Args.hasArg(options::OPT_flto) ||
+ Args.hasArg(options::OPT_O4)) {
types::ID Output =
Args.hasArg(options::OPT_S) ? types::TY_LLVMAsm : types::TY_LLVMBC;
return new CompileJobAction(Input, Output);
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index bc5a7cf..afb02fa 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -278,9 +278,12 @@
A->render(Args, CmdArgs);
}
- // Manually translate -O to -O1; let clang reject others.
- if (Arg *A = Args.getLastArg(options::OPT_O)) {
- if (A->getValue(Args)[0] == '\0')
+ // Manually translate -O to -O1 and -O4 to -O3; let clang reject
+ // others.
+ if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+ if (A->getOption().getId() == options::OPT_O4)
+ CmdArgs.push_back("-O3");
+ else if (A->getValue(Args)[0] == '\0')
CmdArgs.push_back("-O1");
else
A->render(Args, CmdArgs);