[llvm] 01bdd8c - [llvm-jitlink] Rename -show-graph option to -show-graphs, make it a regex.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 16:05:56 PDT 2023


Author: Lang Hames
Date: 2023-03-24T16:05:51-07:00
New Revision: 01bdd8cffcaf97636b5fb6ee4933e62c872528d3

URL: https://github.com/llvm/llvm-project/commit/01bdd8cffcaf97636b5fb6ee4933e62c872528d3
DIFF: https://github.com/llvm/llvm-project/commit/01bdd8cffcaf97636b5fb6ee4933e62c872528d3.diff

LOG: [llvm-jitlink] Rename -show-graph option to -show-graphs, make it a regex.

The original -show-graph option dumped the LinkGraph for all graphs loaded into
the session, but can make it difficult to see small graphs (e.g. reduced test
cases) among the surrounding larger files (especially the ORC runtime).

The new -show-graphs option takes a regex and dumps only those graphs matching
the regex. This allows testcases to specify exactly which graphs to dump.

Added: 
    

Modified: 
    llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_dead_strip.test
    llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_no_dead_strip.test
    llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_weak_duplicate.s
    llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test
    llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_no_strip.s
    llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s
    llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
    llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
    llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test
    llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp
    llvm/tools/llvm-jitlink/llvm-jitlink.h

Removed: 
    


################################################################################
diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_dead_strip.test b/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_dead_strip.test
index ad6b5a06abfca..99f4d7a41bbcb 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_dead_strip.test
+++ b/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_dead_strip.test
@@ -1,8 +1,8 @@
 # RUN: yaml2obj %s -o %t
 # RUN: llvm-jitlink -noexec \
 # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
-# RUN: -show-graph -noexec %t 2>&1 | FileCheck %s
-# 
+# RUN: -show-graphs='.*' -noexec %t 2>&1 | FileCheck %s
+#
 # Check a comdat child block connected by associative selection type is dead strip when
 # parent block is dead.
 #

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_no_dead_strip.test b/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_no_dead_strip.test
index 2979d5b6ede62..9cf59e72eba9f 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_no_dead_strip.test
+++ b/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_no_dead_strip.test
@@ -1,8 +1,8 @@
 # RUN: yaml2obj %s -o %t
 # RUN: llvm-jitlink -noexec \
 # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
-# RUN: -show-graph -noexec %t 2>&1 | FileCheck %s
-# 
+# RUN: -show-graphs='.*' -noexec %t 2>&1 | FileCheck %s
+#
 # Check a comdat child block connected by associative selection type is not dead strip when
 # parent block is alive.
 #

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_weak_duplicate.s b/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_weak_duplicate.s
index a740ce1b41afc..bc4da910018f9 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_weak_duplicate.s
+++ b/llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_weak_duplicate.s
@@ -2,10 +2,10 @@
 # RUN: yaml2obj %S/Inputs/COFF_comdat_weak_def.yaml -o %t/COFF_weak_1.o
 # RUN: yaml2obj %S/Inputs/COFF_comdat_weak_def.yaml -o %t/COFF_weak_2.o
 # RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc %s -o %t/COFF_main.o
-# RUN: 
+# RUN:
 # RUN: llvm-jitlink -noexec %t/COFF_main.o %t/COFF_weak_1.o %t/COFF_weak_2.o \
 # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
-# RUN: -show-graph -noexec 2>&1 | FileCheck %s
+# RUN: -show-graphs='.*' -noexec 2>&1 | FileCheck %s
 #
 # Check that duplicate comdat any definitions don't generate duplicate definition error.
 #
@@ -26,4 +26,4 @@
 	.p2align	4, 0x90
 main:
     callq func
-	retq
\ No newline at end of file
+	retq

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test b/llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test
index 5e469ec9d30f6..f27ed8a433fd9 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test
+++ b/llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %s -o %t
 # RUN: llvm-jitlink -noexec \
 # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
-# RUN: -show-graph -noexec %t 2>&1 | FileCheck %s
+# RUN: -show-graphs='.*' -noexec %t 2>&1 | FileCheck %s
 #
 # Check a label symbol with an offset is created as defined symbol.
 #

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_no_strip.s b/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_no_strip.s
index d6e0cba051940..80f4f15afd169 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_no_strip.s
+++ b/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_no_strip.s
@@ -2,7 +2,7 @@
 # RUN: 
 # RUN: llvm-jitlink -abs __ImageBase=0xdeadbeaf -noexec %t \
 # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
-# RUN: -show-graph -noexec 2>&1 | FileCheck %s
+# RUN: -show-graphs='.*' -noexec 2>&1 | FileCheck %s
 #
 # Check that basic seh frame inside pdata of alive function is not dead-stripped out.
 # CHECK: section .xdata:

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s b/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s
index 2dad04fa18d07..e3a752df471c2 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s
+++ b/llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s
@@ -2,7 +2,7 @@
 # RUN: 
 # RUN: llvm-jitlink -abs __ImageBase=0xdeadbeaf -noexec %t \
 # RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
