[PATCH] D114201: [LTO] Add a function `LTOCodeGenerator::getMergedModule`

Shilei Tian via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 20 17:02:07 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG75a5eaf7c6d6: [LTO] Add a function `LTOCodeGenerator::getMergedModule` (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114201/new/

https://reviews.llvm.org/D114201

Files:
  llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
  llvm/test/tools/llvm-lto/dump.ll
  llvm/tools/llvm-lto/llvm-lto.cpp


Index: llvm/tools/llvm-lto/llvm-lto.cpp
===================================================================
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -197,6 +197,11 @@
                    cl::desc("Write merged LTO module to file before CodeGen"),
                    cl::cat(LTOCategory));
 
+static cl::opt<bool>
+    DumpLinkedModule("dump-linked-module", cl::init(false),
+                     cl::desc("Dump linked LTO module before optimize"),
+                     cl::cat(LTOCategory));
+
 static cl::list<std::string> InputFilenames(cl::Positional, cl::OneOrMore,
                                             cl::desc("<input bitcode files>"),
                                             cl::cat(LTOCategory));
@@ -316,11 +321,11 @@
       if (!CurrentActivity.empty())
         OS << ' ' << CurrentActivity;
       OS << ": ";
-  
+
       DiagnosticPrinterRawOStream DP(OS);
       DI.print(DP);
       OS << '\n';
-  
+
       if (DI.getSeverity() == DS_Error)
         exit(1);
       return true;
@@ -1115,6 +1120,14 @@
       error("error compiling the code");
 
   } else {
+    if (DumpLinkedModule) {
+      if (SaveLinkedModuleFile)
+        error(": -dump-linked-module must be used without -dump-linked-module");
+
+      Module &M = CodeGen.getMergedModule();
+      M.dump();
+    }
+
     if (Parallelism != 1)
       error("-j must be specified together with -o");
 
Index: llvm/test/tools/llvm-lto/dump.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-lto/dump.ll
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s > %t1
+; RUN: llvm-lto --dump-linked-module %t1 2>&1 | FileCheck %s
+
+; CHEKCK: target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; CHECK: define void @f() {
+define void @f() {
+; CHECK-NEXT: entry:
+entry:
+; CHECK-NEXT: ret void
+  ret void
+; CHECK-NEXT: }
+}
Index: llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
===================================================================
--- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
+++ llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
@@ -193,6 +193,8 @@
   void resetMergedModule() { MergedModule.reset(); }
   void DiagnosticHandler(const DiagnosticInfo &DI);
 
+  Module &getMergedModule() { return *MergedModule; }
+
 private:
   /// Verify the merged module on first call.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114201.395550.patch
Type: text/x-patch
Size: 2441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211221/3d41f490/attachment.bin>


More information about the llvm-commits mailing list