[cfe-commits] r67645 - in /cfe/trunk: include/clang/Driver/Options.def include/clang/Driver/Types.def lib/Driver/Driver.cpp lib/Driver/Tools.cpp test/Driver/lto.c
Daniel Dunbar
daniel at zuster.org
Tue Mar 24 13:17:30 PDT 2009
Author: ddunbar
Date: Tue Mar 24 15:17:30 2009
New Revision: 67645
URL: http://llvm.org/viewvc/llvm-project?rev=67645&view=rev
Log:
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
Added:
cfe/trunk/test/Driver/lto.c
Modified:
cfe/trunk/include/clang/Driver/Options.def
cfe/trunk/include/clang/Driver/Types.def
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=67645&r1=67644&r2=67645&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Tue Mar 24 15:17:30 2009
@@ -85,6 +85,7 @@
OPTION("<I group>", I_Group, Group, INVALID, INVALID, "", 0)
OPTION("<M group>", M_Group, Group, INVALID, INVALID, "", 0)
OPTION("<T group>", T_Group, Group, INVALID, INVALID, "", 0)
+OPTION("<O group>", O_Group, Group, INVALID, INVALID, "", 0)
OPTION("<W group>", W_Group, Group, INVALID, INVALID, "", 0)
OPTION("<clang W group>", clang_W_Group, Group, W_Group, INVALID, "", 0)
OPTION("<X group>", X_Group, Group, INVALID, INVALID, "", 0)
@@ -247,9 +248,10 @@
OPTION("-MT", MT, JoinedOrSeparate, M_Group, INVALID, "", 0)
OPTION("-Mach", Mach, Flag, INVALID, INVALID, "", 0)
OPTION("-M", M, Flag, M_Group, INVALID, "", 0)
+OPTION("-O4", O4, Joined, O_Group, INVALID, "", 0)
OPTION("-ObjC++", ObjCXX, Flag, INVALID, INVALID, "d", 0)
OPTION("-ObjC", ObjC, Flag, INVALID, INVALID, "d", 0)
-OPTION("-O", O, Joined, INVALID, INVALID, "", 0)
+OPTION("-O", O, Joined, O_Group, INVALID, "", 0)
OPTION("-P", P, Flag, INVALID, INVALID, "", 0)
OPTION("-Qn", Qn, Flag, INVALID, INVALID, "", 0)
OPTION("-Q", Q, Flag, INVALID, INVALID, "", 0)
@@ -373,6 +375,7 @@
OPTION("-flat_namespace", flat__namespace, Flag, INVALID, INVALID, "", 0)
OPTION("-flax-vector-conversions", flax_vector_conversions, Flag, clang_f_Group, INVALID, "", 0)
OPTION("-flimited-precision=", flimited_precision_EQ, Joined, f_Group, INVALID, "", 0)
+OPTION("-flto", flto, Flag, f_Group, INVALID, "", 0)
OPTION("-fmath-errno", fmath_errno, Flag, f_Group, INVALID, "", 0)
OPTION("-fmessage-length=", fmessage_length_EQ, Joined, clang_ignored_f_Group, INVALID, "", 0)
OPTION("-fms-extensions", fms_extensions, Flag, clang_f_Group, INVALID, "", 0)
Modified: cfe/trunk/include/clang/Driver/Types.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.def?rev=67645&r1=67644&r2=67645&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Types.def (original)
+++ cfe/trunk/include/clang/Driver/Types.def Tue Mar 24 15:17:30 2009
@@ -67,8 +67,8 @@
TYPE("java", Java, INVALID, 0, "u")
// Misc.
-TYPE("llvm-asm", LLVMAsm, INVALID, "ll", "")
-TYPE("llvm-bc", LLVMBC, INVALID, "bc", "")
+TYPE("llvm-asm", LLVMAsm, INVALID, "s", "")
+TYPE("llvm-bc", LLVMBC, INVALID, "o", "")
TYPE("plist", Plist, INVALID, "plist", "")
TYPE("precompiled-header", PCH, INVALID, "gch", "A")
TYPE("object", Object, INVALID, "o", "")
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=67645&r1=67644&r2=67645&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 24 15:17:30 2009
@@ -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);
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=67645&r1=67644&r2=67645&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Mar 24 15:17:30 2009
@@ -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);
Added: cfe/trunk/test/Driver/lto.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/lto.c?rev=67645&view=auto
==============================================================================
--- cfe/trunk/test/Driver/lto.c (added)
+++ cfe/trunk/test/Driver/lto.c Tue Mar 24 15:17:30 2009
@@ -0,0 +1,25 @@
+// -emit-llvm, -flto, and -O4 all cause a switch to llvm-bc object
+// files.
+// RUN: clang -ccc-print-phases -c %s -flto 2> %t.log &&
+// RUN: grep '2: compiler, {1}, llvm-bc' %t.log &&
+// RUN: clang -ccc-print-phases -c %s -O4 2> %t.log &&
+// RUN: grep '2: compiler, {1}, llvm-bc' %t.log &&
+
+// and -emit-llvm doesn't alter pipeline (unfortunately?).
+// RUN: clang -ccc-print-phases %s -emit-llvm 2> %t.log &&
+// RUN: grep '0: input, ".*lto.c", c' %t.log &&
+// RUN: grep '1: preprocessor, {0}, cpp-output' %t.log &&
+// RUN: grep '2: compiler, {1}, llvm-bc' %t.log &&
+// RUN: grep '3: linker, {2}, image' %t.log &&
+
+// llvm-bc and llvm-ll outputs need to match regular suffixes
+// (unfortunately).
+// RUN: clang %s -emit-llvm -save-temps -### 2> %t.log &&
+// RUN: grep '"-o" ".*lto\.i" "-x" "c" ".*lto\.c"' %t.log &&
+// RUN: grep '"-o" ".*lto\.o" .*".*lto\.i"' %t.log &&
+// RUN: grep '".*a.out" .*".*lto\.o"' %t.log &&
+
+// RUN: clang %s -emit-llvm -S -### 2> %t.log &&
+// RUN: grep '"-o" ".*lto\.s" "-x" "c" ".*lto\.c"' %t.log &&
+
+// RUN: true
More information about the cfe-commits
mailing list