Skip to content

Commit d8b5bde

Browse files
author
Chris Bieneman
committed
[CMake] Support generation of linker order files using dtrace
Summary: This patch extends the lit-based perf-training tooling supplied for PGO data generation to also generate linker order files using dtrace. This patch should work on any system that has dtrace. If CMake can find the dtrace tool it will generate a target 'generate-order-file' which will run the per-training tests wrapped by dtrace to capture function entries. There are several algorithms implemented for sorting the order files which can be experimented with for best performance. The dtrace wrapper also supports bot oneshot and pid probes. The perf-helper.py changes to support order file construction are ported from internal changes by ddunbar; he gets all the credit for the hard work here, I just copy and pasted. Note: I've tested these patches on FreeBSD and OS X 10.10. Reviewers: ddunbar, bogner, silvas Subscribers: llvm-commits, emaste Differential Revision: http://reviews.llvm.org/D16134 llvm-svn: 257934
1 parent 44b3f96 commit d8b5bde

File tree

4 files changed

+408
-22
lines changed

4 files changed

+408
-22
lines changed
Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
if(LLVM_BUILD_INSTRUMENTED)
2-
if (CMAKE_CFG_INTDIR STREQUAL ".")
3-
set(LLVM_BUILD_MODE ".")
4-
else ()
5-
set(LLVM_BUILD_MODE "%(build_mode)s")
6-
endif ()
1+
if (CMAKE_CFG_INTDIR STREQUAL ".")
2+
set(LLVM_BUILD_MODE ".")
3+
else ()
4+
set(LLVM_BUILD_MODE "%(build_mode)s")
5+
endif ()
76

8-
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
7+
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
98

9+
if(LLVM_BUILD_INSTRUMENTED)
1010
configure_lit_site_cfg(
1111
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
12-
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
12+
${CMAKE_CURRENT_BINARY_DIR}/pgo-data/lit.site.cfg
1313
)
1414

1515
add_lit_testsuite(generate-profraw "Generating clang PGO data"
16-
${CMAKE_CURRENT_BINARY_DIR}
16+
${CMAKE_CURRENT_BINARY_DIR}/pgo-data/
1717
DEPENDS clang clear-profraw
1818
)
1919

2020
add_custom_target(clear-profraw
21-
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR}
21+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} profraw
2222
COMMENT "Clearing old profraw data")
2323

2424
if(NOT LLVM_PROFDATA)
@@ -34,3 +34,26 @@ if(LLVM_BUILD_INSTRUMENTED)
3434
COMMENT "Merging profdata"
3535
DEPENDS generate-profraw)
3636
endif()
37+
38+
find_program(DTRACE dtrace)
39+
if(DTRACE)
40+
configure_lit_site_cfg(
41+
${CMAKE_CURRENT_SOURCE_DIR}/order-files.lit.site.cfg.in
42+
${CMAKE_CURRENT_BINARY_DIR}/order-files/lit.site.cfg
43+
)
44+
45+
add_lit_testsuite(generate-dtrace-logs "Generating clang dtrace data"
46+
${CMAKE_CURRENT_BINARY_DIR}/order-files/
47+
DEPENDS clang clear-dtrace-logs
48+
)
49+
50+
add_custom_target(clear-dtrace-logs
51+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} dtrace
52+
COMMENT "Clearing old dtrace data")
53+
54+
55+
add_custom_target(generate-order-file
56+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $<TARGET_FILE:clang> --output ${CMAKE_CURRENT_BINARY_DIR}/clang.order ${CMAKE_CURRENT_BINARY_DIR}
57+
COMMENT "Generating order file"
58+
DEPENDS generate-dtrace-logs)
59+
endif()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- Python -*-
2+
3+
from lit import Test
4+
import lit.formats
5+
import lit.util
6+
import os
7+
8+
def getSysrootFlagsOnDarwin(config, lit_config):
9+
# On Darwin, support relocatable SDKs by providing Clang with a
10+
# default system root path.
11+
if 'darwin' in config.target_triple:
12+
try:
13+
out = lit.util.capture(['xcrun', '--show-sdk-path']).strip()
14+
res = 0
15+
except OSError:
16+
res = -1
17+
if res == 0 and out:
18+
sdk_path = out
19+
lit_config.note('using SDKROOT: %r' % sdk_path)
20+
return '-isysroot %s' % sdk_path
21+
return ''
22+
23+
sysroot_flags = getSysrootFlagsOnDarwin(config, lit_config)
24+
25+
config.clang = os.path.realpath(lit.util.which('clang', config.clang_tools_dir)).replace('\\', '/')
26+
27+
config.name = 'Clang Perf Training'
28+
config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap']
29+
30+
dtrace_wrapper = '%s %s/perf-helper.py dtrace' % (config.python_exe, config.test_source_root)
31+
32+
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
33+
config.test_format = lit.formats.ShTest(use_lit_shell == "0")
34+
config.substitutions.append( ('%clang_cpp', ' %s %s --driver-mode=cpp %s ' % (dtrace_wrapper, config.clang, sysroot_flags)))
35+
config.substitutions.append( ('%clang_cc1', ' %s %s -cc1 %s ' % (dtrace_wrapper, config.clang, sysroot_flags)))
36+
config.substitutions.append( ('%clang', ' %s %s %s ' % (dtrace_wrapper, config.clang, sysroot_flags) ) )
37+
config.substitutions.append( ('%test_root', config.test_exec_root ) )
38+
39+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
3+
## Autogenerated by LLVM/Clang configuration.
4+
# Do not edit!
5+
config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
6+
config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
7+
config.test_source_root = "@CMAKE_CURRENT_SOURCE_DIR@"
8+
config.target_triple = "@TARGET_TRIPLE@"
9+
config.python_exe = "@PYTHON_EXECUTABLE@"
10+
11+
# Support substitution of the tools and libs dirs with user parameters. This is
12+
# used when we can't determine the tool dir at configuration time.
13+
try:
14+
config.clang_tools_dir = config.clang_tools_dir % lit_config.params
15+
except KeyError:
16+
e = sys.exc_info()[1]
17+
key, = e.args
18+
lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
19+
20+
# Let the main config do the real work.
21+
lit_config.load_config(config, "@CLANG_SOURCE_DIR@/utils/perf-training/order-files.lit.cfg")

0 commit comments

Comments
 (0)