<div dir="ltr">Oops -- yes, thanks David. I'll keep that in mind next time.<div><br></div><div>Cheers</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 1, 2016 at 4:11 AM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">(when recommitting a patch it's helpful to include the original commit/revert revisions, and notes on what's changed/fixed - makes it easier to review the fixes)</div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Oct 25, 2016 at 9:23 PM Dean Michael Berris via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dberris<br class="gmail_msg">
Date: Tue Oct 25 23:14:34 2016<br class="gmail_msg">
New Revision: 285165<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=285165&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=285165&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
[XRay] Implement `llvm-xray extract`, start of the llvm-xray tool<br class="gmail_msg">
<br class="gmail_msg">
Usage:<br class="gmail_msg">
<br class="gmail_msg">
  llvm-xray extract <object file> [-o <filename or '-'>]<br class="gmail_msg">
<br class="gmail_msg">
The tool gets the XRay instrumentation map from an object file and turns<br class="gmail_msg">
it into YAML.  We first support ELF64 sleds on x86_64 binaries, with<br class="gmail_msg">
provision for supporting other supported platforms and formats later.<br class="gmail_msg">
<br class="gmail_msg">
This is the first of a many-part change to fully implement the<br class="gmail_msg">
`llvm-xray` tool.<br class="gmail_msg">
<br class="gmail_msg">
We also define a subcommand registration and dispatch mechanism to be<br class="gmail_msg">
used by other further subcommand implementations for llvm-xray.<br class="gmail_msg">
<br class="gmail_msg">
Diffusion Revision: <a href="https://reviews.llvm.org/D21987" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D21987</a><br class="gmail_msg">
<br class="gmail_msg">
Added:<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin   (with props)<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin   (with props)<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin   (with props)<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin   (with props)<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/Inputs/empty-file.bin<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/bad-instrmap-sizes.bin<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/empty.txt<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap.ll<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/lit.local.cfg<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/no-instr-map.txt<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/no-such-file.txt<br class="gmail_msg">
    llvm/trunk/test/tools/llvm-xray/X86/unsupported-elf32.txt<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/CMakeLists.txt<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/llvm-xray.cc<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/xray-extract.cc<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/xray-extract.h<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/xray-registry.cc<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/xray-registry.h<br class="gmail_msg">
    llvm/trunk/tools/llvm-xray/xray-sleds.h<br class="gmail_msg">
Modified:<br class="gmail_msg">
    llvm/trunk/test/lit.cfg<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/test/lit.cfg<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=285165&r1=285164&r2=285165&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=285165&r1=285164&r2=285165&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/lit.cfg (original)<br class="gmail_msg">
