-
Notifications
You must be signed in to change notification settings - Fork 171
Add llvm-profdata action, support env #666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keith
wants to merge
1
commit into
bazelbuild:main
Choose a base branch
from
keith:ks/add-llvm-profdata-action-support-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| load(":cc_binary_configured_target_tests.bzl", "cc_binary_configured_target_tests") | ||
| load(":cc_common_test.bzl", "cc_common_tests") | ||
| load(":cc_fdo_env_test.bzl", "cc_fdo_env_tests") | ||
|
|
||
| cc_binary_configured_target_tests(name = "cc_binary_configured_target_tests") | ||
|
|
||
| cc_common_tests(name = "cc_common_tests") | ||
|
|
||
| cc_fdo_env_tests(name = "cc_fdo_env_tests") |
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,119 @@ | ||
| """Tests for FDO action environment variables.""" | ||
|
|
||
| load("@bazel_features//private:util.bzl", _bazel_version_ge = "ge") | ||
| load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") | ||
| load("@rules_testing//lib:util.bzl", "TestingAspectInfo") | ||
| load("//cc:action_names.bzl", "ACTION_NAMES") | ||
| load("//cc/toolchains:fdo_profile.bzl", "fdo_profile") | ||
| load("//tests/cc/testutil/toolchains:features.bzl", "FEATURE_NAMES") | ||
|
|
||
| def _test_fdo_profdata_env(name, **kwargs): | ||
| native.genrule( | ||
| name = name + "_profraw", | ||
| outs = [name + "/profile.profraw"], | ||
| cmd = "touch $@", | ||
| ) | ||
|
|
||
| fdo_profile( | ||
| name = name + "_profile", | ||
| profile = name + "_profraw", | ||
| ) | ||
|
|
||
| analysis_test( | ||
| name = name, | ||
| impl = _test_fdo_profdata_env_impl, | ||
| target = "//tests/cc/testutil/toolchains:cc-compiler-k8-compiler", | ||
| config_settings = _fdo_config_settings(name), | ||
| **kwargs | ||
| ) | ||
|
|
||
| def _fdo_config_settings(name): | ||
| return { | ||
| str(Label("//tests/cc/testutil/toolchains:with_features")): [ | ||
| FEATURE_NAMES.fdo_optimize, | ||
| FEATURE_NAMES.llvm_profdata_env, | ||
| ], | ||
| str(Label("//tests/cc/testutil/toolchains:with_action_configs")): [ | ||
| ACTION_NAMES.llvm_profdata, | ||
| ], | ||
| "//command_line_option:fdo_optimize": "//tests/cc/common:" + name + "_profile", | ||
| "//command_line_option:compilation_mode": "opt", | ||
| } | ||
|
|
||
| def _assert_profdata_env(env, target, expected_mnemonics): | ||
| profdata_actions = [] | ||
| seen_mnemonics = {} | ||
| for action in target[TestingAspectInfo].actions: | ||
| if action.mnemonic in expected_mnemonics: | ||
| profdata_actions.append(action) | ||
| seen_mnemonics[action.mnemonic] = True | ||
|
|
||
| env.expect.that_collection(seen_mnemonics.keys()).contains_at_least(expected_mnemonics) | ||
| for action in profdata_actions: | ||
| env.expect.where( | ||
| detail = "mnemonic: %s" % action.mnemonic, | ||
| ).that_dict(action.env).contains_at_least({"LLVM_PROFDATA_ENV_KEY": "LLVM_PROFDATA_ENV_VALUE"}) | ||
|
|
||
| env.expect.where( | ||
| detail = "mnemonic: %s" % action.mnemonic, | ||
| ).that_dict(action.env).keys().contains("PATH") | ||
|
|
||
| def _test_fdo_profdata_env_impl(env, target): | ||
| _assert_profdata_env(env, target, ["LLVMProfDataAction"]) | ||
|
|
||
| def _test_csfdo_profdata_merge_env(name, **kwargs): | ||
| """Tests that LLVMProfDataMergeAction gets env vars from the feature configuration. | ||
|
|
||
| CS-FDO requires both --fdo_optimize and --cs_fdo_profile, triggering a merge action. | ||
| """ | ||
| native.genrule( | ||
| name = name + "_profraw", | ||
| outs = [name + "/profile.profraw"], | ||
| cmd = "touch $@", | ||
| ) | ||
|
|
||
| fdo_profile( | ||
| name = name + "_profile", | ||
| profile = name + "_profraw", | ||
| ) | ||
|
|
||
| config = _fdo_config_settings(name) | ||
| config["//command_line_option:cs_fdo_profile"] = str(Label("//tests/cc/common:cs_fdo_profile")) | ||
| analysis_test( | ||
| name = name, | ||
| impl = _test_csfdo_profdata_merge_env_impl, | ||
| target = "//tests/cc/testutil/toolchains:cc-compiler-k8-compiler", | ||
| config_settings = config, | ||
| **kwargs | ||
| ) | ||
|
|
||
| def _test_csfdo_profdata_merge_env_impl(env, target): | ||
| _assert_profdata_env(env, target, ["LLVMProfDataMergeAction"]) | ||
|
|
||
| def cc_fdo_env_tests(name): | ||
| """Creates tests for FDO actions. | ||
|
|
||
| Args: | ||
| name: The name of the test suite. | ||
| """ | ||
| native.genrule( | ||
| name = "cs_fdo_profraw", | ||
| outs = ["cs_profile.profraw"], | ||
| cmd = "touch $@", | ||
| ) | ||
|
|
||
| fdo_profile( | ||
| name = "cs_fdo_profile", | ||
| profile = ":cs_fdo_profraw", | ||
| ) | ||
|
|
||
| tests = [] | ||
| if _bazel_version_ge("9.0.0"): | ||
| tests = [ | ||
| _test_fdo_profdata_env, | ||
| _test_csfdo_profdata_merge_env, | ||
| ] | ||
| test_suite( | ||
| name = name, | ||
| tests = tests, | ||
| ) |
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.
is there a different API I can use for this without having to force it to be
enabled = True? without this calling these other functions fails ofcThere 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.
updated to automatically request that feature automatically instead