Skip to content

Commit

Permalink
Add opt-viewer testing
Browse files Browse the repository at this point in the history
Detects whether we have the Python modules (pygments, yaml) required by
opt-viewer and hooks this up to REQUIRES.

This fixes https://bugs.llvm.org/show_bug.cgi?id=34129 (the lack of opt-viewer
testing).

It's also related to apple/swift#12938 and the idea is
to expose LLVM_HAVE_OPT_VIEWER_MODULES to the Swift cmake.

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

llvm-svn: 319073
  • Loading branch information
anemet committed Nov 27, 2017
1 parent ed7a932 commit cbdd238
Show file tree
Hide file tree
Showing 12 changed files with 1,152 additions and 0 deletions.
31 changes: 31 additions & 0 deletions llvm/cmake/config-ix.cmake
Expand Up @@ -628,3 +628,34 @@ else()
endif()

string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")

function(find_python_module module)
string(TOUPPER ${module} module_upper)
set(FOUND_VAR PY_${module_upper}_FOUND)

execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}"
RESULT_VARIABLE status
ERROR_QUIET)

if(status)
set(${FOUND_VAR} 0 PARENT_SCOPE)
message(STATUS "Could NOT find Python module ${module}")
else()
set(${FOUND_VAR} 1 PARENT_SCOPE)
message(STATUS "Found Python module ${module}")
endif()
endfunction()

set (PYTHON_MODULES
pygments
yaml
)
foreach(module ${PYTHON_MODULES})
find_python_module(${module})
endforeach()

if(PY_PYGMENTS_FOUND AND PY_YAML_FOUND)
set (LLVM_HAVE_OPT_VIEWER_MODULES 1)
else()
set (LLVM_HAVE_OPT_VIEWER_MODULES 0)
endif()
5 changes: 5 additions & 0 deletions llvm/test/lit.cfg.py
Expand Up @@ -123,6 +123,7 @@ def get_asan_rtlib():
ocamlopt_command = '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' % (
config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)

opt_viewer_cmd = '%s %s/tools/opt-viewer/opt-viewer.py' % (sys.executable, config.llvm_src_root)

tools = [
ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),
Expand All @@ -132,6 +133,7 @@ def get_asan_rtlib():
ToolSubst('%ld64', ld64_cmd, unresolved='ignore'),
ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'),
ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'),
ToolSubst('%opt-viewer', opt_viewer_cmd),
]

# FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
Expand Down Expand Up @@ -286,3 +288,6 @@ def have_ld64_plugin_support():

if config.llvm_libxml2_enabled == '1':
config.available_features.add('libxml2')

if config.have_opt_viewer_modules:
config.available_features.add('have_opt_viewer_modules')
1 change: 1 addition & 0 deletions llvm/test/lit.site.cfg.py.in
Expand Up @@ -43,6 +43,7 @@ config.link_llvm_dylib = @LLVM_LINK_LLVM_DYLIB@
config.llvm_libxml2_enabled = "@LLVM_LIBXML2_ENABLED@"
config.llvm_host_triple = '@LLVM_HOST_TRIPLE@'
config.host_arch = "@HOST_ARCH@"
config.have_opt_viewer_modules = @LLVM_HAVE_OPT_VIEWER_MODULES@

# Support substitution of the tools_dir with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/tools/opt-viewer/Inputs/basic/or.c
@@ -0,0 +1,21 @@
void bar();
void foo() { bar(); }

