[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.
This commit is contained in:
Lang Hames
2023-03-24 14:43:32 -07:00
parent 0430324289
commit 01bdd8cffc
12 changed files with 35 additions and 24 deletions

View File

@@ -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.
#

View File

@@ -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.
#

View File

@@ -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
retq

View File

@@ -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.
#

View File

@@ -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:

View File

@@ -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
#

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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();
});

View File

@@ -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);
};