[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 14 04:33:44 PDT 2021


tbaeder created this revision.
tbaeder added a reviewer: tejohnson.
Herald added subscribers: dang, inglorion.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The current behavior was introduced in https://github.com/llvm/llvm-project/commit/1628486548420f85b3467026d54663d1516404f5 and simply ignores the options, which will of course not turn on any form of LTO. When they are passed, I think it's sensible to at least turn on full LTO.

This makes clang basically accept all `-flto=val` values and treat them like `-flto=full`. I didn't implement anything that checks for only `=auto` or `=jobserver`, I'm not sure if that would be the right thing to do.

Thoughts?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102479

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/clang_f_opts.c


Index: clang/test/Driver/clang_f_opts.c
===================================================================
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -258,7 +258,6 @@
 // RUN:     -fstrength-reduce -fno-strength-reduce                            \
 // RUN:     -finline-limit=1000                                               \
 // RUN:     -finline-limit                                                    \
-// RUN:     -flto=1                                                           \
 // RUN:     -falign-labels                                                    \
 // RUN:     -falign-labels=100                                                \
 // RUN:     -falign-loops                                                     \
@@ -292,7 +291,6 @@
 // RUN:     -fno-delete-null-pointer-checks -fdelete-null-pointer-checks      \
 // RUN:     -fno-inline-small-functions -finline-small-functions              \
 // RUN:     -fno-fat-lto-objects -ffat-lto-objects                            \
-// RUN:     -flto=auto -flto=jobserver                                        \
 // RUN:     -fno-merge-constants -fmerge-constants                            \
 // RUN:     -fno-caller-saves -fcaller-saves                                  \
 // RUN:     -fno-reorder-blocks -freorder-blocks                              \
@@ -332,6 +330,8 @@
 // RUN: -funroll-all-loops                                                    \
 // RUN: -funswitch-loops                                                      \
 // RUN: -flto=1                                                               \
+// RUN: -flto=auto                                                            \
+// RUN: -flto=jobserver                                                       \
 // RUN: -falign-labels                                                        \
 // RUN: -falign-labels=100                                                    \
 // RUN: -falign-loops                                                         \
@@ -392,7 +392,9 @@
 // CHECK-WARNING-DAG: optimization flag '-ftracer' is not supported
 // CHECK-WARNING-DAG: optimization flag '-funroll-all-loops' is not supported
 // CHECK-WARNING-DAG: optimization flag '-funswitch-loops' is not supported
-// CHECK-WARNING-DAG: unsupported argument '1' to option 'flto='
+// CHECK-WARNING_DAG: Unknown option -flto=1, treating as -flto=full
+// CHECK-WARNING_DAG: Unknown option -flto=auto, treating as -flto=full
+// CHECK-WARNING_DAG: Unknown option -flto=jobserver, treating as -flto=full
 // CHECK-WARNING-DAG: optimization flag '-falign-labels' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-labels=100' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-loops' is not supported
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1707,8 +1707,7 @@
     StringRef S = A->getValue();
     if (S == "thin")
       Opts.PrepareForThinLTO = true;
-    else if (S != "full")
-      Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+    // -flto=full and invalid values are handled elsewhere.
   }
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
     if (IK.getLanguage() != Language::LLVM_IR)
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -613,9 +613,12 @@
                 .Default(LTOK_Unknown);
 
   if (LTOMode == LTOK_Unknown) {
+    // Treat all other options as "full", but warn that the option
+    // value is unknown.
     assert(A);
-    Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName()
-                                                    << A->getValue();
+    Diag(diag::warn_drv_treating_option_as)
+        << A->getAsString(Args) << "-flto=full";
+    LTOMode = LTOK_Full;
   }
 }
 
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4226,8 +4226,6 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, Group<clang_ignored_gcc_optimization_f_Group>;
 defm default_inline : BooleanFFlag<"default-inline">, Group<clang_ignored_gcc_optimization_f_Group>;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, Group<clang_ignored_gcc_optimization_f_Group>;
-def : Flag<["-"], "flto=auto">, Group<clang_ignored_gcc_optimization_f_Group>;
-def : Flag<["-"], "flto=jobserver">, Group<clang_ignored_gcc_optimization_f_Group>;
 defm float_store : BooleanFFlag<"float-store">, Group<clang_ignored_gcc_optimization_f_Group>;
 defm friend_injection : BooleanFFlag<"friend-injection">, Group<clang_ignored_f_Group>;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, Group<clang_ignored_f_Group>;
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -556,4 +556,6 @@
 def err_cc1_round_trip_fail_then_ok : Error<"Original arguments parse failed, then succeeded in round-trip">;
 def err_cc1_round_trip_ok_then_fail : Error<"Generated arguments parse failed in round-trip">;
 def err_cc1_round_trip_mismatch : Error<"Generated arguments do not match in round-trip">;
+
+def warn_drv_treating_option_as : Warning<"Unknown option %0, treating as %1.">;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102479.345395.patch
Type: text/x-patch
Size: 5671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210514/1a7e6fc7/attachment.bin>


More information about the cfe-commits mailing list