-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ORC][JITLink] Add Intel VTune support to JITLink #83957
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
Conversation
This patch relands llvm#81826 This patch adds two plugins: VTuneSupportPlugin.cpp and JITLoaderVTune.cpp. The testing is done in a manner similar to llvm-jitlistener. Currently, we only support the old version of Intel VTune API.
Fixed the cyclic library dependency: llvm#83909
You can test this locally with the following command:git-clang-format --diff 564b81db8541468ce296d3bdcacab05b9581297c e7e6d8f4a2e268b633e613a17a4c1d20868e3332 -- llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h llvm/include/llvm/ExecutionEngine/Orc/Shared/VTuneSharedStructs.h llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.cpp llvm/tools/llvm-jitlink/llvm-jitlink.cpp View the diff from clang-format here.diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
index afb7df592f..52b9476947 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
@@ -27,5 +27,3 @@ extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_test_registerVTuneImpl(const char *Data, uint64_t Size);
#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_JITLOADERVTUNE_H
-
-
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the code, so I am just commenting on the code style...
ExecutorAddr RegisterVTuneImplAddr; | ||
ExecutorAddr UnregisterVTuneImplAddr; | ||
std::mutex PluginMutex; | ||
uint64_t NextMethodID{0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: = 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
ExecutorAddr UnregisterVTuneImplAddr; | ||
std::mutex PluginMutex; | ||
uint64_t NextMethodID{0}; | ||
DenseMap<MaterializationResponsibility *, std::pair<uint64_t, uint64_t>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include DenseMap for IWYU
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
VTuneStringTable Strings; | ||
}; | ||
|
||
typedef std::vector<std::pair<uint64_t, uint64_t>> VTuneUnloadedMethodIDs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: prefer using
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
using namespace llvm::orc; | ||
using namespace llvm::jitlink; | ||
|
||
namespace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://llvm.org/docs/CodingStandards.html#anonymous-namespaces
In .cpp, basically anonymous namespaces are only for struct
, class
, enum
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
@@ -2,10 +2,18 @@ if( CMAKE_HOST_UNIX AND HAVE_LIBRT ) | |||
set(rt_lib rt) | |||
endif() | |||
|
|||
set(intel_jit_profiling ) | |||
if( LLVM_USE_INTEL_JITEVENTS ) | |||
set(intel_jit_profiling IntelJITProfiling) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed~
using namespace llvm; | ||
using namespace llvm::orc; | ||
|
||
static std::unique_ptr<IntelJITEventsWrapper> Wrapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this global variable be placed into a context class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Fangrui, I fixed it into a context class, but I do not see the reason why we need a context class here because Wrapper
is only used in JITLoaderVTune.cpp
. Could you please elaborate more on it? Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to avoid a global state, more preferrable if the state can be shared between multiple threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Fixed! Please let me know if there is anything else I need to change.
|
||
// For Testing: following code comes from llvm-jitlistener.cpp in llvm tools | ||
namespace { | ||
typedef std::vector<std::pair<std::string, unsigned int>> SourceLocations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed~
@@ -0,0 +1,52 @@ | |||
# REQUIRES: native && x86_64-linux && intel-jitevents | |||
|
|||
# RUN: rm -rf %t && mkdir -p %t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove -p
since the file/directory is guaranteed to be absent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
# REQUIRES: native && x86_64-linux && intel-jitevents | ||
|
||
# RUN: rm -rf %t && mkdir -p %t | ||
# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove -position-independent
. Only mips/sparc use the option for some assembly design flaws.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
uint64_t NextMethodID{0}; | ||
DenseMap<MaterializationResponsibility *, std::pair<uint64_t, uint64_t>> | ||
PendingMethodIDs; | ||
DenseMap<ResourceKey, std::vector<std::pair<uint64_t, uint64_t>>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing std::vector<X>
with SmallVector<X, 0>
, since SmallVector
is smaller in size and is often more efficient. When used in another container like DenseMap
, the advantage of SmallVector is larger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it too!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments aside this looks great. Thank you for resolving the layering issue!
#ifndef LLVM_EXECUTIONENGINE_ORC_AMPLIFIERSUPPORTPLUGIN_H | ||
#define LLVM_EXECUTIONENGINE_ORC_AMPLIFIERSUPPORTPLUGIN_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The include guards should match the filename -- LLVM_EXECUTIONENGINE_ORC_DEBUGGING_VTUNESUPPORT_H
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
} // end namespace orc | ||
} // end namespace llvm | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @yugier!
This patch relands #81826
Note to reviewers: I split this pull requests in two commits. One for reland #81826 and the other one for fixing #83909. I'll squash those two into one once they are ready to be merged.
This patch adds two plugins: VTuneSupportPlugin.cpp and JITLoaderVTune.cpp. The testing is done in a manner similar to llvm-jitlistener. Currently, we only support the old version of Intel VTune API.