Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE! Temporarily patch in perf support to llvm. #456

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 82 additions & 0 deletions conda-recipes/0001-perf_tools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
From 438c17d4ccea4acbde0440fb09afd9619c28f4bf Mon Sep 17 00:00:00 2001
From: Stuart Archibald <redacted>
Date: Fri, 25 Jan 2019 15:21:06 +0000
Subject: [PATCH] This patch is based on https://reviews.llvm.org/D47343

It is almost certainly invalid and not the right way to do this (not as a
result of D47343 but as a result of it being shoehorned in), however, it has
the desired effect to permit exploration of linux perf with Numba JIT.
---


---
lib/ExecutionEngine/GDBRegistrationListener.cpp | 4 ++--
lib/ExecutionEngine/MCJIT/MCJIT.cpp | 16 ++++++++++++++--
lib/ExecutionEngine/MCJIT/MCJIT.h | 2 ++
3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/ExecutionEngine/GDBRegistrationListener.cpp b/lib/ExecutionEngine/GDBRegistrationListener.cpp
index fd4f0746..041e6261 100644
--- a/lib/ExecutionEngine/GDBRegistrationListener.cpp
+++ b/lib/ExecutionEngine/GDBRegistrationListener.cpp
@@ -164,8 +164,8 @@ void GDBJITRegistrationListener::NotifyObjectEmitted(

assert(Key && "Attempt to register a null object with a debugger.");
llvm::MutexGuard locked(*JITDebugLock);
- assert(ObjectBufferMap.find(Key) == ObjectBufferMap.end() &&
- "Second attempt to perform debug registration.");
+// assert(ObjectBufferMap.find(Key) == ObjectBufferMap.end() &&
+// "Second attempt to perform debug registration.");
jit_code_entry* JITCodeEntry = new jit_code_entry();

if (!JITCodeEntry) {
diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 2c663c2e..b2439eef 100644
--- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -226,8 +226,10 @@ void MCJIT::generateCodeForModule(Module *M) {
if (Dyld.hasError())
report_fatal_error(Dyld.getErrorString());

- NotifyObjectEmitted(*LoadedObject.get(), *L);
-
+ // Can't call notifiers yet, as relocations have not yet been
+ // performed, and memory hasn't been marked executable.
+ PendingLoadedObjects.push_back(LoadedObject->get());
+ PendingLoadedObjectInfos.push_back(std::move(L));
Buffers.push_back(std::move(ObjectToLoad));
LoadedObjects.push_back(std::move(*LoadedObject));

@@ -247,6 +249,16 @@ void MCJIT::finalizeLoadedModules() {

// Set page permissions.
MemMgr->finalizeMemory();
+
+ // Notify listeners about loaded objects, now that memory is marked
+ // executable and relocations have been performed.
+ for (size_t i = 0; i < PendingLoadedObjects.size(); i++) {
+ auto &Obj = PendingLoadedObjects[i];
+ auto &Info = PendingLoadedObjectInfos[i];
+ NotifyObjectEmitted(*Obj, *Info);
+ }
+ PendingLoadedObjects.clear();
+ PendingLoadedObjectInfos.clear();
}

// FIXME: Rename this.
diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.h b/lib/ExecutionEngine/MCJIT/MCJIT.h
index 943b1494..c1f3016e 100644
--- a/lib/ExecutionEngine/MCJIT/MCJIT.h
+++ b/lib/ExecutionEngine/MCJIT/MCJIT.h
@@ -190,6 +190,8 @@ class MCJIT : public ExecutionEngine {
SmallVector<std::unique_ptr<MemoryBuffer>, 2> Buffers;

SmallVector<std::unique_ptr<object::ObjectFile>, 2> LoadedObjects;
+ SmallVector<object::ObjectFile*, 2> PendingLoadedObjects;
+ SmallVector<std::unique_ptr<RuntimeDyld::LoadedObjectInfo>, 2> PendingLoadedObjectInfos;

// An optional ObjectCache to be notified of compiled objects and used to
// perform lookup of pre-compiled code to avoid re-compilation.
--
2.17.1

1 change: 1 addition & 0 deletions conda-recipes/llvmdev/.label
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_tool
1 change: 1 addition & 0 deletions conda-recipes/llvmdev/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if [[ $(uname) == Darwin ]]; then
_cmake_config+=(-DDARWIN_osx_ARCHS=x86_64)
elif [[ $(uname) == Linux ]]; then
_cmake_config+=(-DLLVM_USE_INTEL_JITEVENTS=ON)
_cmake_config+=(-DLLVM_USE_PERF=ON)
# _cmake_config+=(-DLLVM_BINUTILS_INCDIR=${PREFIX}/lib/gcc/${cpu_arch}-${vendor}-linux-gnu/${compiler_ver}/plugin/include)
fi

Expand Down
8 changes: 6 additions & 2 deletions conda-recipes/llvmdev/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% set shortversion = "7.0" %}
{% set version = "7.0.0" %}
{% set version_suffix = "_perf_tool" %}
{% set sha256_llvm = "8bc1f844e6cbde1b652c19c1edebc1864456fd9c78b8c1bea038e51b363fe222" %}
{% set sha256_lld = "fbcf47c5e543f4cdac6bb9bbbc6327ff24217cd7eafc5571549ad6d237287f9c" %}
{% set build_number = "1" %}
{% set build_number = "0" %}

package:
name: llvmdev
version: {{ version }}
version: {{ "%s%s" % (version, version_suffix) }}

source:
- url: http://llvm.org/releases/{{ version }}/llvm-{{ version }}.src.tar.xz
Expand All @@ -29,6 +30,9 @@ source:
# for details:
- ../0001-RuntimeDyld-Fix-a-bug-in-RuntimeDyld-loadObjectImpl-.patch
- ../0001-RuntimeDyld-Add-test-case-that-was-accidentally-left.patch
# Patch based on: https://reviews.llvm.org/D47343
# to allow linux perf to work with MCJIT
- ../0001-perf_tools.patch # [linux]

- url: http://releases.llvm.org/{{ version }}/lld-{{ version }}.src.tar.xz
fn: lld-{{ version }}.src.tar.xz
Expand Down
1 change: 1 addition & 0 deletions conda-recipes/llvmlite/.label
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_tool
6 changes: 3 additions & 3 deletions conda-recipes/llvmlite/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set VERSION_SUFFIX = "" %} # debug version suffix, appended to the version
{% set VERSION_SUFFIX = "_perf_tool" %} # debug version suffix, appended to the version

package:
name: llvmlite
Expand Down Expand Up @@ -27,11 +27,11 @@ requirements:
host:
- python
# On channel https://anaconda.org/numba/
- llvmdev 7.0*
- llvmdev 7.0.0_perf_tool*
- vs2015_runtime # [win]
- enum34 # [py27]
# llvmdev is built with libz compression support
- zlib # [unix and not (armv6l or armv7l or aarch64)]
- zlib # [unix and not (armv6l or armv7l or aarch64)]
run:
- python
- enum34 # [py27]
Expand Down
10 changes: 10 additions & 0 deletions ffi/executionengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ LLVMPY_EnableJITEvents(LLVMExecutionEngineRef EE)
llvm::unwrap(EE)->RegisterJITEventListener(listener);
result = true;
}
listener = llvm::JITEventListener::createPerfJITEventListener();
// if listener is null, then LLVM was not compiled with perf JIT events.
if (listener) {
llvm::unwrap(EE)->RegisterJITEventListener(listener);
printf("Perf listener registered\n");
result = true;
} else {
printf("Could not register Perf listener\n");
}

#endif
listener = llvm::JITEventListener::createIntelJITEventListener();
// if listener is null, then LLVM was not compiled for Intel JIT events.
Expand Down