#include "or.h"

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();
}
16 changes: 16 additions & 0 deletions llvm/test/tools/opt-viewer/Inputs/basic/or.h
@@ -0,0 +1,16 @@
void TestH(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();
}
227 changes: 227 additions & 0 deletions llvm/test/tools/opt-viewer/Inputs/basic/or.yaml
@@ -0,0 +1,227 @@
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: basic/or.c, Line: 2, Column: 14 }
Function: foo
Args:
- Callee: bar
- String: ' will not be inlined into '
- Caller: foo
- String: ' because its definition is unavailable'
...
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: basic/or.h, Line: 15, Column: 10 }
Function: TestH
Args:
- Callee: bar
- String: ' will not be inlined into '
- Caller: TestH
- String: ' because its definition is unavailable'
...
--- !Analysis
Pass: inline
Name: CanBeInlined
DebugLoc: { File: basic/or.h, Line: 13, Column: 3 }
Function: TestH
Args:
- Callee: foo
- String: ' can be inlined into '
- Caller: TestH
- String: ' with cost='
- Cost: '30'
- String: ' (threshold='
- Threshold: '412'
- String: ')'
...
--- !Passed
Pass: inline
Name: Inlined
DebugLoc: { File: basic/or.h, Line: 13, Column: 3 }
Function: TestH
Args:
- Callee: foo
- String: ' inlined into '
- Caller: TestH
...
--- !Analysis
Pass: inline
Name: CanBeInlined
DebugLoc: { File: basic/or.h, Line: 15, Column: 3 }
Function: TestH
Args:
- Callee: foo
- String: ' can be inlined into '
- Caller: TestH
- String: ' with cost='
- Cost: '30'
- String: ' (threshold='
- Threshold: '412'
- String: ')'
...
--- !Passed
Pass: inline
Name: Inlined
DebugLoc: { File: basic/or.h, Line: 15, Column: 3 }
Function: TestH
Args:
- Callee: foo
- String: ' inlined into '
- Caller: TestH
...
--- !Analysis
Pass: inline
Name: CanBeInlined
DebugLoc: { File: basic/or.h, Line: 15, Column: 17 }
Function: TestH
Args:
- Callee: foo
- String: ' can be inlined into '
- Caller: TestH
- String: ' with cost='
- Cost: '30'
- String: ' (threshold='
- Threshold: '412'
- String: ')'
...
--- !Passed
Pass: inline
Name: Inlined
DebugLoc: { File: basic/or.h, Line: 15, Column: 17 }
Function: TestH
Args:
- Callee: foo
- String: ' inlined into '
- Caller: TestH
...
--- !Passed
Pass: loop-unroll
Name: FullyUnrolled
DebugLoc: { File: basic/or.h, Line: 9, Column: 3 }
Function: TestH
Args:
- String: 'completely unrolled loop with '
- UnrollCount: '16'
- String: ' iterations'
...
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: basic/or.c, Line: 20, Column: 10 }
Function: Test
Args:
- Callee: bar
- String: ' will not be inlined into '
- Caller: Test
- String: ' because its definition is unavailable'
...
--- !Analysis
Pass: inline
Name: CanBeInlined
DebugLoc: { File: basic/or.c, Line: 18, Column: 3 }
Function: Test
Args:
- Callee: foo
- String: ' can be inlined into '
- Caller: Test
- String: ' with cost='
- Cost: '30'
- String: ' (threshold='
- Threshold: '412'
- String: ')'
...
--- !Passed
Pass: inline
Name: Inlined
DebugLoc: { File: basic/or.c, Line: 18, Column: 3 }
Function: Test
Args:
- Callee: foo
- String: ' inlined into '
- Caller: Test
...
--- !Analysis
Pass: inline
Name: CanBeInlined
DebugLoc: { File: basic/or.c, Line: 20, Column: 3 }
Function: Test
Args:
- Callee: foo
- String: ' can be inlined into '
- Caller: Test
- String: ' with cost='
- Cost: '30'
- String: ' (threshold='
- Threshold: '412'
- String: ')'
...
--- !Passed
Pass: inline
Name: Inlined
DebugLoc: { File: basic/or.c, Line: 20, Column: 3 }
Function: Test
Args:
- Callee: foo
- String: ' inlined into '
- Caller: Test
...
--- !Analysis
Pass: inline
Name: CanBeInlined
DebugLoc: { File: basic/or.c, Line: 20, Column: 17 }
Function: Test
Args:
- Callee: foo
- String: ' can be inlined into '
- Caller: Test
- String: ' with cost='
- Cost: '30'
- String: ' (threshold='
- Threshold: '412'
- String: ')'
...
--- !Passed
Pass: inline
Name: Inlined
DebugLoc: { File: basic/or.c, Line: 20, Column: 17 }
Function: Test
Args:
- Callee: foo
- String: ' inlined into '
- Caller: Test
...
--- !Passed
Pass: loop-unroll
Name: FullyUnrolled
DebugLoc: { File: basic/or.c, Line: 14, Column: 3 }
Function: Test
Args:
- String: 'completely unrolled loop with '
- UnrollCount: '16'
- String: ' iterations'
...
--- !Passed
Pass: loop-vectorize
Name: Vectorized
DebugLoc: { File: basic/or.h, Line: 5, Column: 3 }
Function: TestH
Args:
- String: 'vectorized loop (vectorization width: '
- VectorizationFactor: '4'
- String: ', interleaved count: '
- InterleaveCount: '2'
- String: ')'
...
--- !Passed
Pass: loop-vectorize
Name: Vectorized
DebugLoc: { File: basic/or.c, Line: 10, Column: 3 }
Function: Test
Args:
- String: 'vectorized loop (vectorization width: '
- VectorizationFactor: '4'
- String: ', interleaved count: '
- InterleaveCount: '2'
- String: ')'
...

0 comments on commit cbdd238

Please sign in to comment.