-# RUN: -show-graph -noexec 2>&1 | FileCheck %s
+# RUN: -show-graphs='.*' -noexec 2>&1 | FileCheck %s
 #
 # Check that basic seh frame of dead block is dead-stripped out
 #

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test b/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
index d2895e448a3c0..c82e852a80dc0 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test
@@ -1,5 +1,5 @@
 # RUN: yaml2obj %s -o %t
-# RUN: llvm-jitlink -noexec -show-graph %t | FileCheck %s
+# RUN: llvm-jitlink -noexec -show-graphs='.*' %t | FileCheck %s
 
 # The below describes an object with two local symbols named _foo, each
 # referenced by _main to keep it live. Ensure we can link it.

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
index f227411908a4b..faedeb639a249 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
@@ -1,5 +1,5 @@
 # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s
-# RUN: llvm-jitlink -noexec %t -show-graph | FileCheck %s
+# RUN: llvm-jitlink -noexec %t -show-graphs='.*' | FileCheck %s
 
 # CHECK: linkage: weak, scope: local, live  -   _foo_weak
 

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test
index 54f8a8a12df26..dfeeba1e39b60 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test
@@ -1,7 +1,7 @@
 # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %S/Inputs/x86-64_self_relocation.s
-# RUN: llvm-jitlink -noexec -show-graph %t 2>&1 | \
+# RUN: llvm-jitlink -noexec -show-graphs='.*' %t 2>&1 | \
 # RUN:   FileCheck -check-prefix=WITHOUT %s
-# RUN: llvm-jitlink -noexec -show-graph -add-self-relocations %t 2>&1 | \
+# RUN: llvm-jitlink -noexec -show-graphs='.*' -add-self-relocations %t 2>&1 | \
 # RUN:   FileCheck -check-prefix=CHECK %s
 
 # WITHOUT: block

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test
index 49a1c00dcefe9..b12e87b74cde9 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test
@@ -1,6 +1,6 @@
 # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %S/Inputs/x86-64_self_relocation.s
-# RUN: llvm-jitlink -show-graph %t
-# RUN: llvm-jitlink -show-graph -add-self-relocations %t
+# RUN: llvm-jitlink -show-graphs='.*' %t
+# RUN: llvm-jitlink -show-graphs='.*' -add-self-relocations %t
 
 # Ensure that the added relocation does not create an incorrect pointer.
 

diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 15b26a80e2274..48df846bccdf9 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/Regex.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/Timer.h"
 
@@ -175,10 +176,11 @@ static cl::opt<bool> ShowAddrs(
     cl::desc("Print registered symbol, section, got and stub addresses"),
     cl::init(false), cl::cat(JITLinkCategory));
 
-static cl::opt<bool> ShowLinkGraph(
-    "show-graph",
-    cl::desc("Print the link graph after fixups have been applied"),
-    cl::init(false), cl::cat(JITLinkCategory));
+static cl::opt<std::string> ShowLinkGraphs(
+    "show-graphs",
+    cl::desc("Takes a posix regex and prints the link graphs of all files "
+             "matching that regex after fixups have been applied"),
+    cl::Optional, cl::cat(JITLinkCategory));
 
 static cl::opt<bool> ShowSizes(
     "show-sizes",
@@ -1062,6 +1064,9 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
   // external.
   for (auto &DefName : HarnessDefinitions)
     HarnessExternals.erase(DefName.getKey());
+
+  if (!ShowLinkGraphs.empty())
+    ShowGraphsRegex = Regex(ShowLinkGraphs);
 }
 
 void Session::dumpSessionInfo(raw_ostream &OS) {
@@ -1086,10 +1091,14 @@ void Session::modifyPassConfig(const Triple &TT,
                                      inconvertibleErrorCode());
     });
 
-  if (ShowLinkGraph)
-    PassConfig.PostFixupPasses.push_back([](LinkGraph &G) -> Error {
-      outs() << "Link graph \"" << G.getName() << "\" post-fixup:\n";
-      G.dump(outs());
+  if (ShowGraphsRegex)
+    PassConfig.PostFixupPasses.push_back([this](LinkGraph &G) -> Error {
+      // Print graph if ShowLinkGraphs is specified-but-empty, or if
+      // it contains the given graph.
+      if (ShowGraphsRegex->match(G.getName())) {
+        outs() << "Link graph \"" << G.getName() << "\" post-fixup:\n";
+        G.dump(outs());
+      }
       return Error::success();
     });
 

diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h
index 3b6023958db53..8ec668ab86b99 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.h
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h
@@ -83,6 +83,8 @@ struct Session {
   StringSet<> HarnessDefinitions;
   DenseMap<StringRef, StringRef> CanonicalWeakDefs;
 
+  std::optional<Regex> ShowGraphsRegex;
+
 private:
   Session(std::unique_ptr<orc::ExecutorProcessControl> EPC, Error &Err);
 };


        


More information about the llvm-commits mailing list