1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
llvm-mirror/tools
Hal Finkel e0e1eceb55 Add an llvm-opt-report tool to generate basic source-annotated optimization summaries
LLVM now has the ability to record information from optimization remarks in a
machine-consumable YAML file for later analysis. This can be enabled in opt
(see r282539), and D25225 adds a Clang flag to do the same. This patch adds
llvm-opt-report, a tool to generate basic optimization "listing" files
(annotated sources with information about what optimizations were performed)
from one of these YAML inputs.

D19678 proposed to add this capability directly to Clang, but this more-general
YAML-based infrastructure was the direction we decided upon in that review
thread.

For this optimization report, I focused on making the output as succinct as
possible while providing information on inlining and loop transformations. The
goal here is that the source code should still be easily readable in the
report. My primary inspiration here is the reports generated by Cray's tools
(http://docs.cray.com/books/S-2496-4101/html-S-2496-4101/z1112823641oswald.html).
These reports are highly regarded within the HPC community. Intel's compiler,
for example, also has an optimization-report capability
(https://software.intel.com/sites/default/files/managed/55/b1/new-compiler-optimization-reports.pdf).

  $ cat /tmp/v.c
  void bar();
  void foo() { bar(); }

  void Test(int *res, int *c, int *d, int *p, int n) {
    int i;

  #pragma clang loop vectorize(assume_safety)
    for (i = 0; i < 1600; i++) {
      res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
    }

    for (i = 0; i < 16; i++) {
      res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
    }

    foo();

    foo(); bar(); foo();
  }

D25225 adds -fsave-optimization-record (and
-fsave-optimization-record=filename), and this would be used as follows:

  $ clang -O3 -o /tmp/v.o -c /tmp/v.c -fsave-optimization-record
  $ llvm-opt-report /tmp/v.yaml > /tmp/v.lst
  $ cat /tmp/v.lst

  < /tmp/v.c
   2          | void bar();
   3          | void foo() { bar(); }
   4          |
   5          | void Test(int *res, int *c, int *d, int *p, int n) {
   6          |   int i;
   7          |
   8          | #pragma clang loop vectorize(assume_safety)
   9     V4,2 |   for (i = 0; i < 1600; i++) {
  10          |     res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
  11          |   }
  12          |
  13  U16     |   for (i = 0; i < 16; i++) {
  14          |     res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
  15          |   }
  16          |
  17 I        |   foo();
  18          |
  19          |   foo(); bar(); foo();
     I        |   ^
     I        |                 ^
  20          | }

Each source line gets a prefix giving the line number, and a few columns for
important optimizations: inlining, loop unrolling and loop vectorization. An
'I' is printed next to a line where a function was inlined, a 'U' next to an
unrolled loop, and 'V' next to a vectorized loop. These are printed on the
relevant code line when that seems unambiguous, or on subsequent lines when
multiple potential options exist (messages, both positive and negative, from
the same optimization with different column numbers are taken to indicate
potential ambiguity). When on subsequent lines, a '^' is output in the relevant
column.

Annotated source for all relevant input files are put into the listing file
(each starting with '<' and then the file name).

You can disable having the unrolling/vectorization factors appear by using the
-s flag.

Differential Revision: https://reviews.llvm.org/D25262

llvm-svn: 283398
2016-10-05 22:10:35 +00:00
..
bugpoint Retire bugpoint's -R. hack. 2016-10-01 07:34:18 +00:00
bugpoint-passes Remove autoconf support 2016-01-26 21:29:08 +00:00
dsymutil Replace "fallthrough" comments with LLVM_FALLTHROUGH 2016-08-17 05:10:15 +00:00
gold LTO: Simplify caching interface. 2016-09-23 21:33:43 +00:00
llc Revert "Use StringRef instead of raw pointer in TargetRegistry API (NFC)" 2016-10-01 07:08:23 +00:00
lli [ORC] Rename RPCChannel to RPCByteChannel. NFC. 2016-09-11 18:41:05 +00:00
llvm-ar Use the range variant of find_if instead of unpacking begin/end 2016-08-12 00:18:03 +00:00
llvm-as Search for llvm-symbolizer binary in the same directory as argv[0], before 2016-06-09 00:53:21 +00:00
llvm-as-fuzzer Remove every uses of getGlobalContext() in LLVM (but the C API) 2016-04-14 21:59:01 +00:00
llvm-bcanalyzer Rename Error -> ReportError. 2016-10-03 18:17:18 +00:00
llvm-c-test Add support for callsite in the new C API for attributes 2016-06-15 05:14:29 +00:00
llvm-config Replace a few more "fall through" comments with LLVM_FALLTHROUGH 2016-08-17 20:30:52 +00:00
llvm-cov [llvm-cov] Silence a warning from the MSVC runtime (NFC) 2016-09-26 17:57:13 +00:00
llvm-cxxdump [Object] Re-apply r275316 now that I have the corresponding LLD patch ready. 2016-07-14 02:24:01 +00:00
llvm-cxxfilt [llvm-cxxfilt] Use llvm::outs(). Simplify. 2016-09-27 18:50:30 +00:00
llvm-diff [NFC] Header cleanup 2016-04-18 09:17:29 +00:00
llvm-dis IR: Allow metadata attachments on declarations, and fix lazy loaded metadata issue with globals. 2016-06-21 23:42:48 +00:00
llvm-dwarfdump Revert r282238 "Revert r282235 "[llvm-dwarfdump] - Teach dwarfdump to dump gdb-index section."" 2016-09-23 11:01:53 +00:00
llvm-dwp MC] Provide an MCTargetOptions to implementors of MCAsmBackendCtorTy, NFC 2016-07-25 17:18:28 +00:00
llvm-extract Search for llvm-symbolizer binary in the same directory as argv[0], before 2016-06-09 00:53:21 +00:00
llvm-go [llvm-go] parameterize $GOPATH construction 2016-07-27 03:21:51 +00:00
llvm-jitlistener Search for llvm-symbolizer binary in the same directory as argv[0], before 2016-06-09 00:53:21 +00:00
llvm-link Fix auto-upgrade of TBAA tags in Bitcode Reader 2016-09-14 22:29:59 +00:00
llvm-lto [ThinLTO] Add an option to llvm-lto to print some basic statistics for the index 2016-09-14 21:04:59 +00:00
llvm-lto2 LTO: Simplify caching interface. 2016-09-23 21:33:43 +00:00
llvm-mc Fix a typo, depricated -> deprecated 2016-09-27 19:45:30 +00:00
llvm-mc-fuzzer [llvm-mc-fuzzer] Use LLVMFuzzerInitialize() instead of a custom main() and FuzzerDriver() 2016-05-13 10:23:04 +00:00
llvm-mcmarkup Search for llvm-symbolizer binary in the same directory as argv[0], before 2016-06-09 00:53:21 +00:00
llvm-nm Use the range variant of transform instead of unpacking begin/end 2016-08-12 04:32:45 +00:00
llvm-objdump Use StringRef instead of raw pointers in MCAsmInfo/MCInstrInfo APIs (NFC) 2016-10-01 06:46:33 +00:00
llvm-opt-report Add an llvm-opt-report tool to generate basic source-annotated optimization summaries 2016-10-05 22:10:35 +00:00
llvm-pdbdump Do not pass a superblock to PDBFileBuilder. 2016-09-30 20:52:12 +00:00
llvm-profdata [Profile] dump ic value profile value/site-count histogram 2016-09-20 21:04:22 +00:00
llvm-readobj [Stackmap] Added callsite counts to emitted function information. 2016-09-14 20:22:03 +00:00
llvm-rtdyld [ExecutionEngine][MCJIT][Orc] Replace RuntimeDyld::SymbolInfo with JITSymbol. 2016-08-01 20:49:11 +00:00
llvm-shlib Revert "[CMake] LINK_LIBS need to be public for Darwin dylib targets" 2016-05-26 04:35:35 +00:00
llvm-size llvm-size: Add --totals option 2016-09-12 17:08:28 +00:00
llvm-split Remove every uses of getGlobalContext() in LLVM (but the C API) 2016-04-14 21:59:01 +00:00
llvm-stress Use StringRef in CommandLine Options handling (NFC) 2016-10-01 03:43:20 +00:00
llvm-symbolizer Search for llvm-symbolizer binary in the same directory as argv[0], before 2016-06-09 00:53:21 +00:00
lto Use StringRef in LTOModule implementation (NFC) 2016-10-01 01:18:16 +00:00
msbuild MSBuild integration: fix the loop in install.bat 2014-09-30 22:30:06 +00:00
obj2yaml [macho2yaml] String table can contain null strings 2016-08-04 19:19:25 +00:00
opt Use StringRef in Pass/PassManager APIs (NFC) 2016-10-01 02:56:57 +00:00
sancov [sancov] renamed symcov-report-server to coverage-report-server 2016-10-04 19:18:23 +00:00
sanstats [Symbolize] Check if the PE file has a PDB and emit an error if we can't load it 2016-06-03 20:25:09 +00:00
verify-uselistorder Search for llvm-symbolizer binary in the same directory as argv[0], before 2016-06-09 00:53:21 +00:00
xcode-toolchain [CMake] Minor fix to regex in r279152 2016-08-18 21:36:36 +00:00
yaml2obj Misc improvements to StringTableBuilder. 2016-10-04 22:43:25 +00:00
CMakeLists.txt Fixup r271533, or check-clang didn't find llvm-lto as the target. 2016-06-02 20:39:24 +00:00
LLVMBuild.txt llvm-dwp: Initial layout 2015-12-01 00:48:34 +00:00