[lld] r245027 - COFF: Introduce flag /opt:lldlto=N for controlling LTO optimization level.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 21:47:08 PDT 2015


Author: pcc
Date: Thu Aug 13 23:47:07 2015
New Revision: 245027

URL: http://llvm.org/viewvc/llvm-project?rev=245027&view=rev
Log:
COFF: Introduce flag /opt:lldlto=N for controlling LTO optimization level.

Differential Revision: http://reviews.llvm.org/D12024

Added:
    lld/trunk/test/COFF/lto-opt-level.ll
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/SymbolTable.cpp

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=245027&r1=245026&r2=245027&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Thu Aug 13 23:47:07 2015
@@ -87,6 +87,9 @@ struct Configuration {
   // Used for /opt:icf
   bool ICF = false;
 
+  // Used for /opt:lldlto=N
+  unsigned LTOOptLevel = 2;
+
   // Used for /merge:from=to (e.g. /merge:.rdata=.text)
   std::map<StringRef, StringRef> Merge;
 

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=245027&r1=245026&r2=245027&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Aug 13 23:47:07 2015
@@ -369,6 +369,14 @@ void LinkerDriver::link(llvm::ArrayRef<c
       Config->ICF = true;
       continue;
     }
+    if (StringRef(S).startswith("lldlto=")) {
+      StringRef OptLevel = StringRef(S).substr(7);
+      if (OptLevel.getAsInteger(10, Config->LTOOptLevel) ||
+          Config->LTOOptLevel > 3) {
+        error("/opt:lldlto: invalid optimization level: " + OptLevel);
+      }
+      continue;
+    }
     if (S != "ref" && S != "icf" && S != "noicf" &&
         S != "lbr" && S != "nolbr" &&
         !StringRef(S).startswith("icf=")) {

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=245027&r1=245026&r2=245027&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Aug 13 23:47:07 2015
@@ -343,6 +343,7 @@ void SymbolTable::addCombinedLTOObject()
   // Create an object file and add it to the symbol table by replacing any
   // DefinedBitcode symbols with the definitions in the object file.
   LTOCodeGenerator CG;
+  CG.setOptLevel(Config->LTOOptLevel);
   ObjectFile *Obj = createLTOObject(&CG);
 
   for (SymbolBody *Body : Obj->getSymbols()) {

Added: lld/trunk/test/COFF/lto-opt-level.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lto-opt-level.ll?rev=245027&view=auto
==============================================================================
--- lld/trunk/test/COFF/lto-opt-level.ll (added)
+++ lld/trunk/test/COFF/lto-opt-level.ll Thu Aug 13 23:47:07 2015
@@ -0,0 +1,21 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link /out:%t0.exe /entry:main /subsystem:console /opt:lldlto=0 /debug %t.obj
+; RUN: llvm-nm %t0.exe | FileCheck --check-prefix=CHECK-O0 %s
+; RUN: lld-link /out:%t2.exe /entry:main /subsystem:console /opt:lldlto=2 /debug %t.obj
+; RUN: llvm-nm %t2.exe | FileCheck --check-prefix=CHECK-O2 %s
+; RUN: lld-link /out:%t2a.exe /entry:main /subsystem:console /debug %t.obj
+; RUN: llvm-nm %t2a.exe | FileCheck --check-prefix=CHECK-O2 %s
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; CHECK-O0: foo
+; CHECK-O2-NOT: foo
+define internal void @foo() {
+  ret void
+}
+
+define void @main() {
+  call void @foo()
+  ret void
+}




More information about the llvm-commits mailing list