Skip to content

Commit

Permalink
[llvm-jitlink] Rename -show-graph option to -show-graphs, make it a r…
Browse files Browse the repository at this point in the history
…egex.

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.
  • Loading branch information
lhames committed Mar 24, 2023
1 parent 0430324 commit 01bdd8c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -26,4 +26,4 @@
.p2align 4, 0x90
main:
callq func
retq
retq
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/X86/COFF_label.test
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/X86/COFF_pdata_strip.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
25 changes: 17 additions & 8 deletions llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
});

Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/llvm-jitlink/llvm-jitlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit 01bdd8c

Please sign in to comment.