Skip to content

Commit 01bdd8c

Browse files
committed
[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.
1 parent 0430324 commit 01bdd8c

12 files changed

+35
-24
lines changed

llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_dead_strip.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# RUN: yaml2obj %s -o %t
22
# RUN: llvm-jitlink -noexec \
33
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
4-
# RUN: -show-graph -noexec %t 2>&1 | FileCheck %s
5-
#
4+
# RUN: -show-graphs='.*' -noexec %t 2>&1 | FileCheck %s
5+
#
66
# Check a comdat child block connected by associative selection type is dead strip when
77
# parent block is dead.
88
#

llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_associative_no_dead_strip.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# RUN: yaml2obj %s -o %t
22
# RUN: llvm-jitlink -noexec \
33
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
4-
# RUN: -show-graph -noexec %t 2>&1 | FileCheck %s
5-
#
4+
# RUN: -show-graphs='.*' -noexec %t 2>&1 | FileCheck %s
5+
#
66
# Check a comdat child block connected by associative selection type is not dead strip when
77
# parent block is alive.
88
#

llvm/test/ExecutionEngine/JITLink/X86/COFF_comdat_weak_duplicate.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# RUN: yaml2obj %S/Inputs/COFF_comdat_weak_def.yaml -o %t/COFF_weak_1.o
33
# RUN: yaml2obj %S/Inputs/COFF_comdat_weak_def.yaml -o %t/COFF_weak_2.o
44
# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc %s -o %t/COFF_main.o
5-
# RUN:
5+
# RUN:
66
# RUN: llvm-jitlink -noexec %t/COFF_main.o %t/COFF_weak_1.o %t/COFF_weak_2.o \
77
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
8-
# RUN: -show-graph -noexec 2>&1 | FileCheck %s
8+
# RUN: -show-graphs='.*' -noexec 2>&1 | FileCheck %s
99
#
1010
# Check that duplicate comdat any definitions don't generate duplicate definition error.
1111
#
@@ -26,4 +26,4 @@
2626
.p2align 4, 0x90
2727
main:
2828
callq func
29-
retq
29+
retq

llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: yaml2obj %s -o %t
22
# RUN: llvm-jitlink -noexec \
33
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
4-
# RUN: -show-graph -noexec %t 2>&1 | FileCheck %s
4+
# RUN: -show-graphs='.*' -noexec %t 2>&1 | FileCheck %s
55
#
66
# Check a label symbol with an offset is created as defined symbol.
77
#

llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_no_strip.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN:
33
# RUN: llvm-jitlink -abs __ImageBase=0xdeadbeaf -noexec %t \
44
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
5-
# RUN: -show-graph -noexec 2>&1 | FileCheck %s
5+
# RUN: -show-graphs='.*' -noexec 2>&1 | FileCheck %s
66
#
77
# Check that basic seh frame inside pdata of alive function is not dead-stripped out.
88
# CHECK: section .xdata:

llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN:
33
# RUN: llvm-jitlink -abs __ImageBase=0xdeadbeaf -noexec %t \
44
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
5-
# RUN: -show-graph -noexec 2>&1 | FileCheck %s
5+
# RUN: -show-graphs='.*' -noexec 2>&1 | FileCheck %s
66
#
77
# Check that basic seh frame of dead block is dead-stripped out
88
#

llvm/test/ExecutionEngine/JITLink/X86/MachO-duplicate-local.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: yaml2obj %s -o %t
2-
# RUN: llvm-jitlink -noexec -show-graph %t | FileCheck %s
2+
# RUN: llvm-jitlink -noexec -show-graphs='.*' %t | FileCheck %s
33

44
# The below describes an object with two local symbols named _foo, each
55
# referenced by _main to keep it live. Ensure we can link it.

llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s
2-
# RUN: llvm-jitlink -noexec %t -show-graph | FileCheck %s
2+
# RUN: llvm-jitlink -noexec %t -show-graphs='.*' | FileCheck %s
33

44
# CHECK: linkage: weak, scope: local, live - _foo_weak
55

llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %S/Inputs/x86-64_self_relocation.s
2-
# RUN: llvm-jitlink -noexec -show-graph %t 2>&1 | \
2+
# RUN: llvm-jitlink -noexec -show-graphs='.*' %t 2>&1 | \
33
# RUN: FileCheck -check-prefix=WITHOUT %s
4-
# RUN: llvm-jitlink -noexec -show-graph -add-self-relocations %t 2>&1 | \
4+
# RUN: llvm-jitlink -noexec -show-graphs='.*' -add-self-relocations %t 2>&1 | \
55
# RUN: FileCheck -check-prefix=CHECK %s
66

77
# WITHOUT: block

llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %S/Inputs/x86-64_self_relocation.s
2-
# RUN: llvm-jitlink -show-graph %t
3-
# RUN: llvm-jitlink -show-graph -add-self-relocations %t
2+
# RUN: llvm-jitlink -show-graphs='.*' %t
3+
# RUN: llvm-jitlink -show-graphs='.*' -add-self-relocations %t
44

55
# Ensure that the added relocation does not create an incorrect pointer.
66

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/Support/MemoryBuffer.h"
5151
#include "llvm/Support/Path.h"
5252
#include "llvm/Support/Process.h"
53+
#include "llvm/Support/Regex.h"
5354
#include "llvm/Support/TargetSelect.h"
5455
#include "llvm/Support/Timer.h"
5556

@@ -175,10 +176,11 @@ static cl::opt<bool> ShowAddrs(
175176
cl::desc("Print registered symbol, section, got and stub addresses"),
176177
cl::init(false), cl::cat(JITLinkCategory));
177178

178-
static cl::opt<bool> ShowLinkGraph(
179-
"show-graph",
180-
cl::desc("Print the link graph after fixups have been applied"),
181-
cl::init(false), cl::cat(JITLinkCategory));
179+
static cl::opt<std::string> ShowLinkGraphs(
180+
"show-graphs",
181+
cl::desc("Takes a posix regex and prints the link graphs of all files "
182+
"matching that regex after fixups have been applied"),
183+
cl::Optional, cl::cat(JITLinkCategory));
182184

183185
static cl::opt<bool> ShowSizes(
184186
"show-sizes",
@@ -1062,6 +1064,9 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
10621064
// external.
10631065
for (auto &DefName : HarnessDefinitions)
10641066
HarnessExternals.erase(DefName.getKey());
1067+
1068+
if (!ShowLinkGraphs.empty())
1069+
ShowGraphsRegex = Regex(ShowLinkGraphs);
10651070
}
10661071

10671072
void Session::dumpSessionInfo(raw_ostream &OS) {
@@ -1086,10 +1091,14 @@ void Session::modifyPassConfig(const Triple &TT,
10861091
inconvertibleErrorCode());
10871092
});
10881093

1089-
if (ShowLinkGraph)
1090-
PassConfig.PostFixupPasses.push_back([](LinkGraph &G) -> Error {
1091-
outs() << "Link graph \"" << G.getName() << "\" post-fixup:\n";
1092-
G.dump(outs());
1094+
if (ShowGraphsRegex)
1095+
PassConfig.PostFixupPasses.push_back([this](LinkGraph &G) -> Error {
1096+
// Print graph if ShowLinkGraphs is specified-but-empty, or if
1097+
// it contains the given graph.
1098+
if (ShowGraphsRegex->match(G.getName())) {
1099+
outs() << "Link graph \"" << G.getName() << "\" post-fixup:\n";
1100+
G.dump(outs());
1101+
}
10931102
return Error::success();
10941103
});
10951104

llvm/tools/llvm-jitlink/llvm-jitlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct Session {
8383
StringSet<> HarnessDefinitions;
8484
DenseMap<StringRef, StringRef> CanonicalWeakDefs;
8585

86+
std::optional<Regex> ShowGraphsRegex;
87+
8688
private:
8789
Session(std::unique_ptr<orc::ExecutorProcessControl> EPC, Error &Err);
8890
};

0 commit comments

Comments
 (0)