[PATCH] D23615: [LTO] Adds a "CodeGenOnly" option. Allows the client to skip the optimizer.

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 10:44:51 PDT 2016


mehdi_amini created this revision.
mehdi_amini added a reviewer: tejohnson.
mehdi_amini added a subscriber: llvm-commits.
Herald added a subscriber: mehdi_amini.

Slowly getting on par with libLTO

https://reviews.llvm.org/D23615

Files:
  include/llvm/LTO/Config.h
  lib/LTO/LTO.cpp
  lib/LTO/LTOBackend.cpp

Index: lib/LTO/LTOBackend.cpp
===================================================================
--- lib/LTO/LTOBackend.cpp
+++ lib/LTO/LTOBackend.cpp
@@ -224,8 +224,9 @@
   std::unique_ptr<TargetMachine> TM =
       createTargetMachine(C, M->getTargetTriple(), *TOrErr);
 
-  if (!opt(C, TM.get(), 0, *M, /*IsThinLto=*/false))
-    return Error();
+  if (!C.CodeGenOnly)
+    if (!opt(C, TM.get(), 0, *M, /*IsThinLto=*/false))
+      return Error();
 
   if (ParallelCodeGenParallelismLevel == 1)
     codegen(C, TM.get(), AddOutput, 0, *M);
@@ -247,6 +248,11 @@
   std::unique_ptr<TargetMachine> TM =
       createTargetMachine(Conf, Mod.getTargetTriple(), *TOrErr);
 
+  if (Conf.CodeGenOnly) {
+    codegen(Conf, TM.get(), AddOutput, Task, Mod);
+    return Error();
+  }
+
   if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
     return Error();
 
Index: lib/LTO/LTO.cpp
===================================================================
--- lib/LTO/LTO.cpp
+++ lib/LTO/LTO.cpp
@@ -411,27 +411,29 @@
       !Conf.PreOptModuleHook(0, *RegularLTO.CombinedModule))
     return Error();
 
-  for (const auto &R : GlobalResolutions) {
-    if (R.second.IRName.empty())
-      continue;
-    if (R.second.Partition != 0 &&
-        R.second.Partition != GlobalResolution::External)
-      continue;
+  if (!Conf.CodeGenOnly) {
+    for (const auto &R : GlobalResolutions) {
+      if (R.second.IRName.empty())
+        continue;
+      if (R.second.Partition != 0 &&
+          R.second.Partition != GlobalResolution::External)
+        continue;
+
+      GlobalValue *GV =
+          RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
+      // Ignore symbols defined in other partitions.
+      if (!GV || GV->hasLocalLinkage())
+        continue;
+      GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global
+                                              : GlobalValue::UnnamedAddr::None);
+      if (R.second.Partition == 0)
+        GV->setLinkage(GlobalValue::InternalLinkage);
+    }
 
-    GlobalValue *GV = RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
-    // Ignore symbols defined in other partitions.
-    if (!GV || GV->hasLocalLinkage())
-      continue;
-    GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global
-                                            : GlobalValue::UnnamedAddr::None);
-    if (R.second.Partition == 0)
-      GV->setLinkage(GlobalValue::InternalLinkage);
+    if (Conf.PostInternalizeModuleHook &&
+        !Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))
+      return Error();
   }
-
-  if (Conf.PostInternalizeModuleHook &&
-      !Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))
-    return Error();
-
   return backend(Conf, AddOutput, RegularLTO.ParallelCodeGenParallelismLevel,
                  std::move(RegularLTO.CombinedModule));
 }
Index: include/llvm/LTO/Config.h
===================================================================
--- include/llvm/LTO/Config.h
+++ include/llvm/LTO/Config.h
@@ -59,6 +59,9 @@
   unsigned OptLevel = 2;
   bool DisableVerify = false;
 
+  /// Disable entirely the optimizer, including importing for ThinLTO
+  bool CodeGenOnly = false;
+
   /// Setting this field will replace target triples in input files with this
   /// triple.
   std::string OverrideTriple;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23615.68386.patch
Type: text/x-patch
Size: 3360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160817/49e036eb/attachment.bin>


More information about the llvm-commits mailing list