This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Enable PGO for release/1.1.0 on Windows x64 #7805
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/python | ||
|
||
import argparse | ||
import json | ||
import sys | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description="""Extracts information from a json file by navigating the JSON object using a | ||
sequence of property accessors and returning the JSON subtree, or the raw data, found | ||
at that location.""" | ||
) | ||
|
||
parser.add_argument( | ||
'-f', '--file', | ||
metavar='<project.json>', | ||
help="Path to project.json file to parse", | ||
required=True, | ||
) | ||
|
||
parser.add_argument( | ||
'property', | ||
metavar='property_name', | ||
help="""Name of property to extract using object notation. | ||
Pass multiple values to drill down into nested objects (in order).""", | ||
nargs='*', | ||
) | ||
|
||
parser.add_argument( | ||
'-r', '--raw', | ||
help="""Dumps the raw object found at the requested location. | ||
If omitted, returns a JSON formatted object instead.""", | ||
action='store_true', | ||
default=False | ||
) | ||
|
||
return parser.parse_args() | ||
|
||
def main(): | ||
args = parse_args() | ||
|
||
with open(args.file) as json_file: | ||
selected_property = json.load(json_file) | ||
|
||
for prop in args.property: | ||
selected_property = selected_property[prop] | ||
|
||
if args.raw: | ||
print(selected_property) | ||
else: | ||
print(json.dumps(selected_property)) | ||
|
||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
function(clr_pgo_unknown_arch) | ||
if (WIN32) | ||
message(FATAL_ERROR "Only AMD64, ARM and I386 are supported for PGO") | ||
else() | ||
message(FATAL_ERROR "PGO not currently supported on the current platform") | ||
endif() | ||
endfunction(clr_pgo_unknown_arch) | ||
|
||
# Adds Profile Guided Optimization (PGO) flags to the current target | ||
function(add_pgo TargetName) | ||
if(WIN32) | ||
set(ProfileFileName "${TargetName}.pgd") | ||
endif(WIN32) | ||
|
||
file(TO_NATIVE_PATH | ||
"${CLR_CMAKE_PACKAGES_DIR}/${CLR_CMAKE_OPTDATA_PACKAGEWITHRID}/${CLR_CMAKE_OPTDATA_VERSION}/data/${ProfileFileName}" | ||
ProfilePath | ||
) | ||
|
||
# Enable PGO only for optimized configs | ||
set(ConfigTypeList RELEASE RELWITHDEBINFO) | ||
|
||
foreach(ConfigType IN LISTS ConfigTypeList) | ||
set(LinkFlagsProperty "LINK_FLAGS_${ConfigType}") | ||
if(CLR_CMAKE_PGO_INSTRUMENT) | ||
if(WIN32) | ||
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY ${LinkFlagsProperty} "/LTCG /GENPROFILE") | ||
endif(WIN32) | ||
else(CLR_CMAKE_PGO_INSTRUMENT) | ||
# If we don't have profile data availble, gracefully fall back to a non-PGO opt build | ||
if(EXISTS ${ProfilePath}) | ||
if(WIN32) | ||
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY ${LinkFlagsProperty} "/LTCG /USEPROFILE:PGD=${ProfilePath}") | ||
endif(WIN32) | ||
endif(EXISTS ${ProfilePath}) | ||
endif(CLR_CMAKE_PGO_INSTRUMENT) | ||
endforeach(ConfigType) | ||
endfunction(add_pgo) | ||
|
||
set(CLR_CMAKE_OPTDATA_PACKAGEID "optimization.PGO.CoreCLR") | ||
set(CLR_CMAKE_OPTDATA_PACKAGEWITHRID "optimization.${CLR_CMAKE_TARGET_OS}-${CLR_CMAKE_TARGET_ARCH}.PGO.CoreCLR") | ||
|
||
# Parse optdata package version from project.json | ||
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}/extract-from-json.py" ExtractFromJsonScript) | ||
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}/src/.nuget/optdata/project.json" OptDataProjectJsonPath) | ||
execute_process( | ||
COMMAND python "${ExtractFromJsonScript}" -rf "${OptDataProjectJsonPath}" dependencies "${CLR_CMAKE_OPTDATA_PACKAGEID}" | ||
OUTPUT_VARIABLE CLR_CMAKE_OPTDATA_VERSION | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
if(WIN32) | ||
if(CLR_CMAKE_PGO_INSTRUMENT) | ||
# Instrumented PGO binaries on Windows introduce an additional runtime dependency, pgort<ver>.dll. | ||
# Make sure we copy it next to the installed product to make it easier to redistribute the package. | ||
|
||
string(SUBSTRING ${CMAKE_VS_PLATFORM_TOOLSET} 1 -1 VS_PLATFORM_VERSION_NUMBER) | ||
set(PGORT_FILENAME "pgort${VS_PLATFORM_VERSION_NUMBER}.dll") | ||
|
||
get_filename_component(PATH_CXX_ROOTDIR ${CMAKE_CXX_COMPILER} DIRECTORY) | ||
|
||
if(CLR_CMAKE_PLATFORM_ARCH_I386) | ||
set(PATH_VS_PGORT_DLL "${PATH_CXX_ROOTDIR}/${PGORT_FILENAME}") | ||
elseif(CLR_CMAKE_PLATFORM_ARCH_AMD64) | ||
set(PATH_VS_PGORT_DLL "${PATH_CXX_ROOTDIR}/../amd64/${PGORT_FILENAME}") | ||
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM) | ||
set(PATH_VS_PGORT_DLL "${PATH_CXX_ROOTDIR}/../arm/${PGORT_FILENAME}") | ||
else() | ||
clr_pgo_unknown_arch() | ||
endif() | ||
|
||
if (EXISTS ${PATH_VS_PGORT_DLL}) | ||
message(STATUS "Found PGO runtime: ${PATH_VS_PGORT_DLL}") | ||
install(PROGRAMS ${PATH_VS_PGORT_DLL} DESTINATION .) | ||
else() | ||
message(FATAL_ERROR "file not found: ${PATH_VS_PGORT_DLL}") | ||
endif() | ||
|
||
endif(CLR_CMAKE_PGO_INSTRUMENT) | ||
endif(WIN32) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"dependencies": { | ||
"optimization.PGO.CoreCLR": "1.1.0-release-20161025" | ||
}, | ||
"frameworks": { | ||
"netstandard": {} | ||
}, | ||
"runtimes": { | ||
"win7-x64": {} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have no effect on single config generators like Unix make generator. In that case, there is just single LINK_FLAGS property, not LINK_FLAGS_xxx per each config.
So for Unix, you'll need to use if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO) and add to LINK_FLAGS if it is true.
So I would just put the whole body of the add_pgo under if(WIN32) for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, @janvorli. Unfortunate behavior, but I agree with the conclusion. Fixed here, and we'll make the change in master in a subsequent PR.