<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Eli,</div><div><br></div><div>This all looks pretty reasonable, although I confess I'm no expert on the Intel profiling libs.</div><div><br></div><div>Can you elaborate on why the support is a configure time option? I assume it's due to reference Intel headers and such? Assuming so, or something along those lines, we should not build the source files for the support at all when it's not configured, rather than using #if inside the files. That is, building the code or not should be handled by the build system, not via macros in the source. Specifically, I'd really like to avoid things like "#if USE_OPROFILE" around the contents of a .cpp file.</div><div><br></div><div>Specific, mostly just nitty details, comments inline. I'll generally explicitly comment only comment on the first instance of any recurring patterns to avoid bloating the email more than necessary. Please do go through and look for additional instances, though. Please format to fit within 80 columns. I'm seeing lots of lines longer than that in the patch. Likewise, there's a bit of trailing whitespace that should be removed. Mostly indentation on blank lines.</div><div><div><br></div></div><div>Lots of this is style stuff. See <a href="http://llvm.org/docs/CodingStandards.html">http://llvm.org/docs/CodingStandards.html</a> for the gory details.</div><div><br></div><div><div>(Chris: context sensitive question for you in the body of "OProfileWrapper")</div><div><br></div></div><div>Regards,</div><div>  Jim</div><div><br></div><div>ps, I still owe you a couple more emails on other JIT related stuff. Haven't forgotten!</div><div><br></div><div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#ifndef INTEL_JIT_EVENTS_WRAPPER_H</font></div><div><font class="Apple-style-span" color="#000000">+#define INTEL_JIT_EVENTS_WRAPPER_H</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "jitprofiling.h"</font></div></blockquote><div><br></div><div>This should use the <> style include since the file isn't in the current directory.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Function pointer types for testing implementation of Intel jitprofiling</font></div><div><font class="Apple-style-span" color="#000000">+// library</font></div><div><font class="Apple-style-span" color="#000000">+typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);</font></div><div><font class="Apple-style-span" color="#000000">+typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );</font></div><div><font class="Apple-style-span" color="#000000">+typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);</font></div><div><font class="Apple-style-span" color="#000000">+typedef void (*FinalizeThreadPtr)(void);</font></div><div><font class="Apple-style-span" color="#000000">+typedef void (*FinalizeProcessPtr)(void);</font></div><div><font class="Apple-style-span" color="#000000">+typedef unsigned int (*GetNewMethodIDPtr)(void);</font></div><div></div></blockquote><div><br></div><div>These should be members of the IntelJITEventsWrapper class, not out in the general llvm namespace.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class IntelJITEventsWrapper {</font></div><div><font class="Apple-style-span" color="#000000">+  NotifyEventPtr NotifyEventFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  RegisterCallbackExPtr RegisterCallbackExFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  IsProfilingActivePtr IsProfilingActiveFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  FinalizeThreadPtr FinalizeThreadFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  FinalizeProcessPtr FinalizeProcessFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  GetNewMethodIDPtr GetNewMethodIDFunc;</font></div></blockquote><div><br></div><div>Some brief comments on what these are for those not as familiar with the profiler would be awesome. Not a big deal, would just be a nice addition if it's not too much trouble.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+public:</font></div><div><font class="Apple-style-span" color="#000000">+  bool IsAmplifierRunning() {</font></div></blockquote><div><br></div><div>Function names start with a lower case letter.</div><div><br></div><div>On a side note, yes LLVM is very inconsistent about this at the moment. It's a recent(ish) change to the standards and the codebase hasn't been fully migrated over yet.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+    return IsProfilingActive() == iJIT_SAMPLING_ON;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  IntelJITEventsWrapper()</font></div><div><font class="Apple-style-span" color="#000000">+  : NotifyEventFunc(::iJIT_NotifyEvent)</font></div><div><font class="Apple-style-span" color="#000000">+  , RegisterCallbackExFunc(::iJIT_RegisterCallbackEx)</font></div><div><font class="Apple-style-span" color="#000000">+  , IsProfilingActiveFunc(::iJIT_IsProfilingActive)</font></div><div><font class="Apple-style-span" color="#000000">+  , FinalizeThreadFunc(::FinalizeThread)</font></div><div><font class="Apple-style-span" color="#000000">+  , FinalizeProcessFunc(::FinalizeProcess)</font></div><div><font class="Apple-style-span" color="#000000">+  , GetNewMethodIDFunc(::iJIT_GetNewMethodID) {</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  IntelJITEventsWrapper(NotifyEventPtr notify_event_impl,</font></div><div><font class="Apple-style-span" color="#000000">+                   RegisterCallbackExPtr register_callback_ex_impl,</font></div><div><font class="Apple-style-span" color="#000000">+                   IsProfilingActivePtr is_profiling_active_impl,</font></div><div><font class="Apple-style-span" color="#000000">+                   FinalizeThreadPtr finalize_thread_impl,</font></div><div><font class="Apple-style-span" color="#000000">+                   FinalizeProcessPtr finalize_process_impl,</font></div><div><font class="Apple-style-span" color="#000000">+                   GetNewMethodIDPtr get_new_method_id_impl)</font></div><div><font class="Apple-style-span" color="#000000">+  : NotifyEventFunc(notify_event_impl)</font></div><div><font class="Apple-style-span" color="#000000">+  , RegisterCallbackExFunc(register_callback_ex_impl)</font></div><div><font class="Apple-style-span" color="#000000">+  , IsProfilingActiveFunc(is_profiling_active_impl)</font></div><div><font class="Apple-style-span" color="#000000">+  , FinalizeThreadFunc(finalize_thread_impl)</font></div><div><font class="Apple-style-span" color="#000000">+  , FinalizeProcessFunc(finalize_process_impl)</font></div><div><font class="Apple-style-span" color="#000000">+  , GetNewMethodIDFunc(get_new_method_id_impl) {</font></div></blockquote><div><br></div><div>Commas on preceding line, not at the start of the next line.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  int  NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (0 == NotifyEventFunc) {</font></div></blockquote><div><br></div><div>LLVM style is to put the constant value on the right hand side and use the compiler warnings to catch inadvertant misuse of the assignment vs. the comparison operators.</div><div><br></div><div>For NULL comparisons of pointers, it's OK to just have "if (ptrval)" as well.</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+      return -1;</font></div><div></div></blockquote><div><br></div>When there's only a single statement, in particular a single line statement, following an 'if', 'for', 'while', et. al., LLVM style is to not use a compound statement unless necessary to make control flow (nested 'if' statements, e.g.) clear.</div><div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+    } else {</font></div></blockquote><div><br></div><div>No need to have this in an 'else' clause at all since the 'true' clause doesn't fall through.</div><div><br></div><div>i.e., something like:</div><div>int NotifyEvent(…) {</div><div>  if (NotifyEventFunc)</div><div>    return -1;</div><div>  return NotifiyEventFunc(…);</div><div>}</div><div><br></div><div>Similarly for the other functions.</div><div><br></div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+      return NotifyEventFunc(EventType, EventSpecificData);'</font></div></blockquote><div><br></div><div>I gather the normal function returns more than just a success/failure code? If it's just a zero/non-zero for success vs. failure like lots of C interfaces, we should convert that to a bool for LLVM's C++ wrappers.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+    }</font></div></blockquote><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void RegisterCallbackEx(void *userdata, iJIT_ModeChangedEx NewModeCallBackFuncEx) {</font></div></blockquote><div><br></div><div>"userdata" should be "UserData". Camelcase variable names starting w/ a capital.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+    if (0 != RegisterCallbackExFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+      RegisterCallbackExFunc(userdata, NewModeCallBackFuncEx);</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  iJIT_IsProfilingActiveFlags IsProfilingActive(void) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (0 == IsProfilingActiveFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+      // No jitprofiling library connection, so report nothing running</font></div><div><font class="Apple-style-span" color="#000000">+      return iJIT_NOTHING_RUNNING;</font></div><div><font class="Apple-style-span" color="#000000">+    } else {</font></div><div><font class="Apple-style-span" color="#000000">+      return IsProfilingActiveFunc();</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void FinalizeThread(void) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (0 != FinalizeThreadFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+      FinalizeThreadFunc();</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void FinalizeProcess(void) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (0 != FinalizeProcessFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+      FinalizeProcessFunc();</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  unsigned int GetNewMethodID(void) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (0 == GetNewMethodIDFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+      return -1;</font></div><div><font class="Apple-style-span" color="#000000">+    } else {</font></div><div><font class="Apple-style-span" color="#000000">+      return GetNewMethodIDFunc();</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} //namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //INTEL_JIT_EVENTS_WRAPPER_H</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/include/llvm/ExecutionEngine/JITEventListener.h b/include/llvm/ExecutionEngine/JITEventListener.h</font></div><div><font class="Apple-style-span" color="#000000">index 94212e1..b41ab79 100644</font></div><div><font class="Apple-style-span" color="#000000">--- a/include/llvm/ExecutionEngine/JITEventListener.h</font></div><div><font class="Apple-style-span" color="#000000">+++ b/include/llvm/ExecutionEngine/JITEventListener.h</font></div><div><font class="Apple-style-span" color="#000000">@@ -74,9 +74,22 @@ public:</font></div><div><font class="Apple-style-span" color="#000000">   virtual void NotifyFreeingMachineCode(void *) {}</font></div><div><font class="Apple-style-span" color="#000000"> };</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">-// This returns NULL if support isn't available.</font></div><div><font class="Apple-style-span" color="#000000">+// Construct an OProfileJITEventListener</font></div><div><font class="Apple-style-span" color="#000000"> JITEventListener *createOProfileJITEventListener();</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">+// Construct an IntelJITEventListener</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createIntelJITEventListener();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class OProfileWrapper;</font></div></blockquote><div><br></div><div>Forward class declarations should go at the top of the header file, not interspersed throughout immediately prior to usage.</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Construct an OProfileJITEventListener with a test opagent implementation</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createOProfileJITEventListener(OProfileWrapper* alternativeImpl);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class IntelJITEventsWrapper;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Construct an IntelJITEventListener with a test Intel JIT API implementation</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createIntelJITEventListener(IntelJITEventsWrapper* alternativeImpl);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div></blockquote><div><br></div><div>It strikes me that these might be better as static method on the relevant classes, if that's possible. i.e.,</div><div>JITEventListener *OProfileWrapper::Create(…);</div><div><br></div><div>I don't know the details of how these are used well enough to know for sure, but that would be good if it's a reasonable alternative.</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000"> } // end namespace llvm.</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> #endif</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/include/llvm/ExecutionEngine/OProfileWrapper.h b/include/llvm/ExecutionEngine/OProfileWrapper.h</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..a7533ee</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/include/llvm/ExecutionEngine/OProfileWrapper.h</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,118 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===-- OProfileWrapper.h - OProfile JIT API Wrapper -------------*- C++ -*-===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+// This file defines a OProfileWrapper object that detects if the oprofile</font></div><div><font class="Apple-style-span" color="#000000">+// daemon is running, and provides wrappers for opagent functions used to</font></div><div><font class="Apple-style-span" color="#000000">+// communicate with the oprofile JIT interface. The dynamic library libopagent</font></div><div><font class="Apple-style-span" color="#000000">+// does not need to be linked directly as this object lazily loads the library</font></div><div><font class="Apple-style-span" color="#000000">+// when the first op_ function is called.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// See <a href="http://oprofile.sourceforge.net/doc/devel/jit-interface.html">http://oprofile.sourceforge.net/doc/devel/jit-interface.html</a> for the</font></div><div><font class="Apple-style-span" color="#000000">+// definition of the interface.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#ifndef OPROFILE_WRAPPER_H</font></div><div><font class="Apple-style-span" color="#000000">+#define OPROFILE_WRAPPER_H</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#if USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include <stdint.h></font></div><div><font class="Apple-style-span" color="#000000">+#include <opagent.h></font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+typedef  op_agent_t    (*op_open_agent_ptr_t)();</font></div><div><font class="Apple-style-span" color="#000000">+typedef  int           (*op_close_agent_ptr_t)(op_agent_t);</font></div><div><font class="Apple-style-span" color="#000000">+typedef  int           (*op_write_native_code_ptr_t)(op_agent_t, const char*, uint64_t, void const*, const unsigned int);</font></div><div><font class="Apple-style-span" color="#000000">+typedef  int           (*op_write_debug_line_info_ptr_t)(op_agent_t, void const*, size_t, struct debug_line_info const*);</font></div><div><font class="Apple-style-span" color="#000000">+typedef  int           (*op_unload_native_code_ptr_t)(op_agent_t, uint64_t);</font></div></blockquote><div><br></div><div>Move into the OProfileWrapper class. Change to adhere to the LLVM naming conventions. (see below)</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Also used for op_minor_version function which has the same signature</font></div><div><font class="Apple-style-span" color="#000000">+typedef  int           (*op_major_version_ptr_t)(void);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// This is not a part of the opagent API, but is useful nonetheless</font></div><div><font class="Apple-style-span" color="#000000">+typedef  bool          (*IsOProfileRunningPtrT)(void);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class OProfileWrapper {</font></div><div><font class="Apple-style-span" color="#000000">+  op_agent_t                      Agent;</font></div><div><font class="Apple-style-span" color="#000000">+  op_open_agent_ptr_t             OpenAgentFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  op_close_agent_ptr_t            CloseAgentFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  op_write_native_code_ptr_t      WriteNativeCodeFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  op_write_debug_line_info_ptr_t  WriteDebugLineInfoFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  op_unload_native_code_ptr_t     UnloadNativeCodeFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  op_major_version_ptr_t          MajorVersionFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  op_major_version_ptr_t          MinorVersionFunc;</font></div><div><font class="Apple-style-span" color="#000000">+  IsOProfileRunningPtrT           IsOProfileRunningFunc;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  bool Initialized;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+public:</font></div><div><font class="Apple-style-span" color="#000000">+  OProfileWrapper();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  //For testing with a mock opagent implementation, skips the dynamic load and the function</font></div><div><font class="Apple-style-span" color="#000000">+  //resolution.</font></div><div><font class="Apple-style-span" color="#000000">+  OProfileWrapper(op_open_agent_ptr_t OpenAgentImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  op_close_agent_ptr_t CloseAgentImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  op_write_native_code_ptr_t WriteNativeCodeImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  op_write_debug_line_info_ptr_t WriteDebugLineInfoImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  op_unload_native_code_ptr_t UnloadNativeCodeImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  op_major_version_ptr_t MajorVersionImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  op_major_version_ptr_t MinorVersionImpl,</font></div><div><font class="Apple-style-span" color="#000000">+                  IsOProfileRunningPtrT MockIsOProfileRunningImpl = 0)</font></div><div><font class="Apple-style-span" color="#000000">+  : OpenAgentFunc(OpenAgentImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , CloseAgentFunc(CloseAgentImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , WriteNativeCodeFunc(WriteNativeCodeImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , WriteDebugLineInfoFunc(WriteDebugLineInfoImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , UnloadNativeCodeFunc(UnloadNativeCodeImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , MajorVersionFunc(MajorVersionImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , MinorVersionFunc(MinorVersionImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , IsOProfileRunningFunc(MockIsOProfileRunningImpl)</font></div><div><font class="Apple-style-span" color="#000000">+  , Initialized(true)</font></div><div><font class="Apple-style-span" color="#000000">+  {</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // Calls op_open_agent in the oprofile JIT library and saves the returned op_agent_t</font></div><div><font class="Apple-style-span" color="#000000">+  // handle internally so it can be used when calling all the other op_* functions. Callers</font></div><div><font class="Apple-style-span" color="#000000">+  // of this class do not need to keep track of op_agent_t objects.</font></div><div><font class="Apple-style-span" color="#000000">+  bool open_agent();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  int close_agent();</font></div><div><font class="Apple-style-span" color="#000000">+  int write_native_code(const char* name,</font></div><div><font class="Apple-style-span" color="#000000">+                        uint64_t addr,</font></div><div><font class="Apple-style-span" color="#000000">+                        void const* code,</font></div><div><font class="Apple-style-span" color="#000000">+                        const unsigned int size);</font></div><div><font class="Apple-style-span" color="#000000">+  int write_debug_line_info(void const* code,</font></div><div><font class="Apple-style-span" color="#000000">+                            size_t num_entries,</font></div><div><font class="Apple-style-span" color="#000000">+                            struct debug_line_info const* info);</font></div><div><font class="Apple-style-span" color="#000000">+  int unload_native_code(uint64_t addr);</font></div><div><font class="Apple-style-span" color="#000000">+  int major_version(void);</font></div><div><font class="Apple-style-span" color="#000000">+  int minor_version(void);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // Returns true if the oprofiled process is running, the opagent library is loaded</font></div><div><font class="Apple-style-span" color="#000000">+  // and a connection to the agent has been established, and false otherwise.</font></div><div><font class="Apple-style-span" color="#000000">+  bool have_agent();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div></blockquote><br><div>These are wrappers for API functions of the same names in the Intel library, I gather? I can see why that would be clearer to have them be identical even though it means the names aren't following the LLVM conventions. I don't have a strong opinion either way. Chris will be better able to guide us here.</div><div><br></div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+private:</font></div><div><font class="Apple-style-span" color="#000000">+  // Loads the libopagent library and initializes this wrapper if the oprofile</font></div><div><font class="Apple-style-span" color="#000000">+  // daemon is running</font></div><div><font class="Apple-style-span" color="#000000">+  bool initialize();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // Searches /proc for the oprofile daemon and returns true if the process if</font></div><div><font class="Apple-style-span" color="#000000">+  // found, or false otherwise.</font></div><div><font class="Apple-style-span" color="#000000">+  bool CheckForOProfileProcEntry();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  bool IsOProfileRunning();</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //OPROFILE_WRAPPER_H</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/lib/ExecutionEngine/JIT/EventListenerCommon.h b/lib/ExecutionEngine/JIT/EventListenerCommon.h</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..9ef71cd</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/lib/ExecutionEngine/JIT/EventListenerCommon.h</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,63 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===-- JIT.h - Abstract Execution Engine Interface -------------*- C++ -*-===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// Common functionality for JITEventListener implementations</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#ifndef EVENT_LISTENER_COMMON_H</font></div><div><font class="Apple-style-span" color="#000000">+#define EVENT_LISTENER_COMMON_H</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Metadata.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Analysis/DebugInfo.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ADT/DenseMap.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/ValueHandle.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/Path.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class FilenameCache {</font></div><div></div></blockquote><div><br></div><div>This should probably either get a less generic name since it's in a header now, or, probably better, be put in a dedicated profiler namespace.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+  // Holds the filename of each Scope, so that we can pass a null-terminated</font></div><div><font class="Apple-style-span" color="#000000">+  // string into oprofile.  Use an AssertingVH rather than a ValueMap because we</font></div><div><font class="Apple-style-span" color="#000000">+  // shouldn't be modifying any MDNodes while this map is alive.</font></div><div><font class="Apple-style-span" color="#000000">+  DenseMap<AssertingVH<MDNode>, std::string> Filenames;</font></div><div><font class="Apple-style-span" color="#000000">+  DenseMap<AssertingVH<MDNode>, std::string> Paths;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+ public:</font></div><div><font class="Apple-style-span" color="#000000">+  const char *getFilename(MDNode *Scope) {</font></div><div><font class="Apple-style-span" color="#000000">+    std::string &Filename = Filenames[Scope];</font></div><div><font class="Apple-style-span" color="#000000">+    if (Filename.empty()) {</font></div><div><font class="Apple-style-span" color="#000000">+      DIScope di_scope(Scope);</font></div><div><font class="Apple-style-span" color="#000000">+      Filename = di_scope.getFilename();</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+    return Filename.c_str();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  const char *getFullPath(MDNode *Scope) {</font></div><div><font class="Apple-style-span" color="#000000">+    std::string &P = Paths[Scope];</font></div><div><font class="Apple-style-span" color="#000000">+    if (P.empty()) {</font></div><div><font class="Apple-style-span" color="#000000">+      DIScope di_scope(Scope);</font></div><div><font class="Apple-style-span" color="#000000">+      StringRef dir_name = di_scope.getDirectory();</font></div><div><font class="Apple-style-span" color="#000000">+      StringRef file_name = di_scope.getFilename();</font></div><div><font class="Apple-style-span" color="#000000">+      SmallString<256> full_path;</font></div><div><font class="Apple-style-span" color="#000000">+      if (dir_name != "." && dir_name != "") {</font></div><div><font class="Apple-style-span" color="#000000">+        full_path = dir_name;</font></div><div><font class="Apple-style-span" color="#000000">+      }</font></div><div><font class="Apple-style-span" color="#000000">+      if (file_name != "") {</font></div><div><font class="Apple-style-span" color="#000000">+        sys::path::append(full_path, file_name);</font></div><div><font class="Apple-style-span" color="#000000">+      }</font></div><div><font class="Apple-style-span" color="#000000">+      P = full_path.str();</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+    return P.c_str();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //EVENT_LISTENER_COMMON_H</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/lib/ExecutionEngine/JIT/IntelJITEventListener.cpp b/lib/ExecutionEngine/JIT/IntelJITEventListener.cpp</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..b77017c</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/lib/ExecutionEngine/JIT/IntelJITEventListener.cpp</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,201 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===-- IntelJITEventListener.cpp - Tell Parallel Amplifier XE about JITted code ----===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file defines a JITEventListener object to tell Intel(R) VTune(TM)</font></div><div><font class="Apple-style-span" color="#000000">+// Amplifier XE 2011 about JITted functions.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Config/config.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#if USE_INTEL_JITEVENTS</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#define DEBUG_TYPE "amplifier-jit-event-listener"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Function.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Metadata.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ADT/DenseMap.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ADT/OwningPtr.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Analysis/DebugInfo.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/CodeGen/MachineFunction.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/JITEventListener.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/Debug.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/raw_ostream.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/Errno.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/ValueHandle.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "EventListenerCommon.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class IntelJITEventListener : public JITEventListener {</font></div><div><font class="Apple-style-span" color="#000000">+  typedef DenseMap<void*, unsigned int> method_id_map_t;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  IntelJITEventsWrapper& Wrapper;</font></div><div><font class="Apple-style-span" color="#000000">+  method_id_map_t MethodIDs;</font></div><div><font class="Apple-style-span" color="#000000">+  FilenameCache Filenames;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+public:</font></div><div><font class="Apple-style-span" color="#000000">+  IntelJITEventListener(IntelJITEventsWrapper& libraryWrapper)</font></div><div><font class="Apple-style-span" color="#000000">+  : Wrapper(libraryWrapper) {</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  ~IntelJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  virtual void NotifyFunctionEmitted(const Function &F,</font></div><div><font class="Apple-style-span" color="#000000">+                                     void *FnStart, size_t FnSize,</font></div><div><font class="Apple-style-span" color="#000000">+                                     const EmittedFunctionDetails &Details);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  virtual void NotifyFreeingMachineCode(void *OldPtr);</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+static LineNumberInfo LineStartToIntelJITFormat(</font></div><div><font class="Apple-style-span" color="#000000">+    uintptr_t StartAddress,</font></div><div><font class="Apple-style-span" color="#000000">+    uintptr_t Address,</font></div><div><font class="Apple-style-span" color="#000000">+    DebugLoc Loc) {</font></div><div><font class="Apple-style-span" color="#000000">+  LineNumberInfo Result;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  Result.Offset = Address - StartAddress;</font></div><div><font class="Apple-style-span" color="#000000">+  Result.LineNumber = Loc.getLine();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  return Result;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+static iJIT_Method_Load FunctionDescToIntelJITFormat(</font></div><div><font class="Apple-style-span" color="#000000">+    IntelJITEventsWrapper& Wrapper,</font></div><div><font class="Apple-style-span" color="#000000">+    const char* FnName,</font></div><div><font class="Apple-style-span" color="#000000">+    uintptr_t FnStart,</font></div><div><font class="Apple-style-span" color="#000000">+    size_t FnSize) {</font></div><div><font class="Apple-style-span" color="#000000">+  iJIT_Method_Load Result;</font></div><div><font class="Apple-style-span" color="#000000">+  memset(&Result, 0, sizeof(iJIT_Method_Load));</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  Result.method_id = Wrapper.GetNewMethodID();</font></div><div><font class="Apple-style-span" color="#000000">+  Result.method_name = const_cast<char*>(FnName);</font></div><div><font class="Apple-style-span" color="#000000">+  Result.method_load_address = reinterpret_cast<void*>(FnStart);</font></div><div><font class="Apple-style-span" color="#000000">+  Result.method_size = FnSize;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  Result.class_id = 0;</font></div><div><font class="Apple-style-span" color="#000000">+  Result.class_file_name = NULL;</font></div><div><font class="Apple-style-span" color="#000000">+  Result.user_data = NULL;</font></div><div><font class="Apple-style-span" color="#000000">+  Result.user_data_size = 0;</font></div><div><font class="Apple-style-span" color="#000000">+  Result.env = iJDE_JittingAPI;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  return Result;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Adds the just-emitted function to the symbol table.</font></div><div><font class="Apple-style-span" color="#000000">+void IntelJITEventListener::NotifyFunctionEmitted(</font></div><div><font class="Apple-style-span" color="#000000">+    const Function &F, void *FnStart, size_t FnSize,</font></div><div><font class="Apple-style-span" color="#000000">+    const EmittedFunctionDetails &Details) {</font></div><div><font class="Apple-style-span" color="#000000">+  iJIT_Method_Load functionMessage = FunctionDescToIntelJITFormat(Wrapper,</font></div><div><font class="Apple-style-span" color="#000000">+                                      F.getName().data(),</font></div><div><font class="Apple-style-span" color="#000000">+                                      reinterpret_cast<uint64_t>(FnStart),</font></div><div><font class="Apple-style-span" color="#000000">+                                      FnSize);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  std::vector<LineNumberInfo> LineInfo;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Details.LineStarts.empty()) {</font></div><div><font class="Apple-style-span" color="#000000">+    // Now convert the line number information from the address/DebugLoc</font></div><div><font class="Apple-style-span" color="#000000">+    // format in Details to the offset/lineno in Intel JIT API format.</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    LineInfo.reserve(Details.LineStarts.size() + 1);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    DebugLoc FirstLoc = Details.LineStarts[0].Loc;</font></div><div><font class="Apple-style-span" color="#000000">+    assert(!FirstLoc.isUnknown()</font></div><div><font class="Apple-style-span" color="#000000">+           && "LineStarts should not contain unknown DebugLocs");</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    MDNode *FirstLocScope = FirstLoc.getScope(F.getContext());</font></div><div><font class="Apple-style-span" color="#000000">+    DISubprogram FunctionDI = getDISubprogram(FirstLocScope);</font></div><div><font class="Apple-style-span" color="#000000">+    if (FunctionDI.Verify()) {</font></div><div><font class="Apple-style-span" color="#000000">+      functionMessage.source_file_name = const_cast<char*>(</font></div><div><font class="Apple-style-span" color="#000000">+                                          Filenames.getFullPath(FirstLocScope));</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+      LineNumberInfo first_line;</font></div><div><font class="Apple-style-span" color="#000000">+      first_line.Offset = 0;</font></div><div><font class="Apple-style-span" color="#000000">+      first_line.LineNumber = FunctionDI.getLineNumber();</font></div><div><font class="Apple-style-span" color="#000000">+      LineInfo.push_back(first_line);</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    for (std::vector<EmittedFunctionDetails::LineStart>::const_iterator I =</font></div><div><font class="Apple-style-span" color="#000000">+          Details.LineStarts.begin(), E = Details.LineStarts.end();</font></div><div><font class="Apple-style-span" color="#000000">+          I != E; ++I) {</font></div><div><font class="Apple-style-span" color="#000000">+      // This implementation ignores the DebugLoc filename because the Intel</font></div><div><font class="Apple-style-span" color="#000000">+      // JIT API does not support multiple source files associated with a single</font></div><div><font class="Apple-style-span" color="#000000">+      // JIT function</font></div><div><font class="Apple-style-span" color="#000000">+      LineInfo.push_back(LineStartToIntelJITFormat(</font></div><div><font class="Apple-style-span" color="#000000">+                          reinterpret_cast<uintptr_t>(FnStart),</font></div><div><font class="Apple-style-span" color="#000000">+                          I->Address,</font></div><div><font class="Apple-style-span" color="#000000">+                          I->Loc));</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+      // If we have no file name yet for the function, use the filename from</font></div><div><font class="Apple-style-span" color="#000000">+      // the first instruction that has one</font></div><div><font class="Apple-style-span" color="#000000">+      if (0 == functionMessage.source_file_name) {</font></div><div><font class="Apple-style-span" color="#000000">+        MDNode* scope = I->Loc.getScope(Details.MF->getFunction()->getContext());</font></div><div><font class="Apple-style-span" color="#000000">+        functionMessage.source_file_name = const_cast<char*>(Filenames.getFullPath(scope));</font></div><div><font class="Apple-style-span" color="#000000">+      }</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    functionMessage.line_number_size = LineInfo.size();</font></div><div><font class="Apple-style-span" color="#000000">+    functionMessage.line_number_table = &*LineInfo.begin();</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    functionMessage.line_number_size = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    functionMessage.line_number_table = 0;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  Wrapper.NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &functionMessage);</font></div><div><font class="Apple-style-span" color="#000000">+  MethodIDs[FnStart] = functionMessage.method_id;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+void IntelJITEventListener::NotifyFreeingMachineCode(void *FnStart) {</font></div><div><font class="Apple-style-span" color="#000000">+  method_id_map_t::iterator i = MethodIDs.find(FnStart);</font></div><div><font class="Apple-style-span" color="#000000">+  if (i != MethodIDs.end()) {</font></div><div><font class="Apple-style-span" color="#000000">+    Wrapper.NotifyEvent(iJVM_EVENT_TYPE_METHOD_UNLOAD_START, &i->second);</font></div><div><font class="Apple-style-span" color="#000000">+    MethodIDs.erase(i);</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+}  // anonymous namespace.</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createIntelJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">+  static OwningPtr<IntelJITEventsWrapper> jitprofilingWrapper(</font></div><div><font class="Apple-style-span" color="#000000">+                                            new IntelJITEventsWrapper);</font></div><div><font class="Apple-style-span" color="#000000">+  return new IntelJITEventListener(*jitprofilingWrapper);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// for testing</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createIntelJITEventListener(IntelJITEventsWrapper* test_impl) {</font></div><div><font class="Apple-style-span" color="#000000">+  return new IntelJITEventListener(*test_impl);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#else  // USE_INTEL_JITEVENTS</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class IntelJITEventsWrapper;</font></div><div><font class="Apple-style-span" color="#000000">+class JITEventListener;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// By defining this to return NULL, we can let clients call it unconditionally,</font></div><div><font class="Apple-style-span" color="#000000">+// even if they haven't configured the build with the Intel JIT API support</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createIntelJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createIntelJITEventListener(IntelJITEventsWrapper* test_impl) {</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+}  // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif  // USE_INTEL_JITEVENTS</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp b/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp</font></div><div><font class="Apple-style-span" color="#000000">index 9a9ed6d..803b475 100644</font></div><div><font class="Apple-style-span" color="#000000">--- a/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp</font></div><div><font class="Apple-style-span" color="#000000">+++ b/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp</font></div><div><font class="Apple-style-span" color="#000000">@@ -7,51 +7,56 @@</font></div><div><font class="Apple-style-span" color="#000000"> //</font></div><div><font class="Apple-style-span" color="#000000"> //===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000"> //</font></div><div><font class="Apple-style-span" color="#000000">-// This file defines a JITEventListener object that calls into OProfile to tell</font></div><div><font class="Apple-style-span" color="#000000">-// it about JITted functions.  For now, we only record function names and sizes,</font></div><div><font class="Apple-style-span" color="#000000">-// but eventually we'll also record line number information.</font></div><div><font class="Apple-style-span" color="#000000">-//</font></div><div><font class="Apple-style-span" color="#000000">-// See <a href="http://oprofile.sourceforge.net/doc/devel/jit-interface.html">http://oprofile.sourceforge.net/doc/devel/jit-interface.html</a> for the</font></div><div><font class="Apple-style-span" color="#000000">-// definition of the interface we're using.</font></div><div><font class="Apple-style-span" color="#000000">+// This file defines a JITEventListener object that uses OProfileWrapper to tell</font></div><div><font class="Apple-style-span" color="#000000">+// oprofile about JITted functions, including source line information.</font></div><div><font class="Apple-style-span" color="#000000"> //</font></div><div><font class="Apple-style-span" color="#000000"> //===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Config/config.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#if USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000"> #define DEBUG_TYPE "oprofile-jit-event-listener"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/Function.h"</font></div><div><font class="Apple-style-span" color="#000000">-#include "llvm/Metadata.h"</font></div><div><font class="Apple-style-span" color="#000000">-#include "llvm/ADT/DenseMap.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ADT/OwningPtr.h"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/Analysis/DebugInfo.h"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/CodeGen/MachineFunction.h"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/ExecutionEngine/JITEventListener.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/OProfileWrapper.h"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/Support/Debug.h"</font></div><div><font class="Apple-style-span" color="#000000">-#include "llvm/Support/ValueHandle.h"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/Support/raw_ostream.h"</font></div><div><font class="Apple-style-span" color="#000000"> #include "llvm/Support/Errno.h"</font></div><div><font class="Apple-style-span" color="#000000">-#include "llvm/Config/config.h"</font></div><div><font class="Apple-style-span" color="#000000">-#include <stddef.h></font></div><div><font class="Apple-style-span" color="#000000">-using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000">+#include "EventListenerCommon.h"</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">-#if USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+#include <dirent.h></font></div><div><font class="Apple-style-span" color="#000000">+#include <fcntl.h></font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">-#include <opagent.h></font></div><div><font class="Apple-style-span" color="#000000">+using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> namespace {</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> class OProfileJITEventListener : public JITEventListener {</font></div><div><font class="Apple-style-span" color="#000000">-  op_agent_t Agent;</font></div><div><font class="Apple-style-span" color="#000000">+  OProfileWrapper& Wrapper;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void initialize();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000"> public:</font></div><div><font class="Apple-style-span" color="#000000">-  OProfileJITEventListener();</font></div><div><font class="Apple-style-span" color="#000000">+  OProfileJITEventListener(OProfileWrapper& libraryWrapper)</font></div><div><font class="Apple-style-span" color="#000000">+  : Wrapper(libraryWrapper) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">   ~OProfileJITEventListener();</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">   virtual void NotifyFunctionEmitted(const Function &F,</font></div><div><font class="Apple-style-span" color="#000000">                                      void *FnStart, size_t FnSize,</font></div><div><font class="Apple-style-span" color="#000000">-                                     const EmittedFunctionDetails &Details);</font></div><div><font class="Apple-style-span" color="#000000">+                                     const JITEvent_EmittedFunctionDetails &Details);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">   virtual void NotifyFreeingMachineCode(void *OldPtr);</font></div><div><font class="Apple-style-span" color="#000000"> };</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">-OProfileJITEventListener::OProfileJITEventListener()</font></div><div><font class="Apple-style-span" color="#000000">-    : Agent(op_open_agent()) {</font></div><div><font class="Apple-style-span" color="#000000">-  if (Agent == NULL) {</font></div><div><font class="Apple-style-span" color="#000000">+void OProfileJITEventListener::initialize() {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Wrapper.open_agent()) {</font></div><div><font class="Apple-style-span" color="#000000">     const std::string err_str = sys::StrError();</font></div><div><font class="Apple-style-span" color="#000000">     DEBUG(dbgs() << "Failed to connect to OProfile agent: " << err_str << "\n");</font></div><div><font class="Apple-style-span" color="#000000">   } else {</font></div><div><font class="Apple-style-span" color="#000000">@@ -60,8 +65,8 @@ OProfileJITEventListener::OProfileJITEventListener()</font></div><div><font class="Apple-style-span" color="#000000"> }</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> OProfileJITEventListener::~OProfileJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">-  if (Agent != NULL) {</font></div><div><font class="Apple-style-span" color="#000000">-    if (op_close_agent(Agent) == -1) {</font></div><div><font class="Apple-style-span" color="#000000">+  if (Wrapper.have_agent()) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (Wrapper.close_agent() == -1) {</font></div><div><font class="Apple-style-span" color="#000000">       const std::string err_str = sys::StrError();</font></div><div><font class="Apple-style-span" color="#000000">       DEBUG(dbgs() << "Failed to disconnect from OProfile agent: "</font></div><div><font class="Apple-style-span" color="#000000">                    << err_str << "\n");</font></div><div><font class="Apple-style-span" color="#000000">@@ -71,22 +76,6 @@ OProfileJITEventListener::~OProfileJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">   }</font></div><div><font class="Apple-style-span" color="#000000"> }</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">-class FilenameCache {</font></div><div><font class="Apple-style-span" color="#000000">-  // Holds the filename of each Scope, so that we can pass a null-terminated</font></div><div><font class="Apple-style-span" color="#000000">-  // string into oprofile.  Use an AssertingVH rather than a ValueMap because we</font></div><div><font class="Apple-style-span" color="#000000">-  // shouldn't be modifying any MDNodes while this map is alive.</font></div><div><font class="Apple-style-span" color="#000000">-  DenseMap<AssertingVH<MDNode>, std::string> Filenames;</font></div><div><font class="Apple-style-span" color="#000000">-</font></div><div><font class="Apple-style-span" color="#000000">- public:</font></div><div><font class="Apple-style-span" color="#000000">-  const char *getFilename(MDNode *Scope) {</font></div><div><font class="Apple-style-span" color="#000000">-    std::string &Filename = Filenames[Scope];</font></div><div><font class="Apple-style-span" color="#000000">-    if (Filename.empty()) {</font></div><div><font class="Apple-style-span" color="#000000">-      Filename = DIScope(Scope).getFilename();</font></div><div><font class="Apple-style-span" color="#000000">-    }</font></div><div><font class="Apple-style-span" color="#000000">-    return Filename.c_str();</font></div><div><font class="Apple-style-span" color="#000000">-  }</font></div><div><font class="Apple-style-span" color="#000000">-};</font></div><div><font class="Apple-style-span" color="#000000">-</font></div><div><font class="Apple-style-span" color="#000000"> static debug_line_info LineStartToOProfileFormat(</font></div><div><font class="Apple-style-span" color="#000000">     const MachineFunction &MF, FilenameCache &Filenames,</font></div><div><font class="Apple-style-span" color="#000000">     uintptr_t Address, DebugLoc Loc) {</font></div><div><font class="Apple-style-span" color="#000000">@@ -103,9 +92,9 @@ static debug_line_info LineStartToOProfileFormat(</font></div><div><font class="Apple-style-span" color="#000000"> // Adds the just-emitted function to the symbol table.</font></div><div><font class="Apple-style-span" color="#000000"> void OProfileJITEventListener::NotifyFunctionEmitted(</font></div><div><font class="Apple-style-span" color="#000000">     const Function &F, void *FnStart, size_t FnSize,</font></div><div><font class="Apple-style-span" color="#000000">-    const EmittedFunctionDetails &Details) {</font></div><div><font class="Apple-style-span" color="#000000">+    const JITEvent_EmittedFunctionDetails &Details) {</font></div><div><font class="Apple-style-span" color="#000000">   assert(F.hasName() && FnStart != 0 && "Bad symbol to add");</font></div><div><font class="Apple-style-span" color="#000000">-  if (op_write_native_code(Agent, F.getName().data(),</font></div><div><font class="Apple-style-span" color="#000000">+  if (Wrapper.write_native_code(F.getName().data(),</font></div><div><font class="Apple-style-span" color="#000000">                            reinterpret_cast<uint64_t>(FnStart),</font></div><div><font class="Apple-style-span" color="#000000">                            FnStart, FnSize) == -1) {</font></div><div><font class="Apple-style-span" color="#000000">     DEBUG(dbgs() << "Failed to tell OProfile about native function "</font></div><div><font class="Apple-style-span" color="#000000">@@ -151,8 +140,8 @@ void OProfileJITEventListener::NotifyFunctionEmitted(</font></div><div><font class="Apple-style-span" color="#000000">     // line info's address to include the start of the function.</font></div><div><font class="Apple-style-span" color="#000000">     LineInfo[0].vma = reinterpret_cast<uintptr_t>(FnStart);</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">-    if (op_write_debug_line_info(Agent, FnStart,</font></div><div><font class="Apple-style-span" color="#000000">-                                 LineInfo.size(), &*LineInfo.begin()) == -1) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (Wrapper.write_debug_line_info(FnStart, LineInfo.size(),</font></div><div><font class="Apple-style-span" color="#000000">+                                      &*LineInfo.begin()) == -1) {</font></div><div><font class="Apple-style-span" color="#000000">       DEBUG(dbgs()</font></div><div><font class="Apple-style-span" color="#000000">             << "Failed to tell OProfile about line numbers for native function "</font></div><div><font class="Apple-style-span" color="#000000">             << F.getName() << " at ["</font></div><div><font class="Apple-style-span" color="#000000">@@ -164,7 +153,7 @@ void OProfileJITEventListener::NotifyFunctionEmitted(</font></div><div><font class="Apple-style-span" color="#000000"> // Removes the being-deleted function from the symbol table.</font></div><div><font class="Apple-style-span" color="#000000"> void OProfileJITEventListener::NotifyFreeingMachineCode(void *FnStart) {</font></div><div><font class="Apple-style-span" color="#000000">   assert(FnStart && "Invalid function pointer");</font></div><div><font class="Apple-style-span" color="#000000">-  if (op_unload_native_code(Agent, reinterpret_cast<uint64_t>(FnStart)) == -1) {</font></div><div><font class="Apple-style-span" color="#000000">+  if (Wrapper.unload_native_code(reinterpret_cast<uint64_t>(FnStart)) == -1) {</font></div><div><font class="Apple-style-span" color="#000000">     DEBUG(dbgs()</font></div><div><font class="Apple-style-span" color="#000000">           << "Failed to tell OProfile about unload of native function at "</font></div><div><font class="Apple-style-span" color="#000000">           << FnStart << "\n");</font></div><div><font class="Apple-style-span" color="#000000">@@ -175,18 +164,38 @@ void OProfileJITEventListener::NotifyFreeingMachineCode(void *FnStart) {</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000"> JITEventListener *createOProfileJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">-  return new OProfileJITEventListener;</font></div><div><font class="Apple-style-span" color="#000000">+  static OwningPtr<OProfileWrapper> oprofileWrapper(new OProfileWrapper);</font></div><div><font class="Apple-style-span" color="#000000">+  return new OProfileJITEventListener(*oprofileWrapper);</font></div><div><font class="Apple-style-span" color="#000000"> }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// for testing</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createOProfileJITEventListener(OProfileWrapper* test_impl) {</font></div><div><font class="Apple-style-span" color="#000000">+  return new OProfileJITEventListener(*test_impl);</font></div><div><font class="Apple-style-span" color="#000000"> }</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000">+} // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000"> #else  // USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class OProfileWrapper;</font></div><div><font class="Apple-style-span" color="#000000">+class JITEventListener;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000"> // By defining this to return NULL, we can let clients call it unconditionally,</font></div><div><font class="Apple-style-span" color="#000000">-// even if they haven't configured with the OProfile libraries.</font></div><div><font class="Apple-style-span" color="#000000">-JITEventListener *createOProfileJITEventListener() {</font></div><div><font class="Apple-style-span" color="#000000">-  return NULL;</font></div><div><font class="Apple-style-span" color="#000000">+// even if they haven't configured the build with the cmake option</font></div><div><font class="Apple-style-span" color="#000000">+// LLVM_USE_OPROFILE (or configure flag --with-oprofile=)</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createOProfileJITEventListener()</font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+JITEventListener *createOProfileJITEventListener(OProfileWrapper* test_impl)</font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000"> }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000"> }  // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000"> </font></div><div><font class="Apple-style-span" color="#000000"> #endif  // USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/lib/ExecutionEngine/JIT/OProfileWrapper.cpp b/lib/ExecutionEngine/JIT/OProfileWrapper.cpp</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..251a7dd</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/lib/ExecutionEngine/JIT/OProfileWrapper.cpp</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,286 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===-- OProfileWrapper.cpp - OProfile JIT API Wrapper implementation -----===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file implements the interface in OProfileWrapper.h. It is responsible</font></div><div><font class="Apple-style-span" color="#000000">+// for loading the opagent dynamic library when the first call to an op_</font></div><div><font class="Apple-style-span" color="#000000">+// function occurs.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===----------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#if USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/OProfileWrapper.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#define DEBUG_TYPE "oprofile-wrapper"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/Debug.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/raw_ostream.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/DynamicLibrary.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/Mutex.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/MutexGuard.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include <sstream></font></div><div><font class="Apple-style-span" color="#000000">+#include <cstring></font></div><div><font class="Apple-style-span" color="#000000">+#include <stddef.h></font></div><div><font class="Apple-style-span" color="#000000">+#include <dirent.h></font></div><div><font class="Apple-style-span" color="#000000">+#include <sys/stat.h></font></div><div><font class="Apple-style-span" color="#000000">+#include <fcntl.h></font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Global mutex to ensure a single thread initializes oprofile agent.</font></div><div><font class="Apple-style-span" color="#000000">+llvm::sys::Mutex OProfileInitializationMutex;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+template<typename TO, typename FROM></font></div><div><font class="Apple-style-span" color="#000000">+TO bitwise_cast(FROM source) {</font></div><div><font class="Apple-style-span" color="#000000">+  union {</font></div><div><font class="Apple-style-span" color="#000000">+    FROM src;</font></div><div><font class="Apple-style-span" color="#000000">+    TO dst;</font></div><div><font class="Apple-style-span" color="#000000">+  } u;</font></div><div><font class="Apple-style-span" color="#000000">+  u.src = source;</font></div><div><font class="Apple-style-span" color="#000000">+  return u.dst;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div></blockquote><div><br></div><div>This is just used for the function pointers, so is way overkill. Plain vanilla casting is fine. Either C or C++ style.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+} // anonymous namespace</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace llvm {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+OProfileWrapper::OProfileWrapper()</font></div><div><font class="Apple-style-span" color="#000000">+: Agent(0)</font></div><div><font class="Apple-style-span" color="#000000">+, OpenAgentFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, CloseAgentFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, WriteNativeCodeFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, WriteDebugLineInfoFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, UnloadNativeCodeFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, MajorVersionFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, MinorVersionFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, IsOProfileRunningFunc(0)</font></div><div><font class="Apple-style-span" color="#000000">+, Initialized(false) {</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+bool OProfileWrapper::initialize() {</font></div><div><font class="Apple-style-span" color="#000000">+  using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000">+  using namespace llvm::sys;</font></div><div></div></blockquote><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div></blockquote><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+  llvm::MutexGuard guard(OProfileInitializationMutex);</font></div><div></div></blockquote><div><br></div><div>This probably doesn't need the "llvm::" since we just had the 'using' above.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    return OpenAgentFunc != 0;</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    Initialized = true;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // If the oprofile daemon is not running, don't load the opagent library</font></div><div><font class="Apple-style-span" color="#000000">+  if (!IsOProfileRunning()) {</font></div><div><font class="Apple-style-span" color="#000000">+    DEBUG(dbgs() << "OProfile daemon is not detected.\n");</font></div><div><font class="Apple-style-span" color="#000000">+    return false;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  std::string error;</font></div><div><font class="Apple-style-span" color="#000000">+  if(!DynamicLibrary::LoadLibraryPermanently("libopagent.so", &error)) {</font></div></blockquote><div><br></div><div>Is this support Linux only? I didn't see enforced in the configure script. If not, the name of the library is not always going to be this, most likely. If it is linux only, even just for now, the configure script should enforce that.</div><br><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+    DEBUG(dbgs() << "OProfile connector library libopagent.so could not be loaded: "</font></div><div><font class="Apple-style-span" color="#000000">+      << error << "\n");</font></div><div></div></blockquote><div><br></div><div>Indent the "<<" to line up with the "<<" on the preceding line.</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // Get the addresses of the opagent functions</font></div><div><font class="Apple-style-span" color="#000000">+  OpenAgentFunc = bitwise_cast<op_open_agent_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_open_agent"));</font></div><div><font class="Apple-style-span" color="#000000">+  CloseAgentFunc = bitwise_cast<op_close_agent_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_close_agent"));</font></div><div><font class="Apple-style-span" color="#000000">+  WriteNativeCodeFunc = bitwise_cast<op_write_native_code_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_write_native_code"));</font></div><div><font class="Apple-style-span" color="#000000">+  WriteDebugLineInfoFunc = bitwise_cast<op_write_debug_line_info_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_write_debug_line_info"));</font></div><div><font class="Apple-style-span" color="#000000">+  UnloadNativeCodeFunc = bitwise_cast<op_unload_native_code_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_unload_native_code"));</font></div><div><font class="Apple-style-span" color="#000000">+  MajorVersionFunc = bitwise_cast<op_major_version_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_major_version"));</font></div><div><font class="Apple-style-span" color="#000000">+  MinorVersionFunc = bitwise_cast<op_major_version_ptr_t>(</font></div><div><font class="Apple-style-span" color="#000000">+          DynamicLibrary::SearchForAddressOfSymbol("op_minor_version"));</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // With missing functions, we can do nothing</font></div><div><font class="Apple-style-span" color="#000000">+  if (!OpenAgentFunc</font></div><div><font class="Apple-style-span" color="#000000">+    || !CloseAgentFunc</font></div><div><font class="Apple-style-span" color="#000000">+    || !WriteNativeCodeFunc</font></div><div><font class="Apple-style-span" color="#000000">+    || !WriteDebugLineInfoFunc</font></div><div><font class="Apple-style-span" color="#000000">+    || !UnloadNativeCodeFunc) {</font></div><div></div></blockquote><div><br></div><div>Indent the operators to line up one character after the open-paren of the 'if'.</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+    OpenAgentFunc = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    CloseAgentFunc = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    WriteNativeCodeFunc = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    WriteDebugLineInfoFunc = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    UnloadNativeCodeFunc = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    return false;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  return true;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+bool OProfileWrapper::IsOProfileRunning() {</font></div><div><font class="Apple-style-span" color="#000000">+  if (IsOProfileRunningFunc != 0) {</font></div><div><font class="Apple-style-span" color="#000000">+    return IsOProfileRunningFunc();</font></div><div><font class="Apple-style-span" color="#000000">+  } else</font></div><div><font class="Apple-style-span" color="#000000">+    return CheckForOProfileProcEntry();</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+bool OProfileWrapper::CheckForOProfileProcEntry() {</font></div><div><font class="Apple-style-span" color="#000000">+  DIR* proc_dir;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  proc_dir = opendir("/proc");</font></div><div><font class="Apple-style-span" color="#000000">+  if (!proc_dir) {</font></div><div><font class="Apple-style-span" color="#000000">+    return false;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // Walk the /proc tree looking for the oprofile daemon</font></div><div><font class="Apple-style-span" color="#000000">+  struct dirent* entry;</font></div><div><font class="Apple-style-span" color="#000000">+  while (0 != (entry = readdir(proc_dir))) {</font></div><div><font class="Apple-style-span" color="#000000">+    if (entry->d_type == DT_DIR) {</font></div><div><font class="Apple-style-span" color="#000000">+      // Build a path from the current entry name</font></div><div><font class="Apple-style-span" color="#000000">+      std::stringstream cmdline_fname;</font></div></blockquote><div><br></div><div>LLVM uses a raw_svector_ostream writing to a SmallString for things like this.</div><div><br></div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+      cmdline_fname << "/proc/" << entry->d_name << "/cmdline";</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+      // Open the cmdline file</font></div><div><font class="Apple-style-span" color="#000000">+      int cmdline_fd = open(cmdline_fname.str().c_str(), S_IRUSR);</font></div><div><font class="Apple-style-span" color="#000000">+      if (cmdline_fd != -1) {</font></div><div><font class="Apple-style-span" color="#000000">+        char    exename[PATH_MAX+1];</font></div><div><font class="Apple-style-span" color="#000000">+        char*   basename = 0;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+        // Read the cmdline file</font></div><div><font class="Apple-style-span" color="#000000">+        ssize_t num_read = read(cmdline_fd, exename, PATH_MAX+1);</font></div><div><font class="Apple-style-span" color="#000000">+        close(cmdline_fd);</font></div><div><font class="Apple-style-span" color="#000000">+        ssize_t idx = 0;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+        // Find the terminator for the first string</font></div><div><font class="Apple-style-span" color="#000000">+        while (idx < num_read-1 && exename[idx] != 0) {</font></div><div><font class="Apple-style-span" color="#000000">+          idx++;</font></div><div><font class="Apple-style-span" color="#000000">+        }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+        // Go back to the last non-null character</font></div><div><font class="Apple-style-span" color="#000000">+        idx--;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+        // Find the last path separator in the first string</font></div><div><font class="Apple-style-span" color="#000000">+        while (idx > 0) {</font></div><div><font class="Apple-style-span" color="#000000">+          if (exename[idx] == '/') {</font></div><div><font class="Apple-style-span" color="#000000">+            basename = exename + idx + 1;</font></div><div><font class="Apple-style-span" color="#000000">+            break;</font></div><div><font class="Apple-style-span" color="#000000">+          }</font></div><div><font class="Apple-style-span" color="#000000">+          idx--;</font></div><div><font class="Apple-style-span" color="#000000">+        }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+        // Test this to see if it is the oprofile daemon</font></div><div><font class="Apple-style-span" color="#000000">+        if (basename != 0 && !strcmp("oprofiled", basename)) {</font></div><div><font class="Apple-style-span" color="#000000">+          // If it is, we're done</font></div><div><font class="Apple-style-span" color="#000000">+          closedir(proc_dir);</font></div><div><font class="Apple-style-span" color="#000000">+          return true;</font></div><div><font class="Apple-style-span" color="#000000">+        }</font></div><div><font class="Apple-style-span" color="#000000">+      }</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // We've looked through all the files and didn't find the daemon</font></div><div><font class="Apple-style-span" color="#000000">+  closedir(proc_dir);</font></div><div><font class="Apple-style-span" color="#000000">+  return false;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+bool OProfileWrapper::open_agent() {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (OpenAgentFunc != 0) {</font></div><div><font class="Apple-style-span" color="#000000">+    Agent = OpenAgentFunc();</font></div><div><font class="Apple-style-span" color="#000000">+    return Agent != 0;</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    return false;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int OProfileWrapper::close_agent() {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  int ret = -1;</font></div><div><font class="Apple-style-span" color="#000000">+  if (Agent && CloseAgentFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+    ret = CloseAgentFunc(Agent);</font></div><div><font class="Apple-style-span" color="#000000">+    if (0 == ret) {</font></div><div><font class="Apple-style-span" color="#000000">+      Agent = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+  return ret;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+bool OProfileWrapper::have_agent() {</font></div><div><font class="Apple-style-span" color="#000000">+  return Agent != 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int OProfileWrapper::write_native_code(const char* name, uint64_t addr, void const* code, unsigned int size) {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (Agent && WriteNativeCodeFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+    return WriteNativeCodeFunc(Agent, name, addr, code, size);</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    return -1;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int OProfileWrapper::write_debug_line_info(</font></div><div><font class="Apple-style-span" color="#000000">+  void const* code,</font></div><div><font class="Apple-style-span" color="#000000">+  size_t num_entries,</font></div><div><font class="Apple-style-span" color="#000000">+  struct debug_line_info const* info) {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (Agent && WriteDebugLineInfoFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+    return WriteDebugLineInfoFunc(Agent, code, num_entries, info);</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    return -1;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int OProfileWrapper::major_version() {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (Agent && MajorVersionFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+    return MajorVersionFunc();</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    return -1;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int OProfileWrapper::minor_version() {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (Agent && MinorVersionFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+    return MinorVersionFunc();</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    return -1;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int  OProfileWrapper::unload_native_code(uint64_t addr) {</font></div><div><font class="Apple-style-span" color="#000000">+  if (!Initialized) {</font></div><div><font class="Apple-style-span" color="#000000">+    initialize();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  if (Agent && UnloadNativeCodeFunc) {</font></div><div><font class="Apple-style-span" color="#000000">+    return UnloadNativeCodeFunc(Agent, addr);</font></div><div><font class="Apple-style-span" color="#000000">+  } else {</font></div><div><font class="Apple-style-span" color="#000000">+    return -1;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} // namespace llvm</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/unittests/ExecutionEngine/JIT/IntelJITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/IntelJITEventListenerTest.cpp</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..3eed428</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/unittests/ExecutionEngine/JIT/IntelJITEventListenerTest.cpp</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,111 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===- JITEventListenerTest.cpp - Tests for Intel JIT API Events JITEventListener --------===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===------------------------------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "JITEventListenerTestCommon.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#if USE_INTEL_JITEVENTS</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include <map></font></div><div><font class="Apple-style-span" color="#000000">+#include <list></font></div></blockquote><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// map of function ("method") IDs to source locations</font></div><div><font class="Apple-style-span" color="#000000">+NativeCodeMap ReportedDebugFuncs;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} // namespace</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+/// Mock implementaion of Intel JIT API jitprofiling library</font></div><div><font class="Apple-style-span" color="#000000">+namespace test_jitprofiling {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {</font></div><div><font class="Apple-style-span" color="#000000">+  switch (EventType) {</font></div><div><font class="Apple-style-span" color="#000000">+    case iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED: {</font></div><div><font class="Apple-style-span" color="#000000">+      EXPECT_TRUE(0 != EventSpecificData);</font></div><div><font class="Apple-style-span" color="#000000">+      iJIT_Method_Load* msg = static_cast<iJIT_Method_Load*>(EventSpecificData);</font></div><div><font class="Apple-style-span" color="#000000">+      </font></div><div><font class="Apple-style-span" color="#000000">+      ReportedDebugFuncs[msg->method_id];</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+      for(unsigned int i = 0; i < msg->line_number_size; ++i) {</font></div><div><font class="Apple-style-span" color="#000000">+        EXPECT_TRUE(0 != msg->line_number_table);</font></div></blockquote></div><div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">+        std::pair<std::string, unsigned int> loc(std::string(msg->source_file_name),</font></div><div><font class="Apple-style-span" color="#000000">+          msg->line_number_table[i].LineNumber);</font></div><div><font class="Apple-style-span" color="#000000">+        ReportedDebugFuncs[msg->method_id].push_back(loc);</font></div><div><font class="Apple-style-span" color="#000000">+      }</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+    break;</font></div><div><font class="Apple-style-span" color="#000000">+    case iJVM_EVENT_TYPE_METHOD_UNLOAD_START: {</font></div><div><font class="Apple-style-span" color="#000000">+      EXPECT_TRUE(0 != EventSpecificData);</font></div><div><font class="Apple-style-span" color="#000000">+      unsigned int UnloadId = *reinterpret_cast<unsigned int*>(EventSpecificData);</font></div><div><font class="Apple-style-span" color="#000000">+      EXPECT_TRUE(1 == ReportedDebugFuncs.erase(UnloadId));</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+    default:</font></div><div><font class="Apple-style-span" color="#000000">+      break;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+iJIT_IsProfilingActiveFlags IsProfilingActive(void) {</font></div><div><font class="Apple-style-span" color="#000000">+  // for testing, pretend we have an Intel Parallel Amplifier XE 2011 instance attached</font></div><div><font class="Apple-style-span" color="#000000">+  return iJIT_SAMPLING_ON;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+unsigned int GetNewMethodID(void) {</font></div><div><font class="Apple-style-span" color="#000000">+  static unsigned int id = 0;</font></div><div><font class="Apple-style-span" color="#000000">+  return ++id;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} //namespace test_jitprofiling</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class IntelJITEventListenerTest</font></div><div><font class="Apple-style-span" color="#000000">+  : public JITEventListenerTestBase<IntelJITEventsWrapper> {</font></div><div><font class="Apple-style-span" color="#000000">+public:</font></div><div><font class="Apple-style-span" color="#000000">+  IntelJITEventListenerTest()</font></div><div><font class="Apple-style-span" color="#000000">+  : JITEventListenerTestBase<IntelJITEventsWrapper>(</font></div><div><font class="Apple-style-span" color="#000000">+      new IntelJITEventsWrapper(test_jitprofiling::NotifyEvent, 0,</font></div><div><font class="Apple-style-span" color="#000000">+        test_jitprofiling::IsProfilingActive, 0, 0,</font></div><div><font class="Apple-style-span" color="#000000">+        test_jitprofiling::GetNewMethodID))</font></div><div><font class="Apple-style-span" color="#000000">+  {</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != MockWrapper);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    Listener.reset(createIntelJITEventListener(MockWrapper.get()));</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != Listener);</font></div><div><font class="Apple-style-span" color="#000000">+    EE->RegisterJITEventListener(Listener.get());</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(IntelJITEventListenerTest, NoDebugInfo) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestNoDebugInfo(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(IntelJITEventListenerTest, SingleLine) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestSingleLine(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(IntelJITEventListenerTest, MultipleLines) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestMultipleLines(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+  </font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// This testcase is disabled because the Intel JIT API does not support a single</font></div><div><font class="Apple-style-span" color="#000000">+// JITted function with source lines associated with multiple files</font></div><div><font class="Apple-style-span" color="#000000">+/*</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(IntelJITEventListenerTest, MultipleFiles) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestMultipleFiles(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+*/</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+testing::Environment* const jit_env =</font></div><div><font class="Apple-style-span" color="#000000">+  testing::AddGlobalTestEnvironment(new JITEnvironment);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //USE_INTEL_JITEVENTS</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h b/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..0067cd4</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,194 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===- JITEventListenerTestCommon.h- Common functionality in JITEventListener tests --------===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===------------------------------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#ifndef JIT_EVENT_LISTENER_TEST_COMMON_H</font></div><div><font class="Apple-style-span" color="#000000">+#define JIT_EVENT_LISTENER_TEST_COMMON_H</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Analysis/DIBuilder.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Analysis/DebugInfo.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/CodeGen/MachineCodeInfo.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Config/config.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/JIT.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/JITEventListener.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Instructions.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Module.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/IRBuilder.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/Dwarf.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/TypeBuilder.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/Support/TargetSelect.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "gtest/gtest.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include <vector></font></div><div><font class="Apple-style-span" color="#000000">+#include <string></font></div><div><font class="Apple-style-span" color="#000000">+#include <utility></font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+typedef std::vector<std::pair<std::string, unsigned int> > SourceLocations;</font></div><div><font class="Apple-style-span" color="#000000">+typedef std::map<uint64_t, SourceLocations> NativeCodeMap;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class JITEnvironment : public testing::Environment {</font></div><div><font class="Apple-style-span" color="#000000">+  virtual void SetUp() {</font></div><div><font class="Apple-style-span" color="#000000">+    // Required to create a JIT.</font></div><div><font class="Apple-style-span" color="#000000">+    llvm::InitializeNativeTarget();</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+inline unsigned int getLine() {</font></div><div><font class="Apple-style-span" color="#000000">+  return 12;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+inline unsigned int getCol() {</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+inline const char* getFilename() {</font></div><div><font class="Apple-style-span" color="#000000">+  return "mock_source_file.cpp";</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+// Test fixture shared by tests for listener implementations</font></div><div><font class="Apple-style-span" color="#000000">+template<typename WrapperT></font></div><div><font class="Apple-style-span" color="#000000">+class JITEventListenerTestBase : public testing::Test {</font></div><div><font class="Apple-style-span" color="#000000">+protected:</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::OwningPtr<WrapperT> MockWrapper;</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::OwningPtr<llvm::JITEventListener> Listener;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+public:</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::Module* M;</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::MDNode* Scope;</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::ExecutionEngine* EE;</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::DIBuilder* DebugBuilder;</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::IRBuilder<> Builder;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  JITEventListenerTestBase(WrapperT* w)</font></div><div><font class="Apple-style-span" color="#000000">+  : MockWrapper(w)</font></div><div><font class="Apple-style-span" color="#000000">+  , M(new llvm::Module("module", llvm::getGlobalContext()))</font></div><div><font class="Apple-style-span" color="#000000">+  , EE(llvm::EngineBuilder(M)</font></div><div><font class="Apple-style-span" color="#000000">+    .setEngineKind(llvm::EngineKind::JIT)</font></div><div><font class="Apple-style-span" color="#000000">+    .setOptLevel(llvm::CodeGenOpt::None)</font></div><div><font class="Apple-style-span" color="#000000">+    .create())</font></div><div><font class="Apple-style-span" color="#000000">+  , DebugBuilder(new llvm::DIBuilder(*M))</font></div><div><font class="Apple-style-span" color="#000000">+  , Builder(llvm::getGlobalContext())</font></div><div><font class="Apple-style-span" color="#000000">+  {</font></div><div><font class="Apple-style-span" color="#000000">+    DebugBuilder->createCompileUnit(llvm::dwarf::DW_LANG_C_plus_plus, "JIT", "JIT", "JIT", true, "", 1);</font></div><div><font class="Apple-style-span" color="#000000">+    Scope = DebugBuilder->createFile(getFilename(), ".");</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  llvm::Function *buildFunction(const SourceLocations& DebugLocations) {</font></div><div><font class="Apple-style-span" color="#000000">+    using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    LLVMContext& GlobalContext = getGlobalContext();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations::const_iterator CurrentDebugLocation = DebugLocations.begin();</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    if (CurrentDebugLocation != DebugLocations.end()) {</font></div><div><font class="Apple-style-span" color="#000000">+      DebugLoc DebugLocation = DebugLoc::get(getLine(), getCol(),</font></div><div><font class="Apple-style-span" color="#000000">+          DebugBuilder->createFile(CurrentDebugLocation->first, "."));</font></div><div><font class="Apple-style-span" color="#000000">+      Builder.SetCurrentDebugLocation(DebugLocation);</font></div><div><font class="Apple-style-span" color="#000000">+      CurrentDebugLocation++;</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    Function *Result = Function::Create(</font></div><div><font class="Apple-style-span" color="#000000">+        TypeBuilder<int32_t(int32_t), false>::get(GlobalContext),</font></div><div><font class="Apple-style-span" color="#000000">+        GlobalValue::ExternalLinkage, "id", M);</font></div><div><font class="Apple-style-span" color="#000000">+    Value *Arg = Result->arg_begin();</font></div><div><font class="Apple-style-span" color="#000000">+    BasicBlock *BB = BasicBlock::Create(M->getContext(), "entry", Result);</font></div><div><font class="Apple-style-span" color="#000000">+    Builder.SetInsertPoint(BB);</font></div><div><font class="Apple-style-span" color="#000000">+    Value* one = ConstantInt::get(GlobalContext, APInt(32, 1));</font></div><div><font class="Apple-style-span" color="#000000">+    for(; CurrentDebugLocation != DebugLocations.end(); ++CurrentDebugLocation) {</font></div><div><font class="Apple-style-span" color="#000000">+      Arg = Builder.CreateMul(Arg, Builder.CreateAdd(Arg, one));</font></div><div><font class="Apple-style-span" color="#000000">+      Builder.SetCurrentDebugLocation(DebugLoc::get(CurrentDebugLocation->second, 0,</font></div><div><font class="Apple-style-span" color="#000000">+          DebugBuilder->createFile(CurrentDebugLocation->first, ".")));</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+    Builder.CreateRet(Arg);</font></div><div><font class="Apple-style-span" color="#000000">+    return Result;</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void TestNoDebugInfo(NativeCodeMap& ReportedDebugFuncs) {</font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations DebugLocations;</font></div><div><font class="Apple-style-span" color="#000000">+    llvm::Function* f = buildFunction(DebugLocations);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != f);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    //Cause JITting and callbacks to our listener</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != EE->getPointerToFunction(f));</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(1 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EE->freeMachineCodeForFunction(f);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void TestSingleLine(NativeCodeMap& ReportedDebugFuncs) {</font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations DebugLocations;</font></div><div><font class="Apple-style-span" color="#000000">+    DebugLocations.push_back(std::make_pair(std::string(getFilename()), getLine()));</font></div><div><font class="Apple-style-span" color="#000000">+    llvm::Function* f = buildFunction(DebugLocations);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != f);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != EE->getPointerToFunction(f));</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(1 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_STREQ(ReportedDebugFuncs.begin()->second.begin()->first.c_str(), getFilename());</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_EQ(ReportedDebugFuncs.begin()->second.begin()->second, getLine());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EE->freeMachineCodeForFunction(f);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void TestMultipleLines(NativeCodeMap& ReportedDebugFuncs) {</font></div><div><font class="Apple-style-span" color="#000000">+    using namespace std;</font></div><div><font class="Apple-style-span" color="#000000">+    </font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations DebugLocations;</font></div><div><font class="Apple-style-span" color="#000000">+    unsigned int c = 5;</font></div><div><font class="Apple-style-span" color="#000000">+    for(unsigned int i = 0; i < c; ++i) {</font></div><div><font class="Apple-style-span" color="#000000">+      DebugLocations.push_back(make_pair(string(getFilename()), getLine() + i));</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    llvm::Function* f = buildFunction(DebugLocations);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != f);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != EE->getPointerToFunction(f));</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(1 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations& FunctionInfo = ReportedDebugFuncs.begin()->second;</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_EQ(c, FunctionInfo.size());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    int VerifyCount = 0;</font></div><div><font class="Apple-style-span" color="#000000">+    for(SourceLocations::iterator i = FunctionInfo.begin(); i != FunctionInfo.end(); ++i) {</font></div><div><font class="Apple-style-span" color="#000000">+      EXPECT_STREQ(i->first.c_str(), getFilename());</font></div><div><font class="Apple-style-span" color="#000000">+      EXPECT_EQ(i->second, getLine() + VerifyCount);</font></div><div><font class="Apple-style-span" color="#000000">+      VerifyCount++;</font></div><div><font class="Apple-style-span" color="#000000">+    }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EE->freeMachineCodeForFunction(f);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  void TestMultipleFiles(NativeCodeMap& ReportedDebugFuncs) {</font></div><div><font class="Apple-style-span" color="#000000">+    </font></div><div><font class="Apple-style-span" color="#000000">+    std::string secondFilename("another_file.cpp");</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations DebugLocations;</font></div><div><font class="Apple-style-span" color="#000000">+    DebugLocations.push_back(std::make_pair(std::string(getFilename()), getLine()));</font></div><div><font class="Apple-style-span" color="#000000">+    DebugLocations.push_back(std::make_pair(secondFilename, getLine()));</font></div><div><font class="Apple-style-span" color="#000000">+    llvm::Function* f = buildFunction(DebugLocations);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != f);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != EE->getPointerToFunction(f));</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(1 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+    SourceLocations& FunctionInfo = ReportedDebugFuncs.begin()->second;</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(2 == FunctionInfo.size());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_STREQ(<a href="http://FunctionInfo.at">FunctionInfo.at</a>(0).first.c_str(), getFilename());</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_STREQ(<a href="http://FunctionInfo.at">FunctionInfo.at</a>(1).first.c_str(), secondFilename.c_str());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_EQ(<a href="http://FunctionInfo.at">FunctionInfo.at</a>(0).second, getLine());</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_EQ(<a href="http://FunctionInfo.at">FunctionInfo.at</a>(1).second, getLine());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    EE->freeMachineCodeForFunction(f);</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 == ReportedDebugFuncs.size());</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //JIT_EVENT_LISTENER_TEST_COMMON_H</font></div><div><font class="Apple-style-span" color="#000000">diff --git a/unittests/ExecutionEngine/JIT/OProfileJITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/OProfileJITEventListenerTest.cpp</font></div><div><font class="Apple-style-span" color="#000000">new file mode 100644</font></div><div><font class="Apple-style-span" color="#000000">index 0000000..de9b8d2</font></div><div><font class="Apple-style-span" color="#000000">--- /dev/null</font></div><div><font class="Apple-style-span" color="#000000">+++ b/unittests/ExecutionEngine/JIT/OProfileJITEventListenerTest.cpp</font></div><div><font class="Apple-style-span" color="#000000">@@ -0,0 +1,158 @@</font></div><div><font class="Apple-style-span" color="#000000">+//===- OProfileJITEventListenerTest.cpp - Unit tests for OProfileJITEventsListener --------===//</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//                     The LLVM Compiler Infrastructure</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+// This file is distributed under the University of Illinois Open Source</font></div><div><font class="Apple-style-span" color="#000000">+// License. See LICENSE.TXT for details.</font></div><div><font class="Apple-style-span" color="#000000">+//</font></div><div><font class="Apple-style-span" color="#000000">+//===---------------------------------------------------------------------------===//</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#if USE_OPROFILE</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include "llvm/ExecutionEngine/OProfileWrapper.h"</font></div><div><font class="Apple-style-span" color="#000000">+#include "JITEventListenerTestCommon.h"</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#include <map></font></div><div><font class="Apple-style-span" color="#000000">+#include <list></font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+using namespace llvm;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+namespace {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+struct OprofileNativeFunction {</font></div><div><font class="Apple-style-span" color="#000000">+  const char* Name;</font></div><div><font class="Apple-style-span" color="#000000">+  uint64_t Addr;</font></div><div><font class="Apple-style-span" color="#000000">+  const void* CodePtr;</font></div><div><font class="Apple-style-span" color="#000000">+  unsigned int CodeSize;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  OprofileNativeFunction(const char* name,</font></div><div><font class="Apple-style-span" color="#000000">+                         uint64_t addr,</font></div><div><font class="Apple-style-span" color="#000000">+                         const void* code,</font></div><div><font class="Apple-style-span" color="#000000">+                         unsigned int size)</font></div><div><font class="Apple-style-span" color="#000000">+  : Name(name)</font></div><div><font class="Apple-style-span" color="#000000">+  , Addr(addr)</font></div><div><font class="Apple-style-span" color="#000000">+  , CodePtr(code)</font></div><div><font class="Apple-style-span" color="#000000">+  , CodeSize(size) {</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+typedef std::list<OprofileNativeFunction> NativeFunctionList;</font></div><div><font class="Apple-style-span" color="#000000">+typedef std::list<debug_line_info> NativeDebugList;</font></div><div><font class="Apple-style-span" color="#000000">+NativeFunctionList NativeFunctions;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+NativeCodeMap ReportedDebugFuncs;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} // namespace</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+/// Mock implementaion of opagent library</font></div><div><font class="Apple-style-span" color="#000000">+namespace test_opagent {</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+op_agent_t globalAgent = reinterpret_cast<op_agent_t>(42);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+op_agent_t open_agent()</font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+  // return non-null op_agent_t</font></div><div><font class="Apple-style-span" color="#000000">+  return globalAgent;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int close_agent(op_agent_t agent)</font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_EQ(globalAgent, agent);</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int write_native_code(op_agent_t agent, const char* name, uint64_t addr, void const* code, unsigned int size)</font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_EQ(globalAgent, agent);</font></div><div><font class="Apple-style-span" color="#000000">+  OprofileNativeFunction func(name, addr, code, size);</font></div><div><font class="Apple-style-span" color="#000000">+  NativeFunctions.push_back(func);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  // Verify no other registration has take place for the same address</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_TRUE(ReportedDebugFuncs.find(addr) == ReportedDebugFuncs.end());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  ReportedDebugFuncs[addr];</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int write_debug_line_info(op_agent_t agent, void const* code, size_t num_entries, struct debug_line_info const* info)</font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_EQ(globalAgent, agent);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  //verify code has been loaded first</font></div><div><font class="Apple-style-span" color="#000000">+  uint64_t addr = reinterpret_cast<uint64_t>(code);</font></div><div><font class="Apple-style-span" color="#000000">+  NativeCodeMap::iterator i = ReportedDebugFuncs.find(addr);</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_TRUE(i != ReportedDebugFuncs.end());</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  NativeDebugList NativeInfo(info, info + num_entries);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  SourceLocations locs;</font></div><div><font class="Apple-style-span" color="#000000">+  for(NativeDebugList::iterator i = NativeInfo.begin(); i != NativeInfo.end(); ++i) {</font></div><div><font class="Apple-style-span" color="#000000">+    locs.push_back(std::make_pair(std::string(i->filename), i->lineno));</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+  ReportedDebugFuncs[addr] = locs;</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int unload_native_code(op_agent_t agent, uint64_t addr) {</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_EQ(globalAgent, agent);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+  //verify that something for the given JIT addr has been loaded first</font></div><div><font class="Apple-style-span" color="#000000">+  NativeCodeMap::iterator i = ReportedDebugFuncs.find(addr);</font></div><div><font class="Apple-style-span" color="#000000">+  EXPECT_TRUE(i != ReportedDebugFuncs.end());</font></div><div><font class="Apple-style-span" color="#000000">+  ReportedDebugFuncs.erase(i);</font></div><div><font class="Apple-style-span" color="#000000">+  return 0;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+int version() {</font></div><div><font class="Apple-style-span" color="#000000">+  return 1;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+bool is_oprofile_running() {</font></div><div><font class="Apple-style-span" color="#000000">+  return true;</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+} //namespace test_opagent</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+class OProfileJITEventListenerTest : public JITEventListenerTestBase<OProfileWrapper></font></div><div><font class="Apple-style-span" color="#000000">+{</font></div><div><font class="Apple-style-span" color="#000000">+public:</font></div><div><font class="Apple-style-span" color="#000000">+  OProfileJITEventListenerTest()</font></div><div><font class="Apple-style-span" color="#000000">+  : JITEventListenerTestBase<OProfileWrapper>(</font></div><div><font class="Apple-style-span" color="#000000">+    new OProfileWrapper(test_opagent::open_agent,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::close_agent,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::write_native_code,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::write_debug_line_info,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::unload_native_code,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::version,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::version,</font></div><div><font class="Apple-style-span" color="#000000">+      test_opagent::is_oprofile_running))</font></div><div><font class="Apple-style-span" color="#000000">+  {</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != MockWrapper);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+    Listener.reset(createOProfileJITEventListener(MockWrapper.get()));</font></div><div><font class="Apple-style-span" color="#000000">+    EXPECT_TRUE(0 != Listener);</font></div><div><font class="Apple-style-span" color="#000000">+    EE->RegisterJITEventListener(Listener.get());</font></div><div><font class="Apple-style-span" color="#000000">+  }</font></div><div><font class="Apple-style-span" color="#000000">+};</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(OProfileJITEventListenerTest, NoDebugInfo) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestNoDebugInfo(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(OProfileJITEventListenerTest, SingleLine) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestSingleLine(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(OProfileJITEventListenerTest, MultipleLines) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestMultipleLines(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+TEST_F(OProfileJITEventListenerTest, MultipleFiles) {</font></div><div><font class="Apple-style-span" color="#000000">+  TestMultipleFiles(ReportedDebugFuncs);</font></div><div><font class="Apple-style-span" color="#000000">+}</font></div><div><font class="Apple-style-span" color="#000000">+  </font></div><div><font class="Apple-style-span" color="#000000">+testing::Environment* const jit_env =</font></div><div><font class="Apple-style-span" color="#000000">+  testing::AddGlobalTestEnvironment(new JITEnvironment);</font></div><div><font class="Apple-style-span" color="#000000">+</font></div><div><font class="Apple-style-span" color="#000000">+#endif //USE_OPROFILE</font></div></blockquote></div><div><div><br></div></div><div><br></div><br><div><div>On Feb 13, 2012, at 10:02 PM, Bendersky, Eli wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Ping #3 !<br><br><br><blockquote type="cite">-----Original Message-----<br></blockquote><blockquote type="cite">From: <a href="mailto:llvm-commits-bounces@cs.uiuc.edu">llvm-commits-bounces@cs.uiuc.edu</a> [mailto:llvm-commits-<br></blockquote><blockquote type="cite"><a href="mailto:bounces@cs.uiuc.edu">bounces@cs.uiuc.edu</a>] On Behalf Of Bendersky, Eli<br></blockquote><blockquote type="cite">Sent: Wednesday, February 08, 2012 08:13<br></blockquote><blockquote type="cite">To: <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote><blockquote type="cite">Subject: Re: [llvm-commits] [PATCH] JIT profiling support with Intel Parallel<br></blockquote><blockquote type="cite">Amplifier XE 2011 (VTune)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Ping!<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">-----Original Message-----<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">From: <a href="mailto:llvm-commits-bounces@cs.uiuc.edu">llvm-commits-bounces@cs.uiuc.edu</a> [mailto:llvm-commits-<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="mailto:bounces@cs.uiuc.edu">bounces@cs.uiuc.edu</a>] On Behalf Of Bendersky, Eli<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Sent: Friday, February 03, 2012 05:18<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">To: <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Subject: Re: [llvm-commits] [PATCH] JIT profiling support with Intel<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Parallel Amplifier XE 2011 (VTune)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Ping!<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">-----Original Message-----<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">From: <a href="mailto:llvm-commits-bounces@cs.uiuc.edu">llvm-commits-bounces@cs.uiuc.edu</a> [mailto:llvm-commits-<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><a href="mailto:bounces@cs.uiuc.edu">bounces@cs.uiuc.edu</a>] On Behalf Of Bendersky, Eli<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Sent: Tuesday, January 31, 2012 11:19<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">To: <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Subject: [llvm-commits] [PATCH] JIT profiling support with Intel<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Parallel Amplifier XE 2011 (VTune)<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Hello,<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Currently the only profiling LLVM JITted code support is via OProfile.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">This patch adds profiling support for Intel Parallel Amplifier XE<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">2011 (used to be called "VTune"), does some refactoring to share<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">code between the implementations, and adds unit tests both for the<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">existing OProfile interface and the new Amplifier XE interface. In more<br></blockquote></blockquote></blockquote><blockquote type="cite">detail:<br></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">- Added Intel JIT Events API compatible JITEventListener, and allow<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">OProfileJITEventListener to load libopagent.so at runtime<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">- Removed link-time requirement on libopagent when building with<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">OProfile support<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">- Added Intel JIT API and OProfile support to cmake builds (Boolean<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">options LLVM_USE_OPROFILE and LLVM_USE_INTEL_JITEVENTS)<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">- Added IntelJITEventListener to connect to Intel JIT API (support<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">for profiling with Parallel Amplifier XE 2011)<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">- Added unit tests for both IntelJIT and OProfile JITEventListener<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">implementations which can still be run in the absence the respective<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">3rd party libraries<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">The change was broken into several patches. The first contains the<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">new implementation and tests. The others are build system changes to<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">incorporate the new code.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">This is essentially similar to the patch sent by Daniel Malea in the<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">beginning of December, but which unfortunately hasn't received a<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">reply. We updated it to cleanly apply to SVN trunk.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Please review<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Eli<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">--------------------------------------------------------------------<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">-<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Intel Israel (74) Limited<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">This e-mail and any attachments may contain confidential material<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">for the sole use of the intended recipient(s). Any review or<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">distribution by others is strictly prohibited. If you are not the<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">intended recipient, please contact the sender and delete all copies.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">---------------------------------------------------------------------<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Intel Israel (74) Limited<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">This e-mail and any attachments may contain confidential material for<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">the sole use of the intended recipient(s). Any review or distribution<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">by others is strictly prohibited. If you are not the intended<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">recipient, please contact the sender and delete all copies.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">_______________________________________________<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">llvm-commits mailing list<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote></blockquote><blockquote type="cite">---------------------------------------------------------------------<br></blockquote><blockquote type="cite">Intel Israel (74) Limited<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This e-mail and any attachments may contain confidential material for the<br></blockquote><blockquote type="cite">sole use of the intended recipient(s). Any review or distribution by others is<br></blockquote><blockquote type="cite">strictly prohibited. If you are not the intended recipient, please contact the<br></blockquote><blockquote type="cite">sender and delete all copies.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">llvm-commits mailing list<br></blockquote><blockquote type="cite"><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote>---------------------------------------------------------------------<br>Intel Israel (74) Limited<br><br>This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></div></blockquote></div><br></body></html>