+++ llvm/trunk/test/lit.cfg Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -310,6 +310,7 @@ for pattern in [r"\bbugpoint\b(?!-)",<br class="gmail_msg">
                 r"\bllvm-tblgen\b",<br class="gmail_msg">
                 r"\bllvm-c-test\b",<br class="gmail_msg">
                 r"\bllvm-cxxfilt\b",<br class="gmail_msg">
+                r"\bllvm-xray\b",<br class="gmail_msg">
                 NOJUNK + r"\bllvm-symbolizer\b",<br class="gmail_msg">
                 NOJUNK + r"\bopt\b",<br class="gmail_msg">
                 r"\bFileCheck\b",<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
Binary files llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin (added) and llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin Tue Oct 25 23:14:34 2016 differ<br class="gmail_msg">
<br class="gmail_msg">
Propchange: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf32-noxray.bin<br class="gmail_msg">
------------------------------------------------------------------------------<br class="gmail_msg">
    svn:executable = *<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
Binary files llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin (added) and llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin Tue Oct 25 23:14:34 2016 differ<br class="gmail_msg">
<br class="gmail_msg">
Propchange: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-badentrysizes.bin<br class="gmail_msg">
------------------------------------------------------------------------------<br class="gmail_msg">
    svn:executable = *<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
Binary files llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin (added) and llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin Tue Oct 25 23:14:34 2016 differ<br class="gmail_msg">
<br class="gmail_msg">
Propchange: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-example.bin<br class="gmail_msg">
------------------------------------------------------------------------------<br class="gmail_msg">
    svn:executable = *<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
Binary files llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin (added) and llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin Tue Oct 25 23:14:34 2016 differ<br class="gmail_msg">
<br class="gmail_msg">
Propchange: llvm/trunk/test/tools/llvm-xray/X86/Inputs/elf64-noinstr-map.bin<br class="gmail_msg">
------------------------------------------------------------------------------<br class="gmail_msg">
    svn:executable = *<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/Inputs/empty-file.bin<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/empty-file.bin?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/Inputs/empty-file.bin?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
    (empty)<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/bad-instrmap-sizes.bin<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/bad-instrmap-sizes.bin?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/bad-instrmap-sizes.bin?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/bad-instrmap-sizes.bin (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/bad-instrmap-sizes.bin Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,3 @@<br class="gmail_msg">
+; RUN: not llvm-xray extract %S/Inputs/elf64-badentrysizes.bin 2>&1 | FileCheck %s<br class="gmail_msg">
+; CHECK: llvm-xray: Cannot extract instrumentation map from '{{.*}}elf64-badentrysizes.bin'.<br class="gmail_msg">
+; CHECK-NEXT: Instrumentation map entries not evenly divisible by size of an XRay sled entry in ELF64.<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/empty.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/empty.txt?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/empty.txt?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/empty.txt (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/empty.txt Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,4 @@<br class="gmail_msg">
+; RUN: not llvm-xray extract %S/Inputs/empty-file.bin 2>&1 | FileCheck %s<br class="gmail_msg">
+<br class="gmail_msg">
+; CHECK: llvm-xray: Cannot extract instrumentation map from '{{.*}}empty-file.bin'.<br class="gmail_msg">
+; CHECK-NEXT: The file was not recognized as a valid object file<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap.ll<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap.ll?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap.ll?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap.ll (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/extract-instrmap.ll Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,15 @@<br class="gmail_msg">
+; This test makes sure we can extract the instrumentation map from an<br class="gmail_msg">
+; XRay-instrumented object file.<br class="gmail_msg">
+;<br class="gmail_msg">
+; RUN: llvm-xray extract %S/Inputs/elf64-example.bin | FileCheck %s<br class="gmail_msg">
+<br class="gmail_msg">
+; CHECK:      ---<br class="gmail_msg">
+; CHECK-NEXT: - { id: 1, address: 0x000000000041C900, function: 0x000000000041C900, kind: function-enter,<br class="gmail_msg">
+; CHECK-NEXT:     always-instrument: true }<br class="gmail_msg">
+; CHECK-NEXT: - { id: 1, address: 0x000000000041C912, function: 0x000000000041C900, kind: function-exit,<br class="gmail_msg">
+; CHECK-NEXT:     always-instrument: true }<br class="gmail_msg">
+; CHECK-NEXT: - { id: 2, address: 0x000000000041C930, function: 0x000000000041C930, kind: function-enter,<br class="gmail_msg">
+; CHECK-NEXT:    always-instrument: true }<br class="gmail_msg">
+; CHECK-NEXT: - { id: 2, address: 0x000000000041C946, function: 0x000000000041C930, kind: function-exit,<br class="gmail_msg">
+; CHECK-NEXT:     always-instrument: true }<br class="gmail_msg">
+; CHECK-NEXT: ...<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/lit.local.cfg<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/lit.local.cfg?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/lit.local.cfg?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/lit.local.cfg (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/lit.local.cfg Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1 @@<br class="gmail_msg">
+config.suffixes = ['.yaml', '.ll', '.txt']<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/no-instr-map.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/no-instr-map.txt?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/no-instr-map.txt?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/no-instr-map.txt (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/no-instr-map.txt Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,4 @@<br class="gmail_msg">
+; RUN: not llvm-xray extract %S/Inputs/elf64-noinstr-map.bin 2>&1 | FileCheck %s<br class="gmail_msg">
+<br class="gmail_msg">
+; CHECK: llvm-xray: Cannot extract instrumentation map from '{{.*}}elf64-noinstr-map.bin'.<br class="gmail_msg">
+; CHECK-NEXT: Failed to find XRay instrumentation map.<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/no-such-file.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/no-such-file.txt?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/no-such-file.txt?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/no-such-file.txt (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/no-such-file.txt Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,4 @@<br class="gmail_msg">
+; RUN: not llvm-xray extract no-such-file 2>&1 | FileCheck %s<br class="gmail_msg">
+<br class="gmail_msg">
+; CHECK: llvm-xray: Cannot extract instrumentation map from 'no-such-file'.<br class="gmail_msg">
+; CHECK-NEXT: No such file or directory<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/tools/llvm-xray/X86/unsupported-elf32.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/unsupported-elf32.txt?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/unsupported-elf32.txt?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/tools/llvm-xray/X86/unsupported-elf32.txt (added)<br class="gmail_msg">
+++ llvm/trunk/test/tools/llvm-xray/X86/unsupported-elf32.txt Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,3 @@<br class="gmail_msg">
+; RUN: not llvm-xray extract %S/Inputs/elf32-noxray.bin 2>&1 | FileCheck %s<br class="gmail_msg">
+; CHECK: llvm-xray: Cannot extract instrumentation map from '{{.*}}elf32-noxray.bin'.<br class="gmail_msg">
+; CHECK-NEXT: File format not supported (only does ELF little endian 64-bit).<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/CMakeLists.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/CMakeLists.txt?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/CMakeLists.txt?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/CMakeLists.txt (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/CMakeLists.txt Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,10 @@<br class="gmail_msg">
+set(LLVM_LINK_COMPONENTS<br class="gmail_msg">
+  ${LLVM_TARGETS_TO_BUILD}<br class="gmail_msg">
+  Support<br class="gmail_msg">
+  Object)<br class="gmail_msg">
+<br class="gmail_msg">
+set(LLVM_XRAY_TOOLS<br class="gmail_msg">
+  xray-extract.cc<br class="gmail_msg">
+  xray-registry.cc)<br class="gmail_msg">
+<br class="gmail_msg">
+add_llvm_tool(llvm-xray llvm-xray.cc ${LLVM_XRAY_TOOLS})<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/llvm-xray.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/llvm-xray.cc?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/llvm-xray.cc?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/llvm-xray.cc (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/llvm-xray.cc Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,42 @@<br class="gmail_msg">
+//===- llvm-xray.cc - XRay Tool Main Program ------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+//                     The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file implements the main entry point for the suite of XRay tools. All<br class="gmail_msg">
+// additional functionality are implemented as subcommands.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// Basic usage:<br class="gmail_msg">
+//<br class="gmail_msg">
+//   llvm-xray [options] <subcommand> [subcommand-specific options]<br class="gmail_msg">
+//<br class="gmail_msg">
+#include "xray-registry.h"<br class="gmail_msg">
+#include "llvm/Support/CommandLine.h"<br class="gmail_msg">
+#include "llvm/Support/FileSystem.h"<br class="gmail_msg">
+#include "llvm/Support/raw_ostream.h"<br class="gmail_msg">
+#include <unistd.h><br class="gmail_msg">
+<br class="gmail_msg">
+using namespace llvm;<br class="gmail_msg">
+using namespace llvm::xray;<br class="gmail_msg">
+<br class="gmail_msg">
+int main(int argc, char *argv[]) {<br class="gmail_msg">
+  cl::ParseCommandLineOptions(argc, argv,<br class="gmail_msg">
+                              "XRay Tools\n\n"<br class="gmail_msg">
+                              "  This program consolidates multiple XRay trace "<br class="gmail_msg">
+                              "processing tools for convenient access.\n");<br class="gmail_msg">
+  for (auto *SC : cl::getRegisteredSubcommands()) {<br class="gmail_msg">
+    if (*SC)<br class="gmail_msg">
+      if (auto C = dispatch(SC)) {<br class="gmail_msg">
+        ExitOnError("llvm-xray: ")(C());<br class="gmail_msg">
+        return 0;<br class="gmail_msg">
+      }<br class="gmail_msg">
+  }<br class="gmail_msg">
+<br class="gmail_msg">
+  cl::PrintHelpMessage(false, true);<br class="gmail_msg">
+}<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/xray-extract.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-extract.cc?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-extract.cc?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/xray-extract.cc (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/xray-extract.cc Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,236 @@<br class="gmail_msg">
+//===- xray-extract.cc - XRay Instrumentation Map Extraction --------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+//                     The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// Implementation of the xray-extract.h interface.<br class="gmail_msg">
+//<br class="gmail_msg">
+// FIXME: Support other XRay-instrumented binary formats other than ELF.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+<br class="gmail_msg">
+#include <type_traits><br class="gmail_msg">
+#include <unistd.h><br class="gmail_msg">
+#include <utility><br class="gmail_msg">
+<br class="gmail_msg">
+#include "xray-extract.h"<br class="gmail_msg">
+<br class="gmail_msg">
+#include "xray-registry.h"<br class="gmail_msg">
+#include "xray-sleds.h"<br class="gmail_msg">
+#include "llvm/Object/ELF.h"<br class="gmail_msg">
+#include "llvm/Object/ObjectFile.h"<br class="gmail_msg">
+#include "llvm/Support/CommandLine.h"<br class="gmail_msg">
+#include "llvm/Support/DataExtractor.h"<br class="gmail_msg">
+#include "llvm/Support/ELF.h"<br class="gmail_msg">
+#include "llvm/Support/Error.h"<br class="gmail_msg">
+#include "llvm/Support/FileSystem.h"<br class="gmail_msg">
+#include "llvm/Support/Format.h"<br class="gmail_msg">
+#include "llvm/Support/YAMLTraits.h"<br class="gmail_msg">
+#include "llvm/Support/raw_ostream.h"<br class="gmail_msg">
+<br class="gmail_msg">
+using namespace llvm;<br class="gmail_msg">
+using namespace llvm::xray;<br class="gmail_msg">
+using namespace llvm::yaml;<br class="gmail_msg">
+<br class="gmail_msg">
+// llvm-xray extract<br class="gmail_msg">
+// ----------------------------------------------------------------------------<br class="gmail_msg">
+static cl::SubCommand Extract("extract", "Extract instrumentation maps");<br class="gmail_msg">
+static cl::opt<std::string> ExtractInput(cl::Positional,<br class="gmail_msg">
+                                         cl::desc("<input file>"), cl::Required,<br class="gmail_msg">
+                                         cl::sub(Extract));<br class="gmail_msg">
+static cl::opt<std::string><br class="gmail_msg">
+    ExtractOutput("output", cl::value_desc("output file"), cl::init("-"),<br class="gmail_msg">
+                  cl::desc("output file; use '-' for stdout"),<br class="gmail_msg">
+                  cl::sub(Extract));<br class="gmail_msg">
+static cl::alias ExtractOutput2("o", cl::aliasopt(ExtractOutput),<br class="gmail_msg">
+                                cl::desc("Alias for -output"),<br class="gmail_msg">
+                                cl::sub(Extract));<br class="gmail_msg">
+<br class="gmail_msg">
+struct YAMLXRaySledEntry {<br class="gmail_msg">
+  int32_t FuncId;<br class="gmail_msg">
+  Hex64 Address;<br class="gmail_msg">
+  Hex64 Function;<br class="gmail_msg">
+  SledEntry::FunctionKinds Kind;<br class="gmail_msg">
+  bool AlwaysInstrument;<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+template <> struct ScalarEnumerationTraits<SledEntry::FunctionKinds> {<br class="gmail_msg">
+  static void enumeration(IO &IO, SledEntry::FunctionKinds &Kind) {<br class="gmail_msg">
+    IO.enumCase(Kind, "function-enter", SledEntry::FunctionKinds::ENTRY);<br class="gmail_msg">
+    IO.enumCase(Kind, "function-exit", SledEntry::FunctionKinds::EXIT);<br class="gmail_msg">
+    IO.enumCase(Kind, "tail-exit", SledEntry::FunctionKinds::TAIL);<br class="gmail_msg">
+  }<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+template <> struct MappingTraits<YAMLXRaySledEntry> {<br class="gmail_msg">
+  static void mapping(IO &IO, YAMLXRaySledEntry &Entry) {<br class="gmail_msg">
+    IO.mapRequired("id", Entry.FuncId);<br class="gmail_msg">
+    IO.mapRequired("address", Entry.Address);<br class="gmail_msg">
+    IO.mapRequired("function", Entry.Function);<br class="gmail_msg">
+    IO.mapRequired("kind", Entry.Kind);<br class="gmail_msg">
+    IO.mapRequired("always-instrument", Entry.AlwaysInstrument);<br class="gmail_msg">
+  }<br class="gmail_msg">
+<br class="gmail_msg">
+  static constexpr bool flow = true;<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLXRaySledEntry);<br class="gmail_msg">
+<br class="gmail_msg">
+namespace {<br class="gmail_msg">
+<br class="gmail_msg">
+llvm::Error LoadBinaryInstrELF(<br class="gmail_msg">
+    StringRef Filename, std::deque<SledEntry> &OutputSleds,<br class="gmail_msg">
+    InstrumentationMapExtractor::FunctionAddressMap &InstrMap,<br class="gmail_msg">
+    InstrumentationMapExtractor::FunctionAddressReverseMap &FunctionIds) {<br class="gmail_msg">
+  auto ObjectFile = object::ObjectFile::createObjectFile(Filename);<br class="gmail_msg">
+<br class="gmail_msg">
+  if (!ObjectFile)<br class="gmail_msg">
+    return ObjectFile.takeError();<br class="gmail_msg">
+<br class="gmail_msg">
+  // FIXME: Maybe support other ELF formats. For now, 64-bit Little Endian only.<br class="gmail_msg">
+  if (!ObjectFile->getBinary()->isELF())<br class="gmail_msg">
+    return make_error<StringError>(<br class="gmail_msg">
+        "File format not supported (only does ELF).",<br class="gmail_msg">
+        std::make_error_code(std::errc::not_supported));<br class="gmail_msg">
+  if (ObjectFile->getBinary()->getArch() != Triple::x86_64)<br class="gmail_msg">
+    return make_error<StringError>(<br class="gmail_msg">
+        "File format not supported (only does ELF little endian 64-bit).",<br class="gmail_msg">
+        std::make_error_code(std::errc::not_supported));<br class="gmail_msg">
+<br class="gmail_msg">
+  // Find the section named "xray_instr_map".<br class="gmail_msg">
+  StringRef Contents = "";<br class="gmail_msg">
+  const auto &Sections = ObjectFile->getBinary()->sections();<br class="gmail_msg">
+  auto I = find_if(Sections, [&](object::SectionRef Section) {<br class="gmail_msg">
+    StringRef Name = "";<br class="gmail_msg">
+    if (Section.getName(Name))<br class="gmail_msg">
+      return false;<br class="gmail_msg">
+    return Name == "xray_instr_map";<br class="gmail_msg">
+  });<br class="gmail_msg">
+  if (I == Sections.end())<br class="gmail_msg">
+    return make_error<StringError>(<br class="gmail_msg">
+        "Failed to find XRay instrumentation map.",<br class="gmail_msg">
+        std::make_error_code(std::errc::not_supported));<br class="gmail_msg">
+  if (I->getContents(Contents))<br class="gmail_msg">
+    return make_error<StringError>(<br class="gmail_msg">
+        "Failed to get contents of 'xray_instr_map' section.",<br class="gmail_msg">
+        std::make_error_code(std::errc::executable_format_error));<br class="gmail_msg">
+<br class="gmail_msg">
+  // Copy the instrumentation map data into the Sleds data structure.<br class="gmail_msg">
+  auto C = Contents.bytes_begin();<br class="gmail_msg">
+  static constexpr size_t ELF64SledEntrySize = 32;<br class="gmail_msg">
+<br class="gmail_msg">
+  if ((C - Contents.bytes_end()) % ELF64SledEntrySize != 0)<br class="gmail_msg">
+    return make_error<StringError>(<br class="gmail_msg">
+        "Instrumentation map entries not evenly divisible by size of an XRay "<br class="gmail_msg">
+        "sled entry in ELF64.",<br class="gmail_msg">
+        std::make_error_code(std::errc::executable_format_error));<br class="gmail_msg">
+<br class="gmail_msg">
+  int32_t FuncId = 1;<br class="gmail_msg">
+  uint64_t CurFn = 0;<br class="gmail_msg">
+  std::deque<SledEntry> Sleds;<br class="gmail_msg">
+  for (; C != Contents.bytes_end(); C += ELF64SledEntrySize) {<br class="gmail_msg">
+    DataExtractor Extractor(<br class="gmail_msg">
+        StringRef(reinterpret_cast<const char *>(C), ELF64SledEntrySize), true,<br class="gmail_msg">
+        8);<br class="gmail_msg">
+    Sleds.push_back({});<br class="gmail_msg">
+    auto &Entry = Sleds.back();<br class="gmail_msg">
+    uint32_t OffsetPtr = 0;<br class="gmail_msg">
+    Entry.Address = Extractor.getU64(&OffsetPtr);<br class="gmail_msg">
+    Entry.Function = Extractor.getU64(&OffsetPtr);<br class="gmail_msg">
+    auto Kind = Extractor.getU8(&OffsetPtr);<br class="gmail_msg">
+    switch (Kind) {<br class="gmail_msg">
+    case 0: // ENTRY<br class="gmail_msg">
+      Entry.Kind = SledEntry::FunctionKinds::ENTRY;<br class="gmail_msg">
+      break;<br class="gmail_msg">
+    case 1: // EXIT<br class="gmail_msg">
+      Entry.Kind = SledEntry::FunctionKinds::EXIT;<br class="gmail_msg">
+      break;<br class="gmail_msg">
+    case 2: // TAIL<br class="gmail_msg">
+      Entry.Kind = SledEntry::FunctionKinds::TAIL;<br class="gmail_msg">
+      break;<br class="gmail_msg">
+    default:<br class="gmail_msg">
+      return make_error<StringError>(<br class="gmail_msg">
+          Twine("Encountered unknown sled type ") + "'" + Twine(int32_t{Kind}) +<br class="gmail_msg">
+              "'.",<br class="gmail_msg">
+          std::make_error_code(std::errc::protocol_error));<br class="gmail_msg">
+    }<br class="gmail_msg">
+    auto AlwaysInstrument = Extractor.getU8(&OffsetPtr);<br class="gmail_msg">
+    Entry.AlwaysInstrument = AlwaysInstrument != 0;<br class="gmail_msg">
+<br class="gmail_msg">
+    // We replicate the function id generation scheme implemented in the runtime<br class="gmail_msg">
+    // here. Ideally we should be able to break it out, or output this map from<br class="gmail_msg">
+    // the runtime, but that's a design point we can discuss later on. For now,<br class="gmail_msg">
+    // we replicate the logic and move on.<br class="gmail_msg">
+    if (CurFn == 0) {<br class="gmail_msg">
+      CurFn = Entry.Function;<br class="gmail_msg">
+      InstrMap[FuncId] = Entry.Function;<br class="gmail_msg">
+      FunctionIds[Entry.Function] = FuncId;<br class="gmail_msg">
+    }<br class="gmail_msg">
+    if (Entry.Function != CurFn) {<br class="gmail_msg">
+      ++FuncId;<br class="gmail_msg">
+      CurFn = Entry.Function;<br class="gmail_msg">
+      InstrMap[FuncId] = Entry.Function;<br class="gmail_msg">
+      FunctionIds[Entry.Function] = FuncId;<br class="gmail_msg">
+    }<br class="gmail_msg">
+  }<br class="gmail_msg">
+  OutputSleds = std::move(Sleds);<br class="gmail_msg">
+  return llvm::Error::success();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace<br class="gmail_msg">
+<br class="gmail_msg">
+InstrumentationMapExtractor::InstrumentationMapExtractor(std::string Filename,<br class="gmail_msg">
+                                                         InputFormats Format,<br class="gmail_msg">
+                                                         Error &EC) {<br class="gmail_msg">
+  ErrorAsOutParameter ErrAsOutputParam(&EC);<br class="gmail_msg">
+  switch (Format) {<br class="gmail_msg">
+  case InputFormats::ELF: {<br class="gmail_msg">
+    EC = handleErrors(<br class="gmail_msg">
+        LoadBinaryInstrELF(Filename, Sleds, FunctionAddresses, FunctionIds),<br class="gmail_msg">
+        [](std::unique_ptr<ErrorInfoBase> E) {<br class="gmail_msg">
+          return joinErrors(<br class="gmail_msg">
+              make_error<StringError>(<br class="gmail_msg">
+                  Twine("Cannot extract instrumentation map from '") +<br class="gmail_msg">
+                      ExtractInput + "'.",<br class="gmail_msg">
+                  std::make_error_code(std::errc::protocol_error)),<br class="gmail_msg">
+              std::move(E));<br class="gmail_msg">
+        });<br class="gmail_msg">
+    break;<br class="gmail_msg">
+  }<br class="gmail_msg">
+  default:<br class="gmail_msg">
+    llvm_unreachable("Input format type not supported yet.");<br class="gmail_msg">
+    break;<br class="gmail_msg">
+  }<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+void InstrumentationMapExtractor::exportAsYAML(raw_ostream &OS) {<br class="gmail_msg">
+  // First we translate the sleds into the YAMLXRaySledEntry objects in a deque.<br class="gmail_msg">
+  std::vector<YAMLXRaySledEntry> YAMLSleds;<br class="gmail_msg">
+  YAMLSleds.reserve(Sleds.size());<br class="gmail_msg">
+  for (const auto &Sled : Sleds) {<br class="gmail_msg">
+    YAMLSleds.push_back({FunctionIds[Sled.Function], Sled.Address,<br class="gmail_msg">
+                         Sled.Function, Sled.Kind, Sled.AlwaysInstrument});<br class="gmail_msg">
+  }<br class="gmail_msg">
+  Output Out(OS);<br class="gmail_msg">
+  Out << YAMLSleds;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+static CommandRegistration Unused(&Extract, [] {<br class="gmail_msg">
+  Error Err;<br class="gmail_msg">
+  xray::InstrumentationMapExtractor Extractor(<br class="gmail_msg">
+      ExtractInput, InstrumentationMapExtractor::InputFormats::ELF, Err);<br class="gmail_msg">
+  if (Err)<br class="gmail_msg">
+    return Err;<br class="gmail_msg">
+<br class="gmail_msg">
+  std::error_code EC;<br class="gmail_msg">
+  raw_fd_ostream OS(ExtractOutput, EC, sys::fs::OpenFlags::F_Text);<br class="gmail_msg">
+  if (EC)<br class="gmail_msg">
+    return make_error<StringError>(<br class="gmail_msg">
+        Twine("Cannot open file '") + ExtractOutput + "' for writing.", EC);<br class="gmail_msg">
+  Extractor.exportAsYAML(OS);<br class="gmail_msg">
+  return Error::success();<br class="gmail_msg">
+});<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/xray-extract.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-extract.h?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-extract.h?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/xray-extract.h (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/xray-extract.h Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,58 @@<br class="gmail_msg">
+//===- xray-extract.h - XRay Instrumentation Map Extraction ---------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+//                     The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// Defines the interface for extracting the instrumentation map from an<br class="gmail_msg">
+// XRay-instrumented binary.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+<br class="gmail_msg">
+#ifndef LLVM_TOOLS_XRAY_EXTRACT_H<br class="gmail_msg">
+#define LLVM_TOOLS_XRAY_EXTRACT_H<br class="gmail_msg">
+<br class="gmail_msg">
+#include <deque><br class="gmail_msg">
+#include <map><br class="gmail_msg">
+#include <string><br class="gmail_msg">
+#include <unordered_map><br class="gmail_msg">
+<br class="gmail_msg">
+#include "xray-sleds.h"<br class="gmail_msg">
+#include "llvm/Support/Error.h"<br class="gmail_msg">
+#include "llvm/Support/raw_ostream.h"<br class="gmail_msg">
+<br class="gmail_msg">
+namespace llvm {<br class="gmail_msg">
+namespace xray {<br class="gmail_msg">
+<br class="gmail_msg">
+class InstrumentationMapExtractor {<br class="gmail_msg">
+public:<br class="gmail_msg">
+  typedef std::unordered_map<int32_t, uint64_t> FunctionAddressMap;<br class="gmail_msg">
+  typedef std::unordered_map<uint64_t, int32_t> FunctionAddressReverseMap;<br class="gmail_msg">
+<br class="gmail_msg">
+  enum class InputFormats { ELF, YAML };<br class="gmail_msg">
+<br class="gmail_msg">
+private:<br class="gmail_msg">
+  std::deque<SledEntry> Sleds;<br class="gmail_msg">
+  FunctionAddressMap FunctionAddresses;<br class="gmail_msg">
+  FunctionAddressReverseMap FunctionIds;<br class="gmail_msg">
+<br class="gmail_msg">
+public:<br class="gmail_msg">
+  /// Loads the instrumentation map from |Filename|. Updates |EC| in case there<br class="gmail_msg">
+  /// were errors encountered opening the file. |Format| defines what the input<br class="gmail_msg">
+  /// instrumentation map is in.<br class="gmail_msg">
+  InstrumentationMapExtractor(std::string Filename, InputFormats Format,<br class="gmail_msg">
+                              Error &EC);<br class="gmail_msg">
+<br class="gmail_msg">
+  const FunctionAddressMap &getFunctionAddresses() { return FunctionAddresses; }<br class="gmail_msg">
+<br class="gmail_msg">
+  /// Exports the loaded function address map as YAML through |OS|.<br class="gmail_msg">
+  void exportAsYAML(raw_ostream &OS);<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace xray<br class="gmail_msg">
+} // namespace llvm<br class="gmail_msg">
+<br class="gmail_msg">
+#endif // LLVM_TOOLS_XRAY_EXTRACT_H<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/xray-registry.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-registry.cc?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-registry.cc?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/xray-registry.cc (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/xray-registry.cc Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,41 @@<br class="gmail_msg">
+//===- xray-registry.cc - Implement a command registry. -------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+//                     The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// Implement a simple subcommand registry.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+#include "xray-registry.h"<br class="gmail_msg">
+<br class="gmail_msg">
+#include "llvm/Support/ManagedStatic.h"<br class="gmail_msg">
+#include <unordered_map><br class="gmail_msg">
+<br class="gmail_msg">
+namespace llvm {<br class="gmail_msg">
+namespace xray {<br class="gmail_msg">
+<br class="gmail_msg">
+using HandlerType = std::function<Error()>;<br class="gmail_msg">
+<br class="gmail_msg">
+ManagedStatic<std::unordered_map<cl::SubCommand *, HandlerType>> Commands;<br class="gmail_msg">
+<br class="gmail_msg">
+CommandRegistration::CommandRegistration(cl::SubCommand *SC,<br class="gmail_msg">
+                                         HandlerType Command) {<br class="gmail_msg">
+  assert(Commands->count(SC) == 0 &&<br class="gmail_msg">
+         "Attempting to overwrite a command handler");<br class="gmail_msg">
+  assert(Command && "Attempting to register an empty std::function<Error()>");<br class="gmail_msg">
+  (*Commands)[SC] = Command;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+HandlerType dispatch(cl::SubCommand *SC) {<br class="gmail_msg">
+  auto It = Commands->find(SC);<br class="gmail_msg">
+  assert(It != Commands->end() &&<br class="gmail_msg">
+         "Attempting to dispatch on un-registered SubCommand.");<br class="gmail_msg">
+  return It->second;<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace xray<br class="gmail_msg">
+} // namespace llvm<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/xray-registry.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-registry.h?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-registry.h?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/xray-registry.h (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/xray-registry.h Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,41 @@<br class="gmail_msg">
+//===- xray-registry.h - Define registry mechanism for commands. ----------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+//                     The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// Implement a simple subcommand registry.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+#ifndef TOOLS_LLVM_XRAY_XRAY_REGISTRY_H<br class="gmail_msg">
+#define TOOLS_LLVM_XRAY_XRAY_REGISTRY_H<br class="gmail_msg">
+<br class="gmail_msg">
+#include "llvm/Support/CommandLine.h"<br class="gmail_msg">
+#include "llvm/Support/Error.h"<br class="gmail_msg">
+<br class="gmail_msg">
+namespace llvm {<br class="gmail_msg">
+namespace xray {<br class="gmail_msg">
+<br class="gmail_msg">
+// Use |CommandRegistration| as a global initialiser that registers a function<br class="gmail_msg">
+// and associates it with |SC|. This requires that a command has not been<br class="gmail_msg">
+// registered to a given |SC|.<br class="gmail_msg">
+//<br class="gmail_msg">
+// Usage:<br class="gmail_msg">
+//<br class="gmail_msg">
+//   // At namespace scope.<br class="gmail_msg">
+//   static CommandRegistration Unused(&MySubCommand, [] { ... });<br class="gmail_msg">
+//<br class="gmail_msg">
+struct CommandRegistration {<br class="gmail_msg">
+  CommandRegistration(cl::SubCommand *SC, std::function<Error()> Command);<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+// Requires that |SC| is not null and has an associated function to it.<br class="gmail_msg">
+std::function<Error()> dispatch(cl::SubCommand *SC);<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace xray<br class="gmail_msg">
+} // namespace llvm<br class="gmail_msg">
+<br class="gmail_msg">
+#endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/tools/llvm-xray/xray-sleds.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-sleds.h?rev=285165&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-sleds.h?rev=285165&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/llvm-xray/xray-sleds.h (added)<br class="gmail_msg">
+++ llvm/trunk/tools/llvm-xray/xray-sleds.h Tue Oct 25 23:14:34 2016<br class="gmail_msg">
@@ -0,0 +1,32 @@<br class="gmail_msg">
+//===- xray-sleds.h - XRay Sleds Data Structure ---------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+//                     The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// Defines the structure used to represent XRay instrumentation map entries.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+<br class="gmail_msg">
+#ifndef LLVM_TOOLS_LLVM_XRAY_XRAY_SLEDS_H<br class="gmail_msg">
+#define LLVM_TOOLS_LLVM_XRAY_XRAY_SLEDS_H<br class="gmail_msg">
+<br class="gmail_msg">
+namespace llvm {<br class="gmail_msg">
+namespace xray {<br class="gmail_msg">
+<br class="gmail_msg">
+struct SledEntry {<br class="gmail_msg">
+  enum class FunctionKinds { ENTRY, EXIT, TAIL };<br class="gmail_msg">
+<br class="gmail_msg">
+  uint64_t Address;<br class="gmail_msg">
+  uint64_t Function;<br class="gmail_msg">
+  FunctionKinds Kind;<br class="gmail_msg">
+  bool AlwaysInstrument;<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace xray<br class="gmail_msg">
+} // namespace llvm<br class="gmail_msg">
+<br class="gmail_msg">
+#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_SLEDS_H<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>
</blockquote></div>