]> granicus.if.org Git - clang/commitdiff
Driver: Handle -flto, -O4, and tweak -emit-llvm to match llvm-gcc.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 24 Mar 2009 20:17:30 +0000 (20:17 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 24 Mar 2009 20:17:30 +0000 (20:17 +0000)
 - -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

include/clang/Driver/Options.def
include/clang/Driver/Types.def
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp
test/Driver/lto.c [new file with mode: 0644]

index e8f156ae91b87dacb3e83e1baf1675cad7b463d5..7c98bc06a31df56bd4b0a00a9f6128f51888e436 100644 (file)
@@ -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("-MQ", MQ, JoinedOrSeparate, M_Group, INVALID, "", 0)
 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("-findirect-virtual-calls", findirect_virtual_calls, Flag, f_Group, INVAL
 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)
index 7b1789f0d8fec821c7022e0cbdf4e1a1e1ba1756..1902d44bfbfae1182d31dd7fd08bb07b23d4c750 100644 (file)
@@ -67,8 +67,8 @@ TYPE("f95-cpp-input",            Fortran,      PP_Fortran,      0,       "u")
 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",     "")
index c8ea4f8efe221b7b1632949e4413fa6fe78ca6e2..2ffd64191014c6919114e4ac41f6e642fb254674 100644 (file)
@@ -532,7 +532,6 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
     // -{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 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
         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 @@ Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
       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);
index bc5a7cf860cee1485e19acb7b881a6e04598ea1a..afb02fa49b5de504c52944b3fc5878530ba7c510 100644 (file)
@@ -278,9 +278,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     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);
diff --git a/test/Driver/lto.c b/test/Driver/lto.c
new file mode 100644 (file)
index 0000000..01ef2eb
--- /dev/null
@@